lava-oushudb-dt-sql-parser/peg/build.js

31 lines
738 B
JavaScript
Raw Normal View History

2018-07-05 11:16:30 +08:00
const pegjs=require("pegjs");
const path=require("path");
const fs=require("fs");
const ENCODING="utf8"
2018-07-05 11:16:30 +08:00
const files=[{
source:path.resolve(process.cwd(),"./peg/comment.pegjs") ,
target:path.resolve(process.cwd(),"./core/comment.js") ,
},{
source:path.resolve(process.cwd(),"./peg/nquery.pegjs") ,
target:path.resolve(process.cwd(),"./core/astParser.js") ,
}];
function writeIn(file,data){
fs.writeFileSync(file,data,{encoding:ENCODING})
}
function build(content){
return pegjs.generate(content,{
output:"source",
format:"umd"
});
}
files.forEach(
(file)=>{
let fileContent=fs.readFileSync(file.source,{encoding:ENCODING})
writeIn(file.target,build(fileContent))
}
)