-
Notifications
You must be signed in to change notification settings - Fork 122
/
update_json_parse.js
executable file
·46 lines (39 loc) · 1.24 KB
/
update_json_parse.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
#!/usr/bin/env node
//
// Update "json_parse" function block in "../lib/jsontool.js".
//
var log = console.log;
var path = require('path');
var fs = require('fs');
var assert = require('assert');
var execFile = require('child_process').execFile;
//---- mainline
var startSep = "// START json_parse\n";
var endSep = "// END json_parse\n";
var jsontoolJs = path.resolve(__dirname, "..", "lib", "jsontool.js")
var content = fs.readFileSync(jsontoolJs, 'utf8');
var startIdx = content.indexOf(startSep);
assert.ok(startIdx !== -1);
var endIdx = content.indexOf(endSep);
assert.ok(endIdx !== -1);
var uglifyjs = path.resolve(__dirname, "../node_modules/.bin/uglifyjs");
var jsonParseJs = path.resolve(__dirname, "../deps/JSON-js/json_parse.js");
execFile(process.execPath, [uglifyjs, "-nc", jsonParseJs],
function (error, minified, stderr) {
assert.ok(!error, error);
var bits = [
content.slice(0, startIdx),
startSep,
minified + '\n',
endSep,
content.slice(endIdx + endSep.length)
];
var newContent = bits.join('');
if (newContent === content) {
log('"'+jsontoolJs+'" not changed.')
} else {
fs.writeFileSync(jsontoolJs, newContent, 'utf8');
log('"'+jsontoolJs+'" updated.')
}
}
);