build: replace rmdirSync with rmSync (#187)
This commit is contained in:
parent
3840ed37b2
commit
12864eea93
@ -1,16 +1,14 @@
|
|||||||
const path = require("path");
|
const path = require('path');
|
||||||
const exec = require("child_process").exec;
|
const exec = require('child_process').exec;
|
||||||
const fs = require("fs");
|
const fs = require('fs');
|
||||||
const argv = require("yargs-parser")(process.argv.slice(2));
|
const argv = require('yargs-parser')(process.argv.slice(2));
|
||||||
const inquirer = require("inquirer");
|
const inquirer = require('inquirer');
|
||||||
const chalk = require("chalk");
|
const chalk = require('chalk');
|
||||||
|
|
||||||
const grammarsPath = path.resolve(__dirname, "../src/grammar");
|
const grammarsPath = path.resolve(__dirname, '../src/grammar');
|
||||||
const outputPath = path.resolve(__dirname, "../src/lib");
|
const outputPath = path.resolve(__dirname, '../src/lib');
|
||||||
|
|
||||||
const languageEntries = fs
|
const languageEntries = fs.readdirSync(grammarsPath).filter((item) => item !== 'impala'); // impala is not support yet.
|
||||||
.readdirSync(grammarsPath)
|
|
||||||
.filter((item) => item !== "impala"); // impala is not support yet.
|
|
||||||
|
|
||||||
const baseCmd = 'antlr4ts -visitor -listener -Xexact-output-dir -o';
|
const baseCmd = 'antlr4ts -visitor -listener -Xexact-output-dir -o';
|
||||||
|
|
||||||
@ -18,9 +16,9 @@ function compile(language) {
|
|||||||
const cmd = `${baseCmd} ${outputPath}/${language} ${grammarsPath}/${language}/*.g4`;
|
const cmd = `${baseCmd} ${outputPath}/${language} ${grammarsPath}/${language}/*.g4`;
|
||||||
|
|
||||||
console.info(chalk.green(`\nRemoving:`, chalk.gray(`${outputPath}/${language}/*`)));
|
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) => {
|
exec(cmd, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(
|
console.error(
|
||||||
@ -38,16 +36,16 @@ function prompt() {
|
|||||||
inquirer
|
inquirer
|
||||||
.prompt([
|
.prompt([
|
||||||
{
|
{
|
||||||
type: "list",
|
type: 'list',
|
||||||
name: "language",
|
name: 'language',
|
||||||
message: "Which language you want compile (or all languages)",
|
message: 'Which language you want compile (or all languages)',
|
||||||
choices: ["All Languages", ...languageEntries],
|
choices: ['All Languages', ...languageEntries],
|
||||||
loop: true,
|
loop: true,
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
const language = result.language;
|
const language = result.language;
|
||||||
if(language === 'All Languages') {
|
if (language === 'All Languages') {
|
||||||
languageEntries.forEach((language) => {
|
languageEntries.forEach((language) => {
|
||||||
compile(language);
|
compile(language);
|
||||||
});
|
});
|
||||||
@ -65,14 +63,12 @@ function main() {
|
|||||||
});
|
});
|
||||||
} else if (argv.lang) {
|
} else if (argv.lang) {
|
||||||
// compile single: yarn antlr4 --lang=generic
|
// compile single: yarn antlr4 --lang=generic
|
||||||
const supportedLanguage = languageEntries.some(
|
const supportedLanguage = languageEntries.some((language) => language === argv.lang);
|
||||||
(language) => language === argv.lang
|
|
||||||
);
|
|
||||||
if (supportedLanguage) {
|
if (supportedLanguage) {
|
||||||
compile(argv.lang);
|
compile(argv.lang);
|
||||||
} else {
|
} else {
|
||||||
console.error(
|
console.error(
|
||||||
chalk.bold.red("\n[Invalid language]:"),
|
chalk.bold.red('\n[Invalid language]:'),
|
||||||
chalk.white.underline(`${argv.lang}\n`)
|
chalk.white.underline(`${argv.lang}\n`)
|
||||||
);
|
);
|
||||||
prompt();
|
prompt();
|
||||||
|
Loading…
Reference in New Issue
Block a user