-
Notifications
You must be signed in to change notification settings - Fork 38
/
sdkBuilder.ts
82 lines (66 loc) · 2.49 KB
/
sdkBuilder.ts
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import program from 'commander';
import path from 'path';
import { existsSync } from 'fs';
import { Builder } from './modules/builder/builder'
const sdkLanguageRegex = /^(purecloudjava|purecloudjava-guest|purecloudjavascript|purecloudjavascript-guest|pureclouddotnet|pureclouddotnet-guest|purecloudpython|purecloudios|purecloudswift4|purecloudgo|purecloudkotlin|clisdkclient|webmessagingjava)$/i;
export class SdkBuilder {
constructor() {
try {
// Parse language regex for hoomans
let sdkLanguages = sdkLanguageRegex.toString().substring(3,sdkLanguageRegex.toString().length - 4).replace(/\|/gi, ", ");
program
.version('1.0.0')
.option('--config <path>', 'Path to SDK config file')
.option('--localconfig <path>', 'Path to SDK local config file')
.option('--sdk [language]', `Generate the SDK for the given swager-codegen language using the default config. Languages: ${sdkLanguages}`, sdkLanguageRegex)
.parse(process.argv);
if (program.sdk) {
// Value is true when a value was specified but didn't match regex
if (program.sdk === true)
throw new Error('Invalid SDK language!');
let configPath = path.resolve(path.join('./resources/sdk', program.sdk.toLowerCase()));
let config = program.config ? program.config : jsonOrYaml(path.join(configPath, 'config'));
let localconfig = program.localconfig ? program.localconfig : jsonOrYaml(path.join(configPath, 'localconfig'));
console.log(`Invoking SDK build for language: ${program.sdk}`);
build(config, localconfig);
return;
}
if (program.config) {
build(program.config, program.localconfig);
return;
}
program.help();
} catch (err: unknown) {
if (err instanceof Error) {
abort(err);
}
}
}
}
function abort(err: Error) {
console.log(err);
console.log('Exiting SDK Builder with exit code 1');
process.exitCode = 1;
}
function build(configPath: string, localConfigPath: string) {
let b = new Builder();
b.init(configPath, localConfigPath).then(() =>
b.fullBuild())
.then(() => console.log('SDK Builder script complete'))
.catch((err) => abort(err));
}
function jsonOrYaml(filePath : string) {
let jsonConfig = `${filePath}.json`;
let yamlConfig = `${filePath}.yml`;
if (existsSync(jsonConfig)) {
console.log(`Found config file ${jsonConfig}`);
return jsonConfig;
}
if (existsSync(yamlConfig)) {
console.log(`Found config file ${yamlConfig}`);
return yamlConfig;
}
console.log(`Unable to find config file: ${filePath}`);
return;
}
new SdkBuilder();