diff --git a/package-lock.json b/package-lock.json index 23e74c5..d6bd39a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@scicave/math-parser", - "version": "2.2.0", + "version": "2.2.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 8c70378..a5693cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@scicave/math-parser", - "version": "2.2.0", + "version": "2.2.1", "description": "A mathematical parser. We mean by mathematical that, e.g., arithmetic operations is considered for example if you pass \"1+2\", the result would by a (add node \"+\") with two children nodes of type number.", "main": "lib/index.js", "files": [ diff --git a/src/version.js b/src/version.js index d00eb2e..6836a24 100644 --- a/src/version.js +++ b/src/version.js @@ -1,4 +1,4 @@ // this file is auto generated // the current version is: -module.exports = "2.2.0"; +module.exports = "2.2.1"; diff --git a/tools/build.js b/tools/build.js index ac21e15..37ff8b5 100644 --- a/tools/build.js +++ b/tools/build.js @@ -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 }); + } +} diff --git a/tools/generate-version-file.js b/tools/generate-version-file.js index ebd22a0..97eba3e 100644 --- a/tools/generate-version-file.js +++ b/tools/generate-version-file.js @@ -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); +