forked from purecloudlabs/platform-client-sdk-common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdkBuilder.js
75 lines (59 loc) · 2.32 KB
/
sdkBuilder.js
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
const program = require('commander');
const path = require('path');
const fs = require('fs');
const swaggerDiff = require('./modules/swaggerDiff');
const Builder = require('./modules/builder');
const sdkLanguageRegex = /^(purecloudjava|purecloudjava-guest|purecloudjavascript|purecloudjavascript-guest|pureclouddotnet|pureclouddotnet-guest|purecloudpython|purecloudios|purecloudswift4|purecloudgo|purecloudkotlin|clisdkclient|webmessagingjava)$/i;
try {
// Parse language regex for hoomans
var 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!');
var configPath = path.resolve(path.join('./resources/sdk', program.sdk.toLowerCase()));
var config = program.config ? program.config : jsonOrYaml(path.join(configPath, 'config'));
var 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) {
abort(err);
}
function abort(err) {
console.log(err);
console.log('Exiting SDK Builder with exit code 1');
process.exitCode = 1;
}
function build(config, localconfig) {
var builder = new Builder(config, localconfig);
builder.fullBuild()
.then(() => console.log('SDK Builder script complete'))
.catch((err) => abort(err));
}
function jsonOrYaml(filePath) {
var jsonConfig = `${filePath}.json`;
var yamlConfig = `${filePath}.yml`;
if (fs.existsSync(jsonConfig)) {
console.log(`Found config file ${jsonConfig}`);
return jsonConfig;
}
if (fs.existsSync(yamlConfig)) {
console.log(`Found config file ${yamlConfig}`);
return yamlConfig;
}
console.log(`Unable to find config file: ${filePath}`);
return;
}