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

Commit 2789137

Browse files
committed
Merge branch 'emilio/luis' of https://github.com/microsoft/botframework-cli into emilio/luis
2 parents a65b239 + bb2908f commit 2789137

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

packages/chatdown/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ OPTIONS
2727
2828
-h, --help Chatdown command help
2929
30-
-o, --out=out Path to the directory where the output of the multiple chat file processing (-f) will be
30+
-o, --out=out Path to the directory where the output of the multiple chat file processing (-o) will be
3131
placed.
3232
3333
-p, --prefix Prefix stdout with package name.

packages/chatdown/src/commands/chatdown.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,11 @@ export default class Chatdown extends Command {
3737
})
3838
}
3939

40+
let outputDir = flags.out ? path.resolve(flags.out) : null
41+
4042
if (inputIsDirectory) {
4143
let inputDir = flags.in ? flags.in.trim() : ''
42-
let outputDir = (flags.out) ? flags.out.trim() : './'
43-
if (outputDir.substr(0, 2) === './') {
44-
outputDir = path.resolve(process.cwd(), outputDir.substr(2))
45-
}
44+
4645
const len = await this.processFiles(inputDir, outputDir)
4746
if (len === 0) {
4847
throw new CLIError('No chat files found at: ' + flags.in)
@@ -51,9 +50,10 @@ export default class Chatdown extends Command {
5150
return
5251
} else {
5352
const fileContents = await this.getInput(flags.in)
53+
const fileName = flags.in ? this.getFileName(flags.in) : ''
5454
if (fileContents) {
5555
const activities = await chatdown(fileContents, flags)
56-
const writeConfirmation = await this.writeOut(activities)
56+
const writeConfirmation = await this.writeOut(activities, fileName, outputDir)
5757
/* tslint:disable:strict-type-predicates */
5858
if (typeof writeConfirmation === 'string') {
5959
process.stdout.write(`${chalk.green('Successfully wrote file:')} ${writeConfirmation}\n`)
@@ -91,21 +91,20 @@ export default class Chatdown extends Command {
9191
}
9292
}
9393

94+
private getFileName(file: any) {
95+
let fileName = path.basename(file, path.extname(file))
96+
return fileName
97+
}
98+
9499
private async processFiles(inputDir: any, outputDir: any) {
95100
return new Promise(async (resolve, reject) => {
96101
let files = glob.sync(inputDir, {ignore: ['**/node_modules/**']})
97102
/* tslint:disable:prefer-for-of */
98103
for (let i = 0; i < files.length; i++) {
99104
try {
100-
let fileName = files[i]
101-
if (files[i].lastIndexOf('/') !== -1) {
102-
fileName = files[i].substr(files[i].lastIndexOf('/'))
103-
}
104-
fileName = fileName.split('.')[0]
105+
const fileName = this.getFileName(files[i])
105106
let activities = await chatdown(await utils.readTextFile(files[i]))
106-
let writeFile = `${outputDir}/${fileName}.transcript`
107-
await fs.ensureFile(writeFile)
108-
await fs.writeJson(writeFile, activities, {spaces: 2})
107+
await this.writeOut(activities, fileName, outputDir)
109108
} catch (e) {
110109
if (e.message.match(/no such file or directory/)) {
111110
reject(new CLIError(e.message))
@@ -119,7 +118,13 @@ export default class Chatdown extends Command {
119118
})
120119
}
121120

122-
private async writeOut(activities: any) {
121+
private async writeOut(activities: any, fileName: string, outputDir: any) {
122+
if (fileName && outputDir) {
123+
let writeFile = path.join(outputDir, `${fileName}.transcript`)
124+
await fs.ensureFile(writeFile)
125+
await fs.writeJson(writeFile, activities, {spaces: 2})
126+
return writeFile
127+
}
123128
const output = JSON.stringify(activities, null, 2)
124129
await new Promise(done => process.stdout.write(output, 'utf-8', () => done()))
125130
return true

packages/chatdown/test/commands/chatdown.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('chatdown', () => {
4444
});
4545

4646
it('should read from file when chat file is passed as an argument', done => {
47-
cp.exec(`node ./bin/run chatdown --in ${path.join(__dirname, '../utils/cli.sample.chat')}`, (error, stdout) => {
47+
cp.exec(`node ./bin/run chatdown --in ./test/utils/cli.sample.chat`, (error, stdout) => {
4848
assert.doesNotThrow(() => JSON.parse(stdout));
4949
done();
5050
});

0 commit comments

Comments
 (0)