Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion packages/aws-cdk/lib/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
fromPath: args['from-path'],
templatePath: args['template-path'],
packageManager: args['package-manager'],
projectName: args.name,
projectName: args.projectName,
});
}
case 'migrate':
Expand Down
15 changes: 15 additions & 0 deletions packages/aws-cdk/test/cli/cli-arguments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@ describe('yargs', () => {
globalOptions: expect.anything(),
});
});

test('init --project-name is correctly passed through', async () => {
Comment thread
sai-ray marked this conversation as resolved.
const input = await parseCommandLineArguments(['init', 'app', '--language', 'typescript', '--project-name', 'my-app']);

const result = convertYargsToUserInput(input);

expect(result).toEqual({
command: 'init',
init: expect.objectContaining({
projectName: 'my-app',
TEMPLATE: 'app',
}),
globalOptions: expect.anything(),
});
});
});

describe('config', () => {
Expand Down
24 changes: 23 additions & 1 deletion packages/aws-cdk/test/commands/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('constructs version', () => {
expect(Object.entries(pj.devDependencies)).toContainEqual(['aws-cdk-lib', '2.100']);
});

cliTest('can specify project name with --name option', async (workDir) => {
cliTest('can specify project name with --project-name option', async (workDir) => {
await cliInit({
ioHelper,
type: 'app',
Expand All @@ -78,6 +78,28 @@ describe('constructs version', () => {
expect(stackFile).toContain('export class MyProjectStack');
});

cliTest('can specify project name with project-name option via CLI', async (workDir) => {
const { exec } = await import('child_process');
const { promisify } = await import('util');
const execAsync = promisify(exec);
const cdkBin = path.join(__dirname, '..', '..', 'bin', 'cdk');

const commonEnv = { ...process.env, CDK_DISABLE_VERSION_CHECK: '1', CI: 'true', TERM: 'dumb', NO_COLOR: '1' };
const execOptions = { timeout: 30_000, killSignal: 9 };

await execAsync(`node ${cdkBin} init app --language typescript --project-name awesome-app --generate-only`, {
cwd: workDir,
env: commonEnv,
...execOptions,
});

const stackFile = await fs.readFile(path.join(workDir, 'lib', 'awesome-app-stack.ts'), 'utf-8');
expect(stackFile).toContain('export class AwesomeAppStack');

const packageJson = await fs.readJson(path.join(workDir, 'package.json'));
expect(packageJson.name).toEqual('awesome-app');
});

cliTest('asking for a nonexistent template fails', async (workDir) => {
await expect(cliInit({
ioHelper,
Expand Down