Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { program } from 'commander';
import buildAction from './util/buildAction';
import printWelcome from './util/print/printWelcome';
import packageJson from '../package.json';

const typedPackageJson = packageJson;

export default function runCli() {
program
Expand Down Expand Up @@ -62,6 +65,10 @@ export default function runCli() {
)
.action(buildAction(import('./commands/notifications')));

program.version(
`The current version of Belt is: ${typedPackageJson.version}`,
);

printWelcome();
program.parse();
}
30 changes: 26 additions & 4 deletions src/util/print/__tests__/printWelcome.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
import { test, vi } from 'vitest';
import { test, vi, describe, expect, beforeEach } from 'vitest';
import chalk from 'chalk';
import printWelcome from '../printWelcome';

vi.mock('../../print', () => ({ default: vi.fn() }));
const consoleSpy = vi.spyOn(console, 'log');

test('doesnt error', () => {
printWelcome();
describe('printWelcome', () => {
beforeEach(() => {
consoleSpy.mockClear();
});

test('prints introduction message', () => {
process.argv = ['node', 'script.js', 'create'];
printWelcome();
expect(console.log).toHaveBeenCalledWith(chalk.bold('\n\n\t👖 Belt 👖\n'));
});

describe('does not print introduction message for version', () => {
test('works for --version', () => {
process.argv = ['node', 'script.js', '--version'];
printWelcome();
expect(consoleSpy.mock.calls.length).toBe(0);
});
test('works for -V', () => {
process.argv = ['node', 'script.js', '-V'];
printWelcome();
expect(consoleSpy.mock.calls.length).toBe(0);
});
});
});
5 changes: 5 additions & 0 deletions src/util/print/printWelcome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import chalk from 'chalk';
import print from '../print';

export default function printWelcome() {
const showVersionCommand =
process.argv.includes('--version') || process.argv.includes('-V');
if (showVersionCommand) {
return;
}
print(chalk.bold('\n\n\t👖 Belt 👖\n'));
print(
'Perform project setup and redundant tasks\n without your pants falling down!\n\n',
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"outDir": "./build",
"skipLibCheck": true,
"types": ["node"],
"typeRoots": ["./src/types", "./node_modules/@types"]
"typeRoots": ["./src/types", "./node_modules/@types"],
"resolveJsonModule": true
},
"ts-node": {
"esm": true,
Expand Down