Add --include-dotfiles option to babel-cli (#6232)
This commit is contained in:
@@ -71,10 +71,13 @@ export default function(commander, filenames, opts) {
|
||||
if (commander.deleteDirOnStart) {
|
||||
util.deleteDir(commander.outDir);
|
||||
}
|
||||
util.readdir(dirname).forEach(function(filename) {
|
||||
const src = path.join(dirname, filename);
|
||||
handleFile(src, filename, dirname);
|
||||
});
|
||||
|
||||
util
|
||||
.readdir(dirname, commander.includeDotfiles)
|
||||
.forEach(function(filename) {
|
||||
const src = path.join(dirname, filename);
|
||||
handleFile(src, filename, dirname);
|
||||
});
|
||||
} else {
|
||||
write(filename, path.basename(filename), path.dirname(filename));
|
||||
}
|
||||
|
||||
@@ -130,9 +130,11 @@ export default function(commander, filenames, opts) {
|
||||
if (stat.isDirectory()) {
|
||||
const dirname = filename;
|
||||
|
||||
util.readdirFilter(filename).forEach(function(filename) {
|
||||
_filenames.push(path.join(dirname, filename));
|
||||
});
|
||||
util
|
||||
.readdirForCompilable(filename, commander.includeDotfiles)
|
||||
.forEach(function(filename) {
|
||||
_filenames.push(path.join(dirname, filename));
|
||||
});
|
||||
} else {
|
||||
_filenames.push(filename);
|
||||
}
|
||||
|
||||
@@ -154,10 +154,14 @@ commander.option(
|
||||
"-D, --copy-files",
|
||||
"When compiling a directory copy over non-compilable files",
|
||||
);
|
||||
commander.option(
|
||||
"--include-dotfiles",
|
||||
"Include dotfiles when compiling and copying non-compilable files",
|
||||
);
|
||||
commander.option("-q, --quiet", "Don't log anything");
|
||||
commander.option(
|
||||
"--delete-dir-on-start",
|
||||
"Delete's the out directory before compilation",
|
||||
"Delete the out directory before compilation",
|
||||
);
|
||||
/* eslint-enable max-len */
|
||||
|
||||
@@ -233,6 +237,7 @@ delete opts.skipInitialBuild;
|
||||
delete opts.outFile;
|
||||
delete opts.outDir;
|
||||
delete opts.copyFiles;
|
||||
delete opts.includeDotfiles;
|
||||
delete opts.quiet;
|
||||
delete opts.configFile;
|
||||
delete opts.deleteDirOnStart;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import commander from "commander";
|
||||
import readdir from "fs-readdir-recursive";
|
||||
import readdirRecursive from "fs-readdir-recursive";
|
||||
import * as babel from "babel-core";
|
||||
import includes from "lodash/includes";
|
||||
import path from "path";
|
||||
@@ -9,13 +9,26 @@ export function chmod(src, dest) {
|
||||
fs.chmodSync(dest, fs.statSync(src).mode);
|
||||
}
|
||||
|
||||
export function readdirFilter(filename) {
|
||||
return readdir(filename).filter(function(filename) {
|
||||
return isCompilableExtension(filename);
|
||||
});
|
||||
type ReaddirFilter = (filename: string) => boolean;
|
||||
|
||||
export function readdir(
|
||||
dirname: string,
|
||||
includeDotfiles: boolean,
|
||||
filter: ReaddirFilter,
|
||||
) {
|
||||
return readdirRecursive(
|
||||
dirname,
|
||||
filename =>
|
||||
(includeDotfiles || filename[0] !== ".") && (!filter || filter(filename)),
|
||||
);
|
||||
}
|
||||
|
||||
export { readdir };
|
||||
export function readdirForCompilable(
|
||||
dirname: string,
|
||||
includeDotfiles: boolean,
|
||||
) {
|
||||
return readdir(dirname, includeDotfiles, isCompilableExtension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a filename ends with a compilable extension.
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
a;
|
||||
@@ -0,0 +1 @@
|
||||
bar;
|
||||
@@ -0,0 +1 @@
|
||||
index;
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"args": [
|
||||
"src",
|
||||
"--out-dir", "lib",
|
||||
"--copy-files",
|
||||
"--include-dotfiles",
|
||||
"--ignore", "src/foo"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
a;
|
||||
@@ -0,0 +1 @@
|
||||
bar;
|
||||
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
index;
|
||||
@@ -0,0 +1 @@
|
||||
src/index.js -> lib/index.js
|
||||
@@ -0,0 +1 @@
|
||||
a;
|
||||
@@ -0,0 +1 @@
|
||||
bar;
|
||||
@@ -0,0 +1 @@
|
||||
index;
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"args": [
|
||||
"src",
|
||||
"--out-dir", "lib",
|
||||
"--copy-files",
|
||||
"--include-dotfiles",
|
||||
"--only", "src/foo"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
a;
|
||||
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
bar;
|
||||
@@ -0,0 +1 @@
|
||||
index;
|
||||
2
packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with only/stdout.txt
vendored
Normal file
2
packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles with only/stdout.txt
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
src/foo/.foo.js -> lib/foo/.foo.js
|
||||
src/foo/bar.js -> lib/foo/bar.js
|
||||
1
packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles/in-files/src/.foo.js
vendored
Normal file
1
packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles/in-files/src/.foo.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
a;
|
||||
0
packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles/in-files/src/.foorc
vendored
Normal file
0
packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles/in-files/src/.foorc
vendored
Normal file
@@ -0,0 +1 @@
|
||||
bar;
|
||||
3
packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles/options.json
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"args": ["src", "--out-dir", "lib", "--copy-files", "--include-dotfiles"]
|
||||
}
|
||||
3
packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles/out-files/lib/.foo.js
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles/out-files/lib/.foo.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
a;
|
||||
0
packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles/out-files/lib/.foorc
vendored
Normal file
0
packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles/out-files/lib/.foorc
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
bar;
|
||||
3
packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles/stdout.txt
vendored
Normal file
3
packages/babel-cli/test/fixtures/babel/--copy-files --include-dotfiles/stdout.txt
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
src/.foo.js -> lib/.foo.js
|
||||
src/bar/index.js -> lib/bar/index.js
|
||||
src/foo/foo.js -> lib/foo/foo.js
|
||||
0
packages/babel-cli/test/fixtures/babel/--copy-files with ignore/in-files/src/.foorc
vendored
Normal file
0
packages/babel-cli/test/fixtures/babel/--copy-files with ignore/in-files/src/.foorc
vendored
Normal file
0
packages/babel-cli/test/fixtures/babel/--copy-files with only/in-files/src/.foorc
vendored
Normal file
0
packages/babel-cli/test/fixtures/babel/--copy-files with only/in-files/src/.foorc
vendored
Normal file
@@ -88,10 +88,14 @@ const assertTest = function(stdout, stderr, opts) {
|
||||
}
|
||||
|
||||
if (opts.outFiles) {
|
||||
const actualFiles = readDir(path.join(tmpLoc));
|
||||
const actualFiles = readDir(path.join(tmpLoc), fileFilter);
|
||||
|
||||
Object.keys(actualFiles).forEach(function(filename) {
|
||||
if (!opts.inFiles.hasOwnProperty(filename)) {
|
||||
if (
|
||||
// saveInFiles always creates an empty .babelrc, so lets exclude for now
|
||||
filename !== ".babelrc" &&
|
||||
!opts.inFiles.hasOwnProperty(filename)
|
||||
) {
|
||||
const expect = opts.outFiles[filename];
|
||||
const actual = actualFiles[filename];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user