Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,11 @@ toolkitLib.package.addField('exports', {
'./package.json': './package.json',
});

toolkitLib.addTask('gen-fixture', {
description: 'Generate cdk.out for test fixtures',
exec: 'tsx scripts/gen-fixture-cdk-out.ts',
receiveArgs: true,
});
const registryTask = toolkitLib.addTask('registry', { exec: 'tsx scripts/gen-code-registry.ts' });
toolkitLib.postCompileTask.spawn(registryTask);
toolkitLib.postCompileTask.exec('build-tools/build-info.sh');
Expand Down Expand Up @@ -1108,6 +1113,7 @@ toolkitLib.gitignore.addPatterns(
'lib/init-templates/**',
'!test/_fixtures/**/app.js',
'!test/_fixtures/**/cdk.out',
'test/_fixtures/**/cdk.out/*.lock',
);

// Add commands for the API Extractor docs
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/toolkit-lib/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions packages/@aws-cdk/toolkit-lib/.projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/@aws-cdk/toolkit-lib/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions packages/@aws-cdk/toolkit-lib/scripts/gen-fixture-cdk-out.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Generate cdk.out directories for test fixtures.
*
* Usage: tsx scripts/gen-fixture-cdk-out.ts [fixture-name ...]
*
* If no fixture names are given, generates cdk.out for all fixtures
* that have an index.ts or index.js builder file.
*/
import * as fs from 'fs';
import * as path from 'path';
import { MemoryContext, Toolkit } from '../lib';

const FIXTURES_DIR = path.join(__dirname, '..', 'test', '_fixtures');

async function generateFixture(name: string) {
const fixtureDir = path.join(FIXTURES_DIR, name);
if (!fs.existsSync(fixtureDir)) {
throw new Error(`Fixture not found: ${name}`);
}

const outdir = path.join(fixtureDir, 'cdk.out');
fs.rmSync(outdir, { recursive: true, force: true });

const toolkit = new Toolkit();
// eslint-disable-next-line @typescript-eslint/no-require-imports
const builder = require(path.join(FIXTURES_DIR, name, 'index')).default;
const source = await toolkit.fromAssemblyBuilder(builder, {
outdir,
contextStore: new MemoryContext(),
});

// Produce the assembly to trigger synthesis
const asm = await source.produce();
await asm.dispose();

// Clean up lock files
for (const file of fs.readdirSync(outdir)) {
if (file.endsWith('.lock')) {
fs.rmSync(path.join(outdir, file));
}
}

console.log(`✅ ${name}/cdk.out`);
}

async function main() {
const args = process.argv.slice(2);

let fixtures: string[];
if (args.length > 0) {
fixtures = args;
} else {
fixtures = fs.readdirSync(FIXTURES_DIR).filter((name) => {
const dir = path.join(FIXTURES_DIR, name);
return fs.statSync(dir).isDirectory()
&& (fs.existsSync(path.join(dir, 'index.ts')) || fs.existsSync(path.join(dir, 'index.js')));
});
}

for (const name of fixtures) {
await generateFixture(name);
}
}

main().catch((e) => {
console.error(e);
process.exit(1);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"version": "53.0.0",
"files": {
"282b08e098be248e5f225b8abf945177517791ba7fce85c257904c6305d7f304": {
"displayName": "Function1/Code",
"source": {
"path": "asset.282b08e098be248e5f225b8abf945177517791ba7fce85c257904c6305d7f304",
"packaging": "zip"
},
"destinations": {
"current_account-current_region-f43b737b": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "282b08e098be248e5f225b8abf945177517791ba7fce85c257904c6305d7f304.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
},
"28a406a51a66f9f35f9d46f5fae1219317cb4673b13cbb4577159abd4b98e229": {
"displayName": "Stack1 Template",
"source": {
"path": "Stack1.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region-064a3fa4": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "28a406a51a66f9f35f9d46f5fae1219317cb4673b13cbb4577159abd4b98e229.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"/Stack1/BootstrapVersion": [
{
"type": "aws:cdk:logicalId",
"data": "BootstrapVersion"
}
],
"/Stack1/CheckBootstrapVersion": [
{
"type": "aws:cdk:logicalId",
"data": "CheckBootstrapVersion"
}
],
"/Stack1/Function1/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "Function1904AA941"
}
],
"/Stack1/CDKMetadata/Default": [
{
"type": "aws:cdk:logicalId",
"data": "CDKMetadata"
}
],
"/Stack1/CDKMetadata/Condition": [
{
"type": "aws:cdk:logicalId",
"data": "CDKMetadataAvailable"
}
],
"/Stack1/Function1/ServiceRole/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "Function1ServiceRole16CD7E62"
}
]
}
Loading
Loading