add -web-template=<web_template_file>

This commit is contained in:
Aleksey Chichenkov 2019-01-31 11:18:26 +03:00
parent 3975898e13
commit ab8477b834
2 changed files with 11 additions and 3 deletions

View File

@ -22,7 +22,7 @@ node lexme.js
## Start ## Start
```bash ```bash
node main.js -inp=<input_file> -o=<output_path> -t=<web|node> <-nb|--no-beautify> <-logs> node main.js -inp=<input_file> -o=<output_path> -t=<web|node> <-nb|--no-beautify> -logs -web-template=<web_template_file>
# or # or
./run.sh ./run.sh
``` ```
@ -35,6 +35,7 @@ Result fill write in <lexer.js> file.
-t=<web|node> -t=<web|node>
-nb|--no-beautify -nb|--no-beautify
-logs -logs
-web-template=<web_template_file>
``` ```
## Test ## Test

11
main.js
View File

@ -50,8 +50,16 @@ var post_process_lexer = function (_string) {
if(args["t"] !== undefined) { if(args["t"] !== undefined) {
switch (args["t"]) { switch (args["t"]) {
case "web": case "web":
if(args["web-template"]){
if(!fs.existsSync(args["web-template"])){
throw "Not exist file: " + args["web-template"];
}
_string = "(function () {var deps = [];define(deps, function(){\n" + _string + "return Lexer; \n});})();"; var template = fs.readFileSync(args["web-template"], "utf8");
_string = template.replace(/<%%LEXER%%>/gm, _string);
} else {
_string = "(function () {var deps = [];define(deps, function(){\n" + _string + "return Lexer; \n});})();";
}
break; break;
case "node": case "node":
_string += "\n module.exports = Lexer"; _string += "\n module.exports = Lexer";
@ -59,7 +67,6 @@ var post_process_lexer = function (_string) {
} }
} }
_string = process_metatags(_string); _string = process_metatags(_string);
if( !(args["no-beautify"] || args["nb"]) ) { if( !(args["no-beautify"] || args["nb"]) ) {