git @ Cat's Eye Technologies Lexeduct / 352dd0e
Translate Python browser-js-generator script to node. --HG-- rename : src/gen-lexeduct-browser.py => src/gen-lexeduct-browser.js Chris Pressey 6 years ago
2 changed file(s) with 18 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
0 #!/usr/bin/env node
1
2 fs = require('fs');
3
4 function write(s) {
5 process.stdout.write(s + "\n");
6 }
7
8 write("module = {};");
9 write("makeFilter = {};");
10 var files = fs.readdirSync('filter');
11 for (var i = 0; i < files.length; i++) {
12 var filename = files[i];
13 var filterName = filename.split('.js')[0];
14 var text = fs.readFileSync('filter/' + filename);
15 write(text);
16 write("makeFilter['" + filterName + "'] = module.exports.makeFilter;");
17 }
+0
-21
src/gen-lexeduct-browser.py less more
0 #!/usr/bin/env python
1
2 # Written in Python right now, but should be converted to node for consistency.
3
4 import os
5
6 def main():
7 print "module = {};"
8 print "makeFilter = {};"
9 for filename in os.listdir('filter'):
10 if not filename.endswith('.js'):
11 continue
12 filter_name = filename[:-3]
13 print
14 with open(os.path.join('filter', filename), 'r') as f:
15 print f.read()
16 print "makeFilter['%s'] = module.exports.makeFilter;" % filter_name
17
18
19 if __name__ == '__main__':
20 main()