-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathgulpfile.js
78 lines (73 loc) · 1.95 KB
/
gulpfile.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
require('@babel/register')
require('@babel/polyfill')
const gulp = require('gulp')
const nodemon = require('gulp-nodemon')
const rename = require('gulp-rename')
const nunjucksRender = require('gulp-nunjucks-render')
const codeGenerate = require('./templates/generate')
const migrate = require('./migration')
var jsScript = 'node'
if (process.env.npm_config_argv !== undefined && process.env.npm_config_argv.indexOf('debug') > 0) {
jsScript = 'node debug'
}
gulp.task('nodemon', function () {
return nodemon({
script: 'build/dev-server.js',
execMap: {
js: jsScript
},
verbose: true,
ignore: ['build/*.js', 'dist/*.js', 'nodemon.json', '.git', 'node_modules/**/node_modules', 'gulpfile.js', 'src/db', 'codeGenerate'],
env: {
NODE_ENV: 'development'
},
ext: 'js json'
})
})
const ServerFullPath = require('./package.json').ServerFullPath;
const FrontendFullPath = require('./package.json').FrontendFullPath;
const nunjucksRenderConfig = {
path: 'templates/server',
envOptions: {
tags: {
blockStart: '<%',
blockEnd: '%>',
variableStart: '<$',
variableEnd: '$>',
commentStart: '<#',
commentEnd: '#>'
},
},
ext: '.js',
ServerFullPath,
FrontendFullPath
}
gulp.task('code', function() {
require('events').EventEmitter.defaultMaxListeners = 0
return codeGenerate.run(gulp, nunjucksRender, rename, nunjucksRenderConfig)
})
gulp.task('migrate', async function(cb) {
let options = process.argv[4]
if (options) {
options = JSON.parse(options)
}
let modules = []
for (let module of options) {
let s = module.split(':')
modules.push({
entity: s[0],
keys: s[1] ? s[1].split(',') : []
})
}
await migrate(modules, cb)
})
gulp.task('add', async function(cb) {
let options = process.argv[4].split('|')
if (options.length === 1) {
options[1] = 'new_api'
}
if (options.length === 2) {
options[2] = options[1]
}
await codeGenerate.quickAdd(options, nunjucksRenderConfig)
})