forked from victorjonsson/jQuery-Form-Validator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·70 lines (61 loc) · 2.19 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env node
var fs = require('fs'),
sys = require('sys'),
exec = require('child_process').exec,
jsPath = 'form-validator/',
mainScript = jsPath + 'jquery.form-validator.js',
mainMinifiedScript = jsPath + 'jquery.form-validator.min.js',
newVersion = -1;
/*
* Find out new version number
*/
var versionParts = fs.readFileSync(mainScript, 'utf-8').split('@version ')[1].split('*/')[0].trim().split('.');
if(versionParts.length < 3) {
// new version number is decided in code
newVersion = versionParts.join('.');
}
else {
// Increase the last number by one
var newSubVersion = parseInt(versionParts.splice(versionParts.length-1, 1)[0]) + 1;
newVersion = versionParts.join('.') + '.' + newSubVersion.toString();
}
console.log('Build version: '+newVersion);
/*
* Get code docs
*/
var documentation = fs.readFileSync(mainScript, 'utf-8').split('*/')[0]+'*/';
var docParts = documentation.split('@version ');
documentation = docParts[0] +'@version '+newVersion+'\n'+docParts[1].split('\n')[1];
/**
* Create new minified version of a file and change
* version number
* @param {String} path
* @param {String} newName
*/
function buildFile(path, newName) {
var codeParts = fs.readFileSync(path, 'utf-8').split('@version ');
var lastCodeParts = codeParts[1].split("\n");
var origCode = codeParts[0] + '@version '+newVersion+ "\n" + lastCodeParts.slice(1, lastCodeParts.length).join("\n") + "";
fs.writeFileSync(path, origCode);
fs.writeFileSync(newName, '');
exec('uglifyjs '+path+' >> '+newName, function (error, stdout, stderr) {
if(stdout)
console.log('stdout: '+stdout);
if(error)
console.log('error: '+error);
if(stderr)
console.log('stderror: '+stderr);
console.log('* '+newName);
});
}
buildFile(mainScript, mainMinifiedScript);
fs.readdirSync(jsPath).forEach(function(f) {
if(f.substr(-7) == '.dev.js') {
var compressedFileName = jsPath + f.substr(0, f.length - 6) + 'js';
buildFile(jsPath+f, compressedFileName);
}
});
/*
* Add docs to main script
*/
fs.writeFileSync(mainMinifiedScript, documentation+"\n"+fs.readFileSync(mainMinifiedScript, 'utf-8'));