Skip to content

Commit

Permalink
fix: move modules installation question and refactor prompt func
Browse files Browse the repository at this point in the history
  • Loading branch information
kikoane committed Dec 11, 2019
1 parent 0839844 commit 5db4287
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 95 deletions.
54 changes: 23 additions & 31 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const TEMPLATE_DIR = join(ROOT_DIR, "template");
const DEFAULT_FILES_DIR = join(TEMPLATE_DIR, "defaultFiles");
const DEFAULT_FILES_INCLUDE = join(TEMPLATE_DIR, "include");
const DEFAULT_FILES_TEST = join(TEMPLATE_DIR, "test");
const GEN_QUESTIONS = require("../src/questions.json");
const { GEN_QUESTIONS, MODULES_QUESTIONS } = require("../src/questions.json");
const { DEV_DEPENDENCIES, NAPI_DEPENDENCIES } = require("../src/dependencies.json");
const TEST_SCRIPTS = {
ava: "cross-env psp && ava --verbose",
Expand Down Expand Up @@ -109,24 +109,24 @@ async function getQueriesResponse() {
if (row.type === "interactive") {
row.symbol = "->";
}
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;
let ret;

while (true) {
ret = await qoa.prompt([row]);
if (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"));
continue;
}
}
}

if (row.handle === "testfw" && ret.testfw === "jest") {
skipNext = true;
response.covpackage = null;
if (row.handle === "testfw" && ret.testfw === "jest") {
skipNext = true;
response.covpackage = null;
}
break ;
}

Object.assign(response, ret);
console.log(gray().bold("----------------------------"));
}
Expand All @@ -153,26 +153,11 @@ async function main() {
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
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 @@ -353,6 +338,13 @@ async function main() {
await writeFile("index.js", "\"use strict\";\n");
}

// Installation of nodes modules
const { modules } = await qoa.prompt([MODULES_QUESTIONS]);
if (modules === false) {
console.log("Nodes modules aren't installed.");
process.exit(0);
}

const spinner = new Spinner().start(white().bold(`Running '${cyan().bold("npm install")}' on node_modules ...`));
try {
const start = performance.now();
Expand Down
130 changes: 66 additions & 64 deletions src/questions.json
Original file line number Diff line number Diff line change
@@ -1,64 +1,66 @@
[
{
"query": "Name of the project ?",
"type": "input",
"handle": "projectname"
},
{
"query": "A description (optional) ?",
"type": "input",
"handle": "projectdesc"
},
{
"query": "What kind of project is this ? ",
"description": "Documentation on each 'kind' can be found here: https://github.com/SlimIO/Manifest#available-types",
"type": "interactive",
"handle": "type",
"menu": ["Addon", "NAPI", "CLI", "Package", "Service", "Degraded"]
},
{
"query": "Which unit-testing package do you want ?",
"description": "If you do not know what it is, take 'japa'",
"type": "interactive",
"handle": "testfw",
"menu": ["japa", "ava", "jest"]
},
{
"query": "Which package do you want for code coverage ?",
"description": "If you do not know what it is, take 'nyc'",
"type": "interactive",
"handle": "covpackage",
"menu": ["nyc", "c8"]
},
{
"query": "In which version do you want to start : 1.0.0 or 0.1.0 ",
"description": "Choose 0.1.0 if the project is an experimentation (or will not be pushed to production after first draft).",
"type": "interactive",
"handle": "version",
"menu": ["1.0.0", "0.1.0"]
},
{
"query": "Do you want a .env file ?",
"description": ".env file are useful to store credentials (Database, WEB API tokens etc..)",
"type": "confirm",
"handle": "env"
},
{
"query": "Do you want a .npmrc file ?",
"description": ".npmrc file are useful to configure npm (Proxy, Registery etc..)",
"type": "confirm",
"handle": "npmrc"
},
{
"query": "Is this project must have a binary entry ?",
"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"
}
]
{
"GEN_QUESTIONS": [
{
"query": "Name of the project ?",
"type": "input",
"handle": "projectname"
},
{
"query": "A description (optional) ?",
"type": "input",
"handle": "projectdesc"
},
{
"query": "What kind of project is this ? ",
"description": "Documentation on each 'kind' can be found here: https://github.com/SlimIO/Manifest#available-types",
"type": "interactive",
"handle": "type",
"menu": ["Addon", "NAPI", "CLI", "Package", "Service", "Degraded"]
},
{
"query": "Which unit-testing package do you want ?",
"description": "If you do not know what it is, take 'japa'",
"type": "interactive",
"handle": "testfw",
"menu": ["japa", "ava", "jest"]
},
{
"query": "Which package do you want for code coverage ?",
"description": "If you do not know what it is, take 'nyc'",
"type": "interactive",
"handle": "covpackage",
"menu": ["nyc", "c8"]
},
{
"query": "In which version do you want to start : 1.0.0 or 0.1.0 ",
"description": "Choose 0.1.0 if the project is an experimentation (or will not be pushed to production after first draft).",
"type": "interactive",
"handle": "version",
"menu": ["1.0.0", "0.1.0"]
},
{
"query": "Do you want a .env file ?",
"description": ".env file are useful to store credentials (Database, WEB API tokens etc..)",
"type": "confirm",
"handle": "env"
},
{
"query": "Do you want a .npmrc file ?",
"description": ".npmrc file are useful to configure npm (Proxy, Registery etc..)",
"type": "confirm",
"handle": "npmrc"
},
{
"query": "Is this project must have a binary entry ?",
"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"
}
],
"MODULES_QUESTIONS": {
"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 5db4287

Please sign in to comment.