Skip to content

Commit

Permalink
refactor: cli gets version directly from package.json
Browse files Browse the repository at this point in the history
import the version via a TS `import` from the _package.json_
  • Loading branch information
rainerhahnekamp authored Jul 24, 2024
1 parent a0b6171 commit 3e942b0
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 18 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/lib/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { list } from './list';
import { cli } from './cli';
import { exportData } from './export-data';
import { version } from './version';
import {version as packageVersion} from '../../../package.json';

export function main(...argv: string[]) {
const [cmd, ...args] = argv;
Expand All @@ -28,7 +29,7 @@ export function main(...argv: string[]) {
break;
default:
cli.log(
cli.bold('Sheriff (0.16.0) - Modularity for TypeScript Projects'),
cli.bold(`Sheriff (${packageVersion}) - Modularity for TypeScript Projects`),
);
cli.log('');
cli.log('Commands:');
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions packages/core/src/lib/cli/tests/main.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { it, expect } from 'vitest';
import { mockCli } from './helpers/mock-cli';
import { main } from '../main';
import { getPackageJsonVersion } from './helpers/get-package-json-version';
import {version} from '../../../../package.json';

it('should include the version in main', () => {
const { allLogs } = mockCli();
main();
expect(allLogs()).toContain(`Sheriff (${getPackageJsonVersion()})`);
expect(allLogs()).toContain(`Sheriff (${version})`);
});
4 changes: 2 additions & 2 deletions packages/core/src/lib/cli/tests/version.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { expect, it } from 'vitest';
import { mockCli } from './helpers/mock-cli';
import { main } from '../main';
import { getPackageJsonVersion } from './helpers/get-package-json-version';
import { version } from '../../../../package.json';

it('should print out the current version according to the package.json', () => {
const { allLogs } = mockCli();
main('version');

expect(allLogs()).toBe(getPackageJsonVersion());
expect(allLogs()).toBe(version);
});
3 changes: 2 additions & 1 deletion packages/core/src/lib/cli/version.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { cli } from '../cli/cli';
import { version as packageVersion } from '../../../package.json';

/**
* Although the version is already shown in the CLI,
Expand All @@ -7,5 +8,5 @@ import { cli } from '../cli/cli';
* version.
*/
export function version() {
cli.log('0.16.0');
cli.log(packageVersion);
}
4 changes: 3 additions & 1 deletion packages/core/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
"exclude": ["src/**/*.spec.ts", "src/**/*.test.ts"]
}
11 changes: 11 additions & 0 deletions packages/core/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist/out-tsc",
"module": "commonjs",
"types": ["vitest", "node"],
"resolveJsonModule": true,
"esModuleInterop": true
},
"include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
}
2 changes: 1 addition & 1 deletion packages/eslint-plugin/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
"exclude": ["src/**/*.spec.ts", "src/**/*.test.ts"]
}

0 comments on commit 3e942b0

Please sign in to comment.