forked from requirejs/r.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dist.js
95 lines (86 loc) · 2.97 KB
/
dist.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
/**
* @license Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/jrburke/requirejs for details
*/
/*
* 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'),
contents = fs.readFileSync('build/jslib/x.js', 'utf8'),
loadRegExp = /\/\/INSERT ([\w\/\.]+)/g,
moduleNameRegExp = /build\/jslib\/([\w\/\-]+)\.js$/,
defRegExp = /define\s*\(/,
envs = ['node', 'rhino'],
//Update this list of files by running the optimizer against
//build/jslib/opto.build.js,
//but then remove any jslib/node entries and make sure there is
//an env! entry for each one of them. Include
//build/jslib/commonjs.js in the list, but remove build/build.js
//since it is loaded separately.
libFiles = [
'build/jslib/env.js',
'env!env/args',
'env!env/load',
'env!env/file',
'build/jslib/lang.js',
'env!env/print',
'build/jslib/logger.js',
'build/jslib/blank.js',
'build/jslib/blank.js',
'build/jslib/uglifyjs/parse-js.js',
'build/jslib/uglifyjs/squeeze-more.js',
'build/jslib/uglifyjs/process.js',
'build/jslib/uglifyjs/index.js',
'build/jslib/parse.js',
'build/jslib/pragma.js',
'env!env/optimize',
'build/jslib/optimize.js',
'build/jslib/requirePatch.js',
'build/jslib/commonJs.js',
'build/jslib/build.js'
],
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 + "', ";
});
}
//Load up all the optimizer files.
libFiles.forEach(function (fileName) {
if (fileName.indexOf('env!') === 0) {
envs.forEach(function (env) {
libText += "\nif(env === '" + env + "') {\n" +
readAndNameModule(fileName.replace(/env!env\//, 'build/jslib/' + env + '/') + '.js') +
"\n}\n";
});
} else {
libText += readAndNameModule(fileName, 'utf8');
}
});
//Inline file contents
contents = contents.replace(loadRegExp, function (match, fileName) {
if (fileName === 'LIB') {
return libText;
} else {
var text = fs.readFileSync(fileName, 'utf8');
if (fileName.indexOf('require.js') !== -1) {
text = text.replace(/var requirejs, require\, define\;/, '');
}
return text;
}
});
//Set the isOpto flag to true
fs.writeFileSync('r.js', contents, 'utf8');