Reputation: 3762
I would like to create a Node CLI to generate new projects based on Node, Typescript, Jest, Express and TSLint. Basically this CLI should create a new project folder, install all the dependencies and call the dependency --init
commands from npm, tsc and jest. It should make some changes to the config files and create some "hello world dummy files" for that new project.
A good example would be the Vue CLI
So I know how to create a CLI application but when the user calls
myCliTool create usersProjectName
How can I install npm dependencies for him then? Node itself doesn't know npm and I think it would be a bad idea to ship with pregenerated files and copy them into the target folder.
Upvotes: 0
Views: 561
Reputation: 552
You can do that through your script command like in script command you can run npm install for the first time when user want to create project.
Here's an example:
"scripts": {
"start": "if-env NODE_ENV=production && npm run start:prod || npm run start:dev",
"start:dev": "set NODE_ENV=development && nodemon app.js",
"start:prod": "export NODE_ENV=test && npm install && nodemon server/app.js",
"lint": "eslint --ignore-path .gitignore .",
"test": "export NODE_ENV=test && mocha **/*.test.js",
"test-watch": "nodemon --exec 'npm test'"
},
Upvotes: 2