]> git.r.bdr.sh - rbdr/dotfiles/blob
d6fc26a7900206b686892a107d96b7306a703797
[rbdr/dotfiles] /
1 /* -*- Mode: js; js-indent-level: 2; -*- */
2 /*
3 * Copyright 2011 Mozilla Foundation and contributors
4 * Licensed under the New BSD license. See LICENSE or:
5 * http://opensource.org/licenses/BSD-3-Clause
6 */
7 var path = require('path');
8 var fs = require('fs');
9 var copy = require('dryice').copy;
10
11 function removeAmdefine(src) {
12 src = String(src).replace(
13 /if\s*\(typeof\s*define\s*!==\s*'function'\)\s*{\s*var\s*define\s*=\s*require\('amdefine'\)\(module,\s*require\);\s*}\s*/g,
14 '');
15 src = src.replace(
16 /\b(define\(.*)('amdefine',?)/gm,
17 '$1');
18 return src;
19 }
20 removeAmdefine.onRead = true;
21
22 function makeNonRelative(src) {
23 return src
24 .replace(/require\('.\//g, 'require(\'source-map/')
25 .replace(/\.\.\/\.\.\/lib\//g, '');
26 }
27 makeNonRelative.onRead = true;
28
29 function buildBrowser() {
30 console.log('\nCreating dist/source-map.js');
31
32 var project = copy.createCommonJsProject({
33 roots: [ path.join(__dirname, 'lib') ]
34 });
35
36 copy({
37 source: [
38 'build/mini-require.js',
39 {
40 project: project,
41 require: [ 'source-map/source-map-generator',
42 'source-map/source-map-consumer',
43 'source-map/source-node']
44 },
45 'build/suffix-browser.js'
46 ],
47 filter: [
48 copy.filter.moduleDefines,
49 removeAmdefine
50 ],
51 dest: 'dist/source-map.js'
52 });
53 }
54
55 function buildBrowserMin() {
56 console.log('\nCreating dist/source-map.min.js');
57
58 copy({
59 source: 'dist/source-map.js',
60 filter: copy.filter.uglifyjs,
61 dest: 'dist/source-map.min.js'
62 });
63 }
64
65 function buildFirefox() {
66 console.log('\nCreating dist/SourceMap.jsm');
67
68 var project = copy.createCommonJsProject({
69 roots: [ path.join(__dirname, 'lib') ]
70 });
71
72 copy({
73 source: [
74 'build/prefix-source-map.jsm',
75 {
76 project: project,
77 require: [ 'source-map/source-map-consumer',
78 'source-map/source-map-generator',
79 'source-map/source-node' ]
80 },
81 'build/suffix-source-map.jsm'
82 ],
83 filter: [
84 copy.filter.moduleDefines,
85 removeAmdefine,
86 makeNonRelative
87 ],
88 dest: 'dist/SourceMap.jsm'
89 });
90
91 // Create dist/test/Utils.jsm
92 console.log('\nCreating dist/test/Utils.jsm');
93
94 project = copy.createCommonJsProject({
95 roots: [ __dirname, path.join(__dirname, 'lib') ]
96 });
97
98 copy({
99 source: [
100 'build/prefix-utils.jsm',
101 'build/assert-shim.js',
102 {
103 project: project,
104 require: [ 'test/source-map/util' ]
105 },
106 'build/suffix-utils.jsm'
107 ],
108 filter: [
109 copy.filter.moduleDefines,
110 removeAmdefine,
111 makeNonRelative
112 ],
113 dest: 'dist/test/Utils.jsm'
114 });
115
116 function isTestFile(f) {
117 return /^test\-.*?\.js/.test(f);
118 }
119
120 var testFiles = fs.readdirSync(path.join(__dirname, 'test', 'source-map')).filter(isTestFile);
121
122 testFiles.forEach(function (testFile) {
123 console.log('\nCreating', path.join('dist', 'test', testFile.replace(/\-/g, '_')));
124
125 copy({
126 source: [
127 'build/test-prefix.js',
128 path.join('test', 'source-map', testFile),
129 'build/test-suffix.js'
130 ],
131 filter: [
132 removeAmdefine,
133 makeNonRelative,
134 function (input, source) {
135 return input.replace('define(',
136 'define("'
137 + path.join('test', 'source-map', testFile.replace(/\.js$/, ''))
138 + '", ["require", "exports", "module"], ');
139 },
140 function (input, source) {
141 return input.replace('{THIS_MODULE}', function () {
142 return "test/source-map/" + testFile.replace(/\.js$/, '');
143 });
144 }
145 ],
146 dest: path.join('dist', 'test', testFile.replace(/\-/g, '_'))
147 });
148 });
149 }
150
151 function ensureDir(name) {
152 var dirExists = false;
153 try {
154 dirExists = fs.statSync(name).isDirectory();
155 } catch (err) {}
156
157 if (!dirExists) {
158 fs.mkdirSync(name, 0777);
159 }
160 }
161
162 ensureDir("dist");
163 ensureDir("dist/test");
164 buildFirefox();
165 buildBrowser();
166 buildBrowserMin();