-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpatch-source.js
More file actions
58 lines (46 loc) · 1.31 KB
/
patch-source.js
File metadata and controls
58 lines (46 loc) · 1.31 KB
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
var Compiler = require('../lib/compiler.js')().Compiler;
var fs = require('fs');
var klaw = require('klaw-sync');
var path = require('path');
var program = require('commander');
program.parse(process.argv);
var filter = function(item) {
return item.path.slice(-3) === '.js'
}
if(program.args.length === 1) {
var directory = program.args[0];
filter = function(item) {
return item.path.slice(-3) === '.js' && path.basename(path.dirname(item.path)) === directory
}
}
else if(program.args.length === 2) {
var directory = program.args[0];
var basename = program.args[1];
filter = function(item) {
return item.path.slice(-3) === '.js' && path.basename(path.dirname(item.path)) === directory && path.basename(item.path).startsWith(basename)
}
}
var files = klaw(path.join(__dirname, '..', 'test', 'fixtures', 'compile'), {
nodir: true,
traverseAll: true,
filter: filter
});
for(var i = 0; i < files.length; i++) {
patch(files[i].path)
}
function patch(file) {
var root = path.dirname(file)
var name = path.basename(file).slice(0, -3);
console.log('patching ' + name + '.ks')
try {
var compiler = new Compiler(path.join(root, name + '.ks'), {
header: false
});
var data = compiler.compile().toSource();
fs.writeFileSync(path.join(root, name + '.js'), data, {
encoding: 'utf8'
});
}
catch(error) {
}
}