forked from HelikarLab/ccNetViz
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
executable file
·118 lines (94 loc) · 2.85 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
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
var Webpack = require("webpack");
var flags = {};
process.argv.forEach(function (val, index, array) {
flags[val] = true;
});
var ClosureCompiler = require('google-closure-compiler').compiler;
function runClosueCompiler(){
if(!flags.compile)
return;
console.log('Compiling ccNetViz library with Google closure compiler');
var fs = require('fs');
var closureCompiler = new ClosureCompiler({
js: 'dist/ccNetViz.js',
compilation_level: 'ADVANCED'
});
var compilerProcess = closureCompiler.run(function(exitCode, stdOut, stdErr) {
//compilation complete
if(exitCode === 0){
console.log(' --- complilation successfully completed');
fs.writeFileSync('dist/ccNetViz.min.js', stdOut);
console.log(' --- created compiled file in dist/ccNetViz.min.js');
}else{
console.log(' --- complilation exited with code '+exitCode);
console.log(stdOut);
console.error(stdErr);
}
});
}
var path = require('path');
// returns a Compiler instance
var webpackinst = Webpack({
entry: './src/ccNetVizMultiLevel.js',
output: {
path: path.join(__dirname, 'dist'),
filename: 'ccNetViz.js',
},
// resolve: {
// extensions: ['', '.js', '.jsx']
// },
devtool: 'source-map',
debug:true,
module:{
loaders: [
{
// test: /\.js?$/g,
exclude: /(node_modules|bower_components)/,
query: {
// plugins: ['transform-es2015-modules-commonjs'],
presets: ['es2015']
// compact: false
},
// loader: 'babel-loader' // 'babel-loader' is also a legal name to reference
loader: 'babel' // 'babel-loader' is also a legal name to reference
}
]
}
},function(err, stats) {
if (err) {
console.error(" --- ERROR in webpack configuration");
console.error(stats);
process.exit(0);
}
});
console.log('Packing ccNetViz library with webpack');
webpackinst.run(function(err, stats) {
if(err){
console.error(" --- ERROR in packing");
console.error(err);
return;
}
setTimeout(function(){
console.log(' --- appending module.exports into dist/ccNetViz.js (import fix)');
var fs = require('fs');
var filedata = [
fs.readFileSync(__dirname+'/dist/ccNetViz.js').toString(),
'if(typeof module !== "undefined")',
'module.exports = ccNetViz;'
];
//append to file export
fs.writeFileSync(__dirname+'/dist/ccNetViz.js', filedata.join('\n'));
console.log(' --- Successfully packed into dist/ccNetViz.js');
runClosueCompiler();
},5*100);
});
/*
// or
webpackinst.watch({ // watch options:
aggregateTimeout: 300, // wait so long for more changes
poll: true // use polling instead of native watchers
// pass a number to set the polling interval
}, function(err, stats) {
// ...
});
*/