/
dist.js
45 lines (38 loc) · 1.25 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
/**
* @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 */
/**
* Escapes a string so it is safe as a JS string
* Taken from Dojo's buildUtil.jsEscape
* @param {String} str
* @returns {String}
*/
function jsEscape(str) {
return ('"' + str.replace(/(["\\])/g, '\\$1') + '"'
).replace(/[\f]/g, '\\f'
).replace(/[\b]/g, '\\b'
).replace(/[\n]/g, '\\n'
).replace(/[\t]/g, '\\t'
).replace(/[\r]/g, '\\r'); // string
}
var fs = require('fs'),
contents = fs.readFileSync('../bin/x.js', 'utf8'),
loadRegExp = /readFile\(requireBuildPath \+ '([\w\/\.]+)'\)/g;
//Inline file contents
contents = contents.replace(loadRegExp, function (match, fileName) {
return jsEscape(fs.readFileSync('../' + fileName, 'utf8'));
});
//Switch the behavior to "inlined mode"
contents = contents.replace(/useRequireBuildPath \= true/, 'useRequireBuildPath = false');
fs.writeFileSync('r.js', contents, 'utf8');