forked from requirejs/r.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dist.js
110 lines (101 loc) · 3.6 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* @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 = ['browser', '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',
'build/jslib/lang.js',
'build/jslib/prim.js',
'env!env/assert',
'env!env/args',
'env!env/load',
'env!env/file',
'env!env/quit',
'env!env/print',
'build/jslib/logger.js',
'build/jslib/blank.js',
'build/jslib/esprima.js',
'build/jslib/uglifyjs/consolidator.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/source-map/array-set.js',
'build/jslib/source-map/base64-vlq.js',
'build/jslib/source-map/base64.js',
'build/jslib/source-map/binary-search.js',
'build/jslib/source-map/source-map-consumer.js',
'build/jslib/source-map/source-map-generator.js',
'build/jslib/source-map/source-node.js',
'build/jslib/source-map/util.js',
'build/jslib/source-map.js',
'build/jslib/uglifyjs2.js',
'build/jslib/parse.js',
'build/jslib/transform.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');