Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions packages/aws-cdk/lib/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,10 @@ export async function printAvailableTemplates(language?: string) {

async function initializeProject(template: InitTemplate, language: string) {
await assertIsEmptyDirectory();
const useGit = await initializeGitRepository();
print(`Applying project template ${colors.green(template.name)} for ${colors.blue(language)}`);
await template.install(language, process.cwd());
await initializeGitRepository();
await postInstall(language);
if (useGit) {
await execute('git', 'add', '.');
await execute('git', 'commit', '--message="Initial commit"', '--no-gpg-sign');
}
if (await fs.pathExists('README.md')) {
print(colors.green(await fs.readFile('README.md', { encoding: 'utf-8' })));
} else {
Expand All @@ -187,8 +183,15 @@ async function assertIsEmptyDirectory() {
async function initializeGitRepository() {
if (await isInGitRepository(process.cwd())) { return false; }
print('Initializing a new git repository...');
await execute('git', 'init');
return true;
try {
await execute('git', 'init');
await execute('git', 'add', '.');
await execute('git', 'commit', '--message="Initial commit"', '--no-gpg-sign');
return true;
} catch (e) {
error('Error initializing git repository; you will have to do this by hand.');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning (it doesn't mean cdk-init failed). I would also relax the wording: Unable to initialize a git repository for your project: ${reason})

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reason (from git) has already been printed to stderr. Nothing to print here, really.

return false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

return true

}
}

async function postInstall(language: string) {
Expand Down