From 57bc6bf50eaaad3db54b663d8486a659a76afe7f Mon Sep 17 00:00:00 2001 From: Frank Essenberger <56544999+FrankEssenberger@users.noreply.github.com> Date: Wed, 8 Jan 2020 17:54:21 +0100 Subject: [PATCH] Rename generate-vdm command to generate-odata-client (#42) * rename command * try out remote build * refactor error * put lock file back in * revert yarn.lock changes. * add util test * Change all remaining instances of VDM to OData client * Fix import Co-authored-by: Florian Richter --- .gitignore | 2 +- README.md | 14 ++-- ...nerate-vdm.ts => generate-odata-client.ts} | 12 ++-- ...-util.ts => generate-odata-client-util.ts} | 0 src/utils/index.ts | 2 +- ....spec.ts => generate-odata-client.spec.ts} | 18 ++--- .../edmxSource/SocialNetworkAccount.edmx | 0 test/utils/generate-odata-client-util.spec.ts | 65 +++++++++++++++++++ 8 files changed, 89 insertions(+), 24 deletions(-) rename src/commands/{generate-vdm.ts => generate-odata-client.ts} (78%) rename src/utils/{generate-vdm-util.ts => generate-odata-client-util.ts} (100%) rename test/{generate-vdm.spec.ts => generate-odata-client.spec.ts} (88%) rename test/resources/{template-generator-vdm => template-generator-odata-client}/edmxSource/SocialNetworkAccount.edmx (100%) create mode 100644 test/utils/generate-odata-client-util.spec.ts diff --git a/.gitignore b/.gitignore index bf2478f9..a8c6845f 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,4 @@ node_modules test/**/*spec/* oclif.manifest.json *.edmx -!test/resources/template-generator-vdm/edmxSource/SocialNetworkAccount.edmx +!test/resources/template-generator-odata-client/edmxSource/SocialNetworkAccount.edmx diff --git a/README.md b/README.md index 9893f91f..6a635f6b 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ Start by running [`sap-cloud-sdk add-approuter`](#sap-cloud-sdk-add-approuter) a * [`sap-cloud-sdk add-cds [PROJECTDIR]`](#sap-cloud-sdk-add-cds-projectdir) * [`sap-cloud-sdk add-cx-server [PROJECTDIR]`](#sap-cloud-sdk-add-cx-server-projectdir) * [`sap-cloud-sdk autocomplete [SHELL]`](#sap-cloud-sdk-autocomplete-shell) -* [`sap-cloud-sdk generate-vdm`](#sap-cloud-sdk-generate-vdm) +* [`sap-cloud-sdk generate-odata-client`](#sap-cloud-sdk-generate-odata-client) * [`sap-cloud-sdk help [COMMAND]`](#sap-cloud-sdk-help-command) * [`sap-cloud-sdk help-page`](#sap-cloud-sdk-help-page) * [`sap-cloud-sdk init [PROJECTDIR]`](#sap-cloud-sdk-init-projectdir) @@ -170,13 +170,13 @@ EXAMPLES _See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v0.1.5/src/commands/autocomplete/index.ts)_ -## `sap-cloud-sdk generate-vdm` +## `sap-cloud-sdk generate-odata-client` -Generates a virtual data model (VDM) from a edmx service file definition. For SAP solutions, you can find these definitions at https://api.sap.com/. +Generates a OData client from a edmx service file definition. For SAP solutions, you can find these definitions at https://api.sap.com/. ``` USAGE - $ sap-cloud-sdk generate-vdm + $ sap-cloud-sdk generate-odata-client OPTIONS -i, --inputDir=inputDir (required) This directory will be recursively searched for @@ -248,11 +248,11 @@ OPTIONS false]. EXAMPLES - $ sap-cloud-sdk generate-vdm -i directoryWithEdmxFiles -o outputDirectory --forceOverwrite - $ sap-cloud-sdk generate-vdm --help + $ sap-cloud-sdk generate-odata-client -i directoryWithEdmxFiles -o outputDirectory --forceOverwrite + $ sap-cloud-sdk generate-odata-client --help ``` -_See code: [src/commands/generate-vdm.ts](https://github.com/SAP/cloud-sdk-cli/blob/v0.1.2/src/commands/generate-vdm.ts)_ +_See code: [src/commands/generate-odata-client.ts](https://github.com/SAP/cloud-sdk-cli/blob/v0.1.2/src/commands/generate-odata-client.ts)_ ## `sap-cloud-sdk help [COMMAND]` diff --git a/src/commands/generate-vdm.ts b/src/commands/generate-odata-client.ts similarity index 78% rename from src/commands/generate-vdm.ts rename to src/commands/generate-odata-client.ts index c872fc89..feccdecf 100644 --- a/src/commands/generate-vdm.ts +++ b/src/commands/generate-odata-client.ts @@ -4,15 +4,15 @@ import { Command } from '@oclif/command'; import { generate, generatorOptionsCli as generatorOptionsSDK } from '@sap/cloud-sdk-generator'; -import { BoolArgType, generatorOptionCli, StringArgType, toBooleanFlag, toGeneratorSDK, toStringFlag } from '../utils/generate-vdm-util'; +import { BoolArgType, generatorOptionCli, StringArgType, toBooleanFlag, toGeneratorSDK, toStringFlag } from '../utils/generate-odata-client-util'; -export default class GenerateVdm extends Command { +export default class GenerateODataClient extends Command { static description = - 'Generates a virtual data model (VDM) from a edmx service file definition. For SAP solutions, you can find these definitions at https://api.sap.com/.'; + '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-vdm -i directoryWithEdmxFiles -o outputDirectory --forceOverwrite', - '$ sap-cloud-sdk generate-vdm --help' + '$ sap-cloud-sdk generate-odata-client -i directoryWithEdmxFiles -o outputDirectory --forceOverwrite', + '$ sap-cloud-sdk generate-odata-client --help' ]; static flags: BoolArgType & StringArgType = { @@ -39,7 +39,7 @@ export default class GenerateVdm extends Command { }; async run() { - const { flags } = this.parse(GenerateVdm); + const { flags } = this.parse(GenerateODataClient); await generate(toGeneratorSDK(flags)); } diff --git a/src/utils/generate-vdm-util.ts b/src/utils/generate-odata-client-util.ts similarity index 100% rename from src/utils/generate-vdm-util.ts rename to src/utils/generate-odata-client-util.ts diff --git a/src/utils/index.ts b/src/utils/index.ts index 8b5eb0bf..e1c04ce4 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -3,7 +3,7 @@ */ export * from './copy-list'; -export * from './generate-vdm-util'; +export * from './generate-odata-client-util'; export * from './git-ignore'; export * from './jest-config'; export * from './manifest-yaml'; diff --git a/test/generate-vdm.spec.ts b/test/generate-odata-client.spec.ts similarity index 88% rename from test/generate-vdm.spec.ts rename to test/generate-odata-client.spec.ts index b3fb107b..2b3f81f1 100644 --- a/test/generate-vdm.spec.ts +++ b/test/generate-odata-client.spec.ts @@ -4,16 +4,16 @@ import { GeneratorOptions as GeneratorOptionsSDK, generatorOptionsCli as generatorOptionsSDK } from '@sap/cloud-sdk-generator'; import * as fs from 'fs-extra'; import * as path from 'path'; -import GenerateVdm from '../src/commands/generate-vdm'; -import * as generateVdmUtil from '../src/utils/generate-vdm-util'; +import GenerateODataClient from '../src/commands/generate-odata-client'; +import * as generateVdmUtil from '../src/utils/generate-odata-client-util'; const spyToGeneratorSDK = jest.spyOn(generateVdmUtil, 'toGeneratorSDK'); -describe('generate-vdm', () => { +describe('generate-odata-client', () => { const pathForTests = path.resolve(__dirname, __filename.replace(/\./g, '-')).replace('-ts', ''); beforeAll(() => { - const pathForResources = path.resolve(__dirname, 'resources', 'template-generator-vdm'); + const pathForResources = path.resolve(__dirname, 'resources', 'template-generator-odata-client'); fs.copySync(pathForResources, pathForTests); }); @@ -23,7 +23,7 @@ describe('generate-vdm', () => { it('should fail if the mandatory parameters are not there', async () => { try { - await GenerateVdm.run([]); + await GenerateODataClient.run([]); } catch (e) { expect(e.message).toContain('-i, --inputDir INPUTDIR'); } @@ -33,7 +33,7 @@ describe('generate-vdm', () => { const expected = getParsedInputWithAllBooleanFlagsFalse(); delete expected.projectDir; try { - await GenerateVdm.run([...getCliInputWithAllBooleanFlagsFalse(), '--projectDir', getProjectDir()]); + await GenerateODataClient.run([...getCliInputWithAllBooleanFlagsFalse(), '--projectDir', getProjectDir()]); } catch (e) { expect(e.message).toContain('ENOENT: no such file or directory'); expect(spyToGeneratorSDK).toHaveReturnedWith(expected); @@ -46,7 +46,7 @@ describe('generate-vdm', () => { const expected = getDefault(getProjectDir()); try { - await GenerateVdm.run(['-i', 'input', '-o', 'output', '--projectDir', getProjectDir()]); + await GenerateODataClient.run(['-i', 'input', '-o', 'output', '--projectDir', getProjectDir()]); } catch (e) { expect(e.message).toContain('ENOENT: no such file or directory'); expect(spyToGeneratorSDK).toHaveReturnedWith(expected); @@ -55,7 +55,7 @@ describe('generate-vdm', () => { }); function getProjectDir() { - return path.resolve(__dirname, 'generate-vdm-spec'); + return path.resolve(__dirname, 'generate-odata-client-spec'); } function getInputAndExpected(key: keyof GeneratorOptionsSDK): { expected: GeneratorOptionsSDK; args: string[] } | undefined { @@ -78,7 +78,7 @@ describe('generate-vdm', () => { const argsExpected = getInputAndExpected(key as keyof GeneratorOptionsSDK); if (argsExpected) { try { - await GenerateVdm.run(argsExpected.args); + await GenerateODataClient.run(argsExpected.args); } catch (e) { expect(e.message).toContain('ENOENT: no such file or directory'); expect(spyToGeneratorSDK).toHaveReturnedWith(argsExpected.expected); diff --git a/test/resources/template-generator-vdm/edmxSource/SocialNetworkAccount.edmx b/test/resources/template-generator-odata-client/edmxSource/SocialNetworkAccount.edmx similarity index 100% rename from test/resources/template-generator-vdm/edmxSource/SocialNetworkAccount.edmx rename to test/resources/template-generator-odata-client/edmxSource/SocialNetworkAccount.edmx diff --git a/test/utils/generate-odata-client-util.spec.ts b/test/utils/generate-odata-client-util.spec.ts new file mode 100644 index 00000000..1491c108 --- /dev/null +++ b/test/utils/generate-odata-client-util.spec.ts @@ -0,0 +1,65 @@ +/*! + * Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. + */ + +import { Options } from 'yargs'; +import { toBooleanFlag, toStringFlag } from '../../src/utils/generate-odata-client-util'; + +describe('Generate OData Client Utils', () => { + describe('Boolean option transformation from yarn to oclif.', () => { + it('should translate the description correctly', () => { + let yargsOption: Options = { describe: 'expectedDescription', default: false }; + expect(toBooleanFlag(yargsOption).description).toBe('expectedDescription [default: false].'); + + yargsOption = { describe: 'expectedDescription', default: true }; + expect(toBooleanFlag(yargsOption).description).toBe('expectedDescription [default: true].'); + }); + + it('should translate the alias correctly.', () => { + const yargsOption: Options = { alias: 'expectedAlias' }; + expect(toBooleanFlag(yargsOption).char).toBe(yargsOption.alias); + }); + + it('should translate the required option correctly.', () => { + let yargsOption: Options = { requiresArg: false }; + expect(toBooleanFlag(yargsOption).required).toBe(yargsOption.requiresArg); + + yargsOption = { requiresArg: true }; + expect(toBooleanFlag(yargsOption).required).toBe(yargsOption.requiresArg); + }); + + it('should translate the default and allowNo option correctly.', () => { + let yargsOption: Options = { default: false }; + expect(toBooleanFlag(yargsOption).default).toBe(yargsOption.default); + expect(toBooleanFlag(yargsOption).allowNo).toBe(yargsOption.default); + + yargsOption = { default: true }; + expect(toBooleanFlag(yargsOption).default).toBe(yargsOption.default); + expect(toBooleanFlag(yargsOption).allowNo).toBe(yargsOption.default); + }); + }); + + describe('String option transformation from yarn to oclif.', () => { + it('should translate all string arguments correctly.', () => { + const yargsOption: Options = { alias: 'expectedAlias', description: 'expectedDescription' }; + expect(toStringFlag(yargsOption).char).toBe(yargsOption.alias); + expect(toStringFlag(yargsOption).description).toBe(yargsOption.describe); + }); + + it('should translate the default option correctly.', () => { + let yargsOption: Options = { default: false }; + expect(toBooleanFlag(yargsOption).default).toBe(yargsOption.default); + + yargsOption = { default: true }; + expect(toBooleanFlag(yargsOption).default).toBe(yargsOption.default); + }); + + it('should translate the required option correctly.', () => { + let yargsOption: Options = { requiresArg: false }; + expect(toBooleanFlag(yargsOption).required).toBe(yargsOption.requiresArg); + + yargsOption = { requiresArg: true }; + expect(toBooleanFlag(yargsOption).required).toBe(yargsOption.requiresArg); + }); + }); +});