forked from jakesgordon/javascript-state-machine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminify
More file actions
executable file
·40 lines (30 loc) · 1.27 KB
/
minify
File metadata and controls
executable file
·40 lines (30 loc) · 1.27 KB
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
#!/usr/bin/env node
//=================================================================================================
//
// This script is used (by npm run build) to minify the distributed source code
//
//=================================================================================================
var fs = require('fs-sync'),
path = require('path'),
uglify = require('uglify-js'),
target = 'dist';
//-------------------------------------------------------------------------------------------------
fs.expand("lib/**/*.js")
.map(minify);
//-------------------------------------------------------------------------------------------------
function minify(file) {
var name = output_name(file),
expanded = path.join(target, name + '.js'),
minified = path.join(target, name + '.min.js')
console.log('copied ' + file + ' to ' + expanded + ' and minified as ' + minified);
fs.copy(file, expanded, { force: true });
fs.write(minified, uglify.minify(expanded).code);
}
function output_name(file) {
var name = path.basename(file, '.js');
if (name === 'state-machine')
return 'state-machine'
else
return 'state-machine-' + name
}
//-------------------------------------------------------------------------------------------------