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

Add CDS sources using the CLI #32

Merged
merged 21 commits into from
Dec 23, 2019
Merged

Add CDS sources using the CLI #32

merged 21 commits into from
Dec 23, 2019

Conversation

marikaner
Copy link
Contributor

@marikaner marikaner commented Dec 18, 2019

Proposed Changes

Adds a command and init flag to enable the creation of a CAP compatible project.
Calling sap-cloud-sdk init --addCds in an empty directory will create a nest app with an additional module that exposes the CDS example catalogue service, as well as a .cdsrc and thedb and srv directories. I also adds dependencies and scripts to the package.json and changes the .gitignore. The same command called within an exiting project will create the same resources except for the additional example nest module (as we don't know whether nest is used). sap-cloud-sdk add-cds again does the same but without the standard init parts.

Limitations: This does not consider deploying on CF. We have to clarify with the CAP colleagues what the best practice is here.

Checklist

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

Further Comments

If the changes are complex, please discuss what alternatives you have evaluated and why you picked this particular solution. Please make sure to highlight any trade-offs that we should know about.

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.

There are 15 comments so github likely hides the middle ones. Please make sure to look at those too 😊

}),
force: flags.boolean({
description: 'Do not fail if a file already exist and overwrite it.'
}),
help: flags.help({ char: 'h' })
};

static args = [
{
name: 'projectDir',
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is necessary. In init I added this as you may create a new directory. Here you need to have a dir already otherwise it doesn't make sense. That's why the --projectDir is currently hidden (mainly there for tests and to quickly enable it if we find out it's needed).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But is it an issue? I would argue either we have it or we don't. So either remove the flag or keep both for consistency (and make it non-hidden, I guess). What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

My assumption was that a simpler (public) API makes it easier to understand the docs. So omitting a flag/arg that is not useful for 99% of users (and can be simply worked around by cd projectDir) would be a positive change.

But I have not validated that assumption, so feel free to change my mind on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have removed all the --projectDir flags as discussed, but I decided to leave the argument, because I think it makes our commands consistent. I don't think projectDir makes the API hard to understand, it is still very simple, while the change is tiny.

Copy link
Contributor

Choose a reason for hiding this comment

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

To throw my 2cts in, I also have no idea whether we need it or not. So the question is how do find that out in the future? Otherwise we'll have the same discussion on the next PR.

src/commands/add-cds.ts Show resolved Hide resolved
src/commands/add-approuter.ts Outdated Show resolved Hide resolved
src/commands/init.ts Outdated Show resolved Hide resolved
// // Reduce stock of books upon incoming orders
// srv.before ('CREATE', 'Orders', async (req) => {
// const tx = cds.transaction(req), order = req.data;
// if (order.Items) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Commented?

src/utils/package-json.ts Show resolved Hide resolved
src/utils/scaffold.ts Show resolved Hide resolved
test/add-approuter.spec.ts Outdated Show resolved Hide resolved
test/add-cx-server.spec.ts Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
@marikaner marikaner changed the title Cap cli Add CDS sources using the CLI Dec 20, 2019
src/commands/init.ts Show resolved Hide resolved
this.log('| |');
this.log('| 🚀 Next steps: |');
private printSuccessMessage(isScaffold: boolean, addCds: boolean) {
const message = ['✅ Init finished successfully.', '', '🚀 Next steps:'];
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the complexity of this function is tied to the combinatorial complexity of the input space (aka the more combinations of input you can have, the more complex it will be to determine what needs to be printed).
If there are things that exclude each other (e.g. scaffold vs no scaffold), that probably needs to be decided upfront. For everything else, maybe a more declarative approach can help, i.e. to simply collect all the message fragments for the input flags/args.

}),
force: flags.boolean({
description: 'Do not fail if a file already exist and overwrite it.'
}),
help: flags.help({ char: 'h' })
};

static args = [
{
name: 'projectDir',
Copy link
Contributor

Choose a reason for hiding this comment

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

To throw my 2cts in, I also have no idea whether we need it or not. So the question is how do find that out in the future? Otherwise we'll have the same discussion on the next PR.

src/utils/package-json.ts Show resolved Hide resolved
src/utils/scaffold.ts Show resolved Hide resolved
test/test-utils.ts Show resolved Hide resolved
test/test-utils.ts Outdated Show resolved Hide resolved
test/utils/scaffold.spec.ts Show resolved Hide resolved
test/utils/templates.spec.ts Show resolved Hide resolved
src/utils/git-ignore.ts Outdated Show resolved Hide resolved
@marikaner marikaner marked this pull request as ready for review December 20, 2019 14:35
@marikaner marikaner dismissed florian-richter’s stale review December 20, 2019 14:35

Implemented all changes

@marikaner marikaner merged commit 9c9bcdf into master Dec 23, 2019
@marikaner marikaner deleted the cap-cli branch December 23, 2019 09:43
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