@choiceopen/automation-plugin-cli 0.0.1 → 0.1.2
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/README.md +9 -134
- package/dist/commands/auth/login.js +12 -10
- package/dist/commands/plugin/index.js +1 -0
- package/dist/commands/plugin/refresh-key.js +103 -0
- package/dist/utils/config.d.ts +3 -0
- package/dist/utils/config.js +12 -2
- package/oclif.manifest.json +6 -337
- package/package.json +1 -1
- package/dist/commands/auth/index.d.ts +0 -11
- package/dist/commands/auth/index.js +0 -15
- package/dist/commands/auth/login.d.ts +0 -15
- package/dist/commands/plugin/checksum.d.ts +0 -13
- package/dist/commands/plugin/checksum.js +0 -22
- package/dist/commands/plugin/index.d.ts +0 -11
- package/dist/commands/plugin/init.d.ts +0 -33
- package/dist/commands/plugin/init.js +0 -363
- package/dist/commands/plugin/pack.d.ts +0 -13
- package/dist/commands/plugin/pack.js +0 -22
- package/dist/commands/plugin/permission.d.ts +0 -13
- package/dist/commands/plugin/permission.js +0 -22
- package/dist/commands/plugin/run.d.ts +0 -13
- package/dist/commands/plugin/run.js +0 -22
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/utils/generator.d.ts +0 -20
- package/dist/utils/generator.js +0 -68
- package/dist/utils/theme.d.ts +0 -13
- package/dist/utils/theme.js +0 -13
- package/dist/utils/views.d.ts +0 -2
- package/dist/utils/views.js +0 -8
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import checkbox, { Separator } from "@inquirer/checkbox";
|
|
3
|
-
import input from "@inquirer/input";
|
|
4
|
-
import select from "@inquirer/select";
|
|
5
|
-
import { Command, Flags } from "@oclif/core";
|
|
6
|
-
import { colorize } from "@oclif/core/ux";
|
|
7
|
-
import { assert, isString } from "es-toolkit";
|
|
8
|
-
import { dedent } from "ts-dedent";
|
|
9
|
-
import z from "zod";
|
|
10
|
-
import { createPluginGenerator } from "../../utils/generator.js";
|
|
11
|
-
import { checkboxTheme, selectTheme } from "../../utils/theme.js";
|
|
12
|
-
const LOCALES = ["en_US", "zh_Hans", "ja_JP"];
|
|
13
|
-
const LANGUAGES = ["elixir", "python", "typescript"];
|
|
14
|
-
const PERMISSIONS = [
|
|
15
|
-
"endpoints:register",
|
|
16
|
-
"model:call_llm",
|
|
17
|
-
"model:call_embedding",
|
|
18
|
-
"model:call_moderation",
|
|
19
|
-
"model:call_rerank",
|
|
20
|
-
"model:call_stt",
|
|
21
|
-
"model:call_tts",
|
|
22
|
-
"storage:kv",
|
|
23
|
-
"tools:invoke",
|
|
24
|
-
];
|
|
25
|
-
export default class PluginInit extends Command {
|
|
26
|
-
static description = dedent `
|
|
27
|
-
Initialize a new plugin with step-by-step interactive instructions.
|
|
28
|
-
|
|
29
|
-
Providing required flags skips interactive flow and completes initialization in one go.
|
|
30
|
-
`;
|
|
31
|
-
static examples = [
|
|
32
|
-
{
|
|
33
|
-
command: "<%= config.bin %> <%= command.id %>",
|
|
34
|
-
description: "Start with interactive initialization:",
|
|
35
|
-
},
|
|
36
|
-
];
|
|
37
|
-
static flags = {
|
|
38
|
-
interactive: Flags.boolean({
|
|
39
|
-
allowNo: true,
|
|
40
|
-
char: "i",
|
|
41
|
-
default: true,
|
|
42
|
-
summary: "Use interactive mode (by default)",
|
|
43
|
-
}),
|
|
44
|
-
name: Flags.string({
|
|
45
|
-
char: "n",
|
|
46
|
-
helpValue: "my-awesome-plugin",
|
|
47
|
-
summary: "Plugin name",
|
|
48
|
-
}),
|
|
49
|
-
description: Flags.string({
|
|
50
|
-
char: "d",
|
|
51
|
-
default: "",
|
|
52
|
-
helpValue: "Descriptive text...",
|
|
53
|
-
summary: "Short description",
|
|
54
|
-
}),
|
|
55
|
-
author: Flags.string({
|
|
56
|
-
char: "a",
|
|
57
|
-
default: "",
|
|
58
|
-
helpValue: "John Doe",
|
|
59
|
-
summary: "Author name",
|
|
60
|
-
}),
|
|
61
|
-
email: Flags.string({
|
|
62
|
-
char: "e",
|
|
63
|
-
default: "",
|
|
64
|
-
helpValue: "john.doe@example.com",
|
|
65
|
-
summary: "Author email address",
|
|
66
|
-
}),
|
|
67
|
-
url: Flags.string({
|
|
68
|
-
char: "u",
|
|
69
|
-
default: "",
|
|
70
|
-
summary: "Repository URL",
|
|
71
|
-
}),
|
|
72
|
-
locales: Flags.option({
|
|
73
|
-
multiple: true,
|
|
74
|
-
options: LOCALES,
|
|
75
|
-
})({
|
|
76
|
-
delimiter: ",",
|
|
77
|
-
summary: "Provide READMEs in which languages",
|
|
78
|
-
}),
|
|
79
|
-
language: Flags.option({
|
|
80
|
-
multiple: false,
|
|
81
|
-
options: LANGUAGES,
|
|
82
|
-
})({
|
|
83
|
-
char: "l",
|
|
84
|
-
summary: "Programming language to use for plugin development",
|
|
85
|
-
}),
|
|
86
|
-
type: Flags.option({
|
|
87
|
-
multiple: false,
|
|
88
|
-
options: ["extension", "llm", "tool", "trigger"],
|
|
89
|
-
})({
|
|
90
|
-
char: "t",
|
|
91
|
-
summary: "Plugin type",
|
|
92
|
-
}),
|
|
93
|
-
permissions: Flags.option({
|
|
94
|
-
multiple: true,
|
|
95
|
-
options: PERMISSIONS,
|
|
96
|
-
})({
|
|
97
|
-
char: "p",
|
|
98
|
-
delimiter: ",",
|
|
99
|
-
summary: "Permissions required by the plugin",
|
|
100
|
-
}),
|
|
101
|
-
};
|
|
102
|
-
async run() {
|
|
103
|
-
const { flags } = await this.parse(PluginInit);
|
|
104
|
-
this.reconcileInteractiveFlag(flags);
|
|
105
|
-
if (flags.interactive) {
|
|
106
|
-
await this.runInteractiveMode(flags);
|
|
107
|
-
}
|
|
108
|
-
assert(flags.name, "flags.name should be valid here...");
|
|
109
|
-
assert(flags.language, "flags.language should be valid here...");
|
|
110
|
-
const generator = createPluginGenerator(flags.language, {
|
|
111
|
-
props: { ...flags, createdAt: new Date().toISOString() },
|
|
112
|
-
target: path.join(process.cwd(), flags.name),
|
|
113
|
-
});
|
|
114
|
-
await generator.generate();
|
|
115
|
-
}
|
|
116
|
-
nameIsValid(name) {
|
|
117
|
-
return isString(name) && /^[a-z][a-z0-9_-]{2,62}[a-z0-9]$/.test(name);
|
|
118
|
-
}
|
|
119
|
-
reconcileInteractiveFlag(flags) {
|
|
120
|
-
if (flags.interactive && this.nameIsValid(flags.name)) {
|
|
121
|
-
flags.interactive = false;
|
|
122
|
-
}
|
|
123
|
-
if (!flags.interactive && !this.nameIsValid(flags.name)) {
|
|
124
|
-
this.log(colorize("redBright", dedent `
|
|
125
|
-
Without interactive mode, you should provide initial information manually.
|
|
126
|
-
Use ${colorize("blue", "automation help plugin init")} to see all available options.
|
|
127
|
-
`));
|
|
128
|
-
this.exit(0);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
async runInteractiveMode(flags) {
|
|
132
|
-
this.log(dedent `
|
|
133
|
-
Guiding you through creating a new plugin in interactive mode
|
|
134
|
-
Please follow the instructions below to complete the process:\n
|
|
135
|
-
`);
|
|
136
|
-
try {
|
|
137
|
-
flags.name = await this.collectName();
|
|
138
|
-
flags.description = await this.collectDescription();
|
|
139
|
-
flags.author = await this.collectAuthor();
|
|
140
|
-
flags.email = await this.collectEmail();
|
|
141
|
-
flags.url = await this.collectURL();
|
|
142
|
-
flags.locales = await this.collectLocales(flags);
|
|
143
|
-
flags.language = await this.collectLanguage();
|
|
144
|
-
flags.type = await this.collectType();
|
|
145
|
-
flags.permissions = await this.collectPermissions(flags);
|
|
146
|
-
}
|
|
147
|
-
catch (error) {
|
|
148
|
-
if (error instanceof Error && error.name === "ExitPromptError") {
|
|
149
|
-
process.exit(0);
|
|
150
|
-
}
|
|
151
|
-
throw error;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
async collectName() {
|
|
155
|
-
return await input({
|
|
156
|
-
message: "What's the name of this new plugin:",
|
|
157
|
-
pattern: /^[a-z][a-z0-9_-]{2,62}[a-z0-9]$/,
|
|
158
|
-
patternError: dedent `
|
|
159
|
-
You must provide a name for the new plugin:
|
|
160
|
-
- Only lowercase letters, digits, underscores, and hyphens are allowed
|
|
161
|
-
- Minimum length of 4 and maximum length of 64
|
|
162
|
-
- Starts with a lowercase letter (not a digit)
|
|
163
|
-
- Ends with a lowercase letter or digit (not underscore or hyphen)
|
|
164
|
-
`,
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
async collectDescription() {
|
|
168
|
-
return await input({
|
|
169
|
-
message: "How do you describe this new plugin:",
|
|
170
|
-
default: "A brief description of the plugin's functionality",
|
|
171
|
-
prefill: "tab",
|
|
172
|
-
pattern: /^.{16,256}$/,
|
|
173
|
-
patternError: dedent `
|
|
174
|
-
You must provide a description for the new plugin:
|
|
175
|
-
- Allows any characters, minimum 16 characters, maximum 256 characters
|
|
176
|
-
`,
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
async collectAuthor() {
|
|
180
|
-
return await input({
|
|
181
|
-
message: "Who is the author of the new plugin:",
|
|
182
|
-
default: "John Doe",
|
|
183
|
-
prefill: "tab",
|
|
184
|
-
pattern: /^.{2,64}$/,
|
|
185
|
-
patternError: dedent `
|
|
186
|
-
You must provide the author name:
|
|
187
|
-
- Allows any characters, minimum 2 characters, maximum 64 characters
|
|
188
|
-
`,
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
async collectEmail() {
|
|
192
|
-
return await input({
|
|
193
|
-
message: "What is the email address of the author:",
|
|
194
|
-
default: "john.doe@example.com",
|
|
195
|
-
prefill: "tab",
|
|
196
|
-
pattern: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(?:\.[a-zA-Z]{2,})*$/,
|
|
197
|
-
patternError: dedent `You must provide the author email`,
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
async collectURL() {
|
|
201
|
-
return await input({
|
|
202
|
-
message: "What is the repository URL address (Optional):",
|
|
203
|
-
default: "https://github.com/[user]/[repo]",
|
|
204
|
-
prefill: "tab",
|
|
205
|
-
validate: (value) => {
|
|
206
|
-
const { success } = z
|
|
207
|
-
.url({ normalize: true, protocol: /https?|git/ })
|
|
208
|
-
.optional()
|
|
209
|
-
.safeParse(value);
|
|
210
|
-
return success || "You must provide a valid URL";
|
|
211
|
-
},
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
async collectLocales(flags) {
|
|
215
|
-
const values = await checkbox({
|
|
216
|
-
choices: [
|
|
217
|
-
{
|
|
218
|
-
checked: flags.locales?.includes("en_US"),
|
|
219
|
-
disabled: "(required)",
|
|
220
|
-
name: "English",
|
|
221
|
-
description: "English (United States)",
|
|
222
|
-
value: "en_US",
|
|
223
|
-
},
|
|
224
|
-
{
|
|
225
|
-
checked: flags.locales?.includes("zh_Hans"),
|
|
226
|
-
disabled: false,
|
|
227
|
-
name: "简体中文",
|
|
228
|
-
description: "Simplified Chinese (China)",
|
|
229
|
-
value: "zh_Hans",
|
|
230
|
-
},
|
|
231
|
-
{
|
|
232
|
-
checked: flags.locales?.includes("ja_JP"),
|
|
233
|
-
disabled: false,
|
|
234
|
-
name: "日本語",
|
|
235
|
-
description: "Japanese (Japan)",
|
|
236
|
-
value: "ja_JP",
|
|
237
|
-
},
|
|
238
|
-
],
|
|
239
|
-
message: "Provide READMEs in which language(s)?",
|
|
240
|
-
theme: checkboxTheme,
|
|
241
|
-
});
|
|
242
|
-
return ["en_US", ...values];
|
|
243
|
-
}
|
|
244
|
-
async collectLanguage() {
|
|
245
|
-
return await select({
|
|
246
|
-
choices: [
|
|
247
|
-
{
|
|
248
|
-
name: "Elixir",
|
|
249
|
-
value: "elixir",
|
|
250
|
-
},
|
|
251
|
-
{
|
|
252
|
-
name: "Python",
|
|
253
|
-
value: "python",
|
|
254
|
-
},
|
|
255
|
-
{
|
|
256
|
-
name: "TypeScript",
|
|
257
|
-
value: "typescript",
|
|
258
|
-
},
|
|
259
|
-
],
|
|
260
|
-
message: "What programming language do you prefer for developing this plugin?",
|
|
261
|
-
theme: selectTheme,
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
async collectType() {
|
|
265
|
-
return await select({
|
|
266
|
-
choices: [
|
|
267
|
-
{
|
|
268
|
-
name: "Extension",
|
|
269
|
-
value: "extension",
|
|
270
|
-
description: "Extend capabilities by integrating with external APIs.",
|
|
271
|
-
},
|
|
272
|
-
{
|
|
273
|
-
name: "Model",
|
|
274
|
-
value: "llm",
|
|
275
|
-
description: "Introduce more LLMs to enhance AI capabilities.",
|
|
276
|
-
},
|
|
277
|
-
{
|
|
278
|
-
name: "Tool",
|
|
279
|
-
value: "tool",
|
|
280
|
-
description: "Complete specific tasks, typically invoked by LLMs.",
|
|
281
|
-
},
|
|
282
|
-
{
|
|
283
|
-
name: "Trigger",
|
|
284
|
-
value: "trigger",
|
|
285
|
-
description: "Run workflows by receiving events through webhooks.",
|
|
286
|
-
},
|
|
287
|
-
],
|
|
288
|
-
message: dedent `
|
|
289
|
-
${colorize("blue", "Choose the type of the new plugin")}
|
|
290
|
-
|
|
291
|
-
Plugins can extend the platform's capabilities in multiple ways, making workflows more flexible and powerful.
|
|
292
|
-
Based on your specific requirement, plugins can be categorized into the following types:
|
|
293
|
-
|
|
294
|
-
- ${colorize("yellowBright", "Extension")}: Provide more functionality to workflows by integrating external service APIs
|
|
295
|
-
- ${colorize("yellowBright", "Model")}: Access more large language models to enrich the AI capabilities of workflows
|
|
296
|
-
- ${colorize("yellowBright", "Tool")}: Customized logic to perform specific tasks, typically invoked by LLMs and/or Agents
|
|
297
|
-
- ${colorize("yellowBright", "Trigger")}: Receive external events through webhooks to start workflows with initial input data
|
|
298
|
-
|
|
299
|
-
Please select the matching type from the following options:
|
|
300
|
-
`,
|
|
301
|
-
theme: selectTheme,
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
async collectPermissions(flags) {
|
|
305
|
-
return await checkbox({
|
|
306
|
-
choices: [
|
|
307
|
-
new Separator(colorize("yellowBright", " ⎯⎯⎯⎯⎯ Endpoints ⎯⎯⎯⎯⎯")),
|
|
308
|
-
{
|
|
309
|
-
checked: flags.permissions?.includes("endpoints:register"),
|
|
310
|
-
value: "endpoints:register",
|
|
311
|
-
description: "Ability to register API endpoints",
|
|
312
|
-
},
|
|
313
|
-
new Separator(colorize("yellowBright", " ⎯⎯⎯⎯⎯ Model ⎯⎯⎯⎯⎯")),
|
|
314
|
-
{
|
|
315
|
-
checked: flags.permissions?.includes("model:call_llm"),
|
|
316
|
-
value: "model:call_llm",
|
|
317
|
-
description: "Ability to call LLMs",
|
|
318
|
-
},
|
|
319
|
-
{
|
|
320
|
-
checked: flags.permissions?.includes("model:call_embedding"),
|
|
321
|
-
value: "model:call_embedding",
|
|
322
|
-
description: "Ability to call embeddings models",
|
|
323
|
-
},
|
|
324
|
-
{
|
|
325
|
-
checked: flags.permissions?.includes("model:call_moderation"),
|
|
326
|
-
value: "model:call_moderation",
|
|
327
|
-
description: "Ability to call moderation models",
|
|
328
|
-
},
|
|
329
|
-
{
|
|
330
|
-
checked: flags.permissions?.includes("model:call_rerank"),
|
|
331
|
-
value: "model:call_rerank",
|
|
332
|
-
description: "Ability to call rerank models",
|
|
333
|
-
},
|
|
334
|
-
{
|
|
335
|
-
checked: flags.permissions?.includes("model:call_stt"),
|
|
336
|
-
value: "model:call_stt",
|
|
337
|
-
description: "Ability to call STT models",
|
|
338
|
-
},
|
|
339
|
-
{
|
|
340
|
-
checked: flags.permissions?.includes("model:call_tts"),
|
|
341
|
-
value: "model:call_tts",
|
|
342
|
-
description: "Ability to call TTS models",
|
|
343
|
-
},
|
|
344
|
-
new Separator(colorize("yellowBright", " ⎯⎯⎯⎯⎯ Storage ⎯⎯⎯⎯⎯")),
|
|
345
|
-
{
|
|
346
|
-
checked: flags.permissions?.includes("storage:kv"),
|
|
347
|
-
value: "storage:kv",
|
|
348
|
-
description: "Ability to use key-value storage",
|
|
349
|
-
},
|
|
350
|
-
new Separator(colorize("yellowBright", " ⎯⎯⎯⎯⎯ Tools ⎯⎯⎯⎯⎯")),
|
|
351
|
-
{
|
|
352
|
-
checked: flags.permissions?.includes("tools:invoke"),
|
|
353
|
-
value: "tools:invoke",
|
|
354
|
-
description: "Ability to invoke other tools",
|
|
355
|
-
},
|
|
356
|
-
],
|
|
357
|
-
loop: false,
|
|
358
|
-
pageSize: 15,
|
|
359
|
-
message: "Select required permissions for the plugin:",
|
|
360
|
-
theme: checkboxTheme,
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Command } from "@oclif/core";
|
|
2
|
-
export default class PluginPack extends Command {
|
|
3
|
-
static args: {
|
|
4
|
-
file: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
5
|
-
};
|
|
6
|
-
static description: string;
|
|
7
|
-
static examples: string[];
|
|
8
|
-
static flags: {
|
|
9
|
-
force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
10
|
-
name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
-
};
|
|
12
|
-
run(): Promise<void>;
|
|
13
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Args, Command, Flags } from "@oclif/core";
|
|
2
|
-
export default class PluginPack extends Command {
|
|
3
|
-
static args = {
|
|
4
|
-
file: Args.string({ description: "file to read" }),
|
|
5
|
-
};
|
|
6
|
-
static description = "describe the command here";
|
|
7
|
-
static examples = ["<%= config.bin %> <%= command.id %>"];
|
|
8
|
-
static flags = {
|
|
9
|
-
// flag with no value (-f, --force)
|
|
10
|
-
force: Flags.boolean({ char: "f" }),
|
|
11
|
-
// flag with a value (-n, --name=VALUE)
|
|
12
|
-
name: Flags.string({ char: "n", description: "name to print" }),
|
|
13
|
-
};
|
|
14
|
-
async run() {
|
|
15
|
-
const { args, flags } = await this.parse(PluginPack);
|
|
16
|
-
const name = flags.name ?? "world";
|
|
17
|
-
this.log(`hello ${name} from /Users/nightire/Code/github.com/choice-open/automation-plugin-cli/src/commands/plugin/pack.ts`);
|
|
18
|
-
if (args.file && flags.force) {
|
|
19
|
-
this.log(`you input --force and --file: ${args.file}`);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Command } from "@oclif/core";
|
|
2
|
-
export default class PluginPermission extends Command {
|
|
3
|
-
static args: {
|
|
4
|
-
file: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
5
|
-
};
|
|
6
|
-
static description: string;
|
|
7
|
-
static examples: string[];
|
|
8
|
-
static flags: {
|
|
9
|
-
force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
10
|
-
name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
-
};
|
|
12
|
-
run(): Promise<void>;
|
|
13
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Args, Command, Flags } from "@oclif/core";
|
|
2
|
-
export default class PluginPermission extends Command {
|
|
3
|
-
static args = {
|
|
4
|
-
file: Args.string({ description: "file to read" }),
|
|
5
|
-
};
|
|
6
|
-
static description = "describe the command here";
|
|
7
|
-
static examples = ["<%= config.bin %> <%= command.id %>"];
|
|
8
|
-
static flags = {
|
|
9
|
-
// flag with no value (-f, --force)
|
|
10
|
-
force: Flags.boolean({ char: "f" }),
|
|
11
|
-
// flag with a value (-n, --name=VALUE)
|
|
12
|
-
name: Flags.string({ char: "n", description: "name to print" }),
|
|
13
|
-
};
|
|
14
|
-
async run() {
|
|
15
|
-
const { args, flags } = await this.parse(PluginPermission);
|
|
16
|
-
const name = flags.name ?? "world";
|
|
17
|
-
this.log(`hello ${name} from /Users/nightire/Code/github.com/choice-open/automation-plugin-cli/src/commands/plugin/permission.ts`);
|
|
18
|
-
if (args.file && flags.force) {
|
|
19
|
-
this.log(`you input --force and --file: ${args.file}`);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Command } from "@oclif/core";
|
|
2
|
-
export default class PluginRun extends Command {
|
|
3
|
-
static args: {
|
|
4
|
-
file: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
5
|
-
};
|
|
6
|
-
static description: string;
|
|
7
|
-
static examples: string[];
|
|
8
|
-
static flags: {
|
|
9
|
-
force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
10
|
-
name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
-
};
|
|
12
|
-
run(): Promise<void>;
|
|
13
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Args, Command, Flags } from "@oclif/core";
|
|
2
|
-
export default class PluginRun extends Command {
|
|
3
|
-
static args = {
|
|
4
|
-
file: Args.string({ description: "file to read" }),
|
|
5
|
-
};
|
|
6
|
-
static description = "describe the command here";
|
|
7
|
-
static examples = ["<%= config.bin %> <%= command.id %>"];
|
|
8
|
-
static flags = {
|
|
9
|
-
// flag with no value (-f, --force)
|
|
10
|
-
force: Flags.boolean({ char: "f" }),
|
|
11
|
-
// flag with a value (-n, --name=VALUE)
|
|
12
|
-
name: Flags.string({ char: "n", description: "name to print" }),
|
|
13
|
-
};
|
|
14
|
-
async run() {
|
|
15
|
-
const { args, flags } = await this.parse(PluginRun);
|
|
16
|
-
const name = flags.name ?? "world";
|
|
17
|
-
this.log(`hello ${name} from /Users/nightire/Code/github.com/choice-open/automation-plugin-cli/src/commands/plugin/run.ts`);
|
|
18
|
-
if (args.file && flags.force) {
|
|
19
|
-
this.log(`you input --force and --file: ${args.file}`);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { run } from "@oclif/core";
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { run } from "@oclif/core";
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Eta } from "eta";
|
|
2
|
-
export interface PluginGenerator {
|
|
3
|
-
context: {
|
|
4
|
-
props: Record<string, unknown>;
|
|
5
|
-
target: string;
|
|
6
|
-
};
|
|
7
|
-
renderer: Eta;
|
|
8
|
-
type: string;
|
|
9
|
-
generate(): Promise<void>;
|
|
10
|
-
}
|
|
11
|
-
export declare function createPluginGenerator(type: PluginGenerator["type"], context: PluginGenerator["context"]): PluginGenerator;
|
|
12
|
-
export declare class TypeScriptPluginGenerator implements PluginGenerator {
|
|
13
|
-
#private;
|
|
14
|
-
context: PluginGenerator["context"];
|
|
15
|
-
type: "typescript";
|
|
16
|
-
renderer: Eta;
|
|
17
|
-
constructor(context: PluginGenerator["context"]);
|
|
18
|
-
generate(): Promise<void>;
|
|
19
|
-
private groupPermissions;
|
|
20
|
-
}
|
package/dist/utils/generator.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { copyFile, mkdir, readdir, writeFile } from "node:fs/promises";
|
|
2
|
-
import { basename, extname, join } from "node:path";
|
|
3
|
-
import { Eta } from "eta";
|
|
4
|
-
export function createPluginGenerator(type, context) {
|
|
5
|
-
switch (type) {
|
|
6
|
-
case "typescript":
|
|
7
|
-
return new TypeScriptPluginGenerator(context);
|
|
8
|
-
default:
|
|
9
|
-
throw new Error(`Plugin generator type "${type}" is not implemented.`);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export class TypeScriptPluginGenerator {
|
|
13
|
-
context;
|
|
14
|
-
type = "typescript";
|
|
15
|
-
renderer = new Eta({
|
|
16
|
-
autoTrim: false,
|
|
17
|
-
autoEscape: false,
|
|
18
|
-
varName: "props",
|
|
19
|
-
views: join(import.meta.dirname, "../templates"),
|
|
20
|
-
});
|
|
21
|
-
constructor(context) {
|
|
22
|
-
this.context = context;
|
|
23
|
-
this.context.props.permissions = this.groupPermissions(this.context.props.permissions);
|
|
24
|
-
}
|
|
25
|
-
async generate() {
|
|
26
|
-
await Promise.all([
|
|
27
|
-
this.#generateFiles(join(import.meta.dirname, "../templates/common")),
|
|
28
|
-
this.#generateFiles(join(import.meta.dirname, `../templates/${this.context.props.language}`)),
|
|
29
|
-
]);
|
|
30
|
-
}
|
|
31
|
-
async #generateFiles(source, target = this.context.target) {
|
|
32
|
-
await mkdir(target, { recursive: true });
|
|
33
|
-
for (const entry of await readdir(source, { withFileTypes: true })) {
|
|
34
|
-
const sourcePath = join(source, entry.name);
|
|
35
|
-
if (entry.isDirectory()) {
|
|
36
|
-
await this.#generateFiles(sourcePath, join(target, entry.name));
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
if (extname(sourcePath).toLowerCase() === ".eta") {
|
|
40
|
-
console.info(sourcePath, entry, this.renderer);
|
|
41
|
-
const fileName = basename(sourcePath, extname(sourcePath));
|
|
42
|
-
const templatePath = sourcePath.replace(this.renderer.config.views ?? "", "");
|
|
43
|
-
const content = this.renderer.render(templatePath, this.context.props);
|
|
44
|
-
const targetPath = join(target, fileName);
|
|
45
|
-
await writeFile(targetPath, content, "utf-8");
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
await copyFile(sourcePath, join(target, entry.name));
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
groupPermissions(permissions) {
|
|
54
|
-
return permissions
|
|
55
|
-
.reduce((finale, permission) => {
|
|
56
|
-
const [scope, entry] = permission.split(":");
|
|
57
|
-
const existing = finale.find((item) => item.scope === scope);
|
|
58
|
-
if (existing) {
|
|
59
|
-
existing.entries.push(entry);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
finale.push({ scope, entries: [entry] });
|
|
63
|
-
}
|
|
64
|
-
return finale;
|
|
65
|
-
}, [])
|
|
66
|
-
.sort((a, b) => a.scope.localeCompare(b.scope, "en"));
|
|
67
|
-
}
|
|
68
|
-
}
|
package/dist/utils/theme.d.ts
DELETED
package/dist/utils/theme.js
DELETED
package/dist/utils/views.d.ts
DELETED