Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 0b53afe

Browse files
author
Jonathan Spruance (Insight Global)
committed
Allow scanning of dir without blob expression
1 parent 3443954 commit 0b53afe

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

packages/chatdown/src/commands/chatdown.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export default class Chatdown extends Command {
4141

4242
if (inputIsDirectory) {
4343
let inputDir = flags.in ? flags.in.trim() : ''
44-
4544
const len = await this.processFiles(inputDir, outputDir)
4645
if (len === 0) {
4746
throw new CLIError('No chat files found at: ' + flags.in)
@@ -93,14 +92,36 @@ export default class Chatdown extends Command {
9392
}
9493
}
9594

95+
private getFiles (directoryPath: any): Promise<any> {
96+
return new Promise((resolve, reject) => {
97+
let fileList: any = [];
98+
fs.readdir(directoryPath, (err: any, files: any) => {
99+
if (err) {
100+
reject('Error scanning directory' + err)
101+
}
102+
fileList = files.map((file: any) => path.join(directoryPath, file))
103+
resolve(fileList)
104+
});
105+
})
106+
}
107+
96108
private getFileName(file: any) {
97109
let fileName = path.basename(file, path.extname(file))
98110
return fileName
99111
}
100112

101113
private async processFiles(inputDir: any, outputDir: any) {
102114
return new Promise(async (resolve, reject) => {
103-
let files = glob.sync(inputDir, {ignore: ['**/node_modules/**']})
115+
let files: any = [];
116+
if (inputDir.indexOf('*') > -1) {
117+
files = glob.sync(inputDir, {ignore: ['**/node_modules/**']})
118+
} else {
119+
try {
120+
files = await this.getFiles(inputDir)
121+
} catch (err) {
122+
console.log(`Failed to scan directory ${err}`)
123+
}
124+
}
104125
/* tslint:disable:prefer-for-of */
105126
for (let i = 0; i < files.length; i++) {
106127
try {

0 commit comments

Comments
 (0)