Skip to content

Commit fd490c9

Browse files
authored
feat(cli): scaffold package (bigcommerce#2010)
1 parent c1519d4 commit fd490c9

14 files changed

Lines changed: 1009 additions & 24 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ playwright/.cache/
1414
bigcommerce.graphql
1515
bigcommerce-graphql.d.ts
1616
.DS_Store
17+
coverage/

packages/cli/.eslintrc.cjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @ts-check
2+
3+
/** @type {import('eslint').Linter.Config} */
4+
const config = {
5+
root: true,
6+
extends: ['@bigcommerce/catalyst/base', '@bigcommerce/catalyst/prettier'],
7+
rules: {
8+
'no-console': 'off',
9+
'import/no-named-as-default': 'off',
10+
'@typescript-eslint/naming-convention': 'off',
11+
},
12+
ignorePatterns: ['/dist/**'],
13+
};
14+
15+
module.exports = config;

packages/cli/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @bigcommerce/catalyst
2+
3+
CLI

packages/cli/package.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "@bigcommerce/catalyst",
3+
"version": "0.1.0",
4+
"type": "module",
5+
"bin": "dist/index.js",
6+
"files": [
7+
"dist"
8+
],
9+
"private": true,
10+
"scripts": {
11+
"dev": "tsup --watch",
12+
"dev:run": "node dist/index.js",
13+
"typecheck": "tsc --noEmit",
14+
"lint": "eslint . --max-warnings 0",
15+
"test": "vitest run",
16+
"test:watch": "vitest",
17+
"test:coverage": "vitest run --coverage",
18+
"build": "tsup"
19+
},
20+
"engines": {
21+
"node": ">=20.0.0"
22+
},
23+
"dependencies": {
24+
"@commander-js/extra-typings": "^12.1.0",
25+
"chalk": "^5.3.0",
26+
"commander": "^12.1.0"
27+
},
28+
"devDependencies": {
29+
"@bigcommerce/eslint-config": "^2.10.0",
30+
"@bigcommerce/eslint-config-catalyst": "workspace:^",
31+
"@types/node": "^20.17.10",
32+
"@vitest/coverage-v8": "^3.0.7",
33+
"@vitest/ui": "^3.0.7",
34+
"eslint": "^8.57.1",
35+
"prettier": "^3.4.2",
36+
"tsup": "^8.3.5",
37+
"typescript": "^5.7.2",
38+
"vitest": "^3.0.7"
39+
}
40+
}

packages/cli/prettier.config.cjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @ts-check
2+
3+
/** @type {import("prettier").Config} */
4+
const config = {
5+
printWidth: 100,
6+
singleQuote: true,
7+
trailingComma: 'all',
8+
};
9+
10+
module.exports = config;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import chalk from 'chalk';
2+
import { Command } from 'commander';
3+
4+
import PACKAGE_INFO from '../../package.json';
5+
6+
export const version = new Command('version')
7+
.description('Display detailed version information')
8+
.action(() => {
9+
console.log(chalk.cyanBright('\nVersion Information:'));
10+
console.log(`${chalk.bold('CLI Version:')} ${PACKAGE_INFO.version}`);
11+
console.log(`${chalk.bold('Node Version:')} ${process.version}`);
12+
console.log(`${chalk.bold('Platform:')} ${process.platform} (${process.arch})\n`);
13+
});

packages/cli/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env node
2+
import { program } from './program';
3+
4+
program.parse(process.argv);

packages/cli/src/program.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import chalk from 'chalk';
2+
import { Command } from 'commander';
3+
4+
import PACKAGE_INFO from '../package.json';
5+
6+
import { version } from './commands/version';
7+
8+
export const program = new Command();
9+
10+
console.log(chalk.cyanBright(`\n◢ ${PACKAGE_INFO.name} v${PACKAGE_INFO.version}\n`));
11+
12+
program
13+
.name(PACKAGE_INFO.name)
14+
.version(PACKAGE_INFO.version)
15+
.description('CLI tool for Catalyst development')
16+
.addCommand(version);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { Command } from '@commander-js/extra-typings';
2+
import { afterEach, beforeEach, expect, MockInstance, test, vi } from 'vitest';
3+
4+
import { version } from '../../src/commands/version';
5+
6+
vi.mock('chalk', () => ({
7+
default: new Proxy(
8+
{},
9+
{
10+
get: () => (str: string) => str,
11+
},
12+
),
13+
}));
14+
15+
let consoleMock: MockInstance;
16+
17+
beforeEach(() => {
18+
consoleMock = vi.spyOn(console, 'log').mockImplementation(() => null);
19+
});
20+
21+
afterEach(() => {
22+
consoleMock.mockReset();
23+
});
24+
25+
test('properly configured Command instance', () => {
26+
expect(version).toBeInstanceOf(Command);
27+
expect(version.name()).toBe('version');
28+
expect(version.description()).toBe('Display detailed version information');
29+
});
30+
31+
test('displays version information when executed', async () => {
32+
await version.parseAsync([]);
33+
34+
expect(consoleMock).toHaveBeenCalledWith(expect.stringContaining('Version Information:'));
35+
36+
expect(consoleMock).toHaveBeenCalledWith(
37+
expect.stringContaining(`CLI Version: ${process.env.npm_package_version}`),
38+
);
39+
40+
expect(consoleMock).toHaveBeenCalledWith(
41+
expect.stringContaining(`Node Version: ${process.version}`),
42+
);
43+
44+
expect(consoleMock).toHaveBeenCalledWith(
45+
expect.stringContaining(`Platform: ${process.platform} (${process.arch})`),
46+
);
47+
});

packages/cli/tests/index.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Command } from '@commander-js/extra-typings';
2+
import { describe, expect, test } from 'vitest';
3+
4+
import { program } from '../src/program';
5+
6+
describe('CLI program', () => {
7+
test('properly configured', () => {
8+
expect(program).toBeInstanceOf(Command);
9+
expect(program.name()).toBe(process.env.npm_package_name);
10+
expect(program.version()).toBe(process.env.npm_package_version);
11+
expect(program.description()).toBe('CLI tool for Catalyst development');
12+
});
13+
14+
test('has expected commands', () => {
15+
const commands = program.commands.map((cmd) => cmd.name());
16+
17+
expect(commands).toContain('version');
18+
});
19+
});

0 commit comments

Comments
 (0)