2018-07-05 11:16:30 +08:00
|
|
|
const pegjs=require("pegjs");
|
|
|
|
const path=require("path");
|
|
|
|
const fs=require("fs");
|
|
|
|
|
2018-07-06 16:58:25 +08:00
|
|
|
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") ,
|
|
|
|
}];
|
|
|
|
|
2018-07-06 16:58:25 +08:00
|
|
|
|
|
|
|
function writeIn(file,data){
|
|
|
|
fs.writeFileSync(file,data,{encoding:ENCODING})
|
|
|
|
}
|
|
|
|
function build(content){
|
|
|
|
return pegjs.generate(content,{
|
|
|
|
output:"source",
|
2018-07-06 17:03:44 +08:00
|
|
|
format:"umd",
|
|
|
|
optimize:"size"
|
2018-07-06 16:58:25 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
files.forEach(
|
|
|
|
(file)=>{
|
|
|
|
let fileContent=fs.readFileSync(file.source,{encoding:ENCODING})
|
|
|
|
writeIn(file.target,build(fileContent))
|
|
|
|
}
|
|
|
|
)
|