Skip to content

Commit

Permalink
feat: add option to install nodes modules
Browse files Browse the repository at this point in the history
  • Loading branch information
kikoane committed Dec 6, 2019
1 parent 2749606 commit 3881324
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
28 changes: 25 additions & 3 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const Spinner = require("@slimio/async-cli-spinner");
const { gray, yellow, cyan, green, white, underline, red } = require("kleur");
const { downloadNodeFile, extract, constants: { File } } = require("@slimio/nodejs-downloader");
const { validate, CONSTANTS } = require("@slimio/validate-addon-name");
const ms = require("ms");

// Require Internal Dependencies
const DEFAULT_PKG = require("../template/package.json");
Expand Down Expand Up @@ -108,7 +109,18 @@ async function getQueriesResponse() {
if (row.type === "interactive") {
row.symbol = "->";
}
const ret = await qoa.prompt([row]);
let ret = await qoa.prompt([row]);

while (row.handle === 'projectname') {
ret.projectname = filterPackageName(ret.projectname);
if (ret.projectname.length <= 1 || ret.projectname.length > 214) {
console.log(red().bold("The project name must be of length 2<>214"));
ret = await qoa.prompt([row]);
}
else
break;
}

if (row.handle === "testfw" && ret.testfw === "jest") {
skipNext = true;
response.covpackage = null;
Expand Down Expand Up @@ -138,18 +150,29 @@ async function main() {

// Prompt all questions
const response = await getQueriesResponse();
const projectName = response.projectname;

/*
const projectName = filterPackageName(response.projectname);
if (projectName.length <= 1 || projectName.length > 214) {
console.log(red().bold("The project name must be of length 2<>214"));
process.exit(0);
}
*/

// Check the addon package name
if (response.type === "Addon" && !validate(projectName)) {
console.log(red().bold(`The addon name not matching expected regex ${CONSTANTS.VALIDATE_REGEX}`));
process.exit(0);
}

// Check if the developer want to install nodes modules
console.log (response);
if (response.modules === false) {
console.log("Nodes modules are required to run the project.");
process.exit(0);
}

console.log(gray().bold(`\n > Start configuring project ${cyan().bold(projectName)}\n`));

// Create initial package.json && write default projects files
Expand Down Expand Up @@ -338,8 +361,7 @@ async function main() {
child.once("close", resolve);
child.once("error", reject);
});

const executeTimeMs = green().bold(`${((performance.now() - start) / 1000).toFixed(2)}ms`);
const executeTimeMs = green().bold(`${(ms(performance.now() - start))}`);
spinner.succeed(white().bold(`Packages installed in ${executeTimeMs}`));
}
catch (err) {
Expand Down
7 changes: 3 additions & 4 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 @@ -28,6 +28,7 @@
"@slimio/validate-addon-name": "^1.2.0",
"cross-spawn": "^7.0.1",
"kleur": "^3.0.3",
"ms": "^2.1.2",
"qoa": "^0.2.0"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions src/questions.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,11 @@
"description": "Most of the time it's only required for CLI projects. Say 'no' if you dont know why you need this.",
"type": "confirm",
"handle": "binary"
},
{
"query": "Do you want to install nodes modules ?",
"description": "Nodes modules are required for use the project",
"type": "confirm",
"handle": "modules"
}
]

0 comments on commit 3881324

Please sign in to comment.