Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
Rename generate-vdm command to generate-odata-client (#42)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
FrankEssenberger and Florian Richter committed Jan 8, 2020
1 parent cdc2707 commit 57bc6bf
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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));
}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
18 changes: 9 additions & 9 deletions test/generate-vdm.spec.ts → test/generate-odata-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand All @@ -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');
}
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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 {
Expand All @@ -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);
Expand Down
65 changes: 65 additions & 0 deletions test/utils/generate-odata-client-util.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
});

0 comments on commit 57bc6bf

Please sign in to comment.