forked from mozilla/butter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake.js
executable file
·283 lines (226 loc) · 7.47 KB
/
make.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#!/usr/bin/env node
var JSLINT = './node_modules/jshint/bin/hint',
CSSLINT = './node_modules/csslint/cli.js',
UGLIFY = './node_modules/uglify-js/bin/uglifyjs',
RJS = './node_modules/requirejs/bin/r.js',
STYLUS = './node_modules/stylus/bin/stylus',
DOX = './tools/dox.py',
DIST_DIR = 'dist',
SRC_DIR = 'src',
CSS_DIR = 'css',
TEMPLATES_DIR = 'templates',
DIALOGS_DIR = 'dialogs',
DOCS_DIR = 'docs',
EDITORS_DIR = 'editors',
DEFAULT_CONFIG = './src/default-config',
BUTTERED_POPCORN = DIST_DIR + '/buttered-popcorn.js',
BUTTERED_POPCORN_MIN = DIST_DIR + '/buttered-popcorn.min.js',
PACKAGE_NAME = 'butter',
SLICE = Array.prototype.slice;
require('shelljs/make');
function checkCSS() {
echo('### Linting CSS files');
var dirs = SLICE.call( arguments ).join( ' ' );
// see cli.js --list-rules.
var warnings = [
// "important",
// "adjoining-classes",
// "duplicate-background-images",
// "qualified-headings",
"fallback-colors",
// "empty-rules",
// "shorthand",
// "overqualified-elements",
// "import",
// "regex-selectors",
// "rules-count",
// "font-sizes",
// "universal-selector",
// "unqualified-attributes",
"zero-units"
].join(",");
var errors = [
"known-properties",
"compatible-vendor-prefixes",
"display-property-grouping",
"duplicate-properties",
"errors",
"gradients",
"font-faces",
"floats",
"vendor-prefix"
].join(",");
exec(CSSLINT + ' --warnings=' + warnings +
' --errors=' + errors +
' --quiet --format=compact' +
' ' + dirs);
}
function checkJS(){
// Takes a string or an array of strings referring to directories.
echo('### Linting JS files');
var dirs = SLICE.call( arguments );
// Get all js and json files in dirs
var files = "";
[ /\.js$/, /\.json$/ ].forEach( function( regexp ){
files += find( dirs ).filter( function( file ) {
return file.match( regexp );
}).join(' ') + ' ';
});
// jshint with non-errors plus linting of json files
exec(JSLINT + ' ' + files + ' --show-non-errors --extra-ext json');
}
target.all = function() {
target.submodules();
target.check();
target.build();
};
target.clean = function() {
rm('-fr', DIST_DIR);
};
target.dist = function() {
mkdir('-p', DIST_DIR);
};
target.submodules = function() {
echo('### Updating git submodules');
exec('git submodule update --init --recursive');
};
target.docs = function() {
echo('### Creating documentation from src...');
mkdir('-p', DOCS_DIR);
var files = find( SRC_DIR ).filter( function( file ) {
return file.match(/\.js$/);
});
var docTypes = [
'md'
];
for (var i = files.length - 1; i >= 0; i--) {
echo('### Processing documentation for ' + files[i]);
for (var j = docTypes.length - 1; j >= 0; j--) {
var newFileName = DOCS_DIR + '/' + files[i].substring(4).replace(/\//g, '-').replace(/\.js$/, '.' + docTypes[j]),
command = 'python ' + DOX + ' -t ' + docTypes[j] + ' -o '+ newFileName + ' -i ' + files[i];
exec(command);
};
};
};
target.check = function() {
checkJS( SRC_DIR, EDITORS_DIR );
checkCSS( CSS_DIR, DIALOGS_DIR, EDITORS_DIR );
};
target['check-templates'] = function() {
checkJS( TEMPLATES_DIR );
checkCSS( TEMPLATES_DIR );
};
target['check-css'] = function( dirs ) {
checkCSS( CSS_DIR, DIALOGS_DIR, EDITORS_DIR );
};
target['check-lint'] = function( dir ) {
checkJS( SRC_DIR, EDITORS_DIR );
};
function build( version ){
echo('### Building butter');
target.clean();
target.dist();
exec(RJS + ' -o tools/build.js');
exec(RJS + ' -o tools/build.optimized.js');
// Stamp Butter.version with supplied version
sed('-i', '@VERSION@', version, 'dist/butter.js');
sed('-i', '@VERSION@', version, 'dist/butter.min.js');
exec(STYLUS + ' css');
cp('css/*.css', DIST_DIR);
}
target.build = function(){
// Use git commit info
var version = exec('git describe',
{silent:true}).output.replace(/\r?\n/m, "");
build( version );
};
target.server = function() {
echo('### Serving butter');
cd('cornfield');
exec('node app.js', { async: true });
};
target.package = function() {
echo('### Making Butter Package');
target.build();
cp('-R', 'resources', DIST_DIR);
cp('-R', 'dialogs', DIST_DIR);
cp('-R', 'editors', DIST_DIR);
cp('-R', 'templates', DIST_DIR);
echo('### Creating butter.zip');
cd(DIST_DIR)
exec('zip -r ' + PACKAGE_NAME + '.zip ' + ls('.').join(' '));
};
target.release = function() {
echo('### Making Butter Release');
// To pass a release version number, use:
// $ VERSION=0.5 node make release
var version = env['VERSION'];
if( !version ){
console.log( "ERROR: Must provide a version when building a release: VERSION=XXX node make release" );
return;
}
build( version );
var defaultConfig = require( DEFAULT_CONFIG ),
popcornDir = defaultConfig.dirs['popcorn-js'].replace( '{{baseDir}}', './' ),
players = defaultConfig.player.players,
plugins = defaultConfig.plugin.plugins,
popcornFiles = [];
// Popcorn License Header
popcornFiles.push( popcornDir + '/LICENSE_HEADER' );
// classList shim
popcornFiles.push( './tools/classlist-shim.js' );
// popcorn IE8 shim
popcornFiles.push( popcornDir + '/ie8/popcorn.ie8.js' );
// popcorn.js
popcornFiles.push( popcornDir + '/popcorn.js' );
// plugins
plugins.forEach( function( plugin ){
popcornFiles.push( plugin.path.replace( '{{baseDir}}', './' ) );
});
// module for baseplayer
popcornFiles.push( popcornDir + '/modules/player/popcorn.player.js' );
// players
players.forEach( function( player ){
popcornFiles.push( player.path.replace( '{{baseDir}}', './' ) );
});
// Stamp Popcorn.version with the git commit sha we are using
var cwd = pwd();
cd( popcornDir );
var popcornVersion = exec('git describe',
{silent:true}).output.replace(/\r?\n/m, "");
cd( cwd );
// Write out dist/buttered-popcorn.js
cat( popcornFiles ).to( BUTTERED_POPCORN );
sed('-i', '@VERSION', popcornVersion, BUTTERED_POPCORN);
// Write out dist/buttered-popcorn.min.js
exec( UGLIFY + ' --output ' + BUTTERED_POPCORN_MIN + ' ' + BUTTERED_POPCORN );
// Copy over templates and other resources
cp('-R', 'resources', DIST_DIR);
cp('-R', 'dialogs', DIST_DIR);
cp('-R', 'editors', DIST_DIR);
cp('-R', 'templates', DIST_DIR);
echo('### Creating butter.zip');
cd(DIST_DIR);
exec('zip -r ' + PACKAGE_NAME + '.zip ' + ls('.').join(' '));
};
target.beautify = function( a ) {
echo('### Beautifying butter');
cd('tools')
exec('./beautify.sh');
};
target.test = function() {
var unbeautified = [ "if.js", "for.js", "while.js", "array.js", "function.js", "object.js", "comments.js", "eolspace.js" ],
beautified = [ "if.expected.js", "for.expected.js", "while.expected.js", "array.expected.js", "function.expected.js", "object.expected.js", "comments.expected.js", "eolspace.expected.js" ],
result;
echo('### Testing Beautifier');
for( var i = 0, l = unbeautified.length; i < l; i++ ) {
result = exec('bash test/beautifier/test.sh ' + unbeautified[ i ] + ' ' + beautified[ i ]);
rm('tmp.txt');
// checking against a length of 1 because if the output is empty a newline character gets returned
if( result.output.length === 1 ) {
echo(unbeautified[ i ] + ' was beautified correctly');
} else {
echo(unbeautified[ i ] + ' did not beautify correctly');
}
}
};