Add --keep-file-extension option to babel-cli (#6221)

* Add --keep-module-extension option to babel-cli

* Rename keep-module-extension option to keep-file-extension; Change option to preserve all file extensions
This commit is contained in:
Laurin Quast 2017-09-12 00:06:44 +02:00 committed by Justin Ridgewell
parent 4daf11528c
commit 8742012b5e
9 changed files with 30 additions and 1 deletions

View File

@ -13,7 +13,7 @@ export default function(commander, filenames, opts) {
}
// remove extension and then append back on .js
relative = relative.replace(/\.(\w*?)$/, "") + ".js";
relative = util.adjustRelative(relative, commander.keepFileExtension);
const dest = getDest(commander, relative, base);

View File

@ -129,6 +129,10 @@ commander.option(
"List of extensions to compile when a directory has been input [.es6,.js,.es,.jsx,.mjs]",
collect,
);
commander.option(
"--keep-file-extension",
"Preserve the file extensions of the input files",
);
commander.option("-w, --watch", "Recompile files on changes");
commander.option(
"--skip-initial-build",
@ -232,6 +236,7 @@ delete opts.copyFiles;
delete opts.quiet;
delete opts.configFile;
delete opts.deleteDirOnStart;
delete opts.keepFileExtension;
// 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.

View File

@ -98,3 +98,10 @@ export function requireChokidar() {
throw err;
}
}
export function adjustRelative(relative, keepFileExtension) {
if (keepFileExtension) {
return relative;
}
return relative.replace(/\.(\w*?)$/, "") + ".js";
}

View File

@ -0,0 +1 @@
arr.map(x => x / DIVIDER);

View File

@ -0,0 +1 @@
arr.map(x => x * MULTIPLIER);

View File

@ -0,0 +1,3 @@
{
"args": ["src", "--out-dir", "lib", "--keep-file-extension"]
}

View File

@ -0,0 +1,5 @@
"use strict";
arr.map(function (x) {
return x / DIVIDER;
});

View File

@ -0,0 +1,5 @@
"use strict";
arr.map(function (x) {
return x * MULTIPLIER;
});

View File

@ -0,0 +1,2 @@
src/bar.mjs -> lib/bar.mjs
src/foo.js -> lib/foo.js