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

Add the VDM generator to the CLI #18

Merged
merged 32 commits into from
Dec 19, 2019
Merged

Add the VDM generator to the CLI #18

merged 32 commits into from
Dec 19, 2019

Conversation

FrankEssenberger
Copy link
Contributor

@FrankEssenberger FrankEssenberger commented Nov 15, 2019

Proposed Changes

Add the vdm generator to the CLI.

@florian-richter I am very unhappy with the forwarding of the arguments from the CLI to the SDK generator. I would like to make this generic in a sense that a change from the SDK generator is automatically reflected in the CLI. Do you have an idea to acheive this? Because I want to see the value help in the CLI.

The best idea I had was to export the options from the SDK some generic format and write an adpater which casts this list to yargs options for the SDK use and oclif options for use within the CLI. This would minimize the double effort, but still there is the question how we add the generator.

  1. I install the generator if it is needed with a prompt.
  2. Or Should one add the generator as a depenency to the CLI? This would add a non public npm dependency to the project. Let's discuss on monday.

Type of Changes

  • Bug Fix
  • New Feature
  • Documentation Update

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation

Breaking Changes

In general avoid breaking changes, but if you think it is necessary give your reasoning in the Further Comments section.

  • I have not introduced breaking changes

src/commands/init.ts Outdated Show resolved Hide resolved

export default class GenerateVdm extends Command {
static description =
'Generates a virtual data model (VDM) from a edmx service file definition. For SAP solution you can find these definitions on https://api.sap.com/';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the correct usage of VDM? I thought only the pre-generated one is a "VDM" and self-generated ones are OData clients. @marikaner could you clarify?

Suggested change
'Generates a virtual data model (VDM) from a edmx service file definition. For SAP solution you can find these definitions on https://api.sap.com/';
'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/.';

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just use "OData client code" or "OData API client". I'm not sure whether we have an official stance on what is and isn't VDM.

.npmrc Outdated Show resolved Hide resolved
src/utils/generate-vdm-util.ts Outdated Show resolved Hide resolved
src/utils/generate-vdm-util.ts Outdated Show resolved Hide resolved
test/generate-vdm.spec.ts Outdated Show resolved Hide resolved
test/generate-vdm.spec.ts Outdated Show resolved Hide resolved
test/generate-vdm.spec.ts Outdated Show resolved Hide resolved
test/generate-vdm.spec.ts Show resolved Hide resolved
test/resources/template-generator-vdm/.npmrc Outdated Show resolved Hide resolved
@florian-richter
Copy link
Contributor

@FrankEssenberger I have removed the EDMX file you added for the tests from the git history. EDMX files should not be pushed in open source repositories (due to license reasons). Please make sure to pull the repository and verify the file is gone before pushing again!

package.json Outdated Show resolved Hide resolved
test/resources/template-generator-vdm/package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/utils/generate-vdm-util.ts Outdated Show resolved Hide resolved
src/utils/generate-vdm-util.ts Outdated Show resolved Hide resolved
src/utils/generate-vdm-util.ts Outdated Show resolved Hide resolved
src/utils/generate-vdm-util.ts Outdated Show resolved Hide resolved
test/generate-vdm.spec.ts Outdated Show resolved Hide resolved
test/generate-vdm.spec.ts Outdated Show resolved Hide resolved
test/generate-vdm.spec.ts Outdated Show resolved Hide resolved
test/generate-vdm.spec.ts Outdated Show resolved Hide resolved
test/generate-vdm.spec.ts Outdated Show resolved Hide resolved
@FrankEssenberger FrankEssenberger marked this pull request as ready for review December 16, 2019 15:40
src/commands/generate-vdm.ts Outdated Show resolved Hide resolved
src/commands/generate-vdm.ts Outdated Show resolved Hide resolved
src/commands/generate-vdm.ts Outdated Show resolved Hide resolved
src/utils/generate-vdm-util.ts Outdated Show resolved Hide resolved
src/utils/generate-vdm-util.ts Outdated Show resolved Hide resolved
src/commands/generate-vdm.ts Outdated Show resolved Hide resolved
src/utils/generate-vdm-util.ts Outdated Show resolved Hide resolved
test/generate-vdm.spec.ts Outdated Show resolved Hide resolved
test/generate-vdm.spec.ts Outdated Show resolved Hide resolved
@florian-richter
Copy link
Contributor

It might be good to add a short paragraph in the README.md that explains that the sdk generator is wrapped here and how it is used (happy path).

You could also consider to link to the generator tutorial? this might be better to be postponed until later once the tutorial is updated

import { flags } from '@oclif/command';
import { AlphabetLowercase, AlphabetUppercase } from '@oclif/parser/lib/alphabet';
import { IBooleanFlag, IOptionFlag } from '@oclif/parser/lib/flags';
import { GeneratorOptions, GeneratorOptions as GeneratorOptionsSDK, generatorOptionsCli as generatorOptionsSDK } from '@sap/cloud-sdk-generator';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is something going wrong here

*/

const warn = jest.fn(message => console.log('MOCKED WARNING: ', message));
jest.mock('@oclif/command', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also remove this warn part as this mock is not needed for the generator as far as I can tell.

Copy link
Contributor

@florian-richter florian-richter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more minor suggestions, but I think this is pretty much good to go 😊

break;
}
return collected;
}, []);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the .reduce 👍 but it could be even more improved:

    return Object.entries(allFalse).reduce((collected: string[], [key, value]) => {
      switch (typeof allFalse[key as keyof generateVdmUtil.FlagsParsed]) {
        case 'string':
          return [...collected, `--${key}`, value!.toString()];
        case 'boolean':
          return generatorOptionsSDK[key as keyof GeneratorOptionsSDK]?.default ? [...collected, `--no-${key}`] : collected;
      }
    }, []);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't played around with it, but if possible I would try to avoid as keyof generateVdmUtil.FlagsParsed and as keyof GeneratorOptionsSDK. Casts don't really typecheck in most cases, so if the compiler doesnt complain without them, I would leave them out.

}
return collected;
}, []);
return [...stringArguments];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't just return the result of the reduce above (see comment above), you can just straight return it here. The copying is unnecessary.

Suggested change
return [...stringArguments];
return stringArguments;

inputDir: path.resolve(projectDir, 'input'),
outputDir: path.resolve(projectDir, 'output'),
serviceMapping: path.resolve(projectDir, 'input', 'service-mapping.json')
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small improvement (avoids an if 😉 )

    return {
      ...(Object.keys(generatorOptionsSDK).reduce((prev, current) => {
        const value = generatorOptionsSDK[current as keyof GeneratorOptionsSDK];
        return value ? { ...prev, [current]: value.default } : prev;
      }, {} as any)),
      inputDir: path.resolve(projectDir, 'input'),
      outputDir: path.resolve(projectDir, 'output'),
      serviceMapping: path.resolve(projectDir, 'input', 'service-mapping.json')
    };

@FrankEssenberger FrankEssenberger merged commit a89ea0f into master Dec 19, 2019
@FrankEssenberger FrankEssenberger deleted the generateVDM branch December 19, 2019 15:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants