@knotx/cli 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +35 -0
- package/dist/index.cjs +303 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +292 -0
- package/package.json +53 -0
- package/templates/README.md.template +23 -0
- package/templates/build.config.ts.template +4 -0
- package/templates/eslint.config.js.template +1 -0
- package/templates/index.ts.template +1 -0
- package/templates/plugin.jsx.template +16 -0
- package/templates/tsconfig.json.template +8 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 格桑
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# @knotx/cli
|
|
2
|
+
|
|
3
|
+
Knotx CLI工具,用于创建和管理Knotx插件。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @knotx/cli
|
|
9
|
+
# 或者
|
|
10
|
+
yarn global add @knotx/cli
|
|
11
|
+
# 或者
|
|
12
|
+
pnpm add -g @knotx/cli
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 使用方法
|
|
16
|
+
|
|
17
|
+
### 创建新插件
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
knotx create-plugin
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
此命令将引导您完成创建新Knotx插件的过程:
|
|
24
|
+
1. 询问插件名称 - 用于生成插件包名和相关文件
|
|
25
|
+
2. 选择插件运行环境 - 可选择 jsx 或 react
|
|
26
|
+
|
|
27
|
+
## 命令列表
|
|
28
|
+
|
|
29
|
+
- `knotx create-plugin` - 创建新的Knotx插件
|
|
30
|
+
- `knotx --help` - 显示帮助信息
|
|
31
|
+
- `knotx --version` - 显示版本信息
|
|
32
|
+
|
|
33
|
+
## 许可证
|
|
34
|
+
|
|
35
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const node_child_process = require('node:child_process');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
const process = require('node:process');
|
|
7
|
+
const chalk = require('chalk');
|
|
8
|
+
const commander = require('commander');
|
|
9
|
+
const fs = require('fs-extra');
|
|
10
|
+
const inquirer = require('inquirer');
|
|
11
|
+
const ora = require('ora');
|
|
12
|
+
|
|
13
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
14
|
+
|
|
15
|
+
const path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
16
|
+
const process__default = /*#__PURE__*/_interopDefaultCompat(process);
|
|
17
|
+
const chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
|
|
18
|
+
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
19
|
+
const inquirer__default = /*#__PURE__*/_interopDefaultCompat(inquirer);
|
|
20
|
+
const ora__default = /*#__PURE__*/_interopDefaultCompat(ora);
|
|
21
|
+
|
|
22
|
+
var __async = (__this, __arguments, generator) => {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
var fulfilled = (value) => {
|
|
25
|
+
try {
|
|
26
|
+
step(generator.next(value));
|
|
27
|
+
} catch (e) {
|
|
28
|
+
reject(e);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var rejected = (value) => {
|
|
32
|
+
try {
|
|
33
|
+
step(generator.throw(value));
|
|
34
|
+
} catch (e) {
|
|
35
|
+
reject(e);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
39
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
const templatesDir = path__default.resolve(__dirname, "..", "templates");
|
|
43
|
+
const program = new commander.Command();
|
|
44
|
+
program.name("knotx").description("Knotx CLI - \u521B\u5EFA\u548C\u7BA1\u7406Knotx\u63D2\u4EF6").version("0.0.1");
|
|
45
|
+
program.command("create-plugin").description("\u521B\u5EFA\u4E00\u4E2A\u65B0\u7684Knotx\u63D2\u4EF6").action(() => __async(undefined, null, function* () {
|
|
46
|
+
console.log(chalk__default.blue("\u{1F539} \u6B22\u8FCE\u4F7F\u7528 Knotx \u63D2\u4EF6\u521B\u5EFA\u5DE5\u5177\uFF01"));
|
|
47
|
+
const answers = yield inquirer__default.prompt([
|
|
48
|
+
{
|
|
49
|
+
type: "input",
|
|
50
|
+
name: "pluginName",
|
|
51
|
+
message: "\u8BF7\u8F93\u5165\u63D2\u4EF6\u540D\u79F0 (\u4F8B\u5982: my-plugin):",
|
|
52
|
+
validate: (input) => {
|
|
53
|
+
if (!input)
|
|
54
|
+
return "\u63D2\u4EF6\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A";
|
|
55
|
+
if (!/^[a-z0-9-]+$/.test(input))
|
|
56
|
+
return "\u63D2\u4EF6\u540D\u79F0\u53EA\u80FD\u5305\u542B\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26";
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
type: "list",
|
|
62
|
+
name: "environment",
|
|
63
|
+
message: "\u8BF7\u9009\u62E9\u63D2\u4EF6\u8FD0\u884C\u73AF\u5883:",
|
|
64
|
+
choices: ["jsx", "react"]
|
|
65
|
+
}
|
|
66
|
+
]);
|
|
67
|
+
const { pluginName, environment } = answers;
|
|
68
|
+
const fullPluginName = `plugins-${pluginName}`;
|
|
69
|
+
const targetDir = path__default.resolve(process__default.cwd(), fullPluginName);
|
|
70
|
+
if (fs__default.existsSync(targetDir)) {
|
|
71
|
+
console.log(chalk__default.red(`\u274C \u9519\u8BEF: \u76EE\u5F55 ${fullPluginName} \u5DF2\u5B58\u5728`));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
let spinner = ora__default("\u{1F4C2} \u521B\u5EFA\u63D2\u4EF6\u76EE\u5F55...").start();
|
|
75
|
+
try {
|
|
76
|
+
yield fs__default.ensureDir(targetDir);
|
|
77
|
+
yield fs__default.ensureDir(path__default.join(targetDir, "src"));
|
|
78
|
+
spinner.succeed("\u{1F4C2} \u63D2\u4EF6\u76EE\u5F55\u521B\u5EFA\u6210\u529F");
|
|
79
|
+
spinner = ora__default("\u{1F50D} \u83B7\u53D6 @knotx \u5305\u7684\u6700\u65B0\u7248\u672C...").start();
|
|
80
|
+
const knotxVersions = yield getKnotxPackageVersions();
|
|
81
|
+
spinner.succeed("\u{1F50D} @knotx \u5305\u7248\u672C\u4FE1\u606F\u83B7\u53D6\u6210\u529F");
|
|
82
|
+
spinner = ora__default("\u{1F4C4} \u521B\u5EFA package.json...").start();
|
|
83
|
+
yield createPackageJson(targetDir, pluginName, environment, knotxVersions);
|
|
84
|
+
spinner.succeed("\u{1F4C4} package.json \u521B\u5EFA\u6210\u529F");
|
|
85
|
+
spinner = ora__default("\u{1F4C4} \u521B\u5EFA\u914D\u7F6E\u6587\u4EF6...").start();
|
|
86
|
+
yield createConfigFiles(targetDir);
|
|
87
|
+
spinner.succeed("\u{1F4C4} \u914D\u7F6E\u6587\u4EF6\u521B\u5EFA\u6210\u529F");
|
|
88
|
+
spinner = ora__default("\u{1F4C4} \u521B\u5EFA\u6E90\u4EE3\u7801\u6587\u4EF6...").start();
|
|
89
|
+
yield createSourceFiles(targetDir, pluginName, environment);
|
|
90
|
+
spinner.succeed("\u{1F4C4} \u6E90\u4EE3\u7801\u6587\u4EF6\u521B\u5EFA\u6210\u529F");
|
|
91
|
+
spinner = ora__default("\u{1F4C4} \u521B\u5EFA README.md...").start();
|
|
92
|
+
yield createReadme(targetDir, pluginName);
|
|
93
|
+
spinner.succeed("\u{1F4C4} README.md \u521B\u5EFA\u6210\u529F");
|
|
94
|
+
console.log(chalk__default.green(`
|
|
95
|
+
\u2705 \u63D2\u4EF6 ${chalk__default.bold(fullPluginName)} \u521B\u5EFA\u6210\u529F\uFF01`));
|
|
96
|
+
console.log(`
|
|
97
|
+
\u{1F4C1} \u63D2\u4EF6\u76EE\u5F55: ${chalk__default.cyan(targetDir)}`);
|
|
98
|
+
console.log(`
|
|
99
|
+
\u8FD0\u884C\u4EE5\u4E0B\u547D\u4EE4\u4EE5\u5B89\u88C5\u4F9D\u8D56\u5E76\u6784\u5EFA:
|
|
100
|
+
`);
|
|
101
|
+
console.log(chalk__default.cyan(` cd ${path__default.relative(process__default.cwd(), targetDir)}`));
|
|
102
|
+
console.log(chalk__default.cyan(" pnpm install"));
|
|
103
|
+
console.log(chalk__default.cyan(" pnpm build"));
|
|
104
|
+
} catch (error) {
|
|
105
|
+
spinner.fail("\u274C \u521B\u5EFA\u63D2\u4EF6\u5931\u8D25");
|
|
106
|
+
console.error(chalk__default.red(error));
|
|
107
|
+
}
|
|
108
|
+
}));
|
|
109
|
+
function getKnotxPackageVersions() {
|
|
110
|
+
return __async(this, null, function* () {
|
|
111
|
+
const knotxVersions = {};
|
|
112
|
+
try {
|
|
113
|
+
const packages = ["@knotx/core", "@knotx/decorators", "@knotx/jsx", "@knotx/build-config", "@knotx/eslint-config", "@knotx/typescript-config"];
|
|
114
|
+
const npmRegistry = "https://registry.npmjs.org";
|
|
115
|
+
for (const pkg of packages) {
|
|
116
|
+
try {
|
|
117
|
+
const version = node_child_process.execSync(`npm view ${pkg} version --registry=${npmRegistry}`, { encoding: "utf8" }).trim();
|
|
118
|
+
knotxVersions[pkg] = `^${version}`;
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.warn(chalk__default.yellow(`\u26A0\uFE0F \u65E0\u6CD5\u83B7\u53D6 ${pkg} \u7684\u6700\u65B0\u7248\u672C\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u7248\u672C`));
|
|
121
|
+
knotxVersions[pkg] = "^0.0.1";
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return knotxVersions;
|
|
125
|
+
} catch (e) {
|
|
126
|
+
console.warn(chalk__default.yellow("\u26A0\uFE0F \u83B7\u53D6 @knotx \u5305\u7248\u672C\u5931\u8D25\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u7248\u672C"));
|
|
127
|
+
return {
|
|
128
|
+
"@knotx/core": "^0.0.1",
|
|
129
|
+
"@knotx/decorators": "^0.0.1",
|
|
130
|
+
"@knotx/jsx": "^0.0.1",
|
|
131
|
+
"@knotx/build-config": "^0.0.1",
|
|
132
|
+
"@knotx/eslint-config": "^0.0.1",
|
|
133
|
+
"@knotx/typescript-config": "^0.0.1"
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function createPackageJson(targetDir, pluginName, environment, knotxVersions) {
|
|
139
|
+
return __async(this, null, function* () {
|
|
140
|
+
const packageJson = {
|
|
141
|
+
name: `@knotx/plugins-${pluginName}`,
|
|
142
|
+
type: "module",
|
|
143
|
+
version: "0.0.1",
|
|
144
|
+
description: `${capitalize(pluginName)} Plugin for Knotx`,
|
|
145
|
+
license: "MIT",
|
|
146
|
+
publishConfig: {
|
|
147
|
+
access: "public"
|
|
148
|
+
},
|
|
149
|
+
sideEffects: false,
|
|
150
|
+
exports: {
|
|
151
|
+
".": {
|
|
152
|
+
types: "./dist/index.d.ts",
|
|
153
|
+
import: "./dist/index.mjs",
|
|
154
|
+
require: "./dist/index.cjs"
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
main: "./dist/index.cjs",
|
|
158
|
+
module: "./dist/index.mjs",
|
|
159
|
+
types: "./dist/index.d.ts",
|
|
160
|
+
files: [
|
|
161
|
+
"dist"
|
|
162
|
+
],
|
|
163
|
+
scripts: {
|
|
164
|
+
build: "unbuild --failOnWarn=false",
|
|
165
|
+
dev: "unbuild --stub",
|
|
166
|
+
lint: "eslint .",
|
|
167
|
+
typecheck: "tsc --noEmit"
|
|
168
|
+
},
|
|
169
|
+
peerDependencies: {},
|
|
170
|
+
dependencies: {
|
|
171
|
+
"@knotx/core": knotxVersions["@knotx/core"],
|
|
172
|
+
"@knotx/decorators": knotxVersions["@knotx/decorators"],
|
|
173
|
+
"@knotx/jsx": knotxVersions["@knotx/jsx"]
|
|
174
|
+
},
|
|
175
|
+
devDependencies: {
|
|
176
|
+
"@knotx/build-config": knotxVersions["@knotx/build-config"],
|
|
177
|
+
"@knotx/eslint-config": knotxVersions["@knotx/eslint-config"],
|
|
178
|
+
"@knotx/typescript-config": knotxVersions["@knotx/typescript-config"],
|
|
179
|
+
"@types/node": "^22.13.5",
|
|
180
|
+
"eslint": "^9.23.0",
|
|
181
|
+
"typescript": "^5.7.3",
|
|
182
|
+
"unbuild": "^3.3.1",
|
|
183
|
+
"vite": "^6.1.0",
|
|
184
|
+
"vitest": "^3.0.0"
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
if (environment === "jsx") ; else if (environment === "react") {
|
|
188
|
+
packageJson.peerDependencies.react = "^17";
|
|
189
|
+
packageJson.peerDependencies["react-dom"] = "^17";
|
|
190
|
+
packageJson.devDependencies.react = "^17";
|
|
191
|
+
packageJson.devDependencies["@vitejs/plugin-react"] = "^4.3.4";
|
|
192
|
+
packageJson.devDependencies["react-dom"] = "^17";
|
|
193
|
+
packageJson.devDependencies["@types/react"] = "^17";
|
|
194
|
+
packageJson.devDependencies["@types/react-dom"] = "^17";
|
|
195
|
+
}
|
|
196
|
+
yield fs__default.writeFile(
|
|
197
|
+
path__default.join(targetDir, "package.json"),
|
|
198
|
+
JSON.stringify(packageJson, null, 2)
|
|
199
|
+
);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
function createConfigFiles(targetDir) {
|
|
203
|
+
return __async(this, null, function* () {
|
|
204
|
+
try {
|
|
205
|
+
const tsconfigTemplate = yield fs__default.readFile(path__default.join(templatesDir, "tsconfig.json.template"), "utf-8");
|
|
206
|
+
const buildConfigTemplate = yield fs__default.readFile(path__default.join(templatesDir, "build.config.ts.template"), "utf-8");
|
|
207
|
+
const eslintConfigTemplate = yield fs__default.readFile(path__default.join(templatesDir, "eslint.config.js.template"), "utf-8");
|
|
208
|
+
yield fs__default.writeFile(path__default.join(targetDir, "tsconfig.json"), tsconfigTemplate);
|
|
209
|
+
yield fs__default.writeFile(path__default.join(targetDir, "build.config.ts"), buildConfigTemplate);
|
|
210
|
+
yield fs__default.writeFile(path__default.join(targetDir, "eslint.config.js"), eslintConfigTemplate);
|
|
211
|
+
} catch (error) {
|
|
212
|
+
console.error("\u65E0\u6CD5\u8BFB\u53D6\u6A21\u677F\u6587\u4EF6:", error);
|
|
213
|
+
const tsconfig = {
|
|
214
|
+
extends: "@knotx/typescript-config/base.json",
|
|
215
|
+
include: [
|
|
216
|
+
"src"
|
|
217
|
+
],
|
|
218
|
+
compilerOptions: {
|
|
219
|
+
outDir: "dist"
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
yield fs__default.writeFile(
|
|
223
|
+
path__default.join(targetDir, "tsconfig.json"),
|
|
224
|
+
JSON.stringify(tsconfig, null, 2)
|
|
225
|
+
);
|
|
226
|
+
yield fs__default.writeFile(
|
|
227
|
+
path__default.join(targetDir, "build.config.ts"),
|
|
228
|
+
'import { defineBuildConfig } from "@knotx/build-config";\n\nexport default defineBuildConfig();'
|
|
229
|
+
);
|
|
230
|
+
yield fs__default.writeFile(
|
|
231
|
+
path__default.join(targetDir, "eslint.config.js"),
|
|
232
|
+
"export { default } from '@knotx/eslint-config';"
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
function createSourceFiles(targetDir, pluginName, environment) {
|
|
238
|
+
return __async(this, null, function* () {
|
|
239
|
+
try {
|
|
240
|
+
const indexTemplate = yield fs__default.readFile(path__default.join(templatesDir, "index.ts.template"), "utf-8");
|
|
241
|
+
const indexContent = indexTemplate.replace(/\{\{pluginName\}\}/g, pluginName);
|
|
242
|
+
yield fs__default.writeFile(path__default.join(targetDir, "src", "index.ts"), indexContent);
|
|
243
|
+
let templatePath;
|
|
244
|
+
if (environment === "jsx") {
|
|
245
|
+
templatePath = path__default.join(templatesDir, "plugin.jsx.template");
|
|
246
|
+
} else {
|
|
247
|
+
templatePath = path__default.join(templatesDir, "plugin.jsx.template");
|
|
248
|
+
}
|
|
249
|
+
const pluginTemplate = yield fs__default.readFile(templatePath, "utf-8");
|
|
250
|
+
const pluginContent = pluginTemplate.replace(/\{\{pluginName\}\}/g, pluginName).replace(/\{\{capitalizedPluginName\}\}/g, capitalize(pluginName));
|
|
251
|
+
const fileName = `${pluginName}.tsx`;
|
|
252
|
+
yield fs__default.writeFile(path__default.join(targetDir, "src", fileName), pluginContent);
|
|
253
|
+
} catch (error) {
|
|
254
|
+
console.error("\u65E0\u6CD5\u8BFB\u53D6\u6A21\u677F\u6587\u4EF6:", error);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
function createReadme(targetDir, pluginName) {
|
|
259
|
+
return __async(this, null, function* () {
|
|
260
|
+
try {
|
|
261
|
+
const readmeTemplate = yield fs__default.readFile(path__default.join(templatesDir, "README.md.template"), "utf-8");
|
|
262
|
+
const description = `${capitalize(pluginName)} Plugin for Knotx`;
|
|
263
|
+
const readmeContent = readmeTemplate.replace(/\{\{pluginName\}\}/g, pluginName).replace(/\{\{description\}\}/g, description);
|
|
264
|
+
yield fs__default.writeFile(path__default.join(targetDir, "README.md"), readmeContent);
|
|
265
|
+
} catch (error) {
|
|
266
|
+
console.error("\u65E0\u6CD5\u8BFB\u53D6 README \u6A21\u677F\u6587\u4EF6:", error);
|
|
267
|
+
const readmeContent = `# @knotx/plugins-${pluginName}
|
|
268
|
+
|
|
269
|
+
${capitalize(pluginName)} Plugin for Knotx
|
|
270
|
+
|
|
271
|
+
## \u5B89\u88C5
|
|
272
|
+
|
|
273
|
+
\`\`\`bash
|
|
274
|
+
npm install @knotx/plugins-${pluginName}
|
|
275
|
+
# \u6216\u8005
|
|
276
|
+
yarn add @knotx/plugins-${pluginName}
|
|
277
|
+
# \u6216\u8005
|
|
278
|
+
pnpm add @knotx/plugins-${pluginName}
|
|
279
|
+
\`\`\`
|
|
280
|
+
|
|
281
|
+
## \u4F7F\u7528\u65B9\u6CD5
|
|
282
|
+
|
|
283
|
+
\`\`\`typescript
|
|
284
|
+
import { ${pluginName} } from '@knotx/plugins-${pluginName}';
|
|
285
|
+
|
|
286
|
+
// \u5728\u60A8\u7684Knotx\u5E94\u7528\u4E2D\u4F7F\u7528\u63D2\u4EF6
|
|
287
|
+
app.use(${pluginName});
|
|
288
|
+
\`\`\`
|
|
289
|
+
|
|
290
|
+
## \u8BB8\u53EF\u8BC1
|
|
291
|
+
|
|
292
|
+
MIT`;
|
|
293
|
+
yield fs__default.writeFile(path__default.join(targetDir, "README.md"), readmeContent);
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
function capitalize(str) {
|
|
298
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
299
|
+
}
|
|
300
|
+
program.parse();
|
|
301
|
+
if (!process__default.argv.slice(2).length) {
|
|
302
|
+
program.outputHelp();
|
|
303
|
+
}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { execSync } from 'node:child_process';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import process from 'node:process';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import { Command } from 'commander';
|
|
7
|
+
import fs from 'fs-extra';
|
|
8
|
+
import inquirer from 'inquirer';
|
|
9
|
+
import ora from 'ora';
|
|
10
|
+
|
|
11
|
+
var __async = (__this, __arguments, generator) => {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
var fulfilled = (value) => {
|
|
14
|
+
try {
|
|
15
|
+
step(generator.next(value));
|
|
16
|
+
} catch (e) {
|
|
17
|
+
reject(e);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var rejected = (value) => {
|
|
21
|
+
try {
|
|
22
|
+
step(generator.throw(value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
28
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
const templatesDir = path.resolve(__dirname, "..", "templates");
|
|
32
|
+
const program = new Command();
|
|
33
|
+
program.name("knotx").description("Knotx CLI - \u521B\u5EFA\u548C\u7BA1\u7406Knotx\u63D2\u4EF6").version("0.0.1");
|
|
34
|
+
program.command("create-plugin").description("\u521B\u5EFA\u4E00\u4E2A\u65B0\u7684Knotx\u63D2\u4EF6").action(() => __async(undefined, null, function* () {
|
|
35
|
+
console.log(chalk.blue("\u{1F539} \u6B22\u8FCE\u4F7F\u7528 Knotx \u63D2\u4EF6\u521B\u5EFA\u5DE5\u5177\uFF01"));
|
|
36
|
+
const answers = yield inquirer.prompt([
|
|
37
|
+
{
|
|
38
|
+
type: "input",
|
|
39
|
+
name: "pluginName",
|
|
40
|
+
message: "\u8BF7\u8F93\u5165\u63D2\u4EF6\u540D\u79F0 (\u4F8B\u5982: my-plugin):",
|
|
41
|
+
validate: (input) => {
|
|
42
|
+
if (!input)
|
|
43
|
+
return "\u63D2\u4EF6\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A";
|
|
44
|
+
if (!/^[a-z0-9-]+$/.test(input))
|
|
45
|
+
return "\u63D2\u4EF6\u540D\u79F0\u53EA\u80FD\u5305\u542B\u5C0F\u5199\u5B57\u6BCD\u3001\u6570\u5B57\u548C\u8FDE\u5B57\u7B26";
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
type: "list",
|
|
51
|
+
name: "environment",
|
|
52
|
+
message: "\u8BF7\u9009\u62E9\u63D2\u4EF6\u8FD0\u884C\u73AF\u5883:",
|
|
53
|
+
choices: ["jsx", "react"]
|
|
54
|
+
}
|
|
55
|
+
]);
|
|
56
|
+
const { pluginName, environment } = answers;
|
|
57
|
+
const fullPluginName = `plugins-${pluginName}`;
|
|
58
|
+
const targetDir = path.resolve(process.cwd(), fullPluginName);
|
|
59
|
+
if (fs.existsSync(targetDir)) {
|
|
60
|
+
console.log(chalk.red(`\u274C \u9519\u8BEF: \u76EE\u5F55 ${fullPluginName} \u5DF2\u5B58\u5728`));
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
let spinner = ora("\u{1F4C2} \u521B\u5EFA\u63D2\u4EF6\u76EE\u5F55...").start();
|
|
64
|
+
try {
|
|
65
|
+
yield fs.ensureDir(targetDir);
|
|
66
|
+
yield fs.ensureDir(path.join(targetDir, "src"));
|
|
67
|
+
spinner.succeed("\u{1F4C2} \u63D2\u4EF6\u76EE\u5F55\u521B\u5EFA\u6210\u529F");
|
|
68
|
+
spinner = ora("\u{1F50D} \u83B7\u53D6 @knotx \u5305\u7684\u6700\u65B0\u7248\u672C...").start();
|
|
69
|
+
const knotxVersions = yield getKnotxPackageVersions();
|
|
70
|
+
spinner.succeed("\u{1F50D} @knotx \u5305\u7248\u672C\u4FE1\u606F\u83B7\u53D6\u6210\u529F");
|
|
71
|
+
spinner = ora("\u{1F4C4} \u521B\u5EFA package.json...").start();
|
|
72
|
+
yield createPackageJson(targetDir, pluginName, environment, knotxVersions);
|
|
73
|
+
spinner.succeed("\u{1F4C4} package.json \u521B\u5EFA\u6210\u529F");
|
|
74
|
+
spinner = ora("\u{1F4C4} \u521B\u5EFA\u914D\u7F6E\u6587\u4EF6...").start();
|
|
75
|
+
yield createConfigFiles(targetDir);
|
|
76
|
+
spinner.succeed("\u{1F4C4} \u914D\u7F6E\u6587\u4EF6\u521B\u5EFA\u6210\u529F");
|
|
77
|
+
spinner = ora("\u{1F4C4} \u521B\u5EFA\u6E90\u4EE3\u7801\u6587\u4EF6...").start();
|
|
78
|
+
yield createSourceFiles(targetDir, pluginName, environment);
|
|
79
|
+
spinner.succeed("\u{1F4C4} \u6E90\u4EE3\u7801\u6587\u4EF6\u521B\u5EFA\u6210\u529F");
|
|
80
|
+
spinner = ora("\u{1F4C4} \u521B\u5EFA README.md...").start();
|
|
81
|
+
yield createReadme(targetDir, pluginName);
|
|
82
|
+
spinner.succeed("\u{1F4C4} README.md \u521B\u5EFA\u6210\u529F");
|
|
83
|
+
console.log(chalk.green(`
|
|
84
|
+
\u2705 \u63D2\u4EF6 ${chalk.bold(fullPluginName)} \u521B\u5EFA\u6210\u529F\uFF01`));
|
|
85
|
+
console.log(`
|
|
86
|
+
\u{1F4C1} \u63D2\u4EF6\u76EE\u5F55: ${chalk.cyan(targetDir)}`);
|
|
87
|
+
console.log(`
|
|
88
|
+
\u8FD0\u884C\u4EE5\u4E0B\u547D\u4EE4\u4EE5\u5B89\u88C5\u4F9D\u8D56\u5E76\u6784\u5EFA:
|
|
89
|
+
`);
|
|
90
|
+
console.log(chalk.cyan(` cd ${path.relative(process.cwd(), targetDir)}`));
|
|
91
|
+
console.log(chalk.cyan(" pnpm install"));
|
|
92
|
+
console.log(chalk.cyan(" pnpm build"));
|
|
93
|
+
} catch (error) {
|
|
94
|
+
spinner.fail("\u274C \u521B\u5EFA\u63D2\u4EF6\u5931\u8D25");
|
|
95
|
+
console.error(chalk.red(error));
|
|
96
|
+
}
|
|
97
|
+
}));
|
|
98
|
+
function getKnotxPackageVersions() {
|
|
99
|
+
return __async(this, null, function* () {
|
|
100
|
+
const knotxVersions = {};
|
|
101
|
+
try {
|
|
102
|
+
const packages = ["@knotx/core", "@knotx/decorators", "@knotx/jsx", "@knotx/build-config", "@knotx/eslint-config", "@knotx/typescript-config"];
|
|
103
|
+
const npmRegistry = "https://registry.npmjs.org";
|
|
104
|
+
for (const pkg of packages) {
|
|
105
|
+
try {
|
|
106
|
+
const version = execSync(`npm view ${pkg} version --registry=${npmRegistry}`, { encoding: "utf8" }).trim();
|
|
107
|
+
knotxVersions[pkg] = `^${version}`;
|
|
108
|
+
} catch (e) {
|
|
109
|
+
console.warn(chalk.yellow(`\u26A0\uFE0F \u65E0\u6CD5\u83B7\u53D6 ${pkg} \u7684\u6700\u65B0\u7248\u672C\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u7248\u672C`));
|
|
110
|
+
knotxVersions[pkg] = "^0.0.1";
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return knotxVersions;
|
|
114
|
+
} catch (e) {
|
|
115
|
+
console.warn(chalk.yellow("\u26A0\uFE0F \u83B7\u53D6 @knotx \u5305\u7248\u672C\u5931\u8D25\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u7248\u672C"));
|
|
116
|
+
return {
|
|
117
|
+
"@knotx/core": "^0.0.1",
|
|
118
|
+
"@knotx/decorators": "^0.0.1",
|
|
119
|
+
"@knotx/jsx": "^0.0.1",
|
|
120
|
+
"@knotx/build-config": "^0.0.1",
|
|
121
|
+
"@knotx/eslint-config": "^0.0.1",
|
|
122
|
+
"@knotx/typescript-config": "^0.0.1"
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function createPackageJson(targetDir, pluginName, environment, knotxVersions) {
|
|
128
|
+
return __async(this, null, function* () {
|
|
129
|
+
const packageJson = {
|
|
130
|
+
name: `@knotx/plugins-${pluginName}`,
|
|
131
|
+
type: "module",
|
|
132
|
+
version: "0.0.1",
|
|
133
|
+
description: `${capitalize(pluginName)} Plugin for Knotx`,
|
|
134
|
+
license: "MIT",
|
|
135
|
+
publishConfig: {
|
|
136
|
+
access: "public"
|
|
137
|
+
},
|
|
138
|
+
sideEffects: false,
|
|
139
|
+
exports: {
|
|
140
|
+
".": {
|
|
141
|
+
types: "./dist/index.d.ts",
|
|
142
|
+
import: "./dist/index.mjs",
|
|
143
|
+
require: "./dist/index.cjs"
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
main: "./dist/index.cjs",
|
|
147
|
+
module: "./dist/index.mjs",
|
|
148
|
+
types: "./dist/index.d.ts",
|
|
149
|
+
files: [
|
|
150
|
+
"dist"
|
|
151
|
+
],
|
|
152
|
+
scripts: {
|
|
153
|
+
build: "unbuild --failOnWarn=false",
|
|
154
|
+
dev: "unbuild --stub",
|
|
155
|
+
lint: "eslint .",
|
|
156
|
+
typecheck: "tsc --noEmit"
|
|
157
|
+
},
|
|
158
|
+
peerDependencies: {},
|
|
159
|
+
dependencies: {
|
|
160
|
+
"@knotx/core": knotxVersions["@knotx/core"],
|
|
161
|
+
"@knotx/decorators": knotxVersions["@knotx/decorators"],
|
|
162
|
+
"@knotx/jsx": knotxVersions["@knotx/jsx"]
|
|
163
|
+
},
|
|
164
|
+
devDependencies: {
|
|
165
|
+
"@knotx/build-config": knotxVersions["@knotx/build-config"],
|
|
166
|
+
"@knotx/eslint-config": knotxVersions["@knotx/eslint-config"],
|
|
167
|
+
"@knotx/typescript-config": knotxVersions["@knotx/typescript-config"],
|
|
168
|
+
"@types/node": "^22.13.5",
|
|
169
|
+
"eslint": "^9.23.0",
|
|
170
|
+
"typescript": "^5.7.3",
|
|
171
|
+
"unbuild": "^3.3.1",
|
|
172
|
+
"vite": "^6.1.0",
|
|
173
|
+
"vitest": "^3.0.0"
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
if (environment === "jsx") ; else if (environment === "react") {
|
|
177
|
+
packageJson.peerDependencies.react = "^17";
|
|
178
|
+
packageJson.peerDependencies["react-dom"] = "^17";
|
|
179
|
+
packageJson.devDependencies.react = "^17";
|
|
180
|
+
packageJson.devDependencies["@vitejs/plugin-react"] = "^4.3.4";
|
|
181
|
+
packageJson.devDependencies["react-dom"] = "^17";
|
|
182
|
+
packageJson.devDependencies["@types/react"] = "^17";
|
|
183
|
+
packageJson.devDependencies["@types/react-dom"] = "^17";
|
|
184
|
+
}
|
|
185
|
+
yield fs.writeFile(
|
|
186
|
+
path.join(targetDir, "package.json"),
|
|
187
|
+
JSON.stringify(packageJson, null, 2)
|
|
188
|
+
);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
function createConfigFiles(targetDir) {
|
|
192
|
+
return __async(this, null, function* () {
|
|
193
|
+
try {
|
|
194
|
+
const tsconfigTemplate = yield fs.readFile(path.join(templatesDir, "tsconfig.json.template"), "utf-8");
|
|
195
|
+
const buildConfigTemplate = yield fs.readFile(path.join(templatesDir, "build.config.ts.template"), "utf-8");
|
|
196
|
+
const eslintConfigTemplate = yield fs.readFile(path.join(templatesDir, "eslint.config.js.template"), "utf-8");
|
|
197
|
+
yield fs.writeFile(path.join(targetDir, "tsconfig.json"), tsconfigTemplate);
|
|
198
|
+
yield fs.writeFile(path.join(targetDir, "build.config.ts"), buildConfigTemplate);
|
|
199
|
+
yield fs.writeFile(path.join(targetDir, "eslint.config.js"), eslintConfigTemplate);
|
|
200
|
+
} catch (error) {
|
|
201
|
+
console.error("\u65E0\u6CD5\u8BFB\u53D6\u6A21\u677F\u6587\u4EF6:", error);
|
|
202
|
+
const tsconfig = {
|
|
203
|
+
extends: "@knotx/typescript-config/base.json",
|
|
204
|
+
include: [
|
|
205
|
+
"src"
|
|
206
|
+
],
|
|
207
|
+
compilerOptions: {
|
|
208
|
+
outDir: "dist"
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
yield fs.writeFile(
|
|
212
|
+
path.join(targetDir, "tsconfig.json"),
|
|
213
|
+
JSON.stringify(tsconfig, null, 2)
|
|
214
|
+
);
|
|
215
|
+
yield fs.writeFile(
|
|
216
|
+
path.join(targetDir, "build.config.ts"),
|
|
217
|
+
'import { defineBuildConfig } from "@knotx/build-config";\n\nexport default defineBuildConfig();'
|
|
218
|
+
);
|
|
219
|
+
yield fs.writeFile(
|
|
220
|
+
path.join(targetDir, "eslint.config.js"),
|
|
221
|
+
"export { default } from '@knotx/eslint-config';"
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
function createSourceFiles(targetDir, pluginName, environment) {
|
|
227
|
+
return __async(this, null, function* () {
|
|
228
|
+
try {
|
|
229
|
+
const indexTemplate = yield fs.readFile(path.join(templatesDir, "index.ts.template"), "utf-8");
|
|
230
|
+
const indexContent = indexTemplate.replace(/\{\{pluginName\}\}/g, pluginName);
|
|
231
|
+
yield fs.writeFile(path.join(targetDir, "src", "index.ts"), indexContent);
|
|
232
|
+
let templatePath;
|
|
233
|
+
if (environment === "jsx") {
|
|
234
|
+
templatePath = path.join(templatesDir, "plugin.jsx.template");
|
|
235
|
+
} else {
|
|
236
|
+
templatePath = path.join(templatesDir, "plugin.jsx.template");
|
|
237
|
+
}
|
|
238
|
+
const pluginTemplate = yield fs.readFile(templatePath, "utf-8");
|
|
239
|
+
const pluginContent = pluginTemplate.replace(/\{\{pluginName\}\}/g, pluginName).replace(/\{\{capitalizedPluginName\}\}/g, capitalize(pluginName));
|
|
240
|
+
const fileName = `${pluginName}.tsx`;
|
|
241
|
+
yield fs.writeFile(path.join(targetDir, "src", fileName), pluginContent);
|
|
242
|
+
} catch (error) {
|
|
243
|
+
console.error("\u65E0\u6CD5\u8BFB\u53D6\u6A21\u677F\u6587\u4EF6:", error);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
function createReadme(targetDir, pluginName) {
|
|
248
|
+
return __async(this, null, function* () {
|
|
249
|
+
try {
|
|
250
|
+
const readmeTemplate = yield fs.readFile(path.join(templatesDir, "README.md.template"), "utf-8");
|
|
251
|
+
const description = `${capitalize(pluginName)} Plugin for Knotx`;
|
|
252
|
+
const readmeContent = readmeTemplate.replace(/\{\{pluginName\}\}/g, pluginName).replace(/\{\{description\}\}/g, description);
|
|
253
|
+
yield fs.writeFile(path.join(targetDir, "README.md"), readmeContent);
|
|
254
|
+
} catch (error) {
|
|
255
|
+
console.error("\u65E0\u6CD5\u8BFB\u53D6 README \u6A21\u677F\u6587\u4EF6:", error);
|
|
256
|
+
const readmeContent = `# @knotx/plugins-${pluginName}
|
|
257
|
+
|
|
258
|
+
${capitalize(pluginName)} Plugin for Knotx
|
|
259
|
+
|
|
260
|
+
## \u5B89\u88C5
|
|
261
|
+
|
|
262
|
+
\`\`\`bash
|
|
263
|
+
npm install @knotx/plugins-${pluginName}
|
|
264
|
+
# \u6216\u8005
|
|
265
|
+
yarn add @knotx/plugins-${pluginName}
|
|
266
|
+
# \u6216\u8005
|
|
267
|
+
pnpm add @knotx/plugins-${pluginName}
|
|
268
|
+
\`\`\`
|
|
269
|
+
|
|
270
|
+
## \u4F7F\u7528\u65B9\u6CD5
|
|
271
|
+
|
|
272
|
+
\`\`\`typescript
|
|
273
|
+
import { ${pluginName} } from '@knotx/plugins-${pluginName}';
|
|
274
|
+
|
|
275
|
+
// \u5728\u60A8\u7684Knotx\u5E94\u7528\u4E2D\u4F7F\u7528\u63D2\u4EF6
|
|
276
|
+
app.use(${pluginName});
|
|
277
|
+
\`\`\`
|
|
278
|
+
|
|
279
|
+
## \u8BB8\u53EF\u8BC1
|
|
280
|
+
|
|
281
|
+
MIT`;
|
|
282
|
+
yield fs.writeFile(path.join(targetDir, "README.md"), readmeContent);
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
function capitalize(str) {
|
|
287
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
288
|
+
}
|
|
289
|
+
program.parse();
|
|
290
|
+
if (!process.argv.slice(2).length) {
|
|
291
|
+
program.outputHelp();
|
|
292
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@knotx/cli",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "CLI tool for Knotx",
|
|
5
|
+
"author": "boenfu",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/boenfu/knotx#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/boenfu/knotx.git",
|
|
11
|
+
"directory": "packages/cli"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.mjs",
|
|
20
|
+
"require": "./dist/index.cjs"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"main": "./dist/index.cjs",
|
|
24
|
+
"module": "./dist/index.mjs",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"bin": {
|
|
27
|
+
"knotx": "./dist/index.cjs"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"templates"
|
|
32
|
+
],
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"chalk": "^5.3.0",
|
|
35
|
+
"commander": "^12.0.0",
|
|
36
|
+
"fs-extra": "^11.2.0",
|
|
37
|
+
"inquirer": "^9.2.15",
|
|
38
|
+
"ora": "^8.0.1"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/fs-extra": "^11.0.4",
|
|
42
|
+
"@types/inquirer": "^9.0.7",
|
|
43
|
+
"@knotx/build-config": "0.0.0",
|
|
44
|
+
"@knotx/typescript-config": "0.0.0",
|
|
45
|
+
"@knotx/eslint-config": "0.0.0"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "unbuild --failOnWarn=false",
|
|
49
|
+
"dev": "unbuild --stub",
|
|
50
|
+
"lint": "eslint .",
|
|
51
|
+
"typecheck": "tsc --noEmit"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @knotx/plugins-{{pluginName}}
|
|
2
|
+
|
|
3
|
+
{{description}}
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @knotx/plugins-{{pluginName}}
|
|
9
|
+
# 或者
|
|
10
|
+
yarn add @knotx/plugins-{{pluginName}}
|
|
11
|
+
# 或者
|
|
12
|
+
pnpm add @knotx/plugins-{{pluginName}}
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 使用方法
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { {{capitalizedPluginName}} } from '@knotx/plugins-{{pluginName}}';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 许可证
|
|
22
|
+
|
|
23
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '@knotx/eslint-config';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './{{pluginName}}';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { NodeData } from '@knotx/core'
|
|
2
|
+
|
|
3
|
+
import { inject, OnInit } from '@knotx/decorators'
|
|
4
|
+
import { BasePlugin } from '@knotx/core'
|
|
5
|
+
|
|
6
|
+
export class {{capitalizedPluginName}} extends BasePlugin<'{{pluginName}}'> {
|
|
7
|
+
name = '{{pluginName}}' as const
|
|
8
|
+
|
|
9
|
+
@inject.nodes()
|
|
10
|
+
nodes!: NodeData[]
|
|
11
|
+
|
|
12
|
+
@OnInit
|
|
13
|
+
init() {
|
|
14
|
+
console.log('{{capitalizedPluginName}} 插件已加载', this.nodes)
|
|
15
|
+
}
|
|
16
|
+
}
|