Skip to content

Commit

Permalink
build: replace rmdirSync with rmSync (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
HaydenOrz authored Oct 24, 2023
1 parent 3840ed3 commit 12864ee
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions scripts/antlr4.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
const path = require("path");
const exec = require("child_process").exec;
const fs = require("fs");
const argv = require("yargs-parser")(process.argv.slice(2));
const inquirer = require("inquirer");
const chalk = require("chalk");
const path = require('path');
const exec = require('child_process').exec;
const fs = require('fs');
const argv = require('yargs-parser')(process.argv.slice(2));
const inquirer = require('inquirer');
const chalk = require('chalk');

const grammarsPath = path.resolve(__dirname, "../src/grammar");
const outputPath = path.resolve(__dirname, "../src/lib");
const grammarsPath = path.resolve(__dirname, '../src/grammar');
const outputPath = path.resolve(__dirname, '../src/lib');

const languageEntries = fs
.readdirSync(grammarsPath)
.filter((item) => item !== "impala"); // impala is not support yet.
const languageEntries = fs.readdirSync(grammarsPath).filter((item) => item !== 'impala'); // impala is not support yet.

const baseCmd = 'antlr4ts -visitor -listener -Xexact-output-dir -o';

function compile(language) {
const cmd = `${baseCmd} ${outputPath}/${language} ${grammarsPath}/${language}/*.g4`;

console.info(chalk.green(`\nRemoving:`, chalk.gray(`${outputPath}/${language}/*`)));
fs.rmdirSync(`${outputPath}/${language}`, { recursive: true })
fs.rmSync(`${outputPath}/${language}`, { recursive: true });

console.info(chalk.green("Executing:"), chalk.gray(cmd));
console.info(chalk.green('Executing:'), chalk.gray(cmd));
exec(cmd, (err) => {
if (err) {
console.error(
Expand All @@ -38,16 +36,16 @@ function prompt() {
inquirer
.prompt([
{
type: "list",
name: "language",
message: "Which language you want compile (or all languages)",
choices: ["All Languages", ...languageEntries],
type: 'list',
name: 'language',
message: 'Which language you want compile (or all languages)',
choices: ['All Languages', ...languageEntries],
loop: true,
},
])
.then((result) => {
const language = result.language;
if(language === 'All Languages') {
if (language === 'All Languages') {
languageEntries.forEach((language) => {
compile(language);
});
Expand All @@ -65,14 +63,12 @@ function main() {
});
} else if (argv.lang) {
// compile single: yarn antlr4 --lang=generic
const supportedLanguage = languageEntries.some(
(language) => language === argv.lang
);
const supportedLanguage = languageEntries.some((language) => language === argv.lang);
if (supportedLanguage) {
compile(argv.lang);
} else {
console.error(
chalk.bold.red("\n[Invalid language]:"),
chalk.bold.red('\n[Invalid language]:'),
chalk.white.underline(`${argv.lang}\n`)
);
prompt();
Expand Down

0 comments on commit 12864ee

Please sign in to comment.