create-clean-node 1.0.8 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,4 +1,22 @@
1
1
  #!/usr/bin/env node
2
+ const yargs = require('yargs/yargs')
3
+ const { hideBin } = require('yargs/helpers')
4
+ // const argv = yargs(hideBin(process.argv)).argv
5
+
6
+
7
+ // If just one argument is passed, it will be the project name
8
+ var argv = require('yargs/yargs')(process.argv.slice(2))
9
+ .usage('Usage: $0 [options]')
10
+ .alias('p', 'projectName')
11
+ .describe('p', 'Name of the project')
12
+ .choices('projectType', ['Express.js', 'Node.js'])
13
+ .alias('t', 'projectType')
14
+ .describe('t', 'Type of the project')
15
+ .help('help')
16
+ .parse()
17
+ if (argv._.length === 1 && !argv.projectName) {
18
+ argv.projectName = argv._[0];
19
+ }
2
20
 
3
21
  const spawn = require('cross-spawn');
4
22
  const fs = require('fs');
@@ -41,43 +59,48 @@ async function createExpressProject(projectName) {
41
59
  async function createNodeProject(projectName) {
42
60
  const inquirer = (await import("inquirer")).default;
43
61
  let template = "template_node";
62
+ await createProject(template, projectName);
63
+ }
44
64
 
45
- const { installReadlineSync } = await inquirer.prompt(
65
+ async function promptProjectName() {
66
+ const inquirer = (await import("inquirer")).default;
67
+ if (argv.projectName) return { projectName: argv.projectName };
68
+ return await inquirer.prompt(
46
69
  {
47
- type: 'confirm',
48
- name: 'installReadlineSync',
49
- message: 'Do you want to install the readline-sync library?',
50
- default: false // Default no installation
51
- }
52
- );
53
-
54
- if (installReadlineSync) {
55
- template = "template_node_readline";
56
- }
57
- await createProject(template, projectName);
70
+ type: 'input',
71
+ name: 'projectName',
72
+ message: 'What is the name of your project?',
73
+ validate: function (input) {
74
+ if (/^[\w-]+$/.test(input)) return true;
75
+ return 'Project name can only include letters, numbers, underscores, and hyphens.';
76
+ }
77
+ });
58
78
  }
59
79
 
60
- async function setupProject() {
80
+ async function promptProjectType() {
61
81
  const inquirer = (await import("inquirer")).default;
62
- try {
63
- let result = await inquirer.prompt({
82
+ let choices = ['Express.js', 'Node.js'];
83
+ if (argv.projectType) {
84
+ if (choices.includes(argv.projectType)) {
85
+ return { projectType: argv.projectType };
86
+ } else {
87
+ console.error('Invalid project type. Please choose from Express.js or Node.js.');
88
+ process.exit(1);
89
+ }
90
+ }
91
+ return await inquirer.prompt(
92
+ {
64
93
  type: 'list',
65
94
  name: 'projectType',
66
95
  message: 'What type of project would you like to create?',
67
- choices: ['Node.js', 'Express.js'],
68
- default: 'Simple Node.js',
96
+ choices: choices
69
97
  });
98
+ }
70
99
 
71
- let projectName = await inquirer.prompt(
72
- {
73
- type: 'input',
74
- name: 'projectName',
75
- message: 'What is the name of your project?',
76
- validate: function (input) {
77
- if (/^[\w-]+$/.test(input)) return true;
78
- return 'Project name can only include letters, numbers, underscores, and hyphens.';
79
- }
80
- });
100
+ async function setupProject() {
101
+ try {
102
+ let result = await promptProjectType();
103
+ let projectName = await promptProjectName();
81
104
 
82
105
  if (result.projectType === 'Express.js') {
83
106
  await createExpressProject(projectName.projectName);
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "create-clean-node",
3
- "version": "1.0.8",
3
+ "version": "1.1.1",
4
4
  "bin": {
5
5
  "create-my-template": "./index.js"
6
6
  },
7
7
  "dependencies": {
8
8
  "cross-spawn": "^7.0.3",
9
- "inquirer": "^9.2.14"
9
+ "inquirer": "^9.2.14",
10
+ "yargs": "^17.7.2"
10
11
  }
11
12
  }
@@ -10,9 +10,9 @@ app.set("view engine", "ejs");
10
10
  app.use(express.json());
11
11
  app.use(express.urlencoded({ extended: true }));
12
12
  app.use(express.static(path.join(__dirname, "public")));
13
- app.set('views', path.join(__dirname, "views"));
13
+ app.set("views", path.join(__dirname, "views"));
14
14
 
15
- app.set("port", process.env.PORT || 3000);
15
+ app.set("port", process.env.PORT ?? 3000);
16
16
 
17
17
  app.get("/", (req, res) => {
18
18
  res.render("index", {
@@ -22,5 +22,5 @@ app.get("/", (req, res) => {
22
22
  });
23
23
 
24
24
  app.listen(app.get("port"), () => {
25
- console.log("Server started on http://localhost:" + app.get('port'));
25
+ console.log("Server started on http://localhost:" + app.get("port"));
26
26
  });