feat(cli): add --help and --version options to main command (#35)
This commit is contained in:
parent
dac43ce95d
commit
960ce08674
3 changed files with 93 additions and 27 deletions
28
packages/cli/src/get-package-info.ts
Normal file
28
packages/cli/src/get-package-info.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import fs from 'node:fs/promises';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
type PackageInfo = {
|
||||
version: string;
|
||||
};
|
||||
|
||||
export const getPackageInfo = async () => {
|
||||
const packageInfoPath = fileURLToPath(new URL('../package.json', import.meta.url));
|
||||
|
||||
try {
|
||||
const content = await fs.readFile(packageInfoPath, 'utf8');
|
||||
const packageJson: unknown = JSON.parse(content);
|
||||
|
||||
if (
|
||||
typeof packageJson === 'object' &&
|
||||
packageJson &&
|
||||
'version' in packageJson &&
|
||||
typeof packageJson.version === 'string'
|
||||
) {
|
||||
return packageJson as PackageInfo;
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
|
||||
throw new Error(`Could not read package info from: ${packageInfoPath}`);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue