forked from skylarkjs/skylark-requirejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
47 lines (38 loc) · 1.34 KB
/
build.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
/*
* This script will create the final r.js file used in node projects to use
* RequireJS.
*
* This file uses Node to run:
* node dist.js
*/
/*jslint strict: false */
/*global require: false, process: false, console: false */
var fs = require('fs'),
child_process = require('child_process'),
x = fs.readFileSync('src/x.js', 'utf8'),
loadRegExp = /\/\/INSERT ([\w\/\.\$\{\}]+)/g,
moduleNameRegExp = /src\/([\w\/\-]+)\.js$/,
defRegExp = /define\s*\(/,
envs = ['browser', 'node', 'rhino', 'xpconnect','webworker'],
optimizerStartFile = 'build/build.js',
libText = '';
function readAndNameModule(fileName) {
var contents = fs.readFileSync(fileName, 'utf8'),
match = moduleNameRegExp.exec(fileName),
moduleName = (match && match[1]) || fileName;
//Insert the module name.
return contents.replace(defRegExp, function (match) {
return match + "'" + moduleName + "', ";
});
}
//Inline file contents
envs.forEach(function(env){
var contents = x.replace(loadRegExp, function (match, fileName) {
fileName = fileName.replaceAll('${env}',env);
console.log("insert file:"+fileName);
var text = fs.readFileSync(fileName, 'utf8');
return text;
});
//Set the isOpto flag to true
fs.writeFileSync('dist/' + env +'/skylark-runtime.js', contents, 'utf8');
});