forked from NodeBB/NodeBB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
216 lines (189 loc) · 5.03 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
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
'use strict';
const path = require('path');
const nconf = require('nconf');
nconf.argv().env({
separator: '__',
});
const winston = require('winston');
const { fork } = require('child_process');
const { env } = process;
let worker;
env.NODE_ENV = env.NODE_ENV || 'development';
const configFile = path.resolve(__dirname, nconf.any(['config', 'CONFIG']) || 'config.json');
const prestart = require('./src/prestart');
prestart.loadConfig(configFile);
const db = require('./src/database');
module.exports = function (grunt) {
const args = [];
if (!grunt.option('verbose')) {
args.push('--log-level=info');
nconf.set('log-level', 'info');
}
prestart.setupWinston();
grunt.initConfig({
watch: {},
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['watch']);
grunt.registerTask('init', async function () {
const done = this.async();
let plugins = [];
if (!process.argv.includes('--core')) {
await db.init();
plugins = await db.getSortedSetRange('plugins:active', 0, -1);
addBaseThemes(plugins);
if (!plugins.includes('nodebb-plugin-composer-default')) {
plugins.push('nodebb-plugin-composer-default');
}
if (!plugins.includes('nodebb-theme-persona')) {
plugins.push('nodebb-theme-persona');
}
}
const styleUpdated_Client = plugins.map(p => `node_modules/${p}/*.less`)
.concat(plugins.map(p => `node_modules/${p}/*.css`))
.concat(plugins.map(p => `node_modules/${p}/+(public|static|less)/**/*.less`))
.concat(plugins.map(p => `node_modules/${p}/+(public|static)/**/*.css`));
const styleUpdated_Admin = plugins.map(p => `node_modules/${p}/*.less`)
.concat(plugins.map(p => `node_modules/${p}/*.css`))
.concat(plugins.map(p => `node_modules/${p}/+(public|static|less)/**/*.less`))
.concat(plugins.map(p => `node_modules/${p}/+(public|static)/**/*.css`));
const clientUpdated = plugins.map(p => `node_modules/${p}/+(public|static)/**/*.js`);
const serverUpdated = plugins.map(p => `node_modules/${p}/*.js`)
.concat(plugins.map(p => `node_modules/${p}/+(lib|src)/**/*.js`));
const templatesUpdated = plugins.map(p => `node_modules/${p}/+(public|static|templates)/**/*.tpl`);
const langUpdated = plugins.map(p => `node_modules/${p}/+(public|static|languages)/**/*.json`);
grunt.config(['watch'], {
styleUpdated_Client: {
files: [
'public/less/**/*.less',
...styleUpdated_Client,
],
options: {
interval: 1000,
},
},
styleUpdated_Admin: {
files: [
'public/less/**/*.less',
...styleUpdated_Admin,
],
options: {
interval: 1000,
},
},
clientUpdated: {
files: [
'public/src/**/*.js',
'public/vendor/**/*.js',
...clientUpdated,
'node_modules/benchpressjs/build/benchpress.js',
],
options: {
interval: 1000,
},
},
serverUpdated: {
files: [
'app.js',
'install/*.js',
'src/**/*.js',
'public/src/modules/translator.js',
'public/src/modules/helpers.js',
'public/src/utils.js',
serverUpdated,
'!src/upgrades/**',
],
options: {
interval: 1000,
},
},
templatesUpdated: {
files: [
'src/views/**/*.tpl',
...templatesUpdated,
],
options: {
interval: 1000,
},
},
langUpdated: {
files: [
'public/language/en-GB/*.json',
'public/language/en-GB/**/*.json',
...langUpdated,
],
options: {
interval: 1000,
},
},
});
const build = require('./src/meta/build');
if (!grunt.option('skip')) {
await build.build(true);
}
run();
done();
});
function run() {
if (worker) {
worker.kill();
}
const execArgv = [];
const inspect = process.argv.find(a => a.startsWith('--inspect'));
if (inspect) {
execArgv.push(inspect);
}
worker = fork('app.js', args, {
env,
execArgv,
});
}
grunt.task.run('init');
grunt.event.removeAllListeners('watch');
grunt.event.on('watch', (action, filepath, target) => {
let compiling;
if (target === 'styleUpdated_Client') {
compiling = 'clientCSS';
} else if (target === 'styleUpdated_Admin') {
compiling = 'acpCSS';
} else if (target === 'clientUpdated') {
compiling = 'js';
} else if (target === 'templatesUpdated') {
compiling = 'tpl';
} else if (target === 'langUpdated') {
compiling = 'lang';
} else if (target === 'serverUpdated') {
// empty require cache
const paths = ['./src/meta/build.js', './src/meta/index.js'];
paths.forEach(p => delete require.cache[require.resolve(p)]);
return run();
}
require('./src/meta/build').build([compiling], (err) => {
if (err) {
winston.error(err.stack);
}
if (worker) {
worker.send({ compiling: compiling });
}
});
});
};
function addBaseThemes(plugins) {
let themeId = plugins.find(p => p.includes('nodebb-theme-'));
if (!themeId) {
return plugins;
}
let baseTheme;
do {
try {
baseTheme = require(`${themeId}/theme`).baseTheme;
} catch (err) {
console.log(err);
}
if (baseTheme) {
plugins.push(baseTheme);
themeId = baseTheme;
}
} while (baseTheme);
return plugins;
}