Commit | Line | Data |
---|---|---|
5480a636 AE |
1 | const childProcess = require("child_process"); |
2 | const compiler = require("./compiler"); | |
3 | const fs = require("fs"); | |
4 | ||
5 | function compile(destination, files, overrides) { | |
6 | let minifiedData = []; | |
7 | ||
8 | files.forEach(filename => { | |
9 | minifiedData.push({ | |
10 | filename: filename, | |
11 | content: compiler.compile(filename, overrides) | |
12 | }); | |
13 | }); | |
14 | ||
15 | let content = `// ${destination} -- DO NOT EDIT\n\n`; | |
16 | ||
17 | minifiedData.forEach(fileData => { | |
18 | content += `// ${fileData.filename}\n`; | |
19 | content += `(function (window, undefined) { ${fileData.content.code} })(this);`; | |
20 | content += "\n\n"; | |
21 | }); | |
22 | ||
23 | fs.writeFileSync(destination, content); | |
24 | }; | |
25 | ||
26 | // | |
27 | // step 1) build `WCF.Combined.min.js` and `WCF.Combined.tiny.min.js` | |
28 | // | |
29 | process.chdir("../wcfsetup/install/files/js/"); | |
30 | [true, false].forEach(COMPILER_TARGET_DEFAULT => { | |
31 | let output = "WCF.Combined" + (COMPILER_TARGET_DEFAULT ? "" : ".tiny") + ".min.js"; | |
32 | console.time(output); | |
33 | { | |
34 | let data = fs.readFileSync(".buildOrder", "utf8"); | |
35 | let files = data | |
36 | .trim() | |
37 | .split(/\r?\n/) | |
38 | .map(filename => `${filename}.js`); | |
39 | ||
40 | compile(output, files, { | |
41 | compress: { | |
42 | global_defs: { | |
43 | COMPILER_TARGET_DEFAULT: COMPILER_TARGET_DEFAULT | |
44 | } | |
45 | } | |
46 | }); | |
47 | } | |
48 | console.timeEnd(output); | |
49 | }); | |
50 | ||
51 | // | |
52 | // step 2) Redactor II + plugins | |
53 | // | |
54 | const redactorCombined = "redactor.combined.min.js"; | |
55 | process.chdir("3rdParty/redactor2/"); | |
56 | ||
57 | console.time(redactorCombined); | |
58 | { | |
59 | let files = ['redactor.js']; | |
60 | fs.readdirSync("./plugins/").forEach(file => { | |
61 | file = `plugins/${file}`; | |
62 | let stat = fs.statSync(file); | |
63 | if (stat.isFile() && !stat.isSymbolicLink()) { | |
64 | files.push(file); | |
65 | } | |
66 | }); | |
67 | ||
68 | compile(redactorCombined, files); | |
69 | } | |
70 | console.timeEnd(redactorCombined); | |
71 | ||
72 | // | |
73 | // step3) build rjs | |
74 | // | |
75 | const rjsCmd = (process.platform === "win32") ? "r.js.cmd" : "r.js"; | |
76 | process.chdir("../../"); | |
77 | ||
78 | { | |
79 | let configFile = "require.build.js"; | |
80 | let outFilename = require(process.cwd() + `/${configFile}`).out; | |
81 | ||
935cdbf3 AE |
82 | const promisePolyfill = fs.readFileSync("./3rdParty/polyfill/promise.min.js"); |
83 | ||
5480a636 | 84 | [true, false].forEach(COMPILER_TARGET_DEFAULT => { |
eec1d83c | 85 | let overrides = "uglify2.compress.global_defs.COMPILER_TARGET_DEFAULT=" + (COMPILER_TARGET_DEFAULT ? "true" : "false"); |
5480a636 AE |
86 | if (!COMPILER_TARGET_DEFAULT) { |
87 | outFilename = outFilename.replace(/\.min\.js$/, '.tiny.min.js'); | |
88 | overrides += " out=" + outFilename; | |
89 | } | |
90 | ||
91 | console.time(outFilename); | |
92 | childProcess.execSync(`${rjsCmd} -o ${configFile} ${overrides}`, { | |
93 | cwd: process.cwd(), | |
94 | stdio: [0, 1, 2] | |
95 | }); | |
96 | console.timeEnd(outFilename); | |
935cdbf3 AE |
97 | |
98 | // prepend the promise polyfill | |
99 | let content = `// promise.min.js\n${promisePolyfill}\n\n// ${outFilename}\n` + fs.readFileSync(outFilename); | |
100 | fs.writeFileSync(outFilename, content); | |
5480a636 AE |
101 | }); |
102 | } | |
103 | ||
104 | // | |
105 | // step 4) legacy ACP scripts | |
106 | // | |
107 | process.chdir("../acp/js/"); | |
108 | ||
109 | fs.readdirSync("./") | |
110 | .filter(filename => { | |
111 | let stat = fs.statSync(filename); | |
112 | if (stat.isFile() && !stat.isSymbolicLink()) { | |
113 | return filename.match(/\.js$/) && !filename.match(/\.min\.js$/); | |
114 | } | |
115 | ||
116 | return false; | |
117 | }) | |
118 | .forEach(filename => { | |
119 | console.time(filename); | |
120 | { | |
121 | let output = compiler.compile(process.cwd() + `/${filename}`); | |
122 | fs.writeFileSync(filename.replace(/\.js$/, '.min.js'), output.code); | |
123 | } | |
124 | console.timeEnd(filename); | |
125 | }); |