forked from mozilla/butter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
make.js
executable file
·195 lines (158 loc) · 4.83 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
#!/usr/bin/env node
var JSLINT = './node_modules/jshint/bin/hint',
CSSLINT = './node_modules/csslint/cli.js',
RJS = './node_modules/requirejs/bin/r.js',
STYLUS = './node_modules/stylus/bin/stylus',
DOX = './tools/dox.py',
DIST_DIR = 'dist',
CSS_DIR = 'css',
TEMPLATES_DIR = 'templates',
DIALOGS_DIR = 'dialogs',
DOCS_DIR = 'docs',
PACKAGE_NAME = 'butter';
require('shelljs/make');
function checkCSS( dirs ) {
echo('### Linting CSS files');
if (dirs instanceof Array) {
dirs = dirs.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( dirs ){
// Takes a string or an array of strings referring to directories.
echo('### Linting JS files');
var files = find(dirs).filter( function( file ) {
return file.match(/\.js$/);
}).join(' ');
exec(JSLINT + ' ' + files + ' --show-non-errors');
}
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').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' );
checkCSS( [CSS_DIR, DIALOGS_DIR] );
};
target['check-templates'] = function() {
checkJS( TEMPLATES_DIR );
checkCSS( TEMPLATES_DIR );
};
target['check-css'] = function( dirs ) {
checkCSS( [CSS_DIR, DIALOGS_DIR] );
};
target['check-lint'] = function( dir ) {
checkJS( 'src' );
};
target.build = function() {
echo('### Building butter');
target.clean();
target.dist();
exec(RJS + ' -o tools/build.js');
exec(RJS + ' -o tools/build.optimized.js');
// Stamp Butter.version with the git commit sha we are using
var version = exec('git describe',
{silent:true}).output.replace(/\r?\n/m, "");
sed('-i', '@VERSION@', version, 'dist/butter.js');
sed('-i', '@VERSION@', version, 'dist/butter.min.js');
exec(STYLUS + ' css');
cp('css/*.css', DIST_DIR);
};
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.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');
}
}
};