Skip to content
This repository was archived by the owner on Sep 12, 2019. It is now read-only.

Commit 82a34f1

Browse files
authored
Merge pull request #82 from netlify/askBeforeInstall
add ora spinner and add a prompt before running postinstall script for an functions:create
2 parents abac9f9 + d472717 commit 82a34f1

File tree

3 files changed

+96
-10
lines changed

3 files changed

+96
-10
lines changed

package-lock.json

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"netlify": "2.4.1",
2525
"node-fetch": "^2.3.0",
2626
"opn": "^5.5.0",
27+
"ora": "^3.4.0",
2728
"safe-join": "^0.1.2",
2829
"static-server": "^2.2.1",
2930
"wait-port": "^0.2.2"

src/commands/functions/create.js

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const http = require("http");
1010
const fetch = require("node-fetch");
1111
const cp = require("child_process");
1212
const { createAddon } = require("netlify/src/addons");
13+
const ora = require("ora");
1314

1415
const templatesDir = path.resolve(__dirname, "../../functions-templates");
1516

@@ -346,9 +347,12 @@ async function scaffoldFromTemplate(flags, args, functionsDir) {
346347
fs.unlinkSync(path.join(functionPath, ".netlify-function-template.js"));
347348
// npm install
348349
if (hasPackageJSON) {
349-
this.log(`installing dependencies for ${name}...`);
350+
const spinner = ora({
351+
text: `installing dependencies for ${name}`,
352+
spinner: "moon"
353+
}).start();
350354
await installDeps(functionPath);
351-
this.log(`installing dependencies for ${name} complete `);
355+
spinner.succeed(`installed dependencies for ${name}`);
352356
}
353357

354358
installAddons.call(this, addons, path.resolve(functionPath));
@@ -367,24 +371,43 @@ async function installAddons(addons = [], fnPath) {
367371
);
368372
return false;
369373
}
374+
console.log("checking Netlify APIs...");
375+
370376
return api.getSite({ siteId }).then(async siteData => {
371377
const accessToken = await this.authenticate();
372378
const arr = addons.map(({ addonName, addonDidInstall }) => {
373-
this.log("installing addon: " + addonName);
379+
console.log("installing addon: " + addonName);
374380
// will prompt for configs if not supplied - we do not yet allow for addon configs supplied by `netlify functions:create` command and may never do so
375381
return createSiteAddon(
376382
accessToken,
377383
addonName,
378384
siteId,
379385
siteData,
380386
this.log
381-
).then(async addonCreateMsg => {
382-
if (addonCreateMsg && addonDidInstall) {
383-
const { addEnvVarsFromAddons } = require("../../utils/dev-exec");
384-
await addEnvVarsFromAddons(site, accessToken);
385-
addonDidInstall(fnPath);
386-
}
387-
});
387+
)
388+
.then(async addonCreateMsg => {
389+
if (addonCreateMsg) {
390+
// spinner.success("installed addon: " + addonName);
391+
if (addonDidInstall) {
392+
const {
393+
addEnvVarsFromAddons
394+
} = require("../../utils/dev-exec");
395+
await addEnvVarsFromAddons(site, accessToken);
396+
const { confirmPostInstall } = await inquirer.prompt([
397+
{
398+
type: "confirm",
399+
name: "confirmPostInstall",
400+
message: `This template has an optional setup script that runs after addon install. This can be helpful for first time users to try out templates. Run the script?`,
401+
default: false
402+
}
403+
]);
404+
if (confirmPostInstall) addonDidInstall(fnPath);
405+
}
406+
}
407+
})
408+
.catch(err => {
409+
console.error("Error installing addon: ", err);
410+
});
388411
});
389412
return Promise.all(arr);
390413
});

0 commit comments

Comments
 (0)