Add missing `license` element in `package.xsd`
[GitHub/WoltLab/WCF.git] / extra / _buildExternal.js
1 const childProcess = require("child_process");
2 const compiler = require("./compiler");
3 const fs = require("fs");
4 const path = require("path");
5
6 if (process.argv.length !== 3) {
7 throw new Error("Requires the path to an existing repository.");
8 }
9
10 const repository = process.argv[2];
11 if (!fs.existsSync(repository)) {
12 throw new Error(`Unable to locate repsitory, the path ${repository} is invalid.`);
13 }
14 process.chdir(repository);
15
16 let rjsPaths = [];
17
18 // get all directories at the repository root
19 fs.readdirSync("./")
20 .filter(directory => fs.statSync(directory).isDirectory())
21 .forEach(directory => {
22 // look for a generic `js` directory
23 let path = `./${directory}/js/`;
24 if (fs.existsSync(path)) {
25 fs.readdirSync(path)
26 .filter(filename => {
27 // ignore build configurations
28 if (filename === "require.build.js") {
29 if (rjsPaths.indexOf(path) === -1) rjsPaths.push(path);
30
31 return false;
32 }
33
34 let stat = fs.statSync(path + filename);
35 // allow only non-minified *.js files
36 if (stat.isFile() && !stat.isSymbolicLink() && filename.match(/\.js$/) && !filename.match(/\.min\.js$/)) {
37 return true;
38 }
39
40 return false;
41 })
42 .forEach(filename => {
43 [true, false].forEach(COMPILER_TARGET_DEFAULT => {
44 let outFilename = filename.replace(/\.js$/, (COMPILER_TARGET_DEFAULT ? "" : ".tiny") + ".min.js");
45 console.time(outFilename);
46 {
47 let output = compiler.compile(path + filename, {
48 compress: {
49 global_defs: {
50 COMPILER_TARGET_DEFAULT: COMPILER_TARGET_DEFAULT
51 }
52 }
53 });
54
55 fs.writeFileSync(path + outFilename, output.code);
56 }
57 console.timeEnd(outFilename);
58 });
59 });
60 }
61 });
62
63 const rjsCmd = (process.platform === "win32") ? "r.js.cmd" : "r.js";
64 rjsPaths.forEach(path => {
65 let buildConfig = `${path}require.build.js`;
66 let outFilename = require(process.cwd() + `/${buildConfig}`).out;
67
68 [true, false].forEach(COMPILER_TARGET_DEFAULT => {
69 let overrides = "uglify2.compress.global_defs.COMPILER_TARGET_DEFAULT=" + (COMPILER_TARGET_DEFAULT ? "true" : "false");
70 if (!COMPILER_TARGET_DEFAULT) {
71 outFilename = outFilename.replace(/\.min\.js$/, '.tiny.min.js');
72 overrides += " out=" + outFilename;
73 }
74
75 console.time(outFilename);
76 childProcess.execSync(`${rjsCmd} -o require.build.js ${overrides}`, {
77 cwd: path,
78 stdio: [0, 1, 2]
79 });
80 console.timeEnd(outFilename);
81 });
82 });