find-duplicate-strings
Advanced tools
Comparing version 2.0.0 to 2.0.1
export {}; |
@@ -16,4 +16,10 @@ "use strict"; | ||
program | ||
.option('-s, --silent', 'Prevent the CLI from printing messages through the console.') | ||
.action(({ silent }) => __awaiter(void 0, void 0, void 0, function* () { return (yield new scanner_1.Scanner(silent).init()).scan().catch((err) => console.error(`Error: ${err.message}`)); })) | ||
.option('--exclusions <items>', 'comma separated list of directories and/or files to exclude') | ||
.option('--extensions <items>', 'comma separated list of extensions to scan') | ||
.option('-s, --silent', 'prevent CLI from printing messages through the console') | ||
.action(({ silent, exclusions, extensions, args }) => __awaiter(void 0, void 0, void 0, function* () { | ||
yield new scanner_1.Scanner({ silent, exclusions, extensions, path: args[0] }).scan().catch((err) => { | ||
console.error(`Error: ${err.message}`); | ||
}); | ||
})) | ||
.parse(process.argv); |
#!/usr/bin/env node | ||
export {}; |
#!/usr/bin/env node | ||
"use strict"; | ||
require('./cli'); |
@@ -0,0 +0,0 @@ import { Question } from './question'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { Question } from './question'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { Question } from './question'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { Question } from './question'; |
@@ -16,3 +16,3 @@ "use strict"; | ||
constructor() { | ||
super('exclusions', 'Please provide any directories that you want to skip (separated list by ;)'); | ||
super('exclusions', 'Please provide any directories or files that you would like to exclude (comma separated list)'); | ||
} | ||
@@ -25,3 +25,3 @@ getAnswer() { | ||
const answer = yield _super.getAnswer.call(this); | ||
return answer.split(';'); | ||
return answer.split(','); | ||
}); | ||
@@ -28,0 +28,0 @@ } |
@@ -0,0 +0,0 @@ import { Question } from './question'; |
@@ -14,5 +14,7 @@ "use strict"; | ||
const question_1 = require("./question"); | ||
const extensions_1 = require("../../extensions"); | ||
const { removeDotPrefix } = new extensions_1.Extensions(); | ||
class ExtensionsQuestion extends question_1.Question { | ||
constructor() { | ||
super('extensions', 'Please provide the file extensions you want to scan or leave empty to scan all files (separated list by ;)'); | ||
super('extensions', 'Please provide the file extensions you want to scan or leave empty to scan all files (comma separated list)'); | ||
} | ||
@@ -24,11 +26,4 @@ getAnswer() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return (yield _super.getAnswer.call(this)) | ||
.split(';') | ||
.map((extension) => { | ||
if (extension.startsWith('.')) { | ||
return extension.substr(1, extension.length); | ||
} | ||
return extension; | ||
}) | ||
.filter((extension) => extension); | ||
const answer = yield _super.getAnswer.call(this); | ||
return removeDotPrefix(answer.split(',')); | ||
}); | ||
@@ -35,0 +30,0 @@ } |
@@ -0,0 +0,0 @@ export { DirectoryQuestion } from './directory'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { Question } from './question'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { QuestionMap } from 'inquirer'; |
@@ -0,0 +0,0 @@ "use strict"; |
export declare class Directory { | ||
private exclusions; | ||
private extensions; | ||
private readonly resolvedDir; | ||
private readonly path; | ||
constructor(directory: string, exclusions: string[], extensions: string[]); | ||
@@ -6,0 +6,0 @@ getFiles(): string[]; |
@@ -28,7 +28,7 @@ "use strict"; | ||
}; | ||
this.resolvedDir = path_1.resolve(process.cwd(), directory); | ||
if (!fs_1.existsSync(this.resolvedDir)) { | ||
this.path = path_1.resolve(process.cwd(), directory); | ||
if (!fs_1.existsSync(this.path)) { | ||
throw new Error('Directory does not exist, please pass a valid path.'); | ||
} | ||
if (!fs_1.statSync(this.resolvedDir).isDirectory()) { | ||
if (!fs_1.statSync(this.path).isDirectory()) { | ||
throw new Error('Path does not point to a directory.'); | ||
@@ -38,5 +38,5 @@ } | ||
getFiles() { | ||
return this.readdirRecursively(this.resolvedDir); | ||
return this.readdirRecursively(this.path); | ||
} | ||
} | ||
exports.Directory = Directory; |
@@ -0,0 +0,0 @@ import { Store } from './store'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ export interface Finding { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
@@ -0,0 +0,0 @@ import { Finding } from './ifinding'; |
@@ -31,3 +31,4 @@ "use strict"; | ||
outputToConsole(output) { | ||
const consoleOutput = output.slice(0, 10).map((finding) => { | ||
const outputCopy = JSON.parse(JSON.stringify(output.slice(0, 10))); | ||
const consoleOutput = outputCopy.map((finding) => { | ||
if (finding.key.length > 32) { | ||
@@ -34,0 +35,0 @@ finding.key = finding.key.substring(0, 32) + '...'; |
@@ -0,9 +1,15 @@ | ||
interface Options { | ||
silent?: boolean; | ||
exclusions?: string; | ||
extensions?: string; | ||
path?: string; | ||
} | ||
export declare class Scanner { | ||
private silent; | ||
private readonly scannedDirs; | ||
private readonly store; | ||
private silent; | ||
private exclusions; | ||
private extensions; | ||
constructor(silent: boolean); | ||
init(): Promise<Scanner>; | ||
private path; | ||
constructor(options: Options); | ||
scan(): Promise<void>; | ||
@@ -13,1 +19,2 @@ private scanDir; | ||
} | ||
export {}; |
@@ -17,31 +17,37 @@ "use strict"; | ||
const output_1 = require("./output"); | ||
const extensions_1 = require("./extensions"); | ||
const questions_1 = require("./cli/questions"); | ||
const { removeDotPrefix } = new extensions_1.Extensions(); | ||
class Scanner { | ||
constructor(silent) { | ||
this.silent = silent; | ||
constructor(options) { | ||
this.scannedDirs = []; | ||
this.store = new store_1.Store(); | ||
this.exclusions = []; | ||
this.extensions = []; | ||
this.path = options.path || ''; | ||
this.silent = !!options.silent; | ||
if (options.exclusions) { | ||
this.exclusions = options.exclusions.split(','); | ||
} | ||
if (options.extensions) { | ||
this.extensions = removeDotPrefix(options.extensions.split(',')); | ||
} | ||
} | ||
init() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.exclusions = yield new questions_1.ExclusionsQuestion().getAnswer(); | ||
this.extensions = yield new questions_1.ExtensionsQuestion().getAnswer(); | ||
return this; | ||
}); | ||
} | ||
scan() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const dirName = yield new questions_1.DirectoryQuestion().getAnswer(); | ||
const path = this.path.length ? this.path : yield new questions_1.DirectoryQuestion().getAnswer(); | ||
if (!this.exclusions) { | ||
this.exclusions = yield new questions_1.ExclusionsQuestion().getAnswer(); | ||
} | ||
if (!this.extensions) { | ||
this.extensions = yield new questions_1.ExtensionsQuestion().getAnswer(); | ||
} | ||
let shouldScan = true; | ||
if (this.scannedDirs.includes(dirName)) { | ||
if (this.scannedDirs.includes(path)) { | ||
shouldScan = yield new questions_1.ConfirmScannedDirQuestion().getAnswer(); | ||
} | ||
if (shouldScan) { | ||
this.scannedDirs.push(dirName); | ||
this.scanDir(dirName); | ||
this.scanDir(path); | ||
this.scannedDirs.push(path); | ||
} | ||
const scanAnotherDir = yield new questions_1.ConfirmDirectoryQuestion().getAnswer(); | ||
if (scanAnotherDir) { | ||
const continueScanning = yield new questions_1.ConfirmDirectoryQuestion().getAnswer(); | ||
if (continueScanning) { | ||
return this.scan(); | ||
@@ -48,0 +54,0 @@ } |
@@ -0,0 +0,0 @@ export declare class Store<T> { |
@@ -0,0 +0,0 @@ "use strict"; |
{ | ||
"name": "find-duplicate-strings", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Easy to use CLI that finds duplicate strings in a directory and stores them in a external file for easy reference", | ||
@@ -15,3 +15,3 @@ "author": "Erwin Heitzman", | ||
"scripts": { | ||
"prepare": "rm -rf lib coverage && tsc", | ||
"prepare": "rm -rf lib coverage && tsc --newLine lf", | ||
"lint": "eslint ./src/**/*.ts --fix", | ||
@@ -18,0 +18,0 @@ "pretest": "npm run lint", |
@@ -22,27 +22,12 @@ [![Build Status](https://travis-ci.org/erwinheitzman/find-duplicate-strings.svg?branch=master)](https://travis-ci.org/erwinheitzman/find-duplicate-strings) | ||
You will be asked to enter a path to a existing directory to be scanned for duplicate string values: | ||
When no arguments are passed, the CLI will ask you for the required information. | ||
```bash | ||
? Please provide a directory to scan for duplicate values. | ||
./data | ||
``` | ||
For more information about what arguments and flags are supported, use the -h or --help flag. | ||
You can provide any directories that you would like to exclude: | ||
Example: | ||
```bash | ||
? Please provide any directories that you want to skip (separated list by ;) (node_modules) | ||
find-duplicate-strings . --exclusions node_modules --extensions ts,js -s | ||
``` | ||
Then you will be asked to enter the file extensions that you want to scan: | ||
```bash | ||
? Please provide the file extensions you want to scan or leave empty to scan all files (separated list by ;) | ||
``` | ||
It will then ask you if you would like to scan any other directories (the results will be stored in a single file): | ||
```bash | ||
? Would you like to scan another directory? (Y/n) | ||
``` | ||
When done, if you aren't running in silent mode it will output a table containing it's first 10 findings: | ||
@@ -68,9 +53,11 @@ | ||
Lastly you will be asked to enter a path to a file that the results can be written to (json): | ||
After that, you will be asked to enter a path for a file to be created that the results can be written to (json): | ||
```bash | ||
? Please provide a filepath to store the output. | ||
./output | ||
./output/filename | ||
``` | ||
This will write the output to `./output/filename.json` if the output directory exists. | ||
## Help | ||
@@ -77,0 +64,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
31937
37
633
0
72