forked from NodeBB/NodeBB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
107 lines (91 loc) · 2.55 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
99
100
101
102
103
104
105
106
107
"use strict";
var fork = require('child_process').fork,
env = process.env,
worker,
incomplete = [];
module.exports = function(grunt) {
var args = [];
if (!grunt.option('verbose')) {
args.push('--log-level=info');
}
function update(action, filepath, target) {
var updateArgs = args.slice(),
fromFile = '',
compiling = '',
time = Date.now();
if (target === 'lessUpdated_Client') {
fromFile = ['js', 'tpl', 'acpLess'];
compiling = 'clientLess';
} else if (target === 'lessUpdated_Admin') {
fromFile = ['js', 'tpl', 'clientLess'];
compiling = 'acpLess';
} else if (target === 'clientUpdated') {
fromFile = ['clientLess', 'acpLess', 'tpl'];
compiling = 'js';
} else if (target === 'templatesUpdated') {
fromFile = ['js', 'clientLess', 'acpLess'];
compiling = 'tpl';
} else if (target === 'serverUpdated') {
fromFile = ['clientLess', 'acpLess', 'js', 'tpl'];
}
fromFile = fromFile.filter(function(ext) {
return incomplete.indexOf(ext) === -1;
});
updateArgs.push('--from-file=' + fromFile.join(','));
incomplete.push(compiling);
worker.kill();
worker = fork('app.js', updateArgs, { env: env });
worker.on('message', function() {
if (incomplete.length) {
incomplete = [];
if (grunt.option('verbose')) {
grunt.log.writeln('NodeBB restarted in ' + (Date.now() - time) + ' ms');
}
}
});
}
grunt.initConfig({
watch: {
lessUpdated_Client: {
files: [
'public/*.less',
'node_modules/nodebb-*/*.less', 'node_modules/nodebb-*/**/*.less',
'!node_modules/nodebb-*/node_modules/**',
'!node_modules/nodebb-*/.git/**'
]
},
lessUpdated_Admin: {
files: ['public/**/*.less']
},
clientUpdated: {
files: [
'public/src/**/*.js',
'node_modules/nodebb-*/*.js', 'node_modules/nodebb-*/**/*.js',
'!node_modules/nodebb-*/node_modules/**',
'node_modules/templates.js/lib/templates.js',
'!node_modules/nodebb-*/.git/**'
]
},
serverUpdated: {
files: ['*.js', 'install/*.js', 'src/**/*.js']
},
templatesUpdated: {
files: [
'src/views/**/*.tpl',
'node_modules/nodebb-*/*.tpl', 'node_modules/nodebb-*/**/*.tpl',
'!node_modules/nodebb-*/node_modules/**',
'!node_modules/nodebb-*/.git/**'
]
}
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
if (grunt.option('skip')) {
grunt.registerTask('default', ['watch:serverUpdated']);
} else {
grunt.registerTask('default', ['watch']);
}
env.NODE_ENV = 'development';
worker = fork('app.js', args, { env: env });
grunt.event.on('watch', update);
};