-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cli): run cdk from inner directories #5772
Conversation
d000945
to
aee3033
Compare
aee3033
to
aaa3b30
Compare
packages/aws-cdk/bin/cdk.ts
Outdated
async function lookupProjectRoot(): Promise<string | undefined> { | ||
|
||
async function ascend(directoryParts: string[]): Promise<string | undefined> { | ||
|
||
if (directoryParts.length === 0) { | ||
return undefined; | ||
} | ||
|
||
const directory = directoryParts.join(path.sep); | ||
|
||
const filePath = path.join(directory, PROJECT_CONFIG); | ||
|
||
if (await fs.pathExists(filePath)) { | ||
return directory; | ||
} | ||
|
||
return ascend(directoryParts.slice(0, -1)); | ||
|
||
} | ||
|
||
return ascend(path.resolve(process.cwd()).split(path.sep)); | ||
|
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I'd just use path.dirname
instead of parsing the path:
async function ascend(dir: string) {
if (dir === path.sep) { return undefined; }
// ...
return ascend(path.dirname(dir));
}
yarn.lock
Outdated
@@ -1454,20 +1454,13 @@ | |||
resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-13.1.0.tgz#c563aa192f39350a1d18da36c5a8da382bbd8228" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert yarn.lock
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
@eladb Have another look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
|
||
function cleanup() { | ||
popd | ||
set -e | ||
} | ||
|
||
trap cleanup EXIT INT | ||
|
||
pushd .. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the cleanup pushd/popd is needed. This script is being executed as a child process.
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
pushd .. | ||
set +e | ||
output="$(cdk diff ${STACK_NAME_PREFIX}-test-1 2>&1)" | ||
set -e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to a temp directory instead. you don't know what's going on in ".."
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request is now being automatically merged. |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request is now being automatically merged. |
Added ability to run
cdk
commands from inner directories (inside the project root wherecdk.json
is located).The
cdk.js
will now lookup the project directory by traversing to parent directories until it findscdk.json
.Closes #5691
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license