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

add ora spinner and add a prompt before running postinstall script for an functions:create #82

Merged
merged 1 commit into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"netlify": "2.4.1",
"node-fetch": "^2.3.0",
"opn": "^5.5.0",
"ora": "^3.4.0",
"safe-join": "^0.1.2",
"static-server": "^2.2.1",
"wait-port": "^0.2.2"
Expand Down
43 changes: 33 additions & 10 deletions src/commands/functions/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const http = require("http");
const fetch = require("node-fetch");
const cp = require("child_process");
const { createAddon } = require("netlify/src/addons");
const ora = require("ora");

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

Expand Down Expand Up @@ -346,9 +347,12 @@ async function scaffoldFromTemplate(flags, args, functionsDir) {
fs.unlinkSync(path.join(functionPath, ".netlify-function-template.js"));
// npm install
if (hasPackageJSON) {
this.log(`installing dependencies for ${name}...`);
const spinner = ora({
text: `installing dependencies for ${name}`,
spinner: "moon"
}).start();
await installDeps(functionPath);
this.log(`installing dependencies for ${name} complete `);
spinner.succeed(`installed dependencies for ${name}`);
}

installAddons.call(this, addons, path.resolve(functionPath));
Expand All @@ -367,24 +371,43 @@ async function installAddons(addons = [], fnPath) {
);
return false;
}
console.log("checking Netlify APIs...");

return api.getSite({ siteId }).then(async siteData => {
const accessToken = await this.authenticate();
const arr = addons.map(({ addonName, addonDidInstall }) => {
this.log("installing addon: " + addonName);
console.log("installing addon: " + addonName);
// 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
return createSiteAddon(
accessToken,
addonName,
siteId,
siteData,
this.log
).then(async addonCreateMsg => {
if (addonCreateMsg && addonDidInstall) {
const { addEnvVarsFromAddons } = require("../../utils/dev-exec");
await addEnvVarsFromAddons(site, accessToken);
addonDidInstall(fnPath);
}
});
)
.then(async addonCreateMsg => {
if (addonCreateMsg) {
// spinner.success("installed addon: " + addonName);
if (addonDidInstall) {
const {
addEnvVarsFromAddons
} = require("../../utils/dev-exec");
await addEnvVarsFromAddons(site, accessToken);
const { confirmPostInstall } = await inquirer.prompt([
{
type: "confirm",
name: "confirmPostInstall",
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?`,
default: false
}
]);
if (confirmPostInstall) addonDidInstall(fnPath);
}
}
})
.catch(err => {
console.error("Error installing addon: ", err);
});
});
return Promise.all(arr);
});
Expand Down