-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57abb75
commit 9aa2a6d
Showing
5 changed files
with
122 additions
and
122 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
// this file is auto generated | ||
// the current version is: | ||
module.exports = "2.2.0"; | ||
module.exports = "2.2.1"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,105 @@ | ||
const pegjs = require("pegjs"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const rimraf = require("rimraf"); | ||
|
||
let dev = process.env.NODE_ENV !== "production"; | ||
|
||
let pegjsOptions = { | ||
output: "source", | ||
format: "commonjs", | ||
}; | ||
|
||
let replacements = [ | ||
{ | ||
text: [ | ||
"module.exports = {", | ||
" SyntaxError: peg$SyntaxError,", | ||
" parse: peg$parse", "};" | ||
].join("\n"), | ||
|
||
replacement: [ | ||
"module.exports = {", | ||
" SyntaxError: peg$SyntaxError,", | ||
" parse: peg$parse,", | ||
" Node,", " version,", | ||
"};" | ||
].join("\n"), | ||
}, | ||
]; | ||
|
||
let grammarFiles = [ | ||
{ | ||
input: "../src/math.pegjs", | ||
output: "../lib/index.js", | ||
dependencies: { | ||
Node: "./mathParserNode.js", | ||
version: "./version.js", | ||
}, | ||
}, | ||
]; | ||
|
||
grammarFiles.forEach((file) => { | ||
pegjsOptions.dependencies = file.dependencies; | ||
let inputPath = path.resolve(__dirname, file.input); | ||
let inputDir = path.dirname(inputPath); | ||
let outputPath = path.resolve(__dirname, file.output); | ||
let outputDir = path.dirname(outputPath); | ||
|
||
if (outputDir !== inputDir) { | ||
prepareOutputDir(outputDir); | ||
} | ||
|
||
console.log("compiling>>>>>>>>>>>>>"); | ||
console.log(inputPath); | ||
console.log(); | ||
|
||
function getParserCode() { | ||
let grammar = fs.readFileSync(inputPath).toString("utf8"); | ||
let code = pegjs.generate(grammar, pegjsOptions); | ||
|
||
/// some targeted replacments | ||
for (let r of replacements) { | ||
code = code.replace(r.text, r.replacement); | ||
} | ||
|
||
/// here we want to replace comment with contents file | ||
code = code.replace(/\/\*\*#\s*require\s*\(\s*"(.*?)"\s*\)\s*\*\//gm, (m, g) => { | ||
return fs.readFileSync(path.resolve(inputDir, g)).toString("utf8"); | ||
}); | ||
|
||
return code; | ||
} | ||
|
||
fs.writeFileSync(outputPath, getParserCode()); | ||
|
||
if (outputDir !== inputDir) { | ||
// copy depedencies to the output directory | ||
for (let d of Object.values(file.dependencies)) { | ||
let p1 = path.resolve(inputDir, d); | ||
let p2 = path.resolve(outputDir, d); | ||
let dist = path.dirname(p2); | ||
|
||
if (!fs.existsSync(dist)) { | ||
fs.mkdirSync(dist, { recursive: true }); | ||
} | ||
|
||
let readable = fs.createReadStream(p1, { encoding: "utf-8" }); | ||
let writable = fs.createWriteStream(p2); | ||
readable.pipe(writable); | ||
} | ||
} | ||
|
||
console.log("js code:::::::::"); | ||
console.log(outputPath); | ||
console.log(); | ||
}); | ||
|
||
function prepareOutputDir(outputDir) { | ||
if (fs.existsSync(outputDir)) { | ||
/// delete all the output dir content | ||
rimraf.sync(path.resolve(outputDir, "*")); | ||
} else { | ||
fs.mkdirSync(outputDir, { recursive: true }); | ||
} | ||
} | ||
const pegjs = require("pegjs"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const rimraf = require("rimraf"); | ||
|
||
let dev = process.env.NODE_ENV !== "production"; | ||
|
||
let pegjsOptions = { | ||
output: "source", | ||
format: "commonjs", | ||
}; | ||
|
||
let replacements = [ | ||
{ | ||
text: [ | ||
"module.exports = {", | ||
" SyntaxError: peg$SyntaxError,", | ||
" parse: peg$parse", "};" | ||
].join("\n"), | ||
|
||
replacement: [ | ||
"module.exports = {", | ||
" SyntaxError: peg$SyntaxError,", | ||
" parse: peg$parse,", | ||
" Node,", " version,", | ||
"};" | ||
].join("\n"), | ||
}, | ||
]; | ||
|
||
let grammarFiles = [ | ||
{ | ||
input: "../src/math.pegjs", | ||
output: "../lib/index.js", | ||
dependencies: { | ||
Node: "./mathParserNode.js", | ||
version: "./version.js", | ||
}, | ||
}, | ||
]; | ||
|
||
grammarFiles.forEach((file) => { | ||
pegjsOptions.dependencies = file.dependencies; | ||
let inputPath = path.resolve(__dirname, file.input); | ||
let inputDir = path.dirname(inputPath); | ||
let outputPath = path.resolve(__dirname, file.output); | ||
let outputDir = path.dirname(outputPath); | ||
|
||
if (outputDir !== inputDir) { | ||
prepareOutputDir(outputDir); | ||
} | ||
|
||
console.log("compiling>>>>>>>>>>>>>"); | ||
console.log(inputPath); | ||
console.log(); | ||
|
||
function getParserCode() { | ||
let grammar = fs.readFileSync(inputPath).toString("utf8"); | ||
let code = pegjs.generate(grammar, pegjsOptions); | ||
|
||
/// some targeted replacments | ||
for (let r of replacements) { | ||
code = code.replace(r.text, r.replacement); | ||
} | ||
|
||
/// here we want to replace comment with contents file | ||
code = code.replace(/\/\*\*#\s*require\s*\(\s*"(.*?)"\s*\)\s*\*\//gm, (m, g) => { | ||
return fs.readFileSync(path.resolve(inputDir, g)).toString("utf8"); | ||
}); | ||
|
||
return code; | ||
} | ||
|
||
fs.writeFileSync(outputPath, getParserCode()); | ||
|
||
if (outputDir !== inputDir) { | ||
// copy depedencies to the output directory | ||
for (let d of Object.values(file.dependencies)) { | ||
let p1 = path.resolve(inputDir, d); | ||
let p2 = path.resolve(outputDir, d); | ||
let dist = path.dirname(p2); | ||
|
||
if (!fs.existsSync(dist)) { | ||
fs.mkdirSync(dist, { recursive: true }); | ||
} | ||
|
||
let readable = fs.createReadStream(p1, { encoding: "utf-8" }); | ||
let writable = fs.createWriteStream(p2); | ||
readable.pipe(writable); | ||
} | ||
} | ||
|
||
console.log("js code:::::::::"); | ||
console.log(outputPath); | ||
console.log(); | ||
}); | ||
|
||
function prepareOutputDir(outputDir) { | ||
if (fs.existsSync(outputDir)) { | ||
/// delete all the output dir content | ||
rimraf.sync(path.resolve(outputDir, "*")); | ||
} else { | ||
fs.mkdirSync(outputDir, { recursive: true }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
let pkg = require('../package.json'); | ||
let filePath = '../src/version.js'; | ||
let version = pkg.version; | ||
let path = require('path'); | ||
let fs = require('fs'); | ||
|
||
let code =` | ||
// this file is auto generated | ||
// the current version is: | ||
module.exports = "${version}"; | ||
`; | ||
|
||
fs.writeFileSync(path.resolve(__dirname, filePath), code); | ||
|
||
let pkg = require('../package.json'); | ||
let filePath = '../src/version.js'; | ||
let version = pkg.version; | ||
let path = require('path'); | ||
let fs = require('fs'); | ||
|
||
let code =` | ||
// this file is auto generated | ||
// the current version is: | ||
module.exports = "${version}"; | ||
`; | ||
|
||
fs.writeFileSync(path.resolve(__dirname, filePath), code); | ||