build: replace rmdirSync with rmSync (#187)

This commit is contained in:
Hayden 2023-10-24 10:34:14 +08:00 committed by GitHub
parent 3840ed37b2
commit 12864eea93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,16 +1,14 @@
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';
@ -18,9 +16,9 @@ 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(
@ -38,10 +36,10 @@ 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,
},
])
@ -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();