-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (34 loc) · 970 Bytes
/
index.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
var vash = require('vash'),
esprima = require('esprima'),
esCodeGen = require('escodegen'),
fs = require('fs'),
m = require('merle'),
concatStream = require('concat-stream'),
browserify = require('browserify');
function getScriptBundle(cb){
var b = browserify();
b.transform('vashify');
b.add(__dirname + '/browser/main.js');
b.bundle().pipe(concatStream(function(bundle){
cb(bundle);
}));
}
function getDataForFile(file){
var fileContents = fs.readFileSync(file),
ast = esprima.parse(fileContents);
m(ast, function(){
if (!this.value || !this.value.type) return;
this.value.code = esCodeGen.generate(this.value);
});
return ast;
}
var strPageTemplate = fs.readFileSync('./page.vash').toString();
var pageTemplate = vash.compile(strPageTemplate);
var data = getDataForFile(process.argv[2]);
getScriptBundle(function(bundle){
var model = {
ast: JSON.stringify(data),
bundle: bundle
};
process.stdout.write(pageTemplate(model));
});