forked from w3tecch/express-typescript-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package-scripts.js
279 lines (271 loc) · 8.58 KB
/
package-scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/**
* Windows: Please do not use trailing comma as windows will fail with token error
*/
const { series, crossEnv, concurrent, rimraf, runInNewWindow } = require('nps-utils');
module.exports = {
scripts: {
default: 'nps start',
/**
* Starts the builded app from the dist directory
*/
start: {
script: 'node dist/app.js',
description: 'Starts the builded app from the dist directory'
},
/**
* Serves the current app and watches for changes to restart it
*/
serve: {
script: series(
'nps banner.serve',
'nodemon --watch src --watch .env'
),
description: 'Serves the current app and watches for changes to restart it'
},
/**
* Setup of the development environment
*/
setup: {
script: series(
'yarn install',
'nps db.drop',
'nps db.migrate',
'nps db.seed'
),
description: 'Setup`s the development environment(yarn & database)'
},
/**
* Creates the needed configuration files
*/
config: {
script: series(
runFast('./commands/tsconfig.ts'),
runFast('./commands/ormconfig.ts')
),
hiddenFromHelp: true
},
/**
* Builds the app into the dist directory
*/
build: {
script: series(
'nps banner.build',
'nps config',
'nps lint',
'nps clean.dist',
'nps transpile',
'nps copy'
),
description: 'Builds the app into the dist directory'
},
/**
* Runs TSLint over your project
*/
lint: {
script: tslint(`./src/**/*.ts`),
hiddenFromHelp: true
},
/**
* Transpile your app into javascript
*/
transpile: {
script: `tsc --project ./tsconfig.build.json`,
hiddenFromHelp: true
},
/**
* Clean files and folders
*/
clean: {
default: {
script: series(
`nps banner.clean`,
`nps clean.dist`
),
description: 'Deletes the ./dist folder'
},
dist: {
script: rimraf('./dist'),
hiddenFromHelp: true
}
},
/**
* Copies static files to the build folder
*/
copy: {
default: {
script: series(
`nps copy.swagger`,
`nps copy.public`
),
hiddenFromHelp: true
},
swagger: {
script: copy(
'./src/api/swagger.json',
'./dist'
),
hiddenFromHelp: true
},
public: {
script: copy(
'./src/public/*',
'./dist'
),
hiddenFromHelp: true
}
},
/**
* Database scripts
*/
db: {
migrate: {
script: series(
'nps banner.migrate',
'nps config',
runFast('./node_modules/typeorm/cli.js migration:run')
),
description: 'Migrates the database to newest version available'
},
revert: {
script: series(
'nps banner.revert',
'nps config',
runFast('./node_modules/typeorm/cli.js migration:revert')
),
description: 'Downgrades the database'
},
seed: {
script: series(
'nps banner.seed',
'nps config',
runFast('./src/lib/seed/cli.ts')
),
description: 'Seeds generated records into the database'
},
drop: {
script: runFast('./node_modules/typeorm/cli.js schema:drop'),
description: 'Drops the schema of the database'
}
},
/**
* These run various kinds of tests. Default is unit.
*/
test: {
default: 'nps test.unit',
unit: {
default: {
script: series(
'nps banner.testUnit',
'nps test.unit.pretest',
'nps test.unit.run'
),
description: 'Runs the unit tests'
},
pretest: {
script: tslint(`./test/unit/**.ts`),
hiddenFromHelp: true
},
run: {
script: 'cross-env NODE_ENV=test jest --testPathPattern=unit',
hiddenFromHelp: true
},
verbose: {
script: 'nps "test --verbose"',
hiddenFromHelp: true
},
coverage: {
script: 'nps "test --coverage"',
hiddenFromHelp: true
}
},
integration: {
default: {
script: series(
'nps banner.testIntegration',
'nps test.integration.pretest',
'nps test.integration.run'
),
description: 'Runs the integration tests'
},
pretest: {
script: tslint(`./test/integration/**.ts`),
hiddenFromHelp: true
},
run: {
// -i. Run all tests serially in the current process, rather than creating a worker pool of child processes that run tests. This can be useful for debugging.
script: 'cross-env NODE_ENV=test jest --testPathPattern=integration -i',
hiddenFromHelp: true
},
verbose: {
script: 'nps "test --verbose"',
hiddenFromHelp: true
},
coverage: {
script: 'nps "test --coverage"',
hiddenFromHelp: true
}
},
e2e: {
default: {
script: series(
'nps banner.testE2E',
'nps test.e2e.pretest',
'nps test.e2e.run'
),
description: 'Runs the e2e tests'
},
pretest: {
script: tslint(`./test/e2e/**.ts`),
hiddenFromHelp: true
},
run: {
// -i. Run all tests serially in the current process, rather than creating a worker pool of child processes that run tests. This can be useful for debugging.
script: 'cross-env NODE_ENV=test jest --testPathPattern=e2e -i',
hiddenFromHelp: true
},
verbose: {
script: 'nps "test --verbose"',
hiddenFromHelp: true
},
coverage: {
script: 'nps "test --coverage"',
hiddenFromHelp: true
}
},
},
/**
* This creates pretty banner to the terminal
*/
banner: {
build: banner('build'),
serve: banner('serve'),
testUnit: banner('test.unit'),
testIntegration: banner('test.integration'),
testE2E: banner('test.e2e'),
migrate: banner('migrate'),
seed: banner('seed'),
revert: banner('revert'),
clean: banner('clean')
}
}
};
function banner(name) {
return {
hiddenFromHelp: true,
silent: true,
description: `Shows ${name} banners to the console`,
script: runFast(`./commands/banner.ts ${name}`),
};
}
function copy(source, target) {
return `copyup ${source} ${target}`;
}
function run(path) {
return `ts-node ${path}`;
}
function runFast(path) {
return `ts-node --transpileOnly ${path}`;
}
function tslint(path) {
return `tslint -c ./tslint.json ${path} --format stylish`;
}