Added --delete-dir-on-start option for babel (#6187)
* added --delete-dir-on-start option added --delete-dir-on-start-option to delete dir on start of compilation to remove deleted files from the orignial files from the --out-dir * added option --delete-dir-on-start added --delete-dir-on-start that option will delete the --out-dir before the compilation of code to remove the deleted files from the source from the out directory * added --delete-dir-on-start option added --delete-dir-on-start-option to delete dir on start of compilation to remove deleted files from the orignial files from the --out-dir * bug removed deleting the correct dir in the previous code, the source dir was deleted each time rather than deleting the out dir * Remove shorthand * Prevent babel-cli option from reaching babel-core * Lint
This commit is contained in:
@@ -63,6 +63,9 @@ export default function(commander, filenames, opts) {
|
||||
if (stat.isDirectory(filename)) {
|
||||
const dirname = filename;
|
||||
|
||||
if (commander.deleteDirOnStart) {
|
||||
util.deleteDir(commander.outDir);
|
||||
}
|
||||
util.readdir(dirname).forEach(function(filename) {
|
||||
const src = path.join(dirname, filename);
|
||||
handleFile(src, filename);
|
||||
|
||||
@@ -147,6 +147,10 @@ commander.option(
|
||||
"When compiling a directory copy over non-compilable files",
|
||||
);
|
||||
commander.option("-q, --quiet", "Don't log anything");
|
||||
commander.option(
|
||||
"--delete-dir-on-start",
|
||||
"Delete's the out directory before compilation",
|
||||
);
|
||||
/* eslint-enable max-len */
|
||||
|
||||
commander.version(pkg.version + " (babel-core " + version + ")");
|
||||
@@ -192,6 +196,9 @@ if (commander.watch) {
|
||||
if (commander.skipInitialBuild && !commander.watch) {
|
||||
errors.push("--skip-initial-build requires --watch");
|
||||
}
|
||||
if (commander.deleteDirOnStart && !commander.outDir) {
|
||||
errors.push("--delete-dir-on-start requires --out-dir");
|
||||
}
|
||||
|
||||
if (errors.length) {
|
||||
console.error(errors.join(". "));
|
||||
@@ -216,6 +223,7 @@ delete opts.outDir;
|
||||
delete opts.copyFiles;
|
||||
delete opts.quiet;
|
||||
delete opts.configFile;
|
||||
delete opts.deleteDirOnStart;
|
||||
|
||||
// Commander will default the "--no-" arguments to true, but we want to leave them undefined so that
|
||||
// babel-core can handle the default-assignment logic on its own.
|
||||
|
||||
@@ -58,6 +58,22 @@ export function compile(filename, opts) {
|
||||
}
|
||||
}
|
||||
|
||||
export function deleteDir(path) {
|
||||
if (fs.existsSync(path)) {
|
||||
fs.readdirSync(path).forEach(function(file) {
|
||||
const curPath = path + "/" + file;
|
||||
if (fs.lstatSync(curPath).isDirectory()) {
|
||||
// recurse
|
||||
deleteDir(curPath);
|
||||
} else {
|
||||
// delete file
|
||||
fs.unlinkSync(curPath);
|
||||
}
|
||||
});
|
||||
fs.rmdirSync(path);
|
||||
}
|
||||
}
|
||||
|
||||
function toErrorStack(err) {
|
||||
if (err._babel && err instanceof SyntaxError) {
|
||||
return `${err.name}: ${err.message}\n${err.codeFrame}`;
|
||||
|
||||
Reference in New Issue
Block a user