diff --git a/README.md b/README.md index 38025d9..8960d4d 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ $ pnpm preview - `tnf generate/g `: Generate a new page (or component and other types in the future). - `tnf preview`: Preview the product after building the project. - `tnf sync --mode=`: Sync the project to the temporary directory. +- `tnf version`: Print the version of tnf. ## API diff --git a/src/cli.ts b/src/cli.ts index e980459..5d3c2f3 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -2,6 +2,8 @@ import assert from 'assert'; import fs from 'fs'; import { instagram } from 'gradient-string'; import path from 'pathe'; +import { fileURLToPath } from 'url'; +import { ar } from 'vitest/dist/chunks/reporters.D7Jzd9GS.js'; import yargsParser from 'yargs-parser'; import { loadConfig } from './config/config.js'; import { ConfigSchema } from './config/types.js'; @@ -19,6 +21,9 @@ import { reactScan } from './funplugins/react_scan/react_scan.js'; import { PluginHookType, PluginManager } from './plugin/plugin_manager.js'; import { type Context, Mode } from './types/index.js'; +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + async function buildContext(cwd: string): Promise { const argv = yargsParser(process.argv.slice(2)); const command = argv._[0]; @@ -98,7 +103,13 @@ async function run(cwd: string) { const context = await buildContext(cwd); - const cmd = context.argv._[0]; + let cmd = context.argv._[0]; + if (context.argv.v || context.argv.version) { + cmd = 'version'; + } + if (context.argv.h || context.argv.help) { + cmd = 'help'; + } assert(cmd, 'Command is required'); if (cmd === 'build' || cmd === 'dev') { @@ -111,6 +122,13 @@ async function run(cwd: string) { } switch (cmd) { + case 'version': + const pkgPath = path.join(__dirname, '../package.json'); + const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8')); + console.log(pkg.version); + return; + case 'help': + throw new Error('Not implemented'); case 'build': const { build } = await import('./build.js'); return build({ context });