More descriptive bin program output (fixes #1)
This commit is contained in:
@@ -32,6 +32,8 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "^3.5.0",
|
"chai": "^3.5.0",
|
||||||
|
"chalk": "^1.1.1",
|
||||||
|
"moment": "^2.11.1",
|
||||||
"pragmatist": "^3.0.3"
|
"pragmatist": "^3.0.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import yargs from 'yargs';
|
import yargs from 'yargs';
|
||||||
import {
|
import {
|
||||||
writeIndex
|
writeIndexCli
|
||||||
} from './../utilities';
|
} from './../utilities';
|
||||||
|
|
||||||
let argv;
|
let argv;
|
||||||
@@ -11,8 +11,4 @@ argv = yargs
|
|||||||
.demand(1)
|
.demand(1)
|
||||||
.argv;
|
.argv;
|
||||||
|
|
||||||
writeIndex(argv._);
|
writeIndexCli(argv._);
|
||||||
|
|
||||||
/* eslint-disable no-console */
|
|
||||||
console.log('OK!');
|
|
||||||
/* eslint-enable no-console */
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
'create index';
|
'create index';
|
||||||
|
|
||||||
export createIndexCode from './createIndexCode.js';
|
export createIndexCode from './createIndexCode.js';
|
||||||
|
export log from './log.js';
|
||||||
export readDirectory from './readDirectory.js';
|
export readDirectory from './readDirectory.js';
|
||||||
export sortByDepth from './sortByDepth.js';
|
export sortByDepth from './sortByDepth.js';
|
||||||
export validateTargetDirectory from './validateTargetDirectory.js';
|
export validateTargetDirectory from './validateTargetDirectory.js';
|
||||||
export writeIndex from './writeIndex.js';
|
export writeIndex from './writeIndex.js';
|
||||||
|
export writeIndexCli from './writeIndexCli.js';
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import chalk from 'chalk';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
|
export default (...append) => {
|
||||||
|
/* eslint-disable no-console */
|
||||||
|
console.log(chalk.dim('[' + moment().format('HH:mm:ss') + ']'), ...append);
|
||||||
|
/* eslint-enable no-console */
|
||||||
|
};
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
import createIndexCode from './createIndexCode';
|
||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import validateTargetDirectory from './validateTargetDirectory';
|
||||||
|
import readDirectory from './readDirectory';
|
||||||
|
import sortByDepth from './sortByDepth';
|
||||||
|
import log from './log';
|
||||||
|
import chalk from 'chalk';
|
||||||
|
|
||||||
|
export default (directoryPaths) => {
|
||||||
|
let sortedDirectoryPaths;
|
||||||
|
|
||||||
|
sortedDirectoryPaths = sortByDepth(directoryPaths);
|
||||||
|
|
||||||
|
log('Target directories', sortedDirectoryPaths);
|
||||||
|
|
||||||
|
_.forEach(sortedDirectoryPaths, (directoryPath) => {
|
||||||
|
validateTargetDirectory(directoryPath);
|
||||||
|
});
|
||||||
|
|
||||||
|
_.forEach(sortedDirectoryPaths, (directoryPath) => {
|
||||||
|
let existingIndexCode,
|
||||||
|
indexCode,
|
||||||
|
indexFilePath,
|
||||||
|
siblings;
|
||||||
|
|
||||||
|
siblings = readDirectory(directoryPath);
|
||||||
|
|
||||||
|
indexCode = createIndexCode(siblings);
|
||||||
|
|
||||||
|
indexFilePath = path.resolve(directoryPath, 'index.js');
|
||||||
|
|
||||||
|
try {
|
||||||
|
existingIndexCode = fs.readFileSync(indexFilePath, 'utf8');
|
||||||
|
/* eslint-disable no-empty */
|
||||||
|
} catch (error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
/* eslint-enable no-empty */
|
||||||
|
|
||||||
|
fs.writeFileSync(indexFilePath, indexCode);
|
||||||
|
|
||||||
|
if (existingIndexCode && existingIndexCode === indexCode) {
|
||||||
|
log(indexFilePath, chalk.yellow('[index have not changed]'));
|
||||||
|
} else if (existingIndexCode && existingIndexCode !== indexCode) {
|
||||||
|
log(indexFilePath, chalk.green('[updated index]'));
|
||||||
|
} else {
|
||||||
|
log(indexFilePath, chalk.green('[created index]'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
log('Done');
|
||||||
|
};
|
||||||
@@ -19,9 +19,11 @@ describe('writeIndex()', () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
fs.unlinkSync(indexFilePath);
|
fs.unlinkSync(indexFilePath);
|
||||||
|
/* eslint-disable no-empty */
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/* eslint-enable no-empty */
|
||||||
|
|
||||||
writeIndex([path.resolve(fixturesPath, './mixed')]);
|
writeIndex([path.resolve(fixturesPath, './mixed')]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user