mirror of
https://github.com/Lydanne/spaceflow.git
synced 2026-03-11 19:52:45 +08:00
chore: 初始化仓库
This commit is contained in:
6
templates/command/README.md.hbs
Normal file
6
templates/command/README.md.hbs
Normal file
@@ -0,0 +1,6 @@
|
||||
# @spaceflow/{{kebabName}}
|
||||
|
||||
{{name}}
|
||||
命令插件 ## 使用方法 ```bash spaceflow
|
||||
{{kebabName}}
|
||||
[options] ``` ## 选项 TODO: 添加命令选项说明
|
||||
6
templates/command/package.json.hbs
Normal file
6
templates/command/package.json.hbs
Normal file
@@ -0,0 +1,6 @@
|
||||
{ "name": "@spaceflow/{{kebabName}}", "version": "1.0.0", "description": "Spaceflow
|
||||
{{name}}
|
||||
命令插件", "main": "./dist/index.js", "type": "module", "spaceflow": { "commands": [ "." ] },
|
||||
"scripts": { "build": "spaceflow build", "dev": "spaceflow dev" }, "peerDependencies": {
|
||||
"spaceflow": "workspace:*", "@nestjs/common": "catalog:", "@nestjs/config": "catalog:",
|
||||
"nest-commander": "catalog:" }, "devDependencies": { "@types/node": "catalog:" } }
|
||||
33
templates/command/src/__name__.command.ts.hbs
Normal file
33
templates/command/src/__name__.command.ts.hbs
Normal file
@@ -0,0 +1,33 @@
|
||||
import { Command, CommandRunner, Option } from "nest-commander";
|
||||
import { {{pascalName}}Service } from "./{{kebabName}}.service";
|
||||
|
||||
export interface {{pascalName}}Options {
|
||||
verbose?: boolean;
|
||||
}
|
||||
|
||||
@Command({
|
||||
name: "{{kebabName}}",
|
||||
description: "{{name}} 命令",
|
||||
})
|
||||
export class {{pascalName}}Command extends CommandRunner {
|
||||
constructor(protected readonly {{camelName}}Service: {{pascalName}}Service) {
|
||||
super();
|
||||
}
|
||||
|
||||
async run(_passedParams: string[], options: {{pascalName}}Options): Promise<void> {
|
||||
try {
|
||||
await this.{{camelName}}Service.execute(options);
|
||||
} catch (error) {
|
||||
console.error("执行失败:", error instanceof Error ? error.message : error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Option({
|
||||
flags: "-v, --verbose",
|
||||
description: "显示详细日志",
|
||||
})
|
||||
parseVerbose(): boolean {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
5
templates/command/src/__name__.module.ts.hbs
Normal file
5
templates/command/src/__name__.module.ts.hbs
Normal file
@@ -0,0 +1,5 @@
|
||||
import { Module } from "@nestjs/common"; import {
|
||||
{{pascalName}}Command } from "./{{kebabName}}.command"; import {
|
||||
{{pascalName}}Service } from "./{{kebabName}}.service"; @Module({ providers: [{{pascalName}}Command,
|
||||
{{pascalName}}Service], }) export class
|
||||
{{pascalName}}Module {}
|
||||
17
templates/command/src/__name__.service.ts.hbs
Normal file
17
templates/command/src/__name__.service.ts.hbs
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
|
||||
export interface {{pascalName}}Options {
|
||||
verbose?: boolean;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class {{pascalName}}Service {
|
||||
async execute(options: {{pascalName}}Options): Promise<void> {
|
||||
if (options.verbose) {
|
||||
console.log("执行 {{name}} 命令...");
|
||||
}
|
||||
|
||||
// TODO: 实现命令逻辑
|
||||
console.log("Hello from {{name}}!");
|
||||
}
|
||||
}
|
||||
9
templates/command/src/index.ts.hbs
Normal file
9
templates/command/src/index.ts.hbs
Normal file
@@ -0,0 +1,9 @@
|
||||
import { SpaceflowPlugin, SpaceflowPluginMetadata } from "spaceflow"; import {
|
||||
{{pascalName}}Module } from "./{{kebabName}}.module"; export class
|
||||
{{pascalName}}Plugin implements SpaceflowPlugin { getMetadata(): SpaceflowPluginMetadata { return {
|
||||
name: "{{kebabName}}", commands: ["{{kebabName}}"], configKey: "{{kebabName}}", version: "1.0.0",
|
||||
description: "{{name}}
|
||||
命令插件", }; } getModule() { return
|
||||
{{pascalName}}Module; } } export default
|
||||
{{pascalName}}Plugin; export * from "./{{kebabName}}.command"; export * from "./{{kebabName}}.service";
|
||||
export * from "./{{kebabName}}.module";
|
||||
2
templates/command/tsconfig.json.hbs
Normal file
2
templates/command/tsconfig.json.hbs
Normal file
@@ -0,0 +1,2 @@
|
||||
{ "extends": "../../core/tsconfig.skill.json", "include": ["src/**/*"], "exclude": ["node_modules",
|
||||
"dist"] }
|
||||
Reference in New Issue
Block a user