Skip to content

Commit 194c0a9

Browse files
committed
better cli for piping results
1 parent 52b84a3 commit 194c0a9

File tree

5 files changed

+36
-47
lines changed

5 files changed

+36
-47
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ yarn-debug.log*
66
yarn-error.log*
77

88
#data folder
9-
data/*
10-
!data/.gitkeep
9+
carvis-data/*
10+
!carvis-data/.gitkeep
1111

1212
#osx remnants
1313
.DS_Store
File renamed without changes.

index.js

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//dependencies
33
const commandLineArgs = require('command-line-args');
44
const Chance = require('chance');
5-
const fs = require('fs');
65
const dayjs = require('dayjs');
76
const readline = require('readline');
87
const {
@@ -94,7 +93,7 @@ const {
9493

9594
function log(data, silent = options.silent) {
9695
if (!silent) {
97-
console.log(data);
96+
process.stderr.write(data);
9897
}
9998
}
10099

@@ -113,11 +112,11 @@ const banner = `
113112
'8888888P' .8' '8. '88888. 8 8888 '88. '8.' 8 8888 'Y8888P ,88P'
114113
`;
115114
log(banner);
116-
log('... maker of CSV files... and more!');
117-
log('by AK');
118-
119-
log('\n');
120-
track('start', {runId, ...options})
115+
log('\n... maker of CSV files... and more!');
116+
log('\n by AK');
117+
118+
log('\n\n');
119+
track('start', { runId, ...options });
121120

122121

123122
if (help) {
@@ -427,8 +426,8 @@ function noMoreThan(num) {
427426

428427
//helper for status bar
429428
function showProgress(p) {
430-
readline.cursorTo(process.stdout, 0);
431-
process.stdout.write(`generated ${p - 1} records...`);
429+
readline.cursorTo(process.stderr, 0);
430+
process.stderr.write(`\tgenerated ${u.comma(p - 1)} records...`);
432431
}
433432

434433
//helper to open the finder
@@ -470,36 +469,26 @@ else {
470469
}
471470

472471
//cool ... write the data
473-
fs.writeFileSync(path.resolve(`${currentDirectory}/${fileName}`), dataToWrite, function (err) {
474-
if (err) {
475-
return console.log(err);
472+
const directory = u.mkdir('./carvis-data');
473+
const filePath = `${directory}/${fileName}`;
474+
u.touch(filePath, dataToWrite).then(() => {
475+
//tell the user what happened
476+
log(`\n\nfinished writing ${rows} records across ${numUsers} users for ${days} days with columns:\n`);
477+
log(` ${columns.map(col => col.header).join(' \n ')}`);
478+
log('\n');
479+
log(`\n...data written to ./carvis-data/${fileName}`);
480+
log('\n\n');
481+
const outputMsg = path.resolve(filePath) + '\n';
482+
if (!silent) {
483+
//attempt to reveal the data folder in finder
484+
try {
485+
openExplorerinMac(currentDirectory);
486+
} catch (e) {
487+
console.error('revealing files only works on a mac; sorry!');
488+
}
489+
476490
}
477-
});
478-
479-
480-
//tell the user what happened
481-
log(`\n\nfinished writing ${rows} records across ${numUsers} users for ${days} days with columns:`);
482-
log(` ${columns.map(col => col.header).join(' \n ')}`);
483-
log('\n');
484-
log(`data written to ./data/${fileName}`);
485-
log('\n');
486-
log('all finished!');
487-
log('\n');
488-
if (silent) {
489-
const outputMsg = path.resolve(`${currentDirectory}/${fileName}`) + '\n';
490491
process.stdout.write(outputMsg);
491-
//process.exit(0);
492-
}
493492

494-
495-
if (!silent) {
496-
//attempt to reveal the data folder in finder
497-
try {
498-
openExplorerinMac(currentDirectory);
499-
} catch (e) {
500-
console.error('revealing files only works on a mac; sorry!');
501-
}
502-
}
503-
504-
track('end', {runId, ...options})
505-
//process.exit(0);
493+
track('end', { runId, ...options });
494+
});

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
22
"name": "carvis",
3-
"version": "1.0.14",
3+
"version": "1.0.16",
44
"description": "a csv making machine",
55
"main": "index.js",
66
"scripts": {
77
"test": "jest",
88
"testWatch": "jest --watchAll --verbose",
9-
"prune": "rm -rf ./data/*",
10-
"carvis": "cd data && node ../index.js",
9+
"prune": "rm -rf ./carvis-data/*",
10+
"carvis": "node ../index.js",
1111
"post": "npm publish"
1212
},
1313
"bin": {
1414
"carvis": "./index.js"
1515
},
16-
"keywords": ["carvis", "mixpanel", "fake data", "dummy data", "csv", "json"],
16+
"keywords": ["carvis", "mixpanel", "fake data", "dummy data", "csv", "json", "CLI"],
1717
"author": "AK",
1818
"license": "ISC",
1919
"dependencies": {

tests/e2e.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const fileExtensions = ['csv', 'ndjson']
1616
const { execSync } = require("child_process");
1717

1818

19-
const command = `cd data && node ../index.js`
20-
const suffix = `--silent && cd ..`
19+
const command = `node ./index.js`
20+
const suffix = `--silent`
2121

2222
describe('do tests work?', () => {
2323
test('a = a', () => {

0 commit comments

Comments
 (0)