forked from LimeSurvey/LimeSurvey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildVueComponents.js
297 lines (269 loc) · 14.6 KB
/
buildVueComponents.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/**
=============================================================================================
|| .____ .__ _________ ||
|| | | |__| _____ ____ / _____/__ ____________ __ ____ ___.__. ||
|| | | | |/ \_/ __ \ \_____ \| | \_ __ \ \/ // __ < | | ||
|| | |___| | Y Y \ ___/ / \ | /| | \/\ /\ ___/\___ | ||
|| |_______ \__|__|_| /\___ >_______ /____/ |__| \_/ \___ > ____| ||
|| \/ \/ \/ \/ \/\/ ||
|| ................................................................................. ||
|| __ __ _____ _ _ ||
|| \ \ / / / ____| (_) | ||
|| \ \ / / _ ___ ______| | ___ _ __ ___ _ __ _| | ___ _ __ ||
|| \ \/ / | | |/ _ \______| | / _ \| '_ ` _ \| '_ \| | |/ _ \ '__| ||
|| \ /| |_| | __/ | |___| (_) | | | | | | |_) | | | __/ | ||
|| \/ \__,_|\___| \_____\___/|_| |_| |_| .__/|_|_|\___|_| ||
|| | | ||
|| |_| ||
=============================================================================================
*
* This file can be run with nodejs on the commandline
* Example `node buildVueComponents.js´
*
* It will descent into every buildable component, run yarn to get the dependencies and start the build process.
* The full runtime will take around 1 Minute.
*
* It needs as well a current nodejs (LTS preferred) as also the yarn package manager installed.
*
*/
const { spawn, execSync } = require('child_process');
const path = require('path');
const fs = require('fs');
const args = process.argv.slice(2)
const isWin = process.platform === "win32";
const yarnInstalled = execSync((isWin ? 'where.exe yarn' : 'which yarn'), {encoding: 'utf8'});
if(yarnInstalled.split('\n').length < 1 ) {
console.log("=".repeat(100));
console.error("ERROR: yarn is not installed");
console.log(`
LimeSurvey uses the yarn package manager to build and manage dependancies.
To get it please visit 'https://yarnpkg.com/lang/en/' and follow the installation instructions.
----
If you have installed yarn, check your PATH, or restart the console.
`);
console.log("=".repeat(100));
process.exit(1);
}
const all = args.includes('-a');
const single = args.includes('-s');
const verbose = args.includes('-v');
const prepareOnly = args.includes('-p');
const runTests = args.includes('-t');
const noReleaseBuild = args.includes('-d');
if(!all && !single) {
console.log(`
=============================================================================================
|| .____ .__ _________ ||
|| | | |__| _____ ____ / _____/__ ____________ __ ____ ___.__. ||
|| | | | |/ \\_/ __ \\ \\_____ \\| | \\_ __ \\ \\/ // __ < | | ||
|| | |___| | Y Y \\ ___/ / \\ | /| | \\/\\ /\\ ___/\\___ | ||
|| |_______ \\__|__|_| /\\___ >_______ /____/ |__| \\_/ \\___ > ____| ||
|| \\/ \\/ \\/ \\/ \\/\\/ ||
|| ................................................................................. ||
|| __ __ _____ _ _ ||
|| \\ \\ / / / ____| (_) | ||
|| \\ \\ / / _ ___ ______| | ___ _ __ ___ _ __ _| | ___ _ __ ||
|| \\ \\/ / | | |/ _ \\______| | / _ \\| '_ \` _ \\| '_ \\| | |/ _ \\ '__| ||
|| \\ /| |_| | __/ | |___| (_) | | | | | | |_) | | | __/ | ||
|| \\/ \\__,_|\\___| \\_____\\___/|_| |_| |_| .__/|_|_|\\___|_| ||
|| | | ||
|| |_| ||
=============================================================================================
|| Usage : ||
|| Either use '-a' to build all components ||
|| Or use '-s [componentname[, componentname]]' to build specific component(s) ||
|| Use '-s' without component name to get a list of possible components ||
|| ||
|| Options: ||
|| -v -> Verbose mode, show all build processes ||
|| -p -> Only prepare (install dependencies) ||
|| -d -> build only the development part ||
|| -t -> run the tests instead of building ||
|| ||
=============================================================================================
`);
process.exit(0);
}
const processDate = (date) => {
const D = String(date.getDay()).padStart(2,'0');
const M = String(date.getMonth()).padStart(2,'0');
const Y = date.getFullYear();
const h = String(date.getHours()).padStart(2,'0');
const m = String(date.getMinutes()).padStart(2,'0');
const s = String(date.getSeconds()).padStart(2,'0');
return `${Y}-${M}-${D} ${h}:${m}:${s}`;
}
const runGetDependenciesInFolder = function (folder) {
return new Promise((resolve, reject) => {
console.log(`|| === Descending into ${folder} and running 'yarn'`);
const fullPath = folder; //path.normalize(folder);
const command = spawn('yarn', [] , {cwd:fullPath, shell:true, stdio: [ 'pipe', (verbose ? process.stdout : 'ignore'), process.stderr ]});
command.on('error', (err) => {
console.log(err);
reject();
})
command.on('close', (code) => {
console.log("|| === Successfully prepared.\n"+"".repeat(32));
resolve(folder);
});
});
};
const runBuildFolder = function (folder) {
return new Promise((resolve, reject) => {
console.log(`|| === Descending into ${folder} and running 'yarn ${(noReleaseBuild ? 'run dev' : 'build')}'`);
const fullPath = folder; //path.normalize(folder);
const command = spawn('yarn', [(noReleaseBuild ? 'run dev' : 'build')], {cwd:fullPath, shell:true, stdio: [ 'pipe', (verbose ? process.stdout : 'ignore'), process.stderr ]});
command.on('error', (err) => {
console.log(err);
reject();
})
command.on('close', (code) => {
console.log("|| === Successfully built.\n"+"".repeat(32));
resolve();
});
});
};
const runTestFolder = function (folder) {
return new Promise((resolve, reject) => {
console.log(`|| === Descending into ${folder} and running 'yarn run test'`);
const fullPath = folder; //path.normalize(folder);
const command = spawn('yarn', ['run test'], {cwd:fullPath, shell:true, stdio: [ 'pipe', process.stdout , process.stderr ]});
command.on('error', (err) => {
console.log(err);
reject();
})
command.on('close', (code) => {
console.log("|| === Test and coverage ran.\n"+"".repeat(32));
resolve();
});
});
};
const runBuild = function() {
const startTime = new Date();
const ckEditorUsersArray = [
['datasecuritysettings', 'assets/packages/datasecuritysettings/'],
['emailtemplates', 'assets/packages/emailtemplates/'],
['questioneditor', 'assets/packages/questioneditor/'],
['questiongroup', 'assets/packages/questiongroup/'],
['panelintegration', 'assets/packages/questiongroup/'],
['textelements', 'assets/packages/textelements/'],
];
const pathArray = [
['adminbasics', 'assets/packages/adminbasics/'],
['adminsidepanel', 'assets/packages/adminsidepanel/'],
['admintoppanel', 'assets/packages/admintoppanel/'],
['datasecuritysettings', 'assets/packages/datasecuritysettings/'],
['emailtemplates', 'assets/packages/emailtemplates/'],
['embeddables', 'assets/packages/embeddables/'],
['filemanager', 'assets/packages/filemanager/'],
['lstutorial', 'assets/packages/lstutorial/'],
['panelintegration', 'assets/packages/panelintegration/'],
['questioneditor', 'assets/packages/questioneditor/'],
['questiongroup', 'assets/packages/questiongroup/'],
['textelements', 'assets/packages/textelements/'],
];
console.log(`
=============================================================================================
|| .____ .__ _________ ||
|| | | |__| _____ ____ / _____/__ ____________ __ ____ ___.__. ||
|| | | | |/ \\_/ __ \\ \\_____ \\| | \\_ __ \\ \\/ // __ < | | ||
|| | |___| | Y Y \\ ___/ / \\ | /| | \\/\\ /\\ ___/\\___ | ||
|| |_______ \\__|__|_| /\\___ >_______ /____/ |__| \\_/ \\___ > ____| ||
|| \\/ \\/ \\/ \\/ \\/\\/ ||
|| ................................................................................. ||
|| __ __ _____ _ _ ||
|| \\ \\ / / / ____| (_) | ||
|| \\ \\ / / _ ___ ______| | ___ _ __ ___ _ __ _| | ___ _ __ ||
|| \\ \\/ / | | |/ _ \\______| | / _ \\| '_ \` _ \\| '_ \\| | |/ _ \\ '__| ||
|| \\ /| |_| | __/ | |___| (_) | | | | | | |_) | | | __/ | ||
|| \\/ \\__,_|\\___| \\_____\\___/|_| |_| |_| .__/|_|_|\\___|_| ||
|| | | ||
|| |_| ||
=============================================================================================
`);
if(!single) {
console.log(`
|| === Starting to ${(prepareOnly ? 'prepare' : 'compile')} the components ${(verbose ? 'and using verbose mode.' : '.')}
|| === Starting time: ${processDate(new Date)}`);
const finalPromise = pathArray.reduce(
async (promise, item) => {
try{
await promise;
} catch(e) { throw e; }
console.log(`=====| ${(prepareOnly ? 'Preparing' : 'Building' )} ${item[0]} |====`);
if(prepareOnly) {
return runGetDependenciesInFolder(item[1]);
} else {
return runGetDependenciesInFolder(item[1]).then(runTests ? runTestFolder : runBuildFolder);
}
},
Promise.all([
runGetDependenciesInFolder('assets/packages/meta/LSRTLPlugin')
])
);
finalPromise.then(()=> {
const endTime = new Date();
const difference = endTime - startTime;
const minutes = String((difference*1000*60)%60).padStart(2,'0');
const seconds = String((difference*1000)%60).padStart(2,'0');
const milliseconds = String(difference%1000).padStart(4,'0');
if(verbose) {
console.log(`|| === Started at ${startTime.toLocaleTimeString('de-DE')}`);
console.log(`|| === Ended at ${endTime.toLocaleTimeString('de-DE')}`);
console.log(`|| === Total milliseconds ${difference}`);
}
console.log(`|| === All build in ${minutes}:${seconds}.${milliseconds}`);
});
} else {
const getSPosition = args.indexOf('-s');
const componentsToBuild = args[getSPosition+1].split(',');
let componentToBuildArray = [];
if(componentsToBuild[0] == 'ckeditorrebuild') {
componentToBuildArray = ckEditorUsersArray;
} else {
componentToBuildArray = pathArray.filter((item) => { return componentsToBuild.indexOf(item[0]) > -1; });
}
if(componentToBuildArray.array == 0 || componentsToBuild == undefined) {
console.error("|| === Component not found or ambiguous, possible options are:")
pathArray.forEach((item) => {
console.log(`|| => ${item[0]}, (${item[1]})`);
});
process.exit(1);
}
console.log(`
|| === Starting to ${(prepareOnly ? 'prepare' : 'compile')} the component(s) ${JSON.stringify(componentsToBuild)}${(verbose ? ' and using verbose mode.' : '.')}
|| === Starting time: ${processDate(new Date)}`);
const finalPromise = componentToBuildArray.reduce(
async (promise, item) => {
try{
await promise;
} catch(e) { throw e; }
console.log(`=====| ${(prepareOnly ? 'Preparing' : 'Building' )} ${item[0]} |====`);
if(prepareOnly) {
return runGetDependenciesInFolder(item[1]);
} else {
return runGetDependenciesInFolder(item[1]).then(runTests ? runTestFolder : runBuildFolder);
}
},
Promise.all([
runGetDependenciesInFolder('assets/packages/meta/LSRTLPlugin')
])
);
finalPromise.then(()=> {
const endTime = new Date();
const difference = endTime - startTime;
const minutes = String(Math.floor(difference/1000/60)%60).padStart(2,'0');
const seconds = String(Math.floor(difference/1000)%60).padStart(2,'0');
const milliseconds = String(difference%1000).padStart(4,'0');
if(verbose) {
console.log(`|| === Started at ${startTime.toLocaleTimeString('de-DE')}`);
console.log(`|| === Ended at ${endTime.toLocaleTimeString('de-DE')}`);
console.log(`|| === Total milliseconds ${difference}`);
}
console.log(`
|| === All build in ${minutes}:${seconds}.${milliseconds}
|| === Finished at: ${processDate(new Date)}`);
});
}
};
runBuild();