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

Commit 3f4c281

Browse files
author
BruceHaley
authored
Merge pull request #2 from microsoft/emimunoz/cli-tools
Adding Unit Test to Chatdown
2 parents 061c6cb + e9b841b commit 3f4c281

22 files changed

Lines changed: 169 additions & 824 deletions

packages/chatdown/package-lock.json

Lines changed: 23 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/chatdown/package.json

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,18 @@
55
"author": "Microsoft",
66
"bugs": "https://github.com/Microsoft/chatdown/issues",
77
"dependencies": {
8-
"@oclif/command": "^1.5.13",
9-
"@oclif/config": "^1.13.0",
10-
"tslib": "^1.9.3",
11-
"botframework-schema": "^4.0.0-preview1.2",
8+
"@oclif/command": "~1.5.13",
9+
"@oclif/config": "~1.13.0",
1210
"chalk": "2.4.1",
13-
"cli-table3": "^0.5.1",
11+
"chatdown": "^1.2.2",
1412
"fs-extra": "^5.0.0",
1513
"glob": "^7.1.3",
16-
"latest-version": "^4.0.0",
1714
"intercept-stdout": "^0.1.2",
18-
"mime-types": "^2.1.18",
19-
"minimist": "^1.2.0",
15+
"latest-version": "^4.0.0",
2016
"please-upgrade-node": "^3.0.1",
2117
"read-text-file": "^1.1.0",
22-
"request": "^2.88.0",
23-
"request-promise-native": "^1.0.5",
2418
"semver": "^5.5.1",
25-
"window-size": "^1.1.0"
19+
"tslib": "^1.9.3"
2620
},
2721
"devDependencies": {
2822
"@oclif/dev-cli": "^1.22.0",

packages/chatdown/src/commands/chatdown.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,31 @@ const runProgram = require('../utils/chatdown.js')
44
export default class Chatdown extends Command {
55
static description = 'Chatdown cli tool used to parse chat dialogs (.chat file) into a mock transcript file'
66

7-
static examples = [`$ bf chatdown`,]
7+
static examples = ['$ bf chatdown']
88

99
static flags = {
1010
help: flags.help({char: 'h'}),
1111
static: flags.boolean({description: 'Use static timestamps when generating timestamps on activities.'}),
12+
folder: flags.string({char: 'f'}),
13+
out_folder: flags.string({char: 'o'}),
14+
version: flags.boolean({char: 'v'}),
15+
prefix: flags.boolean()
1216
}
1317

1418
static args = [{name: 'chat', description: 'The path of the chat file to be parsed. If omitted, stdin will be used.'}]
1519

1620
async run() {
17-
const {argv} = this.parse(Chatdown)
18-
await runProgram.runChatdown(argv);
21+
try {
22+
const {flags, argv} = this.parse(Chatdown)
23+
await runProgram.runChatdown(argv.length === 0 ? flags : argv)
24+
25+
} catch (err) {
26+
if (err instanceof Error) {
27+
this.error(err)
28+
} else {
29+
this._help()
30+
}
31+
this.exit(1)
32+
}
1933
}
2034
}

packages/chatdown/src/utils/chatdown.js

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ if (!semver.satisfies(process.version, requiredVersion)) {
99
}
1010

1111
const chalk = require('chalk');
12-
const help = require('./helpers/help');
13-
const chatdown = require('./helpers/index');
12+
const chatdown = require('chatdown');
1413
const txtfile = require('read-text-file');
1514
const glob = require('glob');
1615
const latestVersion = require('latest-version');
@@ -108,7 +107,7 @@ async function runProgram(args) {
108107

109108
if (args.prefix) {
110109
intercept(function(txt) {
111-
return `[${">=8.0.0"}]\n${txt}`;
110+
return `[${pkg.name}]\n${txt}`;
112111
});
113112
}
114113

@@ -125,18 +124,13 @@ async function runProgram(args) {
125124
}
126125

127126
if (args.version || args.v) {
128-
process.stdout.write("1.2.0");
129-
return 0;
130-
}
131-
132-
if (args.h || args.help) {
133-
help(process.stdout);
127+
process.stdout.write(pkg.version);
134128
return 0;
135129
}
136130

137131
if (args.f || args.folder) {
138-
let inputDir = args.f.trim();
139-
let outputDir = (args.o || args.out_folder) ? args.o.trim() : "./";
132+
let inputDir = args.folder.trim();
133+
let outputDir = (args.o || args.out_folder) ? args.out_folder.trim() : "./";
140134
if (outputDir.substr(0, 2) === "./") {
141135
outputDir = path.resolve(process.cwd(), outputDir.substr(2))
142136
}
@@ -156,27 +150,9 @@ async function runProgram(args) {
156150
return 0;
157151
}
158152
else {
159-
help();
160153
return -1;
161154
}
162155
}
163156
}
164157

165-
/**
166-
* Utility function that exist the process with an
167-
* optional error. If an Error is received, the error
168-
* message is written to stdout, otherwise, the help
169-
* content are displayed.
170-
*
171-
* @param {*} error Either an instance of Error or null
172-
*/
173-
function exitWithError(error) {
174-
if (error instanceof Error) {
175-
process.stderr.write(chalk.red(error));
176-
} else {
177-
help();
178-
}
179-
process.exit(1);
180-
}
181-
182158
module.exports.runChatdown = runProgram;

packages/chatdown/src/utils/helpers/enums/activityField.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/chatdown/src/utils/helpers/enums/activityType.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/chatdown/src/utils/helpers/enums/cardContentTypes.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/chatdown/src/utils/helpers/enums/instructions.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/chatdown/src/utils/helpers/help.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)