Visitar URL original
Improve terminal file creation output (#43) · dojo/cli-create-theme@c3f786d · GitHub
Skip to content

Commit c3f786d

Browse files
authored
Improve terminal file creation output (#43)
Improve terminal output by displaying a create message for all files created during the run.
1 parent 465cdc0 commit c3f786d

4 files changed

Lines changed: 19 additions & 6 deletions

File tree

‎src/createThemeFile.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as camelcase from 'camelcase';
33
import * as fs from 'fs-extra';
44
import chalk from 'chalk';
55
import WidgetDataInterface from './WidgetDataInterface';
6+
import { info } from './logging';
67

78
const pkgDir: any = require('pkg-dir');
89
const packagePath = pkgDir.sync(__dirname);
@@ -23,9 +24,7 @@ function createThemeFile({
2324
const absoluteThemeFilePath = join(process.cwd(), relativeThemeFilePath);
2425

2526
if (fs.existsSync(absoluteThemeFilePath)) {
26-
console.info(
27-
`A theme file already exists in '${chalk.bold.underline(relativeThemeFilePath)}'. Will not overwrite.`
28-
);
27+
info(`A theme file already exists in '${chalk.bold.underline(relativeThemeFilePath)}'. Will not overwrite.`);
2928
return;
3029
}
3130

@@ -55,9 +54,7 @@ function createThemeFile({
5554
}
5655
);
5756

58-
console.info(
59-
`\nPlease import '${chalk.bold.underline(relativeThemeFilePath)}' into your project to use your new theme`
60-
);
57+
info(`\nPlease import '${chalk.bold.underline(relativeThemeFilePath)}' into your project to use your new theme`);
6158
}
6259

6360
export default createThemeFile;

‎src/logging.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function info(message?: any, ...optionalParams: any[]) {
2+
console.info.apply(console, Array.prototype.slice.call(arguments));
3+
}

‎src/run.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import * as fs from 'fs-extra';
33
import * as globby from 'globby';
44
import { mkdirsSync } from 'fs-extra';
55
import { join, basename } from 'path';
6+
import chalk from 'chalk';
67

78
import WidgetDataInterface from './WidgetDataInterface';
89
import createThemeFile from './createThemeFile';
910
import convertSelectorsToCSS from './convertSelectorsToCSS';
1011

1112
import { packageQuestions, getFileQuestions, askForDesiredFiles, askForPackageNames } from './questions';
13+
import { info } from './logging';
1214

1315
export interface CreateThemeArgs {
1416
name: string;
@@ -51,6 +53,7 @@ async function run(helper: Helper, args: CreateThemeArgs) {
5153

5254
mkdirsSync(widgetThemePath);
5355
fs.writeFileSync(newFilePath, newFileOutput);
56+
info(chalk.green.bold(' create ') + newFilePath);
5457

5558
return {
5659
themeKey,

‎tests/unit/main.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as mockery from 'mockery';
22
import * as sinon from 'sinon';
33
import { join } from 'path';
4+
import chalk from 'chalk';
45

56
const { describe, it, beforeEach, afterEach } = intern.getInterface('bdd');
67
const { assert } = intern.getPlugin('chai');
@@ -97,6 +98,7 @@ describe('The main runner', () => {
9798
const mkdirsSyncStub: sinon.SinonStub = sandbox.stub();
9899

99100
const joinStub: sinon.SinonStub = sandbox.stub();
101+
const loggingStub: sinon.SinonStub = sandbox.stub();
100102

101103
joinStub.onCall(2).returns('theme-key-1');
102104
joinStub.onCall(3).returns('./widget/path/1');
@@ -126,6 +128,10 @@ describe('The main runner', () => {
126128
basename: () => 'basename return string'
127129
});
128130

131+
mockery.registerMock('./logging', {
132+
info: loggingStub
133+
});
134+
129135
mockery.registerMock('fs-extra', {
130136
existsSync: () => true,
131137
writeFileSync: writeFileSyncStub,
@@ -156,6 +162,10 @@ describe('The main runner', () => {
156162
assert.equal(writeFileSyncStub.callCount, 2);
157163
assert.deepEqual(writeFileSyncStub.firstCall.args, ['new/file/path-1', 'css file contents']);
158164
assert.deepEqual(writeFileSyncStub.secondCall.args, ['new/file/path-2', 'css file contents']);
165+
166+
assert.equal(loggingStub.callCount, 2);
167+
assert.deepEqual(loggingStub.firstCall.args, [chalk.green.bold(' create ') + 'new/file/path-1']);
168+
assert.deepEqual(loggingStub.secondCall.args, [chalk.green.bold(' create ') + 'new/file/path-2']);
159169
});
160170

161171
it('Creates a theme file', async () => {

0 commit comments

Comments
 (0)