aws-cdk
aws-cdk copied to clipboard
[CLI] support adding cdk project to existing .net solution
From StackOverflow question, add support to add a CDK project to an existing solution.
Currently, cdk init
will fail if run in a directory that already contains a solution (or any files):
❯ cdk init app --language=csharp
`cdk init` cannot be run in a non-empty directory!
Use Case
Add cdk project to an existing solution.
Proposed Solution
Remove check that current directory is empty. Probably add a check that files won't be overwrittne.
Other
- [x] :wave: I may be able to implement this feature request
- [ ] :warning: This feature might incur a breaking change
This is a :rocket: Feature Request
would using something like a --force
flag to allow adding to an existing directory be a more straightforward way to enable this use case?
I think this could cause surprising behavior. Failures might dirty up an existing directory if they simply check that a file will not be overwritten. It feels like allowing this by default could result in unintended errors.
--force
implies I'm trying to get the tool to do something unsafe or something it doesn't really want to do. I feel it's a little un-intuitive to expect a new user to realize that cdk init
can only run on an empty directory.
Perhaps --allow-non-empty
. Seems less scary and makes it feel more like a valid use case.
Would also help prevent conflicting with a future scenario where we may need force
to mean overriding a different safety check?
@ppittle that's a good point. force
is a little overloaded
I like the idea of --allow-non-empty
. perhaps we could also make it a key we support in user/project settings (~/.cdk.json
or cdk.json
) so users would not have to keep specifying it every time.
Would be a great feature to have. It's adding only a few specific directories, so I'm unsure why we've needed it to be done only on empty folders.
I agree it would be nice to have it. Consider the following use case:
- I use VS Code as an IDE, so prior to doing
cdk init
I typically create a folder and convert it to a workspace - so there is already aworkspace.code-workspace
file - Then I typically assemble my commands and env vars in the
Makefile
so that I can be extra confident what AWS Profile and Account ID I am using (super critical for CDK as well, isn't it?) - hence at leastMakefile
there as well.
It's a perfectly valid folder with two non-related to CDK files, yet CDK would complain about the folder not being empty. I think it is over the top precaution. In my opinion, a simple warning with Y/N
prompt to override files would be sufficient.
For my use case I have a prepared VSCode DevContainer project initialized. This will give all developers starting a new CDK project the same environment setup that is free of OS and what is previously installed. It will pre-install CDK and AWS tools and plugins in VSCode.
But as OSX & Windows handles the node_modules folder I have in my devcontainer mounted the node_module "named volume" Resulting that in that folder also the "node_modules" folder will be shown.
When I then want from inside the terminal of the devcontainer want to initialize a new project, that uses the cdk version supplied by the devcontainer it failed to initialize because it is not an empty folder.
In this situation I would really love a feature to allow cdk init
to initialize the project on a folder that is not empty.
Another motivation: I often want to only use the specific CDK version I npm install
into the current project, so that each project we configure can have its own local CDK version, and there's not a global shared CDK version. This means each CDK project can had its CDK version updated independently, and changes to the global CDK version don't interfere with every project. But installing aws-cdk
into a Node project makes its directory non-empty, which means you can't initialize a CDK project there.
Steps to reproduce:
mkdir app
cd app
npm i aws-cdk
npm run -- cdk init app --language typescript
Here's another use case. I want to switch a project from Serverless Framework to CDK. I created a directory inside the project directory, <PROJECT>/tmp/my-cdk-project
and ran cdk init
, which promptly informed me that it could not be run inside of a non empty directory.
I want the ability to override these safeguards when it suits me. I'm a big boy; I can face the consequences if I screw something up.
Any update on this? Still highly wanted!
Would love to see this happen!! Hopefully it'll gain some traction.
:+1: to this.
I really dislike having to install CDK globally to initialize a project and then installing it locally to that project so that different projects can have different CDK versions, it drives me insane every time I have to create a new one.
I wonder if --allow-non-empty feature is added or ?
You can do this with projen, which I generally recommend using for new project scaffolding over cdk init
. We do, however, have a coverage gap there as you can only create CDK apps in java, python, and typescript, so that doesn't fully answer for the issue at hand here.
@TheRealAmazonKendra agree projen's lack of support for the .NET ecosystem means it doesn't solve this issue 😄
A work around until this feature is provided. For a small project with just a few files and has a Git repo initialized...
CAUTION with rm usage!!
rm -rf ./*
cdk init --language typescript
or
npx aws-cdk init --language typescript
git restore . (restore the files your "deleted")
git add . (add all the CDK files to our git working copy)
git commit -m "Project initialized with CDK"