-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathgenerator-cli.ts
executable file
·55 lines (49 loc) · 1.84 KB
/
generator-cli.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
#!/usr/bin/env node
import { resolve, dirname } from 'path';
import { createLogger } from '@sap-cloud-sdk/util';
import { readFileSync } from 'fs-extra';
import yargs from 'yargs';
import { generate } from './generator';
import { GeneratorOptions, generatorOptionsCli } from './generator-options';
const logger = createLogger({
package: 'generator',
messageContext: 'generator-cli'
});
logger.info('Parsing args...');
generate(parseCmdArgs()).then(() =>
logger.info('Generation of services finished successfully.')
);
export function parseCmdArgs(): GeneratorOptions {
const command = yargs.command(
'$0',
'OData Client Code Generator for OData v2 and v4. Generates TypeScript code from .edmx/.xml files for usage with the SAP Cloud SDK for JavaScript.'
);
for (const key in generatorOptionsCli) {
command.option(key, generatorOptionsCli[key]);
}
return (command
.config(
'config',
'Instead of specifying the options on the command line, you can also provide a path to single .json file holding these options. ' +
'The file must be a valid .json file where the keys correspond to the command line flags without dashes. Paths will be interpreted relative to the config file.',
configPath => {
const file = readFileSync(configPath, 'utf-8');
const pathLikeKeys = ['inputDir', 'outputDir', 'serviceMapping'];
return pathLikeKeys.reduce(
(json, pathLikeKey) =>
typeof json[pathLikeKey] === 'undefined'
? json
: {
...json,
[pathLikeKey]: resolve(dirname(configPath), json[pathLikeKey])
},
JSON.parse(file)
);
}
)
.alias('config', 'c')
.alias('version', 'v')
.alias('help', 'h')
.strict(true)
.recommendCommands().argv as unknown) as GeneratorOptions;
}