-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntFile.js
98 lines (88 loc) · 2.22 KB
/
GruntFile.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
module.exports = function (grunt) {
// Load plugins
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-sync');
grunt.loadNpmTasks('grunt-bg-shell');
grunt.loadNpmTasks('grunt-contrib-watch');
// Init Config
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// CleanUp build
clean: {
buildFolder: ['dist'],
},
// Copy files
sync: {
assets: {
files: [{ cwd: 'src/assets', src: ['**'], dest: 'dist/assets/' }],
verbose: true,
failOnError: true,
updateAndDelete: true,
},
meta: {
files: [{ src: './package.json', dest: 'dist/meta.json' }],
},
templates: {
files: [{ cwd: 'src/assets/templates', src: ['**'], dest: 'dist/assets/templates/' }],
verbose: true,
failOnError: true,
updateAndDelete: true,
},
},
// NonGrunt watcher
bgShell: {
_defaults: {
bg: true,
},
// Typescript compiler
tsc: {
cmd: 'npx tsc -p tsconfig.build.json',
bg: false,
},
// Typescript compiler + watch
tscWatch: {
cmd: 'npx tsc -w -p tsconfig.build.json',
},
// Restart server
pm2: {
cmd: 'npx pm2 startOrRestart pm2.config.js',
bg: false,
},
// Restart server
pm2Prod: {
cmd: 'npx pm2 startOrRestart pm2.config.js --env production',
bg: false,
},
},
// Watch for file changes
watch: {
templates: {
files: 'src/assets/template/**/*',
tasks: ['sync:assets'],
},
},
});
grunt.event.on('watch', function (action, filepath, target) {
grunt.log.writeln(target + ': ' + filepath + ' has ' + action);
});
// Register tasks
grunt.registerTask('default', [
'clean:buildFolder',
'bgShell:tsc',
'sync:assets',
'sync:meta',
'bgShell:tscWatch',
'bgShell:pm2',
'watch',
]);
grunt.registerTask('production', [
'clean:buildFolder',
'bgShell:tsc',
'sync:assets',
'sync:meta',
'bgShell:tscWatch',
'bgShell:pm2Prod',
'watch',
]);
grunt.registerTask('build', ['clean:buildFolder', 'sync:assets', 'sync:meta', 'bgShell:parsLocales', 'bgShell:tsc']);
};