chore: clean comment (#220)
* build: add clean comment script * chore: clean comment to hide sensitive information
This commit is contained in:
@ -4,6 +4,7 @@ const fs = require('fs');
|
||||
const argv = require('yargs-parser')(process.argv.slice(2));
|
||||
const inquirer = require('inquirer');
|
||||
const chalk = require('chalk');
|
||||
const { cleanComment } = require('./cleanComment');
|
||||
|
||||
const grammarsPath = path.resolve(__dirname, '../src/grammar');
|
||||
const outputPath = path.resolve(__dirname, '../src/lib');
|
||||
@ -29,7 +30,8 @@ function compile(language) {
|
||||
chalk.gray(err)
|
||||
);
|
||||
} else {
|
||||
console.log(chalk.greenBright(`\nCompile ${language} succeeded!`));
|
||||
cleanComment(language);
|
||||
console.log(chalk.greenBright(`Compile ${language} succeeded!`));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
37
scripts/cleanComment.js
Normal file
37
scripts/cleanComment.js
Normal file
@ -0,0 +1,37 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { globSync } = require('glob');
|
||||
const chalk = require('chalk');
|
||||
|
||||
const basePath = path.resolve(__dirname, '../src/lib');
|
||||
|
||||
function processFile(filePath) {
|
||||
try {
|
||||
const content = fs.readFileSync(filePath, 'utf-8');
|
||||
const firstLineIdx =
|
||||
content.indexOf('\r\n') === -1 ? content.indexOf('\n') : content.indexOf('\r\n');
|
||||
if (firstLineIdx === -1) return;
|
||||
|
||||
let firstLineContent = content.slice(0, firstLineIdx);
|
||||
const restContent = content.slice(firstLineIdx);
|
||||
|
||||
const slices = firstLineContent.split('/src/grammar/');
|
||||
if (slices.length !== 2) return;
|
||||
firstLineContent = `// Generated from dt-sql-parser/src/grammar/` + slices[1];
|
||||
|
||||
fs.writeFileSync(filePath, firstLineContent + restContent, 'utf-8');
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
function main(language) {
|
||||
const base = basePath + (language ? `/${language}` : '');
|
||||
console.info(chalk.green(`\nCleaning comment in:`, chalk.gray(`${base}/**/*.ts`)));
|
||||
const filePaths = globSync(`${base}/**/*.ts`, { absolute: true, nodir: true });
|
||||
filePaths.forEach(processFile);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
cleanComment: main,
|
||||
};
|
3
scripts/cleanCommentCli.js
Normal file
3
scripts/cleanCommentCli.js
Normal file
@ -0,0 +1,3 @@
|
||||
const { cleanComment } = require('./cleanComment');
|
||||
|
||||
cleanComment();
|
Reference in New Issue
Block a user