Repository navigation
Expand file tree
/
Copy pathgenerate.ts
More file actions
49 lines (40 loc) · 2.07 KB
/
Copy pathgenerate.ts
File metadata and controls
49 lines (40 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { Command } from '@oclif/core';
import { PluginGenerateAction } from '../../actions/plugin/generate.js';
import { CommandMetadata } from '../../types/common/command-metadata.js';
import { DirectoryPath } from '../../types/file/directoryPath.js';
import { FlagsProvider } from '../../types/flags-provider.js';
import { ProjectContext } from '../../types/project-context.js';
import { format, intro, outro } from '../../prompts/format.js';
export default class PluginGenerate extends Command {
static readonly summary = 'Generate a context plugin for your SDKs.';
static readonly description =
"Generate a context plugin that teaches an AI coding assistant how to use your SDKs. Requires an input directory containing a `src` directory with your API specification — `apimatic.json` is created if it is not there. It asks for the plugin's name on the first run, and for its languages only when `apimatic.json` records none (`sdk publish` records them). Later runs read both from `apimatic.json` without asking.";
static readonly cmdTxt = format.cmd('apimatic', 'plugin', 'generate');
static readonly examples = [
PluginGenerate.cmdTxt,
`${PluginGenerate.cmdTxt} ${format.flag('input', '"./"')} ${format.flag('destination', '"./plugin"')}`
];
static readonly flags = {
...FlagsProvider.input,
...FlagsProvider.destination('plugin', 'plugin'),
...FlagsProvider.force,
...FlagsProvider.authKey
};
async run(): Promise<void> {
const {
flags: { input, destination, force, 'auth-key': authKey }
} = await this.parse(PluginGenerate);
const project = ProjectContext.at(input);
const commandMetadata: CommandMetadata = {
commandName: PluginGenerate.id,
shell: this.config.shell
};
intro('Generate Context Plugin');
const action = new PluginGenerateAction(this.getConfigDir(), commandMetadata, authKey);
const result = await action.execute(project, project.pluginDirectory(destination), force);
outro(result);
}
private readonly getConfigDir = () => {
return new DirectoryPath(this.config.configDir);
};
}