forked from fabricjs/fabric.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
162 lines (124 loc) · 4.27 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
var fs = require('fs'),
exec = require('child_process').exec;
var buildArgs = process.argv.slice(2),
buildArgsAsObject = { };
buildArgs.forEach(function(arg) {
var key = arg.split('=')[0],
value = arg.split('=')[1];
buildArgsAsObject[key] = value;
});
var modulesToInclude = buildArgsAsObject.modules ? buildArgsAsObject.modules.split(',') : [ ];
var modulesToExclude = buildArgsAsObject.exclude ? buildArgsAsObject.exclude.split(',') : [ ];
var minifier = buildArgsAsObject.minifier || 'yui';
var mininfierCmd;
if (minifier === 'yui') {
mininfierCmd = 'java -jar lib/yuicompressor-2.4.2.jar dist/all.js -o dist/all.min.js';
}
else if (minifier === 'closure') {
mininfierCmd = 'java -jar lib/google_closure_compiler.jar --js dist/all.js --js_output_file dist/all.min.js';
}
var includeAllModules = modulesToInclude.length === 1 && modulesToInclude[0] === 'ALL';
var noStrict = 'no-strict' in buildArgsAsObject;
var distFileContents =
'/* build: `node build.js modules=' +
modulesToInclude.join(',') +
(modulesToExclude.length ? (' exclude=' + modulesToExclude.join(',')) : '') +
(noStrict ? ' no-strict' : '') +
'` */\n';
function appendFileContents(fileNames, callback) {
(function readNextFile() {
if (fileNames.length <= 0) {
return callback();
}
var fileName = fileNames.shift();
if (!fileName) {
return readNextFile();
}
fs.readFile(__dirname + '/' + fileName, function (err, data) {
if (err) throw err;
if (noStrict) {
data = String(data).replace(/"use strict";?\n?/, '');
}
distFileContents += (data + '\n');
readNextFile();
});
})();
}
function ifSpecifiedInclude(moduleName, fileName) {
var isInIncludedList = modulesToInclude.indexOf(moduleName) > -1;
var isInExcludedList = modulesToExclude.indexOf(moduleName) > -1;
// excluded list takes precedence over modules=ALL
return ((isInIncludedList || includeAllModules) && !isInExcludedList) ? fileName : '';
}
function ifSpecifiedDependencyInclude(included, excluded, fileName) {
return (
(
(modulesToInclude.indexOf(included) > -1 || includeAllModules) &&
(modulesToExclude.indexOf(excluded) == -1))
? fileName
: ''
);
}
var filesToInclude = [
'HEADER.js',
ifSpecifiedDependencyInclude('text', 'cufon', 'lib/cufon.js'),
ifSpecifiedDependencyInclude('serialization', 'json', 'lib/json2.js'),
'src/log.js',
'src/observable.js',
'src/util/misc.js',
'src/util/lang_array.js',
'src/util/lang_object.js',
'src/util/lang_string.js',
'src/util/lang_function.js',
'src/util/lang_class.js',
'src/util/dom_event.js',
'src/util/dom_style.js',
'src/util/dom_misc.js',
'src/util/dom_request.js',
ifSpecifiedInclude('easing', 'src/util/anim_ease.js'),
ifSpecifiedInclude('parser', 'src/parser.js'),
'src/gradient.class.js',
'src/point.class.js',
'src/intersection.class.js',
'src/color.class.js',
'src/static_canvas.class.js',
ifSpecifiedInclude('interaction', 'src/canvas.class.js'),
'src/canvas.animation.js',
ifSpecifiedInclude('serialization', 'src/canvas.serialization.js'),
'src/object.class.js',
'src/line.class.js',
'src/circle.class.js',
'src/triangle.class.js',
'src/ellipse.class.js',
'src/rect.class.js',
'src/polyline.class.js',
'src/polygon.class.js',
'src/path.class.js',
'src/path_group.class.js',
'src/group.class.js',
'src/image.class.js',
ifSpecifiedInclude('object_straightening', 'src/object_straightening.js'),
ifSpecifiedInclude('image_filters', 'src/image_filters.js'),
ifSpecifiedInclude('text', 'src/text.class.js'),
ifSpecifiedInclude('node', 'src/node.js')
];
appendFileContents(filesToInclude, function() {
fs.writeFile('dist/all.js', distFileContents, function (err) {
if (err) {
console.log(err);
throw err;
}
console.log('Built distribution to dist/all.js');
exec(mininfierCmd, function (error, output) {
if (!error) {
console.log('Minified using', minifier, 'to dist/all.min.js');
}
exec('gzip -c dist/all.min.js > dist/all.min.js.gz', function (error, output) {
console.log('Gzipped to dist/all.min.js.gz');
exec('ls -l dist', function (error, output) {
console.log(output.replace(/^.*/, ''));
});
});
});
});
});