clwy-express-generator 4.16.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/LICENSE +23 -0
- package/README.md +115 -0
- package/bin/express-cli.js +595 -0
- package/package.json +68 -0
- package/templates/.env.ejs +12 -0
- package/templates/css/style.css +8 -0
- package/templates/css/style.less +8 -0
- package/templates/css/style.sass +6 -0
- package/templates/css/style.scss +10 -0
- package/templates/css/style.styl +5 -0
- package/templates/js/app.js.ejs +44 -0
- package/templates/js/config/routes.js +10 -0
- package/templates/js/gitignore +61 -0
- package/templates/js/index.html +13 -0
- package/templates/js/routes/index.js +11 -0
- package/templates/js/routes/users.js +9 -0
- package/templates/js/www.ejs +90 -0
- package/templates/middlewares/error-handler.js +17 -0
- package/templates/mjs/app.js.ejs +48 -0
- package/templates/mjs/config/routes.js +10 -0
- package/templates/mjs/routes/index.js +11 -0
- package/templates/mjs/routes/users.js +9 -0
- package/templates/mjs/www.ejs +92 -0
- package/templates/prisma/schema.prisma +14 -0
- package/templates/views/error.dust +12 -0
- package/templates/views/error.ejs +3 -0
- package/templates/views/error.hbs +3 -0
- package/templates/views/error.hjs +3 -0
- package/templates/views/error.jade +6 -0
- package/templates/views/error.pug +6 -0
- package/templates/views/error.twig +7 -0
- package/templates/views/error.vash +7 -0
- package/templates/views/index.dust +11 -0
- package/templates/views/index.ejs +11 -0
- package/templates/views/index.hbs +2 -0
- package/templates/views/index.hjs +11 -0
- package/templates/views/index.jade +5 -0
- package/templates/views/index.pug +5 -0
- package/templates/views/index.twig +6 -0
- package/templates/views/index.vash +6 -0
- package/templates/views/layout.hbs +10 -0
- package/templates/views/layout.jade +7 -0
- package/templates/views/layout.pug +7 -0
- package/templates/views/layout.twig +10 -0
- package/templates/views/layout.vash +11 -0
|
@@ -0,0 +1,595 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
var ejs = require('ejs')
|
|
4
|
+
var fs = require('fs')
|
|
5
|
+
var minimatch = require('minimatch')
|
|
6
|
+
var mkdirp = require('mkdirp')
|
|
7
|
+
var parseArgs = require('minimist')
|
|
8
|
+
var path = require('path')
|
|
9
|
+
var readline = require('readline')
|
|
10
|
+
var sortedObject = require('sorted-object')
|
|
11
|
+
var util = require('util')
|
|
12
|
+
|
|
13
|
+
var MODE_0666 = parseInt('0666', 8)
|
|
14
|
+
var MODE_0755 = parseInt('0755', 8)
|
|
15
|
+
var TEMPLATE_DIR = path.join(__dirname, '..', 'templates')
|
|
16
|
+
var VERSION = require('../package').version
|
|
17
|
+
var MIN_ES6_VERSION = 14
|
|
18
|
+
|
|
19
|
+
// parse args
|
|
20
|
+
var unknown = []
|
|
21
|
+
var args = parseArgs(process.argv.slice(2), {
|
|
22
|
+
alias: {
|
|
23
|
+
c: 'css',
|
|
24
|
+
e: 'ejs',
|
|
25
|
+
f: 'force',
|
|
26
|
+
h: 'help',
|
|
27
|
+
H: 'hogan',
|
|
28
|
+
v: 'view',
|
|
29
|
+
o: 'orm'
|
|
30
|
+
},
|
|
31
|
+
boolean: ['ejs', 'es6', 'force', 'git', 'hbs', 'help', 'hogan', 'pug', 'version', 'orm'],
|
|
32
|
+
default: { css: true, view: true },
|
|
33
|
+
string: ['css', 'view'],
|
|
34
|
+
unknown: function (s) {
|
|
35
|
+
if (s.charAt(0) === '-') {
|
|
36
|
+
unknown.push(s)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
args['!'] = unknown
|
|
42
|
+
|
|
43
|
+
// run
|
|
44
|
+
main(args, exit)
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Prompt for confirmation on STDOUT/STDIN
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
function confirm (msg, callback) {
|
|
51
|
+
var rl = readline.createInterface({
|
|
52
|
+
input: process.stdin,
|
|
53
|
+
output: process.stdout
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
rl.question(msg, function (input) {
|
|
57
|
+
rl.close()
|
|
58
|
+
callback(/^y|yes|ok|true$/i.test(input))
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Copy file from template directory.
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
function copyTemplate (from, to) {
|
|
67
|
+
write(to, fs.readFileSync(path.join(TEMPLATE_DIR, from), 'utf-8'))
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Copy multiple files from template directory.
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
function copyTemplateMulti (fromDir, toDir, nameGlob) {
|
|
75
|
+
fs.readdirSync(path.join(TEMPLATE_DIR, fromDir))
|
|
76
|
+
.filter(minimatch.filter(nameGlob, { matchBase: true }))
|
|
77
|
+
.forEach(function (name) {
|
|
78
|
+
copyTemplate(path.join(fromDir, name), path.join(toDir, name))
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Create application at the given directory.
|
|
84
|
+
*
|
|
85
|
+
* @param {string} name
|
|
86
|
+
* @param {string} dir
|
|
87
|
+
* @param {object} options
|
|
88
|
+
* @param {function} done
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
function createApplication (name, dir, options, done) {
|
|
92
|
+
console.log()
|
|
93
|
+
|
|
94
|
+
// Package
|
|
95
|
+
var pkg = {
|
|
96
|
+
name: name,
|
|
97
|
+
version: '0.0.0',
|
|
98
|
+
private: true,
|
|
99
|
+
scripts: {
|
|
100
|
+
start: 'nodemon ./bin/www'
|
|
101
|
+
},
|
|
102
|
+
dependencies: {
|
|
103
|
+
debug: '~2.6.9',
|
|
104
|
+
dotenv: '^16.4.7',
|
|
105
|
+
express: '~4.17.1'
|
|
106
|
+
},
|
|
107
|
+
devDependencies: {
|
|
108
|
+
nodemon: '^3.1.9'
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (options.es6) {
|
|
112
|
+
pkg.type = 'module'
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// JavaScript
|
|
116
|
+
var app = loadTemplate(options.es6 ? 'mjs/app.js' : 'js/app.js')
|
|
117
|
+
var www = loadTemplate(options.es6 ? 'mjs/www' : 'js/www')
|
|
118
|
+
var env = loadTemplate('.env')
|
|
119
|
+
|
|
120
|
+
// App name
|
|
121
|
+
www.locals.name = name
|
|
122
|
+
|
|
123
|
+
// App modules
|
|
124
|
+
app.locals.modules = Object.create(null)
|
|
125
|
+
app.locals.uses = []
|
|
126
|
+
|
|
127
|
+
// Request logger
|
|
128
|
+
app.locals.modules.logger = 'morgan'
|
|
129
|
+
app.locals.uses.push("logger('dev')")
|
|
130
|
+
pkg.dependencies.morgan = '~1.10.0'
|
|
131
|
+
|
|
132
|
+
// Body parsers
|
|
133
|
+
app.locals.uses.push('express.json()')
|
|
134
|
+
app.locals.uses.push('express.urlencoded({ extended: false })')
|
|
135
|
+
|
|
136
|
+
// Cookie parser
|
|
137
|
+
app.locals.modules.cookieParser = 'cookie-parser'
|
|
138
|
+
app.locals.uses.push('cookieParser()')
|
|
139
|
+
pkg.dependencies['cookie-parser'] = '~1.4.5'
|
|
140
|
+
|
|
141
|
+
// Env vars
|
|
142
|
+
env.locals.orm = options.orm
|
|
143
|
+
|
|
144
|
+
if (dir !== '.') {
|
|
145
|
+
mkdir(dir, '.')
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
mkdir(dir, 'public')
|
|
149
|
+
mkdir(dir, 'public/javascripts')
|
|
150
|
+
mkdir(dir, 'public/images')
|
|
151
|
+
mkdir(dir, 'public/stylesheets')
|
|
152
|
+
mkdir(dir, 'middlewares')
|
|
153
|
+
mkdir(dir, 'utils')
|
|
154
|
+
|
|
155
|
+
// copy Prisma templates
|
|
156
|
+
if (options.orm) {
|
|
157
|
+
pkg.dependencies.prisma = '^6.2.1'
|
|
158
|
+
pkg.dependencies['@prisma/client'] = '^6.2.1'
|
|
159
|
+
|
|
160
|
+
mkdir(dir, 'prisma')
|
|
161
|
+
copyTemplateMulti('prisma', dir + '/prisma', '*.prisma')
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// copy css templates
|
|
165
|
+
switch (options.css) {
|
|
166
|
+
case 'less':
|
|
167
|
+
copyTemplateMulti('css', dir + '/public/stylesheets', '*.less')
|
|
168
|
+
break
|
|
169
|
+
case 'stylus':
|
|
170
|
+
copyTemplateMulti('css', dir + '/public/stylesheets', '*.styl')
|
|
171
|
+
break
|
|
172
|
+
case 'compass':
|
|
173
|
+
copyTemplateMulti('css', dir + '/public/stylesheets', '*.scss')
|
|
174
|
+
break
|
|
175
|
+
case 'sass':
|
|
176
|
+
copyTemplateMulti('css', dir + '/public/stylesheets', '*.sass')
|
|
177
|
+
break
|
|
178
|
+
default:
|
|
179
|
+
copyTemplateMulti('css', dir + '/public/stylesheets', '*.css')
|
|
180
|
+
break
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// copy config templates
|
|
184
|
+
mkdir(dir, 'config')
|
|
185
|
+
copyTemplateMulti(
|
|
186
|
+
options.es6 ? 'mjs/config' : 'js/config',
|
|
187
|
+
dir + '/config', '*.js'
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
// copy route templates
|
|
191
|
+
mkdir(dir, 'routes')
|
|
192
|
+
copyTemplateMulti(
|
|
193
|
+
options.es6 ? 'mjs/routes' : 'js/routes',
|
|
194
|
+
dir + '/routes', '*.js')
|
|
195
|
+
|
|
196
|
+
if (options.view) {
|
|
197
|
+
// Copy view templates
|
|
198
|
+
mkdir(dir, 'views')
|
|
199
|
+
pkg.dependencies['http-errors'] = '~1.7.2'
|
|
200
|
+
copyTemplateMulti('middlewares', dir + '/middlewares', '*.js')
|
|
201
|
+
|
|
202
|
+
console.log(1111, options.view)
|
|
203
|
+
switch (options.view) {
|
|
204
|
+
case 'dust':
|
|
205
|
+
copyTemplateMulti('views', dir + '/views', '*.dust')
|
|
206
|
+
break
|
|
207
|
+
case 'ejs':
|
|
208
|
+
copyTemplateMulti('views', dir + '/views', '*.ejs')
|
|
209
|
+
break
|
|
210
|
+
case 'hbs':
|
|
211
|
+
copyTemplateMulti('views', dir + '/views', '*.hbs')
|
|
212
|
+
break
|
|
213
|
+
case 'hjs':
|
|
214
|
+
copyTemplateMulti('views', dir + '/views', '*.hjs')
|
|
215
|
+
break
|
|
216
|
+
case 'jade':
|
|
217
|
+
copyTemplateMulti('views', dir + '/views', '*.jade')
|
|
218
|
+
break
|
|
219
|
+
case 'pug':
|
|
220
|
+
copyTemplateMulti('views', dir + '/views', '*.pug')
|
|
221
|
+
break
|
|
222
|
+
case 'twig':
|
|
223
|
+
copyTemplateMulti('views', dir + '/views', '*.twig')
|
|
224
|
+
break
|
|
225
|
+
case 'vash':
|
|
226
|
+
copyTemplateMulti('views', dir + '/views', '*.vash')
|
|
227
|
+
break
|
|
228
|
+
}
|
|
229
|
+
} else {
|
|
230
|
+
// Copy extra public files
|
|
231
|
+
copyTemplate('js/index.html', path.join(dir, 'public/index.html'))
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// CSS Engine support
|
|
235
|
+
switch (options.css) {
|
|
236
|
+
case 'compass':
|
|
237
|
+
app.locals.modules.compass = 'node-compass'
|
|
238
|
+
app.locals.uses.push("compass({ mode: 'expanded' })")
|
|
239
|
+
pkg.dependencies['node-compass'] = '0.2.3'
|
|
240
|
+
break
|
|
241
|
+
case 'less':
|
|
242
|
+
app.locals.modules.lessMiddleware = 'less-middleware'
|
|
243
|
+
app.locals.uses.push("lessMiddleware(path.join(__dirname, 'public'))")
|
|
244
|
+
pkg.dependencies['less-middleware'] = '~2.2.1'
|
|
245
|
+
break
|
|
246
|
+
case 'sass':
|
|
247
|
+
app.locals.modules.sassMiddleware = 'node-sass-middleware'
|
|
248
|
+
app.locals.uses.push("sassMiddleware({\n src: path.join(__dirname, 'public'),\n dest: path.join(__dirname, 'public'),\n indentedSyntax: true, // true = .sass and false = .scss\n sourceMap: true\n})")
|
|
249
|
+
pkg.dependencies['node-sass-middleware'] = '0.11.0'
|
|
250
|
+
break
|
|
251
|
+
case 'stylus':
|
|
252
|
+
app.locals.modules.stylus = 'stylus'
|
|
253
|
+
app.locals.uses.push("stylus.middleware(path.join(__dirname, 'public'))")
|
|
254
|
+
pkg.dependencies.stylus = '0.54.5'
|
|
255
|
+
break
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Template support
|
|
259
|
+
switch (options.view) {
|
|
260
|
+
case 'dust':
|
|
261
|
+
app.locals.modules.adaro = 'adaro'
|
|
262
|
+
app.locals.view = {
|
|
263
|
+
engine: 'dust',
|
|
264
|
+
render: 'adaro.dust()'
|
|
265
|
+
}
|
|
266
|
+
pkg.dependencies.adaro = '~1.0.4'
|
|
267
|
+
break
|
|
268
|
+
case 'ejs':
|
|
269
|
+
app.locals.view = { engine: 'ejs' }
|
|
270
|
+
pkg.dependencies.ejs = '~2.6.1'
|
|
271
|
+
break
|
|
272
|
+
case 'hbs':
|
|
273
|
+
app.locals.view = { engine: 'hbs' }
|
|
274
|
+
pkg.dependencies.hbs = '~4.0.4'
|
|
275
|
+
break
|
|
276
|
+
case 'hjs':
|
|
277
|
+
app.locals.view = { engine: 'hjs' }
|
|
278
|
+
pkg.dependencies.hjs = '~0.0.6'
|
|
279
|
+
break
|
|
280
|
+
case 'jade':
|
|
281
|
+
app.locals.view = { engine: 'jade' }
|
|
282
|
+
pkg.dependencies.jade = '~1.11.0'
|
|
283
|
+
break
|
|
284
|
+
case 'pug':
|
|
285
|
+
app.locals.view = { engine: 'pug' }
|
|
286
|
+
pkg.dependencies.pug = '2.0.0-beta11'
|
|
287
|
+
break
|
|
288
|
+
case 'twig':
|
|
289
|
+
app.locals.view = { engine: 'twig' }
|
|
290
|
+
pkg.dependencies.twig = '~0.10.3'
|
|
291
|
+
break
|
|
292
|
+
case 'vash':
|
|
293
|
+
app.locals.view = { engine: 'vash' }
|
|
294
|
+
pkg.dependencies.vash = '~0.12.6'
|
|
295
|
+
break
|
|
296
|
+
default:
|
|
297
|
+
app.locals.view = false
|
|
298
|
+
break
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// Static files
|
|
302
|
+
app.locals.uses.push("express.static(path.join(__dirname, 'public'))")
|
|
303
|
+
|
|
304
|
+
if (options.git) {
|
|
305
|
+
copyTemplate('js/gitignore', path.join(dir, '.gitignore'))
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// sort dependencies like npm(1)
|
|
309
|
+
pkg.dependencies = sortedObject(pkg.dependencies)
|
|
310
|
+
|
|
311
|
+
// write files
|
|
312
|
+
write(path.join(dir, 'app.js'), app.render())
|
|
313
|
+
write(path.join(dir, 'package.json'), JSON.stringify(pkg, null, 2) + '\n')
|
|
314
|
+
mkdir(dir, 'bin')
|
|
315
|
+
write(path.join(dir, 'bin/www'), www.render(), MODE_0755)
|
|
316
|
+
write(path.join(dir, '.env'), env.render())
|
|
317
|
+
|
|
318
|
+
var prompt = launchedFromCmd() ? '>' : '$'
|
|
319
|
+
|
|
320
|
+
if (dir !== '.') {
|
|
321
|
+
console.log()
|
|
322
|
+
console.log(' change directory:')
|
|
323
|
+
console.log(' %s cd %s', prompt, dir)
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
console.log()
|
|
327
|
+
console.log(' install dependencies:')
|
|
328
|
+
console.log(' %s npm install', prompt)
|
|
329
|
+
console.log()
|
|
330
|
+
console.log(' run the app:')
|
|
331
|
+
|
|
332
|
+
if (launchedFromCmd()) {
|
|
333
|
+
console.log(' %s SET DEBUG=%s:* & npm start', prompt, name)
|
|
334
|
+
} else {
|
|
335
|
+
console.log(' %s DEBUG=%s:* npm start', prompt, name)
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
console.log()
|
|
339
|
+
|
|
340
|
+
done(0)
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Create an app name from a directory path, fitting npm naming requirements.
|
|
345
|
+
*
|
|
346
|
+
* @param {String} pathName
|
|
347
|
+
*/
|
|
348
|
+
|
|
349
|
+
function createAppName (pathName) {
|
|
350
|
+
return path.basename(pathName)
|
|
351
|
+
.replace(/[^A-Za-z0-9.-]+/g, '-')
|
|
352
|
+
.replace(/^[-_.]+|-+$/g, '')
|
|
353
|
+
.toLowerCase()
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Check if the given directory `dir` is empty.
|
|
358
|
+
*
|
|
359
|
+
* @param {String} dir
|
|
360
|
+
* @param {Function} fn
|
|
361
|
+
*/
|
|
362
|
+
|
|
363
|
+
function emptyDirectory (dir, fn) {
|
|
364
|
+
fs.readdir(dir, function (err, files) {
|
|
365
|
+
if (err && err.code !== 'ENOENT') throw err
|
|
366
|
+
fn(!files || !files.length)
|
|
367
|
+
})
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Display an error.
|
|
372
|
+
*
|
|
373
|
+
* @param {String} message
|
|
374
|
+
*/
|
|
375
|
+
|
|
376
|
+
function error (message) {
|
|
377
|
+
console.error()
|
|
378
|
+
message.split('\n').forEach(function (line) {
|
|
379
|
+
console.error(' error: %s', line)
|
|
380
|
+
})
|
|
381
|
+
console.error()
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Graceful exit for async STDIO
|
|
386
|
+
*/
|
|
387
|
+
|
|
388
|
+
function exit (code) {
|
|
389
|
+
// flush output for Node.js Windows pipe bug
|
|
390
|
+
// https://github.com/joyent/node/issues/6247 is just one bug example
|
|
391
|
+
// https://github.com/visionmedia/mocha/issues/333 has a good discussion
|
|
392
|
+
function done () {
|
|
393
|
+
if (!(draining--)) process.exit(code)
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
var draining = 0
|
|
397
|
+
var streams = [process.stdout, process.stderr]
|
|
398
|
+
|
|
399
|
+
exit.exited = true
|
|
400
|
+
|
|
401
|
+
streams.forEach(function (stream) {
|
|
402
|
+
// submit empty write request and wait for completion
|
|
403
|
+
draining += 1
|
|
404
|
+
stream.write('', done)
|
|
405
|
+
})
|
|
406
|
+
|
|
407
|
+
done()
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Determine if launched from cmd.exe
|
|
412
|
+
*/
|
|
413
|
+
|
|
414
|
+
function launchedFromCmd () {
|
|
415
|
+
return process.platform === 'win32' &&
|
|
416
|
+
process.env._ === undefined
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Load template file.
|
|
421
|
+
*/
|
|
422
|
+
|
|
423
|
+
function loadTemplate (name) {
|
|
424
|
+
var contents = fs.readFileSync(path.join(__dirname, '..', 'templates', (name + '.ejs')), 'utf-8')
|
|
425
|
+
var locals = Object.create(null)
|
|
426
|
+
|
|
427
|
+
function render () {
|
|
428
|
+
return ejs.render(contents, locals, {
|
|
429
|
+
escape: util.inspect
|
|
430
|
+
})
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
return {
|
|
434
|
+
locals: locals,
|
|
435
|
+
render: render
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Main program.
|
|
441
|
+
*/
|
|
442
|
+
|
|
443
|
+
function main (options, done) {
|
|
444
|
+
// top-level argument direction
|
|
445
|
+
if (options['!'].length > 0) {
|
|
446
|
+
usage()
|
|
447
|
+
error('unknown option `' + options['!'][0] + "'")
|
|
448
|
+
done(1)
|
|
449
|
+
} else if (args.help) {
|
|
450
|
+
usage()
|
|
451
|
+
done(0)
|
|
452
|
+
} else if (args.version) {
|
|
453
|
+
version()
|
|
454
|
+
done(0)
|
|
455
|
+
} else if (options.css === '') {
|
|
456
|
+
usage()
|
|
457
|
+
error('option `-c, --css <engine>\' argument missing')
|
|
458
|
+
done(1)
|
|
459
|
+
} else if (options.view === '') {
|
|
460
|
+
usage()
|
|
461
|
+
error('option `-v, --view <engine>\' argument missing')
|
|
462
|
+
done(1)
|
|
463
|
+
} else if (options.es6 && process.versions.node.split('.')[0] < MIN_ES6_VERSION) {
|
|
464
|
+
usage()
|
|
465
|
+
error('option `--es6\' requires Node version ' + MIN_ES6_VERSION + '.x or higher')
|
|
466
|
+
done(1)
|
|
467
|
+
} else {
|
|
468
|
+
console.log(options.view)
|
|
469
|
+
// Path
|
|
470
|
+
var destinationPath = options._[0] || '.'
|
|
471
|
+
|
|
472
|
+
// App name
|
|
473
|
+
var appName = createAppName(path.resolve(destinationPath)) || 'hello-world'
|
|
474
|
+
|
|
475
|
+
// View engine
|
|
476
|
+
if (options.view === true) {
|
|
477
|
+
if (options.ejs) {
|
|
478
|
+
options.view = 'ejs'
|
|
479
|
+
warning("option `--ejs' has been renamed to `--view=ejs'")
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
if (options.hbs) {
|
|
483
|
+
options.view = 'hbs'
|
|
484
|
+
warning("option `--hbs' has been renamed to `--view=hbs'")
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
if (options.hogan) {
|
|
488
|
+
options.view = 'hjs'
|
|
489
|
+
warning("option `--hogan' has been renamed to `--view=hjs'")
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
if (options.pug) {
|
|
493
|
+
options.view = 'pug'
|
|
494
|
+
warning("option `--pug' has been renamed to `--view=pug'")
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// Default view engine
|
|
499
|
+
if (options.view === true) {
|
|
500
|
+
warning('the default view engine will not be ejs in future releases\n' +
|
|
501
|
+
"use `--view=ejs' or `--help' for additional options")
|
|
502
|
+
options.view = 'ejs'
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// Generate application
|
|
506
|
+
emptyDirectory(destinationPath, function (empty) {
|
|
507
|
+
if (empty || options.force) {
|
|
508
|
+
createApplication(appName, destinationPath, options, done)
|
|
509
|
+
} else {
|
|
510
|
+
confirm('destination is not empty, continue? [y/N] ', function (ok) {
|
|
511
|
+
if (ok) {
|
|
512
|
+
process.stdin.destroy()
|
|
513
|
+
createApplication(appName, destinationPath, options, done)
|
|
514
|
+
} else {
|
|
515
|
+
console.error('aborting')
|
|
516
|
+
done(1)
|
|
517
|
+
}
|
|
518
|
+
})
|
|
519
|
+
}
|
|
520
|
+
})
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Make the given dir relative to base.
|
|
526
|
+
*
|
|
527
|
+
* @param {string} base
|
|
528
|
+
* @param {string} dir
|
|
529
|
+
*/
|
|
530
|
+
|
|
531
|
+
function mkdir (base, dir) {
|
|
532
|
+
var loc = path.join(base, dir)
|
|
533
|
+
|
|
534
|
+
console.log(' \x1b[36mcreate\x1b[0m : ' + loc + path.sep)
|
|
535
|
+
mkdirp.sync(loc, MODE_0755)
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* Display the usage.
|
|
540
|
+
*/
|
|
541
|
+
|
|
542
|
+
function usage () {
|
|
543
|
+
console.log('')
|
|
544
|
+
console.log(' Usage: express [options] [dir]')
|
|
545
|
+
console.log('')
|
|
546
|
+
console.log(' Options:')
|
|
547
|
+
console.log('')
|
|
548
|
+
console.log(' -e, --ejs add ejs engine support')
|
|
549
|
+
console.log(' --pug add pug engine support')
|
|
550
|
+
console.log(' --hbs add handlebars engine support')
|
|
551
|
+
console.log(' -H, --hogan add hogan.js engine support')
|
|
552
|
+
console.log(' -v, --view <engine> add view <engine> support (dust|ejs|hbs|hjs|jade|pug|twig|vash) (defaults to ejs)')
|
|
553
|
+
console.log(' --no-view use static html instead of view engine')
|
|
554
|
+
console.log(' -c, --css <engine> add stylesheet <engine> support (less|stylus|compass|sass) (defaults to plain css)')
|
|
555
|
+
console.log(' --git add .gitignore')
|
|
556
|
+
console.log(' --es6 generate ES6 code and module-type project (requires Node 14.x or higher)')
|
|
557
|
+
console.log(' -o, --orm specify the ORM to use Prisma')
|
|
558
|
+
console.log(' -f, --force force on non-empty directory')
|
|
559
|
+
console.log(' --version output the version number')
|
|
560
|
+
console.log(' -h, --help output usage information')
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Display the version.
|
|
565
|
+
*/
|
|
566
|
+
|
|
567
|
+
function version () {
|
|
568
|
+
console.log(VERSION)
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* Display a warning.
|
|
573
|
+
*
|
|
574
|
+
* @param {String} message
|
|
575
|
+
*/
|
|
576
|
+
|
|
577
|
+
function warning (message) {
|
|
578
|
+
console.error()
|
|
579
|
+
message.split('\n').forEach(function (line) {
|
|
580
|
+
console.error(' warning: %s', line)
|
|
581
|
+
})
|
|
582
|
+
console.error()
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* echo str > file.
|
|
587
|
+
*
|
|
588
|
+
* @param {String} file
|
|
589
|
+
* @param {String} str
|
|
590
|
+
*/
|
|
591
|
+
|
|
592
|
+
function write (file, str, mode) {
|
|
593
|
+
fs.writeFileSync(file, str, { mode: mode || MODE_0666 })
|
|
594
|
+
console.log(' \x1b[36mcreate\x1b[0m : ' + file)
|
|
595
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "clwy-express-generator",
|
|
3
|
+
"description": "Express' application generator",
|
|
4
|
+
"homepage": "https://github.com/clwy-cn/clwy-express-generator",
|
|
5
|
+
"version": "4.16.1",
|
|
6
|
+
"author": "TJ Holowaychuk <tj@vision-media.ca>",
|
|
7
|
+
"contributors": [
|
|
8
|
+
"Aaron Heckmann <aaron.heckmann+github@gmail.com>",
|
|
9
|
+
"Ciaran Jessup <ciaranj@gmail.com>",
|
|
10
|
+
"Douglas Christopher Wilson <doug@somethingdoug.com>",
|
|
11
|
+
"Guillermo Rauch <rauchg@gmail.com>",
|
|
12
|
+
"Jonathan Ong <me@jongleberry.com>",
|
|
13
|
+
"Roman Shtylman <shtylman+expressjs@gmail.com>",
|
|
14
|
+
"Liu Dong <canonpd@gmail.com>"
|
|
15
|
+
],
|
|
16
|
+
"keywords": [
|
|
17
|
+
"express",
|
|
18
|
+
"framework",
|
|
19
|
+
"sinatra",
|
|
20
|
+
"web",
|
|
21
|
+
"rest",
|
|
22
|
+
"restful",
|
|
23
|
+
"router",
|
|
24
|
+
"app",
|
|
25
|
+
"api"
|
|
26
|
+
],
|
|
27
|
+
"repository": "expressjs/generator",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"ejs": "2.6.2",
|
|
31
|
+
"minimatch": "3.0.4",
|
|
32
|
+
"minimist": "1.2.5",
|
|
33
|
+
"mkdirp": "0.5.1",
|
|
34
|
+
"sorted-object": "2.0.1"
|
|
35
|
+
},
|
|
36
|
+
"main": "bin/express-cli.js",
|
|
37
|
+
"preferGlobal": true,
|
|
38
|
+
"bin": {
|
|
39
|
+
"express": "./bin/express-cli.js"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"eslint": "7.32.0",
|
|
43
|
+
"eslint-config-standard": "14.1.1",
|
|
44
|
+
"eslint-plugin-import": "2.25.4",
|
|
45
|
+
"eslint-plugin-node": "11.1.0",
|
|
46
|
+
"eslint-plugin-promise": "5.2.0",
|
|
47
|
+
"eslint-plugin-standard": "4.1.0",
|
|
48
|
+
"mocha": "9.1.3",
|
|
49
|
+
"rimraf": "3.0.2",
|
|
50
|
+
"supertest": "6.1.4",
|
|
51
|
+
"tree-kill": "1.2.2",
|
|
52
|
+
"uid-safe": "2.1.5",
|
|
53
|
+
"validate-npm-package-name": "3.0.0"
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">= 0.10"
|
|
57
|
+
},
|
|
58
|
+
"files": [
|
|
59
|
+
"LICENSE",
|
|
60
|
+
"bin/",
|
|
61
|
+
"templates/"
|
|
62
|
+
],
|
|
63
|
+
"scripts": {
|
|
64
|
+
"lint": "eslint .",
|
|
65
|
+
"test": "mocha --reporter spec --bail --check-leaks test/",
|
|
66
|
+
"test-ci": "mocha --reporter spec --check-leaks test/"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# your environment variables
|
|
2
|
+
PORT=3000
|
|
3
|
+
<% if (orm) { -%>
|
|
4
|
+
|
|
5
|
+
# This was inserted by `prisma init`:
|
|
6
|
+
# Environment variables declared in this file are automatically made available to Prisma.
|
|
7
|
+
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
|
|
8
|
+
|
|
9
|
+
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
|
|
10
|
+
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
|
|
11
|
+
DATABASE_URL="mysql://root:password@localhost:3306/mydb"
|
|
12
|
+
<% } -%>
|