-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathgenerate.ts
More file actions
63 lines (54 loc) · 2.19 KB
/
generate.ts
File metadata and controls
63 lines (54 loc) · 2.19 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { Command, Flags } from "@oclif/core";
import { DirectoryPath } from "../../types/file/directoryPath.js";
import { FlagsProvider } from "../../types/flags-provider.js";
import { SdkGeneratePrompts } from "../../prompts/sdk/generate.js";
import { GenerateAction } from "../../actions/sdk/generate.js";
import { Language } from "../../types/sdk/generate.js";
const DEFAULT_WORKING_DIRECTORY = "./";
export default class SdkGenerate extends Command {
static description = "Generate an SDK for your API";
static flags = {
language: Flags.string({
char: 'l',
required: true,
options: Object.values(Language).map((p) => p.toString()),
description: `language for which the sdk will be generated.`
}),
spec: Flags.string({
description: "path to the folder containing the API specification file.",
default: "./src/spec"
}),
destination: Flags.string({
char: "d",
description: `[default: ./sdk/<language>] path where the sdk will be generated.`
}),
...FlagsProvider.force,
zip: Flags.boolean({
default: false,
description: "download the generated SDK as a .zip archive."
}),
...FlagsProvider.authKey
};
static examples = [
`apimatic sdk:generate --language=java`,
`apimatic sdk:generate --language=csharp --spec="./src/spec"`
];
private readonly prompts: SdkGeneratePrompts = new SdkGeneratePrompts();
async run() {
const {
flags: { language, spec, destination, force, zip: zipSdk, "auth-key": authKey }
} = await this.parse(SdkGenerate);
const workingDirectory = new DirectoryPath(DEFAULT_WORKING_DIRECTORY);
const specDirectory = new DirectoryPath(spec);
const sdkDirectory = destination ? new DirectoryPath(destination) : workingDirectory.join("sdk").join(language);
var action = new GenerateAction(this.getConfigDir(), authKey);
const result = await action.execute(specDirectory, sdkDirectory, language as Language, SdkGenerate.id, force, zipSdk);
result.mapAll(
() => this.prompts.displayOutroMessage(sdkDirectory),
(message) => this.prompts.logError(message)
);
}
private getConfigDir = () => {
return new DirectoryPath(this.config.configDir);
};
}