Skip to content

Commit afdd173

Browse files
authored
fix(toolkit): ignore hidden files for 'cdk init' (#1766)
Don't block 'cdk init' on the presence of files start with '.'. In particular, don't care about the presence of a '.git' directory. Fixes #1758.
1 parent c87f09a commit afdd173

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/aws-cdk/lib/init.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ async function initializeProject(template: InitTemplate, language: string, canUs
208208

209209
async function assertIsEmptyDirectory() {
210210
const files = await fs.readdir(process.cwd());
211-
if (files.length !== 0) {
211+
if (files.filter(f => !f.startsWith('.')).length !== 0) {
212212
throw new Error('`cdk init` cannot be run in a non-empty directory!');
213213
}
214214
}

packages/aws-cdk/test/test.init.ts

+12
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ export = {
4545
test.equal(true, await fs.pathExists('package.json'));
4646
test.equal(true, await fs.pathExists('bin'));
4747

48+
test.done();
49+
},
50+
51+
async 'git directory does not throw off the initer!'(test: Test) {
52+
fs.mkdirSync('.git');
53+
54+
await cliInit('app', 'typescript', false);
55+
56+
// Check that package.json and bin/ got created in the current directory
57+
test.equal(true, await fs.pathExists('package.json'));
58+
test.equal(true, await fs.pathExists('bin'));
59+
4860
test.done();
4961
}
5062
};

0 commit comments

Comments
 (0)