-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.js
82 lines (68 loc) · 2.28 KB
/
server.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
var fs = require('fs');
var minifier = require('uglify-js');
var bs = require('browser-sync').create();
var exec = require('child_process').exec;
var moduleName = 'ADM-treeView';
var version = '1.2.0';
var copyRight =
`/*
* Demo: http://amirkabirdataminers.github.io/ADM-treeView
*
* @version ${version}
*
* © 2017 Amirkabir Data Miners <[email protected]> - www.adm-co.net
*/\n\n`;
var updateInFilesVersion = function() {
['./package.json', './bower.json'].map((path) => {
fs.readFile(path, 'utf8', (err, data) => {
if (err) throw err;
data = JSON.parse(data);
data.version = version;
fs.writeFile(path, JSON.stringify(data, null, 2), 'utf8');
});
});
fs.readFile('./README.md', 'utf8', (err, data) => {
if (err) throw err;
data = data.replace(/\/(npm|bower)-v([0-9.]*)-/g, function(match,type,v) {
return ['/',type,'-v',version,'-'].join('');
})
fs.writeFile('./README.md', data, 'utf8');
});
}
var startCompassCommands = () => {
var compass = 'compass watch';
var directories = ['./src', './demo'];
for (var i=0, j=directories.length; i<j; i++)
exec(compass, {cwd: directories[i]});
}
var minifyMainScript = () => {
var code = minifier.minify('./dist/' + moduleName + '.js').code;
fs.writeFile('./dist/min/' + moduleName + '.min.js', copyRight + code, (err) => {
if(err)
return console.log(err);
console.log('[UJ] ' + moduleName + '.js Minified!');
});
}
var startWatchingMainScript = () => {
fs.watchFile('./dist/' + moduleName + '.js', () => {
minifyMainScript();
});
}
var startBrowserSync = () => {
bs.init({
ui: false,
server: {
baseDir: ['.', './demo'],
index: 'index.html'
},
files: ['./dist/min/*.*', './src/*.html', './demo/index.html', './demo/js/*.js', './demo/stylesheets/*.css']
});
}
var initialize = function() {
updateInFilesVersion();
startBrowserSync();
minifyMainScript(); // Comment line for view mode.
startWatchingMainScript(); // Comment line for view mode.
startCompassCommands(); // Comment line for view mode. You need to install Ruby Gem, Compass, SASS before
//nodemon -e js --ignore dist/
}();