forked from AcceDe-Web/tablist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
62 lines (54 loc) · 1.44 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
/* jshint node:true, esversion:6 */
/* Building process:
* - read source file
* - add licensing information
* - output compressed file
* - write uncompressed and compressed files to dist directory
*
* All data for the banner can be found into the package.json file
*/
'use strict';
const pkg = require( './package.json' ),
Uglify = require( 'uglify-js' ),
fs = require( 'fs' ),
source = 'lib/tablist.js',
dest = 'dist/',
files = [ 'tablist.js', 'tablist.min.js' ],
banner = [
`/**`,
` * ${pkg.name} - ${pkg.description}`,
` * @version v${pkg.version}`,
` * @link ${pkg.homepage}`,
` * @license ${pkg.license}`,
` */`,
'\n' ].join( '\n' );
let libCode = [];
fs.readFile( source, ( err, data ) => {
if ( err ) {
throw err;
}
libCode.push( banner + data );
let libMin = Uglify.minify( libCode[ 0 ], {
compress: {},
'fromString': true,
'output': {
'comments': ( node, comment ) => {
const text = comment.value,
type = comment.type;
if ( type === 'comment2' ) {
// multiline comment
return /@preserve|@license|@cc_on/i.test( text );
}
}
}
});
libCode.push( libMin.code );
// write files to /dist folder
libCode.forEach(( code, i ) => {
fs.writeFile( dest + files[ i ], code, ( err ) => {
if ( err ) {
throw err;
}
});
});
});