Skip to content

Commit 5dbd0e5

Browse files
committed
feat: support tnf -v
1 parent 64c7eb0 commit 5dbd0e5

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ $ pnpm preview
6060
- `tnf generate/g <type> <name>`: Generate a new page (or component and other types in the future).
6161
- `tnf preview`: Preview the product after building the project.
6262
- `tnf sync --mode=<mode>`: Sync the project to the temporary directory.
63+
- `tnf version`: Print the version of tnf.
6364

6465
## API
6566

src/cli.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import assert from 'assert';
22
import fs from 'fs';
33
import { instagram } from 'gradient-string';
44
import path from 'pathe';
5+
import { fileURLToPath } from 'url';
56
import yargsParser from 'yargs-parser';
67
import { loadConfig } from './config/config.js';
78
import { ConfigSchema } from './config/types.js';
@@ -19,6 +20,9 @@ import { reactScan } from './funplugins/react_scan/react_scan.js';
1920
import { PluginHookType, PluginManager } from './plugin/plugin_manager.js';
2021
import { type Context, Mode } from './types/index.js';
2122

23+
const __filename = fileURLToPath(import.meta.url);
24+
const __dirname = path.dirname(__filename);
25+
2226
async function buildContext(cwd: string): Promise<Context> {
2327
const argv = yargsParser(process.argv.slice(2));
2428
const command = argv._[0];
@@ -98,7 +102,13 @@ async function run(cwd: string) {
98102

99103
const context = await buildContext(cwd);
100104

101-
const cmd = context.argv._[0];
105+
let cmd = context.argv._[0];
106+
if (context.argv.v || context.argv.version) {
107+
cmd = 'version';
108+
}
109+
if (context.argv.h || context.argv.help) {
110+
cmd = 'help';
111+
}
102112
assert(cmd, 'Command is required');
103113

104114
if (cmd === 'build' || cmd === 'dev') {
@@ -111,6 +121,13 @@ async function run(cwd: string) {
111121
}
112122

113123
switch (cmd) {
124+
case 'version':
125+
const pkgPath = path.join(__dirname, '../package.json');
126+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
127+
console.log(pkg.version);
128+
return;
129+
case 'help':
130+
throw new Error('Not implemented');
114131
case 'build':
115132
const { build } = await import('./build.js');
116133
return build({ context });

0 commit comments

Comments
 (0)