1 const childProcess
= require("child_process");
2 const compiler
= require("./compiler");
3 const fs
= require("fs");
4 const path
= require("path");
6 if (process
.argv
.length
!== 3) {
7 throw new Error("Requires the path to an existing repository.");
10 const repository
= process
.argv
[2];
11 if (!fs
.existsSync(repository
)) {
12 throw new Error(`Unable to locate repsitory, the path ${repository} is invalid.`);
14 process
.chdir(repository
);
18 // get all directories at the repository root
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
)) {
27 // ignore build configurations
28 if (filename
=== "require.build.js") {
29 if (rjsPaths
.indexOf(path
) === -1) rjsPaths
.push(path
);
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$/)) {
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
);
47 let output
= compiler
.compile(path
+ filename
, {
50 COMPILER_TARGET_DEFAULT
: COMPILER_TARGET_DEFAULT
55 fs
.writeFileSync(path
+ outFilename
, output
.code
);
57 console
.timeEnd(outFilename
);
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
;
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
;
75 console
.time(outFilename
);
76 childProcess
.execSync(`${rjsCmd} -o require.build.js ${overrides}`, {
80 console
.timeEnd(outFilename
);