clwy-express-generator 5.0.4 → 5.0.6
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/README.md +53 -47
- package/bin/express-cli.js +43 -36
- package/package.json +1 -1
- package/templates/README.md +15 -0
- package/templates/env.ejs +2 -0
- package/templates/{js/gitignore → gitignore} +14 -0
- package/templates/js/middlewares/error-handler.js +1 -1
- package/templates/js/prettierrc.json +6 -0
- package/templates/mjs/app.js.ejs +21 -21
- package/templates/mjs/config/routes.js +7 -7
- package/templates/mjs/middlewares/error-handler.js +5 -5
- package/templates/mjs/prettierrc.json +6 -0
- package/templates/mjs/routes/index.js +6 -5
- package/templates/mjs/routes/users.js +6 -5
- package/templates/mjs/www.ejs +26 -26
- package/templates/.env.ejs +0 -12
package/README.md
CHANGED
|
@@ -7,99 +7,105 @@
|
|
|
7
7
|
[![Linux Build][github-actions-ci-image]][github-actions-ci-url]
|
|
8
8
|
[![Windows Build][appveyor-image]][appveyor-url]
|
|
9
9
|
|
|
10
|
-
Forked from [express-generator](https://github.com/expressjs/generator)
|
|
10
|
+
Forked from [express-generator](https://github.com/expressjs/generator),此项目是从这个项目派生而来,并添加了一些新特性。
|
|
11
11
|
|
|
12
|
-
##
|
|
12
|
+
## 功能特性
|
|
13
13
|
|
|
14
|
-
- **🚀
|
|
15
|
-
- **🔀
|
|
16
|
-
- **📁
|
|
17
|
-
- **🔧
|
|
18
|
-
- **🔄 nodemon
|
|
14
|
+
- **🚀 ES6支持**:代码更现代简洁。
|
|
15
|
+
- **🔀 路由拆分**:独立文件,便于管理维护。
|
|
16
|
+
- **📁 中间件模块化**:新增文件夹存放中间件。
|
|
17
|
+
- **🔧 增加环境变量配置**:多环境管理更便捷。
|
|
18
|
+
- **🔄 集成nodemon**:开发时自动重启服务。
|
|
19
|
+
- **📄 新增 README.md**:包含项目简介和基本功能说明。
|
|
20
|
+
- **📦 内置配置**:默认包含`.prettierrc`(代码格式化)和`.gitignore`(文件忽略)。
|
|
19
21
|
|
|
20
|
-
##
|
|
22
|
+
## 快速开始
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
使用express最快的方式是利用可执行文件`express(1)`来生成一个应用,如下所示:
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
创建应用:
|
|
25
27
|
|
|
26
28
|
```bash
|
|
27
29
|
$ npx clwy-express-generator --view=ejs --es6 es6-demo && cd es6-demo
|
|
28
30
|
```
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
安装依赖:
|
|
31
33
|
|
|
32
34
|
```bash
|
|
33
35
|
$ npm install
|
|
34
36
|
```
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
在 `http://localhost:3000/` 启动您的 Express.js 应用:
|
|
37
39
|
|
|
38
40
|
```bash
|
|
39
41
|
$ npm start
|
|
40
42
|
```
|
|
41
43
|
|
|
42
|
-
##
|
|
44
|
+
## 命令行选项
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
此生成器还可以通过以下命令行标志进行进一步配置。
|
|
45
47
|
|
|
46
|
-
--version
|
|
47
|
-
-v, --view <engine>
|
|
48
|
-
--no-view
|
|
49
|
-
-c, --css <engine>
|
|
50
|
-
--git
|
|
51
|
-
--es6
|
|
52
|
-
-o, --orm
|
|
53
|
-
-f, --force
|
|
54
|
-
-h, --help
|
|
48
|
+
--version 输出版本号
|
|
49
|
+
-v, --view <engine> 添加视图引擎 <engine> 支持 (dust|ejs|hbs|hjs|pug|twig|vash|api)(默认为 ejs)
|
|
50
|
+
--no-view 使用静态html而不是视图引擎
|
|
51
|
+
-c, --css <engine> 添加样式表引擎 <engine> 支持 (less|stylus|compass|sass)(默认为纯 css)
|
|
52
|
+
--git 添加 .gitignore 文件
|
|
53
|
+
--es6 生成 ES6 代码和模块类型项目(需要Node 14.x或更高版本)
|
|
54
|
+
-o, --orm 使用 Prisma ORM
|
|
55
|
+
-f, --force 强制在非空目录上操作
|
|
56
|
+
-h, --help 输出使用信息
|
|
55
57
|
|
|
56
|
-
|
|
58
|
+
Forked from [express-generator](https://github.com/expressjs/generator), this project is a fork with some new features.
|
|
57
59
|
|
|
58
|
-
|
|
60
|
+
------------
|
|
59
61
|
|
|
60
|
-
##
|
|
62
|
+
## Features
|
|
61
63
|
|
|
62
|
-
- **🚀
|
|
63
|
-
- **🔀
|
|
64
|
-
- **📁
|
|
65
|
-
- **🔧
|
|
66
|
-
- **🔄
|
|
64
|
+
- **🚀 ES6 Support**: Modern and cleaner code.
|
|
65
|
+
- **🔀 Split Routes**: Separate files for easier management and maintenance.
|
|
66
|
+
- **📁 Modular Middleware**: Dedicated folder for middleware.
|
|
67
|
+
- **🔧 Environment Variables**: Easier multi-environment configuration.
|
|
68
|
+
- **🔄 Nodemon Integration**: Auto-restart during development.
|
|
69
|
+
- **📄 Added basic README.md**: Describes the project as a simple Express app with static file serving and basic routing.
|
|
70
|
+
- **📦 Built-in Configs**: Includes `.prettierrc` (code formatting) and `.gitignore` (file exclusion) by default.
|
|
67
71
|
|
|
68
|
-
##
|
|
72
|
+
## Quick Start
|
|
69
73
|
|
|
70
|
-
|
|
74
|
+
The quickest way to get started with express is to utilize the executable `express(1)` to generate an application as shown below:
|
|
71
75
|
|
|
72
|
-
|
|
76
|
+
Create the app:
|
|
73
77
|
|
|
74
78
|
```bash
|
|
75
79
|
$ npx clwy-express-generator --view=ejs --es6 es6-demo && cd es6-demo
|
|
76
80
|
```
|
|
77
81
|
|
|
78
|
-
|
|
82
|
+
Install dependencies:
|
|
79
83
|
|
|
80
84
|
```bash
|
|
81
85
|
$ npm install
|
|
82
86
|
```
|
|
83
87
|
|
|
84
|
-
|
|
88
|
+
Start your Express.js app at `http://localhost:3000/`:
|
|
85
89
|
|
|
86
90
|
```bash
|
|
87
91
|
$ npm start
|
|
88
92
|
```
|
|
89
93
|
|
|
90
|
-
##
|
|
94
|
+
## Command Line Options
|
|
91
95
|
|
|
92
|
-
|
|
96
|
+
This generator can also be further configured with the following command line flags.
|
|
93
97
|
|
|
94
|
-
--version
|
|
95
|
-
-v, --view <engine>
|
|
96
|
-
--no-view
|
|
97
|
-
-c, --css <engine>
|
|
98
|
-
--git
|
|
99
|
-
--es6
|
|
100
|
-
-o, --orm
|
|
101
|
-
-f, --force
|
|
102
|
-
-h, --help
|
|
98
|
+
--version output the version number
|
|
99
|
+
-v, --view <engine> add view <engine> support (dust|ejs|hbs|hjs|pug|twig|vash|api) (defaults to ejs)
|
|
100
|
+
--no-view use static html instead of view engine
|
|
101
|
+
-c, --css <engine> add stylesheet <engine> support (less|stylus|compass|sass) (defaults to plain css)
|
|
102
|
+
--git add .gitignore
|
|
103
|
+
--es6 generate ES6 code and module-type project (requires Node 14.x or higher)
|
|
104
|
+
-o, --orm use the Prisma ORM
|
|
105
|
+
-f, --force force on non-empty directory
|
|
106
|
+
-h, --help output usage information
|
|
107
|
+
|
|
108
|
+
------------
|
|
103
109
|
|
|
104
110
|
## License
|
|
105
111
|
|
package/bin/express-cli.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
const ejs = require('ejs')
|
|
4
|
+
const fs = require('fs')
|
|
5
|
+
const minimatch = require('minimatch')
|
|
6
|
+
const mkdirp = require('mkdirp')
|
|
7
|
+
const parseArgs = require('minimist')
|
|
8
|
+
const path = require('path')
|
|
9
|
+
const readline = require('readline')
|
|
10
|
+
const sortedObject = require('sorted-object')
|
|
11
|
+
const util = require('util')
|
|
12
|
+
|
|
13
|
+
const MODE_0666 = parseInt('0666', 8)
|
|
14
|
+
const MODE_0755 = parseInt('0755', 8)
|
|
15
|
+
const TEMPLATE_DIR = path.join(__dirname, '..', 'templates')
|
|
16
|
+
const VERSION = require('../package').version
|
|
17
|
+
const MIN_ES6_VERSION = 14
|
|
18
18
|
|
|
19
19
|
// parse args
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const unknown = []
|
|
21
|
+
const args = parseArgs(process.argv.slice(2), {
|
|
22
22
|
alias: {
|
|
23
23
|
c: 'css',
|
|
24
24
|
e: 'ejs',
|
|
@@ -48,7 +48,7 @@ main(args, exit)
|
|
|
48
48
|
*/
|
|
49
49
|
|
|
50
50
|
function confirm (msg, callback) {
|
|
51
|
-
|
|
51
|
+
const rl = readline.createInterface({
|
|
52
52
|
input: process.stdin,
|
|
53
53
|
output: process.stdout
|
|
54
54
|
})
|
|
@@ -92,12 +92,13 @@ function createApplication (name, dir, options, done) {
|
|
|
92
92
|
console.log()
|
|
93
93
|
|
|
94
94
|
// Package
|
|
95
|
-
|
|
95
|
+
const pkg = {
|
|
96
96
|
name: name,
|
|
97
97
|
version: '0.0.0',
|
|
98
98
|
private: true,
|
|
99
99
|
scripts: {
|
|
100
|
-
start: 'nodemon ./bin/www'
|
|
100
|
+
start: 'nodemon ./bin/www',
|
|
101
|
+
format: 'prettier --write "**/*.{js,json,md}"'
|
|
101
102
|
},
|
|
102
103
|
dependencies: {
|
|
103
104
|
debug: '~4.4.0',
|
|
@@ -105,7 +106,8 @@ function createApplication (name, dir, options, done) {
|
|
|
105
106
|
express: '~5.1.0'
|
|
106
107
|
},
|
|
107
108
|
devDependencies: {
|
|
108
|
-
nodemon: '^3.1.9'
|
|
109
|
+
nodemon: '^3.1.9',
|
|
110
|
+
prettier: '^3.5.3'
|
|
109
111
|
}
|
|
110
112
|
}
|
|
111
113
|
if (options.es6) {
|
|
@@ -113,9 +115,9 @@ function createApplication (name, dir, options, done) {
|
|
|
113
115
|
}
|
|
114
116
|
|
|
115
117
|
// JavaScript
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
const app = loadTemplate(options.es6 ? 'mjs/app.js' : 'js/app.js')
|
|
119
|
+
const www = loadTemplate(options.es6 ? 'mjs/www' : 'js/www')
|
|
120
|
+
const env = loadTemplate('env')
|
|
119
121
|
|
|
120
122
|
// App name
|
|
121
123
|
www.locals.name = name
|
|
@@ -138,7 +140,7 @@ function createApplication (name, dir, options, done) {
|
|
|
138
140
|
app.locals.uses.push('cookieParser()')
|
|
139
141
|
pkg.dependencies['cookie-parser'] = '~1.4.7'
|
|
140
142
|
|
|
141
|
-
// Env
|
|
143
|
+
// Env consts
|
|
142
144
|
env.locals.orm = options.orm
|
|
143
145
|
|
|
144
146
|
if (dir !== '.') {
|
|
@@ -171,6 +173,9 @@ function createApplication (name, dir, options, done) {
|
|
|
171
173
|
break
|
|
172
174
|
}
|
|
173
175
|
|
|
176
|
+
// copy Prettier templates
|
|
177
|
+
copyTemplate(options.es6 ? 'mjs/prettierrc.json' : 'js/prettierrc.json', path.join(dir, '.prettierrc.json'))
|
|
178
|
+
|
|
174
179
|
// copy config templates
|
|
175
180
|
mkdir(dir, 'config')
|
|
176
181
|
copyTemplateMulti(
|
|
@@ -287,9 +292,11 @@ function createApplication (name, dir, options, done) {
|
|
|
287
292
|
// Static files
|
|
288
293
|
app.locals.uses.push("express.static(path.join(__dirname, 'public'))")
|
|
289
294
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
295
|
+
// Git ignore file
|
|
296
|
+
copyTemplate('gitignore', path.join(dir, '.gitignore'))
|
|
297
|
+
|
|
298
|
+
// Git README file
|
|
299
|
+
copyTemplate('README.md', path.join(dir, 'README.md'))
|
|
293
300
|
|
|
294
301
|
// sort dependencies like npm(1)
|
|
295
302
|
pkg.dependencies = sortedObject(pkg.dependencies)
|
|
@@ -301,7 +308,7 @@ function createApplication (name, dir, options, done) {
|
|
|
301
308
|
write(path.join(dir, 'bin/www'), www.render(), MODE_0755)
|
|
302
309
|
write(path.join(dir, '.env'), env.render())
|
|
303
310
|
|
|
304
|
-
|
|
311
|
+
const prompt = launchedFromCmd() ? '>' : '$'
|
|
305
312
|
|
|
306
313
|
if (dir !== '.') {
|
|
307
314
|
console.log()
|
|
@@ -379,8 +386,8 @@ function exit (code) {
|
|
|
379
386
|
if (!(draining--)) process.exit(code)
|
|
380
387
|
}
|
|
381
388
|
|
|
382
|
-
|
|
383
|
-
|
|
389
|
+
let draining = 0
|
|
390
|
+
const streams = [process.stdout, process.stderr]
|
|
384
391
|
|
|
385
392
|
exit.exited = true
|
|
386
393
|
|
|
@@ -407,8 +414,8 @@ function launchedFromCmd () {
|
|
|
407
414
|
*/
|
|
408
415
|
|
|
409
416
|
function loadTemplate (name) {
|
|
410
|
-
|
|
411
|
-
|
|
417
|
+
const contents = fs.readFileSync(path.join(__dirname, '..', 'templates', (name + '.ejs')), 'utf-8')
|
|
418
|
+
const locals = Object.create(null)
|
|
412
419
|
|
|
413
420
|
function render () {
|
|
414
421
|
return ejs.render(contents, locals, {
|
|
@@ -453,10 +460,10 @@ function main (options, done) {
|
|
|
453
460
|
} else {
|
|
454
461
|
console.log(options.view)
|
|
455
462
|
// Path
|
|
456
|
-
|
|
463
|
+
const destinationPath = options._[0] || '.'
|
|
457
464
|
|
|
458
465
|
// App name
|
|
459
|
-
|
|
466
|
+
const appName = createAppName(path.resolve(destinationPath)) || 'hello-world'
|
|
460
467
|
|
|
461
468
|
// View engine
|
|
462
469
|
if (options.view === true) {
|
|
@@ -515,7 +522,7 @@ function main (options, done) {
|
|
|
515
522
|
*/
|
|
516
523
|
|
|
517
524
|
function mkdir (base, dir) {
|
|
518
|
-
|
|
525
|
+
const loc = path.join(base, dir)
|
|
519
526
|
|
|
520
527
|
console.log(' \x1b[36mcreate\x1b[0m : ' + loc + path.sep)
|
|
521
528
|
mkdirp.sync(loc, MODE_0755)
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "clwy-express-generator",
|
|
3
3
|
"description": "Express' application generator",
|
|
4
4
|
"homepage": "https://github.com/clwy-cn/clwy-express-generator",
|
|
5
|
-
"version": "5.0.
|
|
5
|
+
"version": "5.0.6",
|
|
6
6
|
"author": "TJ Holowaychuk <tj@vision-media.ca>",
|
|
7
7
|
"contributors": [
|
|
8
8
|
"Aaron Heckmann <aaron.heckmann+github@gmail.com>",
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Express Project
|
|
2
|
+
|
|
3
|
+
This project is a simple Express application that serves a static HTML file. It also includes a basic routing setup and a simple middleware function.
|
|
4
|
+
|
|
5
|
+
Install dependencies:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
$ npm install
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Start your Express.js app at `http://localhost:3000/`:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
$ npm start
|
|
15
|
+
```
|
package/templates/mjs/app.js.ejs
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import { fileURLToPath } from 'url'
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import { fileURLToPath } from 'url'
|
|
3
3
|
|
|
4
|
-
import express from 'express'
|
|
4
|
+
import express from 'express'
|
|
5
5
|
<% Object.keys(modules).sort().forEach(function (variable) { -%>
|
|
6
|
-
import <%- variable %> from '<%- modules[variable] %>'
|
|
7
|
-
<% })
|
|
6
|
+
import <%- variable %> from '<%- modules[variable] %>'
|
|
7
|
+
<% }) -%>
|
|
8
8
|
|
|
9
9
|
<% if (view) { -%>
|
|
10
|
-
import createError from 'http-errors'
|
|
11
|
-
import errorHandler from './middlewares/error-handler.js'
|
|
10
|
+
import createError from 'http-errors'
|
|
11
|
+
import errorHandler from './middlewares/error-handler.js'
|
|
12
12
|
<% } -%>
|
|
13
13
|
|
|
14
14
|
// environment variables
|
|
15
|
-
import 'dotenv/config'
|
|
16
|
-
import routes from './config/routes.js'
|
|
15
|
+
import 'dotenv/config'
|
|
16
|
+
import routes from './config/routes.js'
|
|
17
17
|
|
|
18
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
18
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
19
19
|
|
|
20
|
-
const app = express()
|
|
20
|
+
const app = express()
|
|
21
21
|
|
|
22
22
|
<% if (view) { -%>
|
|
23
23
|
// view engine setup
|
|
24
24
|
<% if (view.render) { -%>
|
|
25
|
-
app.engine('<%- view.engine %>', <%- view.render %>)
|
|
25
|
+
app.engine('<%- view.engine %>', <%- view.render %>)
|
|
26
26
|
<% } -%>
|
|
27
|
-
app.set('views', path.join(__dirname, 'views'))
|
|
28
|
-
app.set('view engine', '<%- view.engine %>')
|
|
27
|
+
app.set('views', path.join(__dirname, 'views'))
|
|
28
|
+
app.set('view engine', '<%- view.engine %>')
|
|
29
29
|
|
|
30
30
|
<% } -%>
|
|
31
31
|
<% uses.forEach(function (use) { -%>
|
|
32
|
-
app.use(<%- use %>)
|
|
33
|
-
<% })
|
|
32
|
+
app.use(<%- use %>)
|
|
33
|
+
<% }) -%>
|
|
34
34
|
|
|
35
35
|
// routes
|
|
36
|
-
app.use(routes)
|
|
36
|
+
app.use(routes)
|
|
37
37
|
|
|
38
38
|
<% if (view) { -%>
|
|
39
39
|
// catch 404 and forward to error handler
|
|
40
40
|
app.use((req, res, next) => {
|
|
41
|
-
next(createError(404))
|
|
42
|
-
})
|
|
41
|
+
next(createError(404))
|
|
42
|
+
})
|
|
43
43
|
|
|
44
44
|
// error handler
|
|
45
|
-
app.use(errorHandler)
|
|
45
|
+
app.use(errorHandler)
|
|
46
46
|
|
|
47
47
|
<% } -%>
|
|
48
|
-
export default app
|
|
48
|
+
export default app
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import express from 'express'
|
|
2
|
-
import indexRouter from '../routes/index.js'
|
|
3
|
-
import usersRouter from '../routes/users.js'
|
|
1
|
+
import express from 'express'
|
|
2
|
+
import indexRouter from '../routes/index.js'
|
|
3
|
+
import usersRouter from '../routes/users.js'
|
|
4
4
|
|
|
5
|
-
const router = express.Router()
|
|
5
|
+
const router = express.Router()
|
|
6
6
|
|
|
7
|
-
router.use('/', indexRouter)
|
|
8
|
-
router.use('/users', usersRouter)
|
|
7
|
+
router.use('/', indexRouter)
|
|
8
|
+
router.use('/users', usersRouter)
|
|
9
9
|
|
|
10
|
-
export default router
|
|
10
|
+
export default router
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
export default (err, req, res, next) => {
|
|
4
4
|
// set locals, only providing error in development
|
|
5
|
-
res.locals.message = err.message
|
|
6
|
-
res.locals.error = req.app.get('env') === 'development' ? err : {}
|
|
5
|
+
res.locals.message = err.message
|
|
6
|
+
res.locals.error = req.app.get('env') === 'development' ? err : {}
|
|
7
7
|
|
|
8
8
|
// render the error page
|
|
9
|
-
res.status(err.status || 500)
|
|
9
|
+
res.status(err.status || 500)
|
|
10
10
|
|
|
11
11
|
// if you want to use json, you can use res.json instead of res.render
|
|
12
12
|
// res.json({
|
|
13
13
|
// status: false,
|
|
14
14
|
// message: err.message
|
|
15
15
|
// });
|
|
16
|
-
res.render('error')
|
|
17
|
-
}
|
|
16
|
+
res.render('error')
|
|
17
|
+
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import express from 'express'
|
|
2
|
-
|
|
1
|
+
import express from 'express'
|
|
2
|
+
|
|
3
|
+
const router = express.Router()
|
|
3
4
|
|
|
4
5
|
/* GET home page. */
|
|
5
6
|
router.get('/', (req, res, next) => {
|
|
6
7
|
// if you want to use json, you can use res.json instead of res.render
|
|
7
8
|
// res.json({ title: 'Express' });
|
|
8
|
-
res.render('index', { title: 'Express' })
|
|
9
|
-
})
|
|
9
|
+
res.render('index', { title: 'Express' })
|
|
10
|
+
})
|
|
10
11
|
|
|
11
|
-
export default router
|
|
12
|
+
export default router
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import express from 'express'
|
|
2
|
-
|
|
1
|
+
import express from 'express'
|
|
2
|
+
|
|
3
|
+
const router = express.Router()
|
|
3
4
|
|
|
4
5
|
/* GET users listing. */
|
|
5
6
|
router.get('/', (req, res, next) => {
|
|
6
|
-
res.send('respond with a resource')
|
|
7
|
-
})
|
|
7
|
+
res.send('respond with a resource')
|
|
8
|
+
})
|
|
8
9
|
|
|
9
|
-
export default router
|
|
10
|
+
export default router
|
package/templates/mjs/www.ejs
CHANGED
|
@@ -4,51 +4,51 @@
|
|
|
4
4
|
* Module dependencies.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import http from 'http'
|
|
7
|
+
import http from 'http'
|
|
8
8
|
|
|
9
|
-
import app from '../app.js'
|
|
10
|
-
import debugFunction from 'debug'
|
|
11
|
-
const debug = debugFunction('<%- name %>:server')
|
|
9
|
+
import app from '../app.js'
|
|
10
|
+
import debugFunction from 'debug'
|
|
11
|
+
const debug = debugFunction('<%- name %>:server')
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Get port from environment and store in Express.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
const port = normalizePort(process.env.PORT || '3000')
|
|
18
|
-
app.set('port', port)
|
|
17
|
+
const port = normalizePort(process.env.PORT || '3000')
|
|
18
|
+
app.set('port', port)
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Create HTTP server.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
const server = http.createServer(app)
|
|
24
|
+
const server = http.createServer(app)
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Listen on provided port, on all network interfaces.
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
|
-
server.listen(port)
|
|
31
|
-
server.on('error', onError)
|
|
32
|
-
server.on('listening', onListening)
|
|
30
|
+
server.listen(port)
|
|
31
|
+
server.on('error', onError)
|
|
32
|
+
server.on('listening', onListening)
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* Normalize a port into a number, string, or false.
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
38
|
function normalizePort(val) {
|
|
39
|
-
const port = parseInt(val, 10)
|
|
39
|
+
const port = parseInt(val, 10)
|
|
40
40
|
|
|
41
41
|
if (isNaN(port)) {
|
|
42
42
|
// named pipe
|
|
43
|
-
return val
|
|
43
|
+
return val
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
if (port >= 0) {
|
|
47
47
|
// port number
|
|
48
|
-
return port
|
|
48
|
+
return port
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
return false
|
|
51
|
+
return false
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
@@ -57,25 +57,25 @@ function normalizePort(val) {
|
|
|
57
57
|
|
|
58
58
|
function onError(error) {
|
|
59
59
|
if (error.syscall !== 'listen') {
|
|
60
|
-
throw error
|
|
60
|
+
throw error
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
const bind = typeof port === 'string'
|
|
64
64
|
? 'Pipe ' + port
|
|
65
|
-
: 'Port ' + port
|
|
65
|
+
: 'Port ' + port
|
|
66
66
|
|
|
67
67
|
// handle specific listen errors with friendly messages
|
|
68
68
|
switch (error.code) {
|
|
69
69
|
case 'EACCES':
|
|
70
|
-
console.error(bind + ' requires elevated privileges')
|
|
71
|
-
process.exit(1)
|
|
72
|
-
break
|
|
70
|
+
console.error(bind + ' requires elevated privileges')
|
|
71
|
+
process.exit(1)
|
|
72
|
+
break
|
|
73
73
|
case 'EADDRINUSE':
|
|
74
|
-
console.error(bind + ' is already in use')
|
|
75
|
-
process.exit(1)
|
|
76
|
-
break
|
|
74
|
+
console.error(bind + ' is already in use')
|
|
75
|
+
process.exit(1)
|
|
76
|
+
break
|
|
77
77
|
default:
|
|
78
|
-
throw error
|
|
78
|
+
throw error
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -84,9 +84,9 @@ function onError(error) {
|
|
|
84
84
|
*/
|
|
85
85
|
|
|
86
86
|
function onListening() {
|
|
87
|
-
const addr = server.address()
|
|
87
|
+
const addr = server.address()
|
|
88
88
|
const bind = typeof addr === 'string'
|
|
89
89
|
? 'pipe ' + addr
|
|
90
|
-
: 'port ' + addr.port
|
|
91
|
-
debug('Listening on ' + bind)
|
|
90
|
+
: 'port ' + addr.port
|
|
91
|
+
debug('Listening on ' + bind)
|
|
92
92
|
}
|
package/templates/.env.ejs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
<% } -%>
|