Skip to content

Commit c6ed447

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

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-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: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ 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';
6+
import { ar } from 'vitest/dist/chunks/reporters.D7Jzd9GS.js';
57
import yargsParser from 'yargs-parser';
68
import { loadConfig } from './config/config.js';
79
import { ConfigSchema } from './config/types.js';
@@ -19,6 +21,9 @@ import { reactScan } from './funplugins/react_scan/react_scan.js';
1921
import { PluginHookType, PluginManager } from './plugin/plugin_manager.js';
2022
import { type Context, Mode } from './types/index.js';
2123

24+
const __filename = fileURLToPath(import.meta.url);
25+
const __dirname = path.dirname(__filename);
26+
2227
async function buildContext(cwd: string): Promise<Context> {
2328
const argv = yargsParser(process.argv.slice(2));
2429
const command = argv._[0];
@@ -98,7 +103,13 @@ async function run(cwd: string) {
98103

99104
const context = await buildContext(cwd);
100105

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

104115
if (cmd === 'build' || cmd === 'dev') {
@@ -111,6 +122,13 @@ async function run(cwd: string) {
111122
}
112123

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

0 commit comments

Comments
 (0)