-
Notifications
You must be signed in to change notification settings - Fork 13
/
build
executable file
·50 lines (42 loc) · 1.32 KB
/
build
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
#!/usr/bin/env node
var fs = require('fs');
var toBuild = {
'built/simland.js' : [ 'lib/helper.js', 'lib/simland.js', 'lib/square.js' ],
'built/simland.css' : [ 'lib/simland.css', 'lib/simland-things.css' ]
};
try {
fs.statSync('built');
} catch(err) {
if (err.code=='ENOENT') fs.mkdirSync('built');
else throw err;
}
var licence = fs.readFileSync('lib/simland.js', 'utf8')
.toString().replace(/\*\/[\s\S]*$/, '*/');
// TODO: replace by a real minifier
function minify(code) {
return code.toString()
.replace(/\/\*([^*]*(\*(?!\/))?)*\*\//g,'') // multiline comments
.replace(/\/\/.*\n/g,'') // in-line comments
.replace(/\s+/g,' '); // join lines and remove multiple spaces
}
// TODO: protect UTF8 chars
for ( target in toBuild ) {
var code;
if ( /\.js$/.test(target) ) {
code = licence+'\n(function (exports) {\n';
} else {
code = licence+'\n';
}
for( var piece,i=0; piece=toBuild[target][i]; i++ ) {
console.log( piece +( i==0 ? ' => ' : ' +> ' )+ target );
code += minify( fs.readFileSync(piece, 'utf8') );
}
if ( /\.js$/.test(target) ) code += '\n})(this);';
fs.writeFileSync(target, code, 'utf8');
}
try {
fs.statSync('built/imgs');
} catch(err) {
if (err.code=='ENOENT') fs.symlinkSync('../imgs', 'built/imgs');
else throw err;
}