Skip to content

Commit

Permalink
fix production build
Browse files Browse the repository at this point in the history
  • Loading branch information
splitice committed Oct 18, 2024
1 parent 8491419 commit d13d9a0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules/
RuleParser.production.js
RuleParser.production.*
29 changes: 26 additions & 3 deletions bin/package.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
const fs = require('fs')

function makeid(length) {
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
let counter = 0;
while (counter < length) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
counter += 1;
}
return result;
}

let replacements = {}
const ParserRules = require('../src/RuleParser.ebnf.js')
const rules = JSON.stringify(ParserRules)
RegExp.prototype.toJSON = function(){
// generate a random string:
const randomString = makeid(256)
replacements[randomString] = this
return randomString
}

let rules = JSON.stringify(ParserRules)
for(const key in replacements){
rules = rules.replace(`"${key}"`, replacements[key].toString())
}

fs.writeFileSync('src/RuleParser.ebnf.json', rules)
fs.writeFileSync('src/RuleParser.production.ebnf.js', "module.exports="+rules)

const ruleParserJs = fs.readFileSync('src/RuleParser.js', 'utf8')
const ruleParserJsFixed = ruleParserJs.replace("require('./RuleParser.ebnf.js')", 'require(\'./RuleParser.ebnf.json\')')
const ruleParserJsFixed = ruleParserJs.replace("require('./RuleParser.ebnf.js')", 'require(\'./RuleParser.production.ebnf.js\')')

fs.writeFileSync('src/RuleParser.production.js', ruleParserJsFixed)
1 change: 0 additions & 1 deletion src/RuleParser.ebnf.json

This file was deleted.

0 comments on commit d13d9a0

Please sign in to comment.