This repository has been archived by the owner on Jan 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgenerate-odata-client.ts
73 lines (64 loc) · 3.36 KB
/
generate-odata-client.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
/*!
* Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved.
*/
import { Command } from '@oclif/command';
import cli from 'cli-ux';
import * as execa from 'execa';
import { generatorOptionsSDK } from '../utils';
import { BoolArgType, generatorOptionCli, StringArgType, toBooleanFlag, toStringFlag } from '../utils/generate-odata-client-util';
export default class GenerateODataClient extends Command {
static description =
'Generates a OData client from a edmx service file definition. For SAP solutions, you can find these definitions at https://api.sap.com/.';
static examples = [
'$ sap-cloud-sdk generate-odata-client -i directoryWithEdmxFiles -o outputDirectory --forceOverwrite',
'$ sap-cloud-sdk generate-odata-client --help'
];
static flags: BoolArgType & StringArgType = {
// Options which are 1:1 to the SDK CLI
inputDir: toStringFlag(generatorOptionsSDK.inputDir),
outputDir: toStringFlag(generatorOptionsSDK.outputDir),
generateCSN: toBooleanFlag(generatorOptionsSDK.generateCSN),
generateJs: toBooleanFlag(generatorOptionsSDK.generateJs),
generatePackageJson: toBooleanFlag(generatorOptionsSDK.generatePackageJson),
generateTypedocJson: toBooleanFlag(generatorOptionsSDK.generateTypedocJson),
generateNpmrc: toBooleanFlag(generatorOptionsSDK.generateNpmrc),
useSwagger: toBooleanFlag(generatorOptionsSDK.useSwagger),
serviceMapping: toStringFlag(generatorOptionsSDK.serviceMapping!),
writeReadme: toBooleanFlag(generatorOptionsSDK.writeReadme),
additionalFiles: toStringFlag(generatorOptionsSDK.additionalFiles!),
clearOutputDir: toBooleanFlag(generatorOptionsSDK.clearOutputDir),
aggregatorDirectoryName: toStringFlag(generatorOptionsSDK.aggregatorDirectoryName!),
aggregatorNpmPackageName: toStringFlag(generatorOptionsSDK.aggregatorNpmPackageName!),
sdkAfterVersionScript: toBooleanFlag(generatorOptionsSDK.sdkAfterVersionScript),
s4hanaCloud: toBooleanFlag(generatorOptionsSDK.s4hanaCloud),
forceOverwrite: toBooleanFlag(generatorOptionsSDK.forceOverwrite),
// Options related to the CLI some of them are mapped to SDK CLI attributes
projectDir: toStringFlag(generatorOptionCli.projectDir)
};
async run() {
const { flags } = this.parse(GenerateODataClient);
const yargsFlags = Object.entries(flags)
.filter(([key, value]) => typeof value !== 'undefined' && generatorOptionsSDK.hasOwnProperty(key))
.map(([key, value]) => `--${key}=${value}`);
try {
await execa('npm', ['ls', '-g', '@sap-cloud-sdk/generator']);
} catch ({ exitCode }) {
if (exitCode === 1) {
this.log('');
this.log('To generate an OData client, it is necessary to install the @sap-cloud-sdk/generator.');
this.log('For now, the CLI expects the generator to be installed globally.');
this.log('');
if (await cli.confirm('Do you want to install the @sap-cloud-sdk/generator globally? (y|n)')) {
await execa('npm', ['install', '--global', '--force', '@sap-cloud-sdk/generator']);
} else {
this.error('It is required to have the @sap-cloud-sdk/generator installed globally. Please install and rerun.', { exit: 1 });
}
}
}
const promise = execa('generate-odata-client', yargsFlags, {
cwd: flags.projectDir || '.'
});
promise.stdout?.pipe(process.stdout);
return promise;
}
}