Skip to content

Commit

Permalink
Update package version to v2.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
MuhammadSawalhy committed Aug 31, 2020
1 parent 57abb75 commit 9aa2a6d
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 122 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion src/version.js
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";
210 changes: 105 additions & 105 deletions tools/build.js
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 });
}
}
28 changes: 14 additions & 14 deletions tools/generate-version-file.js
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);

0 comments on commit 9aa2a6d

Please sign in to comment.