基于 Ink 编写的 CLI 的 Next.js 类框架
Next.js 是一个基于 Ink 打造的 CLI 框架。
npm install pastel
npm install --save-dev typescript @sindresorhus/tsconfigtsconfig.json 文件来设置 TypeScript。{
"extends": "@sindresorhus/tsconfig",
"compilerOptions": {
"outDir": "build",
"sourceMap": true
},
"include": [
"source"
]
}source文件夹。mkdir sourcesource/cli.ts 文件,包含以下代码,该代码将作为 CLI 的入口点:#!/usr/bin/env node
import Pastel from 'pastel';
const app = new Pastel({
importMeta: import.meta,
});
await app.run();source/commands 文件夹,用于定义 CLI 命令。mkdir source/commandssource/commands/index.tsx 文件,内容如下:import React from 'react';
import {Text} from 'ink';
import zod from 'zod';
export const options = zod.object({
name: zod.string().describe('Your name'),
});
type Props = {
options: zod.infer<typeof options>;
};
export default function Index({options}: Props) {
return <Text>Hello, {options.name}!</Text>;
}npx tsc暂无开放 Issues,或尚未同步最近议题。