1- const path = require ( " path" ) ;
2- const exec = require ( " child_process" ) . exec ;
3- const fs = require ( "fs" ) ;
4- const argv = require ( " yargs-parser" ) ( process . argv . slice ( 2 ) ) ;
5- const inquirer = require ( " inquirer" ) ;
6- const chalk = require ( " chalk" ) ;
1+ const path = require ( ' path' ) ;
2+ const exec = require ( ' child_process' ) . exec ;
3+ const fs = require ( 'fs' ) ;
4+ const argv = require ( ' yargs-parser' ) ( process . argv . slice ( 2 ) ) ;
5+ const inquirer = require ( ' inquirer' ) ;
6+ const chalk = require ( ' chalk' ) ;
77
8- const grammarsPath = path . resolve ( __dirname , " ../src/grammar" ) ;
9- const outputPath = path . resolve ( __dirname , " ../src/lib" ) ;
8+ const grammarsPath = path . resolve ( __dirname , ' ../src/grammar' ) ;
9+ const outputPath = path . resolve ( __dirname , ' ../src/lib' ) ;
1010
11- const languageEntries = fs
12- . readdirSync ( grammarsPath )
13- . filter ( ( item ) => item !== "impala" ) ; // impala is not support yet.
11+ const languageEntries = fs . readdirSync ( grammarsPath ) . filter ( ( item ) => item !== 'impala' ) ; // impala is not support yet.
1412
1513const baseCmd = 'antlr4ts -visitor -listener -Xexact-output-dir -o' ;
1614
1715function compile ( language ) {
1816 const cmd = `${ baseCmd } ${ outputPath } /${ language } ${ grammarsPath } /${ language } /*.g4` ;
1917
2018 console . info ( chalk . green ( `\nRemoving:` , chalk . gray ( `${ outputPath } /${ language } /*` ) ) ) ;
21- fs . rmdirSync ( `${ outputPath } /${ language } ` , { recursive : true } )
19+ fs . rmSync ( `${ outputPath } /${ language } ` , { recursive : true } ) ;
2220
23- console . info ( chalk . green ( " Executing:" ) , chalk . gray ( cmd ) ) ;
21+ console . info ( chalk . green ( ' Executing:' ) , chalk . gray ( cmd ) ) ;
2422 exec ( cmd , ( err ) => {
2523 if ( err ) {
2624 console . error (
@@ -38,16 +36,16 @@ function prompt() {
3836 inquirer
3937 . prompt ( [
4038 {
41- type : " list" ,
42- name : " language" ,
43- message : " Which language you want compile (or all languages)" ,
44- choices : [ " All Languages" , ...languageEntries ] ,
39+ type : ' list' ,
40+ name : ' language' ,
41+ message : ' Which language you want compile (or all languages)' ,
42+ choices : [ ' All Languages' , ...languageEntries ] ,
4543 loop : true ,
4644 } ,
4745 ] )
4846 . then ( ( result ) => {
4947 const language = result . language ;
50- if ( language === 'All Languages' ) {
48+ if ( language === 'All Languages' ) {
5149 languageEntries . forEach ( ( language ) => {
5250 compile ( language ) ;
5351 } ) ;
@@ -65,14 +63,12 @@ function main() {
6563 } ) ;
6664 } else if ( argv . lang ) {
6765 // compile single: yarn antlr4 --lang=generic
68- const supportedLanguage = languageEntries . some (
69- ( language ) => language === argv . lang
70- ) ;
66+ const supportedLanguage = languageEntries . some ( ( language ) => language === argv . lang ) ;
7167 if ( supportedLanguage ) {
7268 compile ( argv . lang ) ;
7369 } else {
7470 console . error (
75- chalk . bold . red ( " \n[Invalid language]:" ) ,
71+ chalk . bold . red ( ' \n[Invalid language]:' ) ,
7672 chalk . white . underline ( `${ argv . lang } \n` )
7773 ) ;
7874 prompt ( ) ;
0 commit comments