express-sweet-generator 1.0.0 → 1.0.3

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.
Files changed (92) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/README.md +16 -43
  3. package/bin/express-sweet-cli.js +220 -214
  4. package/package.json +1 -1
  5. package/templates/{.env → cjs/.env} +0 -0
  6. package/templates/{app.js → cjs/app.js} +0 -0
  7. package/templates/{bin → cjs/bin}/www.ejs +0 -0
  8. package/templates/{config → cjs/config}/authentication.js +1 -1
  9. package/templates/{config → cjs/config}/config.js +0 -0
  10. package/templates/{config → cjs/config}/database.js +6 -12
  11. package/templates/{config → cjs/config}/view.js +0 -0
  12. package/templates/{ecosystem.config.js.ejs → cjs/ecosystem.config.js.ejs} +5 -1
  13. package/templates/{models → cjs/models}/BookModel.js +0 -0
  14. package/templates/{models → cjs/models}/CommentModel.js +0 -0
  15. package/templates/{models → cjs/models}/ProfileModel.js +0 -0
  16. package/templates/{models → cjs/models}/UserModel.js +0 -0
  17. package/templates/{nginx.sample.conf.ejs → cjs/nginx.sample.conf.ejs} +0 -0
  18. package/templates/{package.json.ejs → cjs/package.json.ejs} +2 -7
  19. package/templates/{views/partials/.gitkeep → cjs/public/assets/home.css} +0 -0
  20. package/templates/cjs/public/assets/home.js +0 -0
  21. package/templates/{public/assets/styles → cjs/public/assets}/login.css +0 -2
  22. package/templates/{public/assets/scripts → cjs/public/assets}/login.js +0 -3
  23. package/templates/{public/assets/images → cjs/public/assets}/logo.svg +0 -0
  24. package/templates/cjs/public/assets/user.css +0 -0
  25. package/templates/{public/assets/scripts → cjs/public/assets}/user.js +0 -3
  26. package/templates/cjs/public/assets/users.css +0 -0
  27. package/templates/{public/assets/scripts → cjs/public/assets}/users.js +11 -9
  28. package/templates/{public → cjs/public}/favicon.ico +0 -0
  29. package/templates/{public → cjs/public}/rekognition-test-image/add-face-to-collection.jpg +0 -0
  30. package/templates/{public → cjs/public}/rekognition-test-image/compare-faces-source.jpg +0 -0
  31. package/templates/{public → cjs/public}/rekognition-test-image/compare-faces-target.jpg +0 -0
  32. package/templates/{public → cjs/public}/rekognition-test-image/detect-faces.jpg +0 -0
  33. package/templates/{routes → cjs/routes}/api/users.js +7 -33
  34. package/templates/{routes → cjs/routes}/home.js +0 -3
  35. package/templates/{routes → cjs/routes}/login.js +0 -3
  36. package/templates/{routes → cjs/routes}/users.js +3 -9
  37. package/templates/{views → cjs/views}/error.hbs +1 -2
  38. package/templates/cjs/views/home.hbs +5 -0
  39. package/templates/{views → cjs/views}/layout/default.hbs +13 -18
  40. package/templates/cjs/views/login.hbs +16 -0
  41. package/templates/cjs/views/partials/.gitkeep +0 -0
  42. package/templates/cjs/views/user.hbs +35 -0
  43. package/templates/cjs/views/users.hbs +18 -0
  44. package/templates/esm/.env +1 -0
  45. package/templates/esm/app.js +10 -0
  46. package/templates/esm/bin/www.ejs +67 -0
  47. package/templates/esm/config/authentication.js +81 -0
  48. package/templates/esm/config/config.js +78 -0
  49. package/templates/esm/config/database.js +35 -0
  50. package/templates/esm/config/view.js +36 -0
  51. package/templates/esm/ecosystem.config.js.ejs +35 -0
  52. package/templates/esm/models/BookModel.js +30 -0
  53. package/templates/esm/models/CommentModel.js +30 -0
  54. package/templates/esm/models/ProfileModel.js +49 -0
  55. package/templates/esm/models/UserModel.js +113 -0
  56. package/templates/esm/nginx.sample.conf.ejs +48 -0
  57. package/templates/esm/package.json.ejs +21 -0
  58. package/templates/esm/public/assets/home.css +0 -0
  59. package/templates/esm/public/assets/home.js +0 -0
  60. package/templates/esm/public/assets/login.css +16 -0
  61. package/templates/esm/public/assets/login.js +29 -0
  62. package/templates/{public/assets/images/logo-dark.svg → esm/public/assets/logo.svg} +2 -2
  63. package/templates/esm/public/assets/user.css +0 -0
  64. package/templates/esm/public/assets/user.js +50 -0
  65. package/templates/esm/public/assets/users.css +0 -0
  66. package/templates/esm/public/assets/users.js +85 -0
  67. package/templates/esm/public/favicon.ico +0 -0
  68. package/templates/esm/public/rekognition-test-image/add-face-to-collection.jpg +0 -0
  69. package/templates/esm/public/rekognition-test-image/compare-faces-source.jpg +0 -0
  70. package/templates/esm/public/rekognition-test-image/compare-faces-target.jpg +0 -0
  71. package/templates/esm/public/rekognition-test-image/detect-faces.jpg +0 -0
  72. package/templates/esm/routes/api/users.js +98 -0
  73. package/templates/esm/routes/home.js +8 -0
  74. package/templates/esm/routes/login.js +8 -0
  75. package/templates/esm/routes/users.js +31 -0
  76. package/templates/esm/views/error.hbs +4 -0
  77. package/templates/esm/views/home.hbs +5 -0
  78. package/templates/esm/views/layout/default.hbs +57 -0
  79. package/templates/esm/views/login.hbs +16 -0
  80. package/templates/esm/views/partials/.gitkeep +0 -0
  81. package/templates/esm/views/user.hbs +35 -0
  82. package/templates/esm/views/users.hbs +18 -0
  83. package/templates/public/assets/scripts/docs.js +0 -1
  84. package/templates/public/assets/scripts/home.js +0 -3
  85. package/templates/public/assets/styles/docs.css +0 -2200
  86. package/templates/public/assets/styles/home.css +0 -1
  87. package/templates/public/assets/styles/user.css +0 -1
  88. package/templates/public/assets/styles/users.css +0 -1
  89. package/templates/views/home.hbs +0 -11
  90. package/templates/views/login.hbs +0 -27
  91. package/templates/views/user.hbs +0 -42
  92. package/templates/views/users.hbs +0 -30
package/CHANGELOG.md CHANGED
@@ -1 +1,31 @@
1
- # Changelog
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ ## [1.0.3] - 2022-05-17
5
+ ### Fixed
6
+ - Fix UX of template views.
7
+
8
+ ## [1.0.2] - 2022-02-13
9
+ ### Fixed
10
+ - Changed the type of 'config/authentication.js#allow_unauthenticated' from'string[]' to'(string|RegExp)[]}'.
11
+
12
+ ## [1.0.1] - 2021-06-10
13
+ ### Fixed
14
+ - Removed packages that don't need to be installed from the template package.json.
15
+ - Added ESM template.
16
+
17
+ Create an EJS template application:
18
+ ```sh
19
+ express-sweet -o esm myapp;
20
+ ```
21
+
22
+ Create a CJS template application:
23
+ ```sh
24
+ express-sweet myapp;
25
+ # or
26
+ express-sweet -o cjs myapp;
27
+ ```
28
+
29
+ [1.0.1]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.0...v1.0.1
30
+ [1.0.2]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.1...v1.0.2
31
+ [1.0.3]: https://github.com/takuya-motoshima/express-sweet-generator/compare/v1.0.2...v1.0.3
package/README.md CHANGED
@@ -1,63 +1,36 @@
1
- <a href="https://takuya-motoshima.github.io/express-sweet/"><img src="https://raw.githubusercontent.com/takuya-motoshima/express-sweet-generator/main/logo.svg" height="140"></a>
2
-
1
+ # express-sweet-generator
3
2
  [Express Sweet](https://www.npmjs.com/package/express-sweet) application generator.
4
3
 
5
- ## Docs
6
-
7
- * <a href="https://takuya-motoshima.github.io/express-sweet/" target="_blank">Website and Documentation</a> - <a href="https://github.com/takuya-motoshima/express-sweet" target="_blank">[website repo]</a>
8
- * <a href="https://github.com/takuya-motoshima/express-sweet-generator/blob/main/CHANGELOG.md" target="_blank">Changelog</a>
9
-
10
4
  ## Installation
11
-
12
5
  ```sh
13
6
  npm install -g express-sweet-generator;
14
7
  ```
15
8
 
16
9
  ## Quick Start
17
-
18
10
  The easiest way to get started with Express Sweet is to install express-sweet-generator and automatically create a template application.
19
- From the beginning, the template includes the following screen and sample programs such as router, model class, and authentication.
20
- Please refer to these and start developing your application.
21
- See <a href="https://takuya-motoshima.github.io/express-sweet/#started-generator" target="_blank">&quot;Express Sweet app generator&quot;</a> for more information on how to use express-sweet-generator.
22
-
23
- <table>
24
- <tr>
25
- <td valign="top">
26
- <div>Login</div>
27
- <img src="https://raw.githubusercontent.com/takuya-motoshima/express-sweet-generator/main/screencaps/login.png" width="400">
28
- </td>
29
- <td valign="top">
30
- <div>Home</div>
31
- <img src="https://raw.githubusercontent.com/takuya-motoshima/express-sweet-generator/main/screencaps/home.png" width="400">
32
- </td>
33
- </tr>
34
- <tr>
35
- <td valign="top">
36
- <div>User list</div>
37
- <img src="https://raw.githubusercontent.com/takuya-motoshima/express-sweet-generator/main/screencaps/user-list.png" width="400">
38
- </td>
39
- <td valign="top">
40
- <div>New user</div>
41
- <img src="https://raw.githubusercontent.com/takuya-motoshima/express-sweet-generator/main/screencaps/new-user.png" width="400">
42
- </td>
43
- </tr>
44
- <tr>
45
- <td valign="top">
46
- <div>Edit user</div>
47
- <img src="https://raw.githubusercontent.com/takuya-motoshima/express-sweet-generator/main/screencaps/edit-user.png" width="400">
48
- </td>
49
- </tr>
50
- </table>
51
11
 
52
- ## Command Line Options
12
+ From the beginning, the template includes views and sample programs for routers, model classes, authentication, etc., as shown below in the template.
13
+ Please use these as a reference to get started.
53
14
 
15
+ See <a href="https://takuya-motoshima.github.io/express-sweet/#quick-start" target="_blank">here</a> for instructions on using express-sweet-generator.
16
+
17
+ <img src="screencaps/login&users.jfif">
18
+
19
+ ## Command Line Options
54
20
  This generator can also be further configured with the following command line flags.
55
21
 
56
22
  --version output the version number
23
+ -o, --output <output> add output <module> support (esm|cjs) (defaults to cjs)
57
24
  -p, --port <port> application listening port (default: 3000)
58
25
  -f, --force force on non-empty directory
59
26
  -h, --help output usage information
60
27
 
61
- ## License
28
+ ## Author
29
+ **Takuya Motoshima**
30
+
31
+ * [github/takuya-motoshima](https://github.com/takuya-motoshima)
32
+ * [twitter/TakuyaMotoshima](https://twitter.com/TakuyaMotoshima)
33
+ * [facebook/takuya.motoshima.7](https://www.facebook.com/takuya.motoshima.7)
62
34
 
35
+ ## License
63
36
  [MIT](LICENSE)
@@ -1,214 +1,220 @@
1
- #!/usr/bin/env node
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
1
  * Install an around function; AOP.
14
-
15
2
  */
16
-
17
-
18
3
  const old = obj[method];
19
-
20
4
  obj[method] = function() {
21
-
22
5
  return fn.call(this, old, [...arguments]);
23
-
24
6
  }
25
-
26
-
27
-
28
-
29
7
  * Install a before function; AOP.
30
-
31
8
  */
32
-
33
-
34
9
  const old = obj[method];
35
-
36
10
  obj[method] = function() {
37
-
38
11
  fn.call(this);
39
-
40
12
  old.apply(this, arguments);
41
-
42
13
  }
43
-
44
-
45
-
46
-
47
14
  * Prompt for confirmation on STDOUT/STDIN
48
-
49
15
  */
50
-
51
-
52
16
  const rl = readline.createInterface({input: process.stdin, output: process.stdout})
53
-
54
17
  rl.question(message, input => {
55
-
56
18
  rl.close();
57
-
58
19
  callback(/^y|yes|ok|true$/i.test(input))
59
-
60
20
  })
61
-
62
-
63
-
64
-
65
21
  * Create application at the given directory.
66
-
67
22
  *
68
-
69
23
  * @param {string} name
70
-
71
24
  * @param {string} destDir
72
-
73
25
  */
74
-
75
-
76
26
  console.log();
77
-
78
-
79
27
  // Application listening port.
80
-
81
28
  const port = program.port;
82
-
83
-
84
29
  // Copy the entire template as a creation application.
85
-
86
30
  const templateDir = path.join(__dirname, '..', 'templates');
87
-
88
31
  fs.copySync(templateDir, destDir);
89
-
90
-
91
32
  // Copy bin/www.
92
-
93
33
  compile(path.join(destDir, 'bin/www'), {name});
94
-
95
-
96
34
  // Copy ecosystem.config.js.
97
-
98
35
  compile(path.join(destDir, 'ecosystem.config.js'), {name, port});
99
-
100
-
101
36
  // Copy nginx.sample.conf.
102
-
103
37
  compile(path.join(destDir, 'nginx.sample.conf'), {name, port});
104
-
105
-
106
38
  // Copy package.json.
107
-
108
39
  compile(path.join(destDir, 'package.json'), {name});
109
-
110
-
111
40
  const prompt = launchedFromCmd() ? '>' : '$'
112
-
113
41
  if (destDir !== '.') {
114
-
115
42
  console.log();
116
-
117
43
  console.log(' change directory:');
118
-
119
44
  console.log(` ${prompt} cd ${destDir}`);
120
-
121
45
  }
122
-
123
46
  console.log();
124
-
125
47
  console.log(' install dependencies:');
126
-
127
48
  console.log(` ${prompt} npm install`);
128
-
129
49
  console.log();
130
-
131
50
  console.log(' run the app:');
132
-
133
51
  if (launchedFromCmd())
134
-
135
52
  console.log(` ${prompt} SET DEBUG=${name}:* & npm start`);
136
-
137
53
  else
138
-
139
54
  console.log(` ${prompt} DEBUG=${name}:* npm start`);
140
-
141
55
  console.log();
142
-
143
-
144
-
145
-
146
56
  * Create an app name from a directory path, fitting npm naming requirements.
147
-
148
57
  *
149
-
150
58
  * @param {String} destDir
151
-
152
59
  */
153
-
154
-
155
60
  return path.basename(destDir)
156
-
157
61
  .replace(/[^A-Za-z0-9.-]+/g, '-')
158
-
159
62
  .replace(/^[-_.]+|-+$/g, '')
160
-
161
63
  .toLowerCase();
162
-
163
-
164
-
165
-
166
64
  * Check if the given directory `dir` is empty.
167
-
168
65
  *
169
-
170
66
  * @param {String} dir
171
-
172
67
  * @param {Function} fn
173
-
174
68
  */
175
-
176
-
177
69
  fs.readdir(dir, (err, files) => {
178
-
179
70
  if (err && err.code !== 'ENOENT') throw err;
180
-
181
71
  fn(!files || !files.length);
182
-
183
72
  })
184
-
185
-
186
-
187
-
188
73
  * Graceful exit for async STDIO
189
-
190
74
  */
191
-
192
-
193
75
  // flush output for Node.js Windows pipe bug
194
-
195
76
  // https://github.com/joyent/node/issues/6247 is just one bug example
196
-
197
77
  // https://github.com/visionmedia/mocha/issues/333 has a good discussion
198
-
199
78
  function done() {
200
-
201
79
  if (!(draining--)) _exit(code)
202
-
203
80
  }
204
-
205
81
  let draining = 0
206
-
207
82
  const streams = [process.stdout, process.stderr]
208
-
209
83
  exit.exited = true
210
-
211
84
  streams.forEach(function(stream) {
212
-
213
85
  // submit empty write request and wait for completion
214
-
215
86
  draining += 1;
216
-
217
87
  stream.write('', done);
218
-
219
88
  });
220
-
221
89
  done();
222
-
223
-
224
-
225
-
226
90
  * Determine if launched from cmd.exe
227
-
228
91
  */
229
-
230
-
231
92
  return process.platform === 'win32' && process.env._ === undefined
232
-
233
-
234
-
235
-
236
93
  * Compile template.
237
-
238
94
  */
239
-
240
-
241
95
  const contents = fs.readFileSync(`${file}.ejs`, 'utf-8');
242
-
243
96
  const compiled = ejs.render(contents, locals, {escape: util.inspect});
244
-
245
97
  fs.writeFileSync(file, compiled, {mode: parseInt('0755', 8)})
246
-
247
98
  console.log(` \x1b[36mcreate\x1b[0m : ${file}`);
248
-
249
99
  fs.unlinkSync(`${file}.ejs`);
250
-
251
-
252
-
253
-
254
100
  * Main program.
255
-
256
101
  */
257
-
258
-
259
102
  // Path.
260
-
261
103
  const destDir = program.args.shift() || '.'
262
-
263
-
264
104
  // App name.
265
-
266
105
  const name = createAppName(path.resolve(destDir)) || 'hello-world'
267
-
268
-
269
106
  // Generate application.
270
-
271
107
  emptyDirectory(destDir, empty => {
272
-
273
108
  if (empty || program.force)
274
-
275
109
  createApplication(name, destDir);
276
-
277
110
  else
278
-
279
111
  confirm('destination is not empty, continue? [y/N] ', ok => {
280
-
281
112
  if (ok) {
282
-
283
113
  process.stdin.destroy()
284
-
285
114
  createApplication(name, destDir)
286
-
287
115
  } else {
288
-
289
116
  console.error('aborting')
290
-
291
117
  exit(1)
292
-
293
118
  }
294
-
295
119
  })
296
-
297
120
  })
298
-
299
-
300
-
301
-
302
-
303
-
304
-
305
-
306
-
307
-
308
121
  program.outputHelp();
309
-
310
122
  fn.apply(this, args);
311
-
312
123
  return {args: [], unknown: []};
313
-
314
-
315
-
316
-
317
124
  // track if help was shown for unknown option
318
-
319
125
  this._helpShown = true;
320
-
321
-
322
-
323
-
324
126
  // allow unknown options if help was shown, to prevent trailing error
325
-
326
127
  this._allowUnknownOption = this._helpShown;
327
-
328
128
  // show help if not yet shown
329
-
330
129
  if (!this._helpShown)
331
-
332
130
  program.outputHelp();
333
-
334
-
335
-
336
-
337
131
  .name('express-sweet')
338
-
339
132
  .version(version, ' --version')
340
-
341
133
  .usage('[options] [dir]')
342
-
343
-
344
134
  .option('-f, --force', 'force on non-empty directory')
345
-
346
135
  .parse(process.argv);
347
-
348
-
349
-
350
136
  main();
137
+ #!/usr/bin/env node
138
+ const ejs = require('ejs');
139
+ const fs = require('fs-extra');
140
+ const path = require('path');
141
+ const program = require('commander');
142
+ const readline = require('readline');
143
+ const util = require('util');
144
+ const version = require('../package').version;
145
+
146
+ /**
147
+ * Install an around function; AOP.
148
+ */
149
+ function around(obj, method, fn) {
150
+ const old = obj[method];
151
+ obj[method] = function() {
152
+ return fn.call(this, old, [...arguments]);
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Install a before function; AOP.
158
+ */
159
+ function before(obj, method, fn) {
160
+ const old = obj[method];
161
+ obj[method] = function() {
162
+ fn.call(this);
163
+ old.apply(this, arguments);
164
+ }
165
+ }
166
+
167
+ /**
168
+ * Prompt for confirmation on STDOUT/STDIN
169
+ */
170
+ function confirm(message, callback) {
171
+ const rl = readline.createInterface({input: process.stdin, output: process.stdout})
172
+ rl.question(message, input => {
173
+ rl.close();
174
+ callback(/^y|yes|ok|true$/i.test(input))
175
+ })
176
+ }
177
+
178
+ /**
179
+ * Create application at the given directory.
180
+ *
181
+ * @param {string} name
182
+ * @param {string} destDir
183
+ */
184
+ function createApplication(name, destDir) {
185
+ console.log();// Output blank line.
186
+
187
+ // Application listening port.
188
+ const port = program.port;
189
+
190
+ // Copy the entire template as a creation application.
191
+ const output = program.output === 'esm' ? 'esm' : 'cjs';
192
+ const templateDir = path.join(__dirname, '..', `templates/${output}`);
193
+ // const templateDir = path.join(__dirname, '..', 'templates/cjs');
194
+ fs.copySync(templateDir, destDir);
195
+
196
+ // Copy bin/www.
197
+ compile(path.join(destDir, 'bin/www'), {name});
198
+
199
+ // Copy ecosystem.config.js.
200
+ compile(path.join(destDir, 'ecosystem.config.js'), {name, port});
201
+
202
+ // Copy nginx.sample.conf.
203
+ compile(path.join(destDir, 'nginx.sample.conf'), {name, port});
204
+
205
+ // Copy package.json.
206
+ compile(path.join(destDir, 'package.json'), {name});
207
+ const prompt = launchedFromCmd() ? '>' : '$'
208
+ if (destDir !== '.') {
209
+ console.log();// Output blank line.
210
+ console.log(' change directory:');
211
+ console.log(` ${prompt} cd ${destDir}`);
212
+ }
213
+ console.log();// Output blank line.
214
+ console.log(' install dependencies:');
215
+ console.log(` ${prompt} npm install`);
216
+ console.log();// Output blank line.
217
+ console.log(' run the app:');
218
+ if (launchedFromCmd())
219
+ console.log(` ${prompt} SET DEBUG=${name}:* & npm start`);
220
+ else
221
+ console.log(` ${prompt} DEBUG=${name}:* npm start`);
222
+ console.log();// Output blank line.
223
+ }
224
+
225
+ /**
226
+ * Create an app name from a directory path, fitting npm naming requirements.
227
+ *
228
+ * @param {String} destDir
229
+ */
230
+ function createAppName(destDir) {
231
+ return path.basename(destDir)
232
+ .replace(/[^A-Za-z0-9.-]+/g, '-')
233
+ .replace(/^[-_.]+|-+$/g, '')
234
+ .toLowerCase();
235
+ }
236
+
237
+ /**
238
+ * Check if the given directory `dir` is empty.
239
+ *
240
+ * @param {String} dir
241
+ * @param {Function} fn
242
+ */
243
+ function emptyDirectory(dir, fn) {
244
+ fs.readdir(dir, (err, files) => {
245
+ if (err && err.code !== 'ENOENT')
246
+ throw err;
247
+ fn(!files || !files.length);
248
+ });
249
+ }
250
+
251
+ /**
252
+ * Graceful exit for async STDIO
253
+ */
254
+ function exit(code) {
255
+ // flush output for Node.js Windows pipe bug
256
+ // https://github.com/joyent/node/issues/6247 is just one bug example
257
+ // https://github.com/visionmedia/mocha/issues/333 has a good discussion
258
+ function done() {
259
+ if (!(draining--))
260
+ _exit(code)
261
+ }
262
+
263
+ let draining = 0
264
+ const streams = [process.stdout, process.stderr]
265
+ exit.exited = true
266
+ streams.forEach(function(stream) {
267
+ // submit empty write request and wait for completion
268
+ draining += 1;
269
+ stream.write('', done);
270
+ });
271
+ done();
272
+ }
273
+
274
+ /**
275
+ * Determine if launched from cmd.exe
276
+ */
277
+ function launchedFromCmd() {
278
+ return process.platform === 'win32' && process.env._ === undefined
279
+ }
280
+
281
+ /**
282
+ * Compile template.
283
+ */
284
+ function compile(file, locals) {
285
+ const contents = fs.readFileSync(`${file}.ejs`, 'utf-8');
286
+ const compiled = ejs.render(contents, locals, {escape: util.inspect});
287
+ fs.writeFileSync(file, compiled, {mode: parseInt('0755', 8)})
288
+ console.log(` \x1b[36mcreate\x1b[0m : ${file}`);
289
+ fs.unlinkSync(`${file}.ejs`);
290
+ }
291
+
292
+ /**
293
+ * Main program.
294
+ */
295
+ function main() {
296
+ // Path.
297
+ const destDir = program.args.shift() || '.'
298
+
299
+ // App name.
300
+ const name = createAppName(path.resolve(destDir)) || 'hello-world'
301
+
302
+ // Generate application.
303
+ emptyDirectory(destDir, empty => {
304
+ if (empty || program.force)
305
+ createApplication(name, destDir);
306
+ else
307
+ confirm('destination is not empty, continue? [y/N] ', ok => {
308
+ if (ok) {
309
+ process.stdin.destroy()
310
+ createApplication(name, destDir)
311
+ } else {
312
+ console.error('aborting')
313
+ exit(1)
314
+ }
315
+ })
316
+ })
317
+ }
318
+
319
+ // Re-assign process.exit because of commander
320
+
321
+ // TODO: Switch to a different command framework
322
+ const _exit = process.exit;
323
+ process.exit = exit;
324
+
325
+ // CLI
326
+ around(program, 'optionMissingArgument', function(fn, args) {
327
+ program.outputHelp();
328
+ fn.apply(this, args);
329
+ return {args: [], unknown: []};
330
+ });
331
+
332
+ before(program, 'outputHelp', function() {
333
+ // track if help was shown for unknown option
334
+ this._helpShown = true;
335
+ });
336
+
337
+ before(program, 'unknownOption', function() {
338
+ // allow unknown options if help was shown, to prevent trailing error
339
+ this._allowUnknownOption = this._helpShown;
340
+
341
+ // show help if not yet shown
342
+ if (!this._helpShown)
343
+ program.outputHelp();
344
+ });
345
+
346
+ program
347
+ .name('express-sweet')
348
+ .version(version, ' --version')
349
+ .usage('[options] [dir]')
350
+ .option('-o, --output <output>', 'add output <module> support (esm|cjs) (defaults to cjs)')
351
+ .option('-p, --port <port>', 'application listening port', value => parseInt(value, 10), 3000)
352
+ .option('-f, --force', 'force on non-empty directory')
353
+ .parse(process.argv);
354
+
355
+ if (!exit.exited)
356
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-sweet-generator",
3
- "version": "1.0.0",
3
+ "version": "1.0.3",
4
4
  "description": "Express Sweet application generator.",
5
5
  "main": "bin/express-sweet-cli.js",
6
6
  "files": [
File without changes
File without changes
File without changes
@@ -70,7 +70,7 @@ module.exports = {
70
70
 
71
71
  /**
72
72
  * URL without authentication. If the URL described in the access URL partially matches, authentication will not be performed, defaults to none.
73
- * @type {string}
73
+ * @type {(string|RegExp)[]}
74
74
  */
75
75
  allow_unauthenticated: ['/api'],
76
76
 
File without changes