Skip to content

Commit

Permalink
feat: support tnf -v
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Dec 31, 2024
1 parent 64c7eb0 commit c6ed447
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ $ pnpm preview
- `tnf generate/g <type> <name>`: Generate a new page (or component and other types in the future).
- `tnf preview`: Preview the product after building the project.
- `tnf sync --mode=<mode>`: Sync the project to the temporary directory.
- `tnf version`: Print the version of tnf.

## API

Expand Down
20 changes: 19 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<Context> {
const argv = yargsParser(process.argv.slice(2));
const command = argv._[0];
Expand Down Expand Up @@ -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') {
Expand All @@ -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 });
Expand Down

0 comments on commit c6ed447

Please sign in to comment.