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

Commit 3c30d69

Browse files
JSprumunozemilio
authored andcommitted
Change static flag to stamp, reorder file write functions (#275)
* Change static flag to stamp, reorder file write functions * Update timestamp test * Fix tests * Fix lint * Add unit test to bump coverage percent
1 parent 085e27d commit 3c30d69

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

packages/chatdown/src/commands/chatdown/convert.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default class ChatdownConvert extends Command {
2424
static flags = {
2525
in: flags.string({char: 'i', description: 'The path of the chat file or directory to be parsed. A glob expression may be passed containing chat files to be processed all at once, ex. ./**/*.chat. If flag is omitted, stdin will be used. If an output directory is not present (-o), it will default the output to the current working directory.'}),
2626
out: flags.string({char: 'o', description: 'Path to the directory where the output of the multiple chat file processing (-o) will be placed.'}),
27-
static: flags.boolean({char: 's', description: 'Use static timestamps when generating timestamps on activities.'}),
27+
stamp: flags.boolean({char: 's', description: 'Use static timestamps when generating timestamps on activities.'}),
2828
prefix: flags.boolean({char: 'p', description: 'Prefix stdout with package name.'}),
2929
force: flags.boolean({char: 'f', description: 'If --out flag is provided with the path to an existing file, overwrites that file', default: false}),
3030
help: flags.help({char: 'h', description: 'Chatdown command help'})
@@ -150,8 +150,8 @@ export default class ChatdownConvert extends Command {
150150
private async writeOut(activities: any, fileName: string, outputDir: any, force: boolean) {
151151
if (fileName && outputDir) {
152152
let writeFile = path.join(outputDir, `${fileName}.transcript`)
153-
await fs.ensureFile(writeFile)
154153
let validatedPath = utils.validatePath(writeFile, '', force)
154+
await fs.ensureFile(writeFile)
155155
await fs.writeJson(validatedPath, activities, {spaces: 2})
156156
return writeFile
157157
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ import * as cp from 'child_process';
33
import * as rimraf from 'rimraf';
44
let pkg = require('../../../package.json');
55
let assert = require('assert');
6+
const fs = require('fs-extra')
67

78
describe('chatdown:convert', () => {
89

10+
before(() => {
11+
fs.mkdirSync('./testout');
12+
});
13+
914
after(() => {
1015
rimraf('./testout', (err) => {
1116
if (err) console.log(err);
@@ -40,8 +45,8 @@ describe('chatdown:convert', () => {
4045
});
4146
});
4247

43-
it('should generate static based timestamps when --static is passed as an argument', done => {
44-
cp.exec(`(echo user=Joe && [ConversationUpdate=MembersAdded=Joe]) | node ./bin/run chatdown:convert --static`, (error, stdout) => {
48+
it('should generate timestamps when --stamp is passed as an argument', done => {
49+
cp.exec(`(echo user=Joe && [ConversationUpdate=MembersAdded=Joe]) | node ./bin/run chatdown:convert --stamp`, (error, stdout) => {
4550
assert.doesNotThrow(() => JSON.parse(stdout));
4651
done();
4752
});
@@ -89,4 +94,11 @@ describe('chatdown:convert', () => {
8994
});
9095
});
9196

97+
it('should display an error message when the out directory does not exist', done => {
98+
cp.exec(`node ./bin/run chatdown:convert -i "./test/utils/cli.sample.chat" -o ./xyz`, (error, stdout, stderr) => {
99+
assert(stderr.includes('Containing directory path doesn\'t exist'));
100+
done();
101+
});
102+
});
103+
92104
})

packages/chatdown/utils/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ let workingDirectory;
3737
* @returns {Promise<Array>} Resolves with an array of Activity objects.
3838
*/
3939
module.exports = async function readContents(fileContents, args = {}) {
40-
if (args.static || args.s) {
40+
if (args.stamp || args.s) {
4141
now = new Date(2015, 9, 15, 12, 0, 0, 0).getTime();
4242
}
4343
// Resolve file paths based on the input file with a fallback to the cwd

0 commit comments

Comments
 (0)