2.0.1 • Published 10 months ago

@atools/cf v2.0.1

Weekly downloads
357
License
-
Repository
-
Last release
10 months ago

@atools/cf

CF Framework 的主应用包,提供完整的命令行工具和模板系统。

安装

npm install @atools/cf
# 或
yarn add @atools/cf
# 或
pnpm add @atools/cf

特性

  • 🎯 命令行工具 - 提供完整的命令行界面
  • 📝 模板系统 - 内置模板,快速创建新命令
  • 🎨 优雅设计 - 简洁的 API 设计,易于使用

基本使用

add 命令

add 命令是框架最重要的功能之一,用于快速创建新的命令模块:

# 使用默认配置
$ cf add

# 自定义输出目录
$ cf add -o custom-commands

# 自定义模板
$ cf add -t custom-template.tpl

[CF] -> command name: hello
[CF] -> command alias: h
[CF] -> command description: Say hello to someone

支持的选项:

  • -o, --output <path>: 输出目录,默认为 commands
  • -t, --template <path>: 模板文件路径,默认使用内置模板

生成的命令文件示例(commands/hello/index.js):

const { BaseCommand } = require('@atools/cf-core');

class Hello extends BaseCommand {
  constructor(config) {
    super(config);
  }

  init(commander) {
    commander
      .option('-n, --name <name>', '要问候的名字');
  }

  async do() {
    const { name = '世界' } = this.config;
    console.log(`你好, ${name}!`);
  }
}

Hello.command = 'hello';
Hello.alias = 'h';
Hello.description = 'Say hello to someone';

module.exports = Hello;

创建命令

你也可以直接创建命令类:

const { BaseCommand } = require('@atools/cf-core');

class MyCommand extends BaseCommand {
  constructor(config) {
    super(config);
  }

  init(commander) {
    commander
      .option('-n, --name <name>', '选项描述');
  }

  async do() {
    const { name } = this.config;
    // 实现你的命令逻辑
  }
}

MyCommand.command = 'my-command';
MyCommand.alias = 'mc';
MyCommand.description = '命令描述';

module.exports = MyCommand;

命令状态

命令状态描述
add✅ 可用添加新命令
ui🚧 开发中交互式 UI
init🚧 开发中项目初始化
remove🚧 开发中移除命令

版本说明

当前版本:2.0.0

这是一个重大版本更新,作为 CF Framework monorepo 重构的一部分发布。主要变化:

  • 核心功能已移至 @atools/cf-core
  • 改进了模板系统
  • 优化了包体积

从 1.x 升级

如果你正在使用 1.x 版本,需要使用我们的迁移 🔧 工具

# 升级到最新版本
npm install @atools/cf@latest

贡献

欢迎提交 issue 和 PR!

许可证

MIT

1.1.1

11 months ago

1.1.0

11 months ago

1.1.5

10 months ago

1.1.4

10 months ago

1.1.3

11 months ago

1.1.2

11 months ago

2.0.1

10 months ago

2.0.0

10 months ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.10

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago