Skip to content

Commit

Permalink
feat: remove detect-roots option
Browse files Browse the repository at this point in the history
This is no longer a necessary option due to `destiny` supporting globs
and multiple paths as input.
  • Loading branch information
sQVe committed Feb 20, 2020
1 parent 758b353 commit 7812dc6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
7 changes: 0 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import { version } from "../package.json";
const { argv } = process;

export type Options = {
detectRoots: boolean;
help: boolean;
version: boolean;
};

const defaultOptions: Options = {
detectRoots: false,
help: false,
version: false,
};
Expand All @@ -36,7 +34,6 @@ const printHelp = (exitCode: number) => {
-V, --version output version number
-h, --help output usage information
-dr, --detect-roots structure after the first level
`
);

Expand All @@ -57,10 +54,6 @@ const parseArgs = (
case "--version":
acc.options.version = true;
break;
case "-dr":
case "--detect-roots":
acc.options.detectRoots = true;
break;
default:
acc.paths.push(arg);
}
Expand Down
17 changes: 3 additions & 14 deletions src/index/getFilePaths.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import glob from "glob";
import path from "path";
import { existsSync, lstatSync, readdirSync } from "fs-extra";
import { existsSync, lstatSync } from "fs-extra";

import logger from "../shared/logger";
import { Options } from "../index";

const isDirectory = (filePath: string) => lstatSync(filePath).isDirectory();
const isFile = (filePath: string) => lstatSync(filePath).isFile();
Expand All @@ -20,8 +19,7 @@ const globSearch = (pattern: string) => {
};

/** Recursively get all file paths. */
export const getFilePaths = (paths: string[], options: Options) => {
let { detectRoots } = options;
export const getFilePaths = (paths: string[]) => {
const files: string[][] = [];

while (paths.length > 0) {
Expand All @@ -39,16 +37,7 @@ export const getFilePaths = (paths: string[], options: Options) => {
if (isFile(filePath)) {
files.push([filePath]);
} else if (isDirectory(filePath)) {
if (detectRoots) {
const childDirectories = readdirSync(path.resolve(filePath))
.map(x => path.join(filePath, x))
.filter(x => isDirectory(x));

paths.push(...childDirectories);
detectRoots = false;
} else {
paths.push(path.join(filePath, "/**/*.*"));
}
paths.push(path.join(filePath, "/**/*.*"));
}
} else {
logger.error(`Unable to resolve the path: ${filePath}`);
Expand Down

0 comments on commit 7812dc6

Please sign in to comment.