in packages/infrastructure/src/projects/typescript/infrastructure-ts-project.ts [76:189]
constructor(options: InfrastructureTsProjectOptions) {
super({
...options,
defaultReleaseBranch: options.defaultReleaseBranch ?? "main",
prettier: options.prettier || true,
packageManager:
options.parent && options.parent instanceof NodeProject
? options.parent.package.packageManager
: options.packageManager,
cdkVersion: options.cdkVersion ?? "2.1.0",
name: options.name,
sampleCode: false,
readme: {
contents: fs
.readFileSync(
path.resolve(
__dirname,
"../../../samples/infrastructure/typescript/README.md"
)
)
.toString(),
},
});
InfrastructureCommands.ensure(this);
this.addDeps("@aws/pdk", "cdk-nag");
const srcDir = path.resolve(
__dirname,
"../../../samples/infrastructure/typescript/src"
);
const testDir = path.resolve(
__dirname,
"../../../samples/infrastructure/typescript/test"
);
const typeSafeApis = [
...(options.typeSafeApis || []),
...(options.typeSafeApi ? [options.typeSafeApi] : []),
];
const typeSafeWebSocketApis = options.typeSafeWebSocketApis ?? [];
const cloudscapeReactTsWebsites = [
...(options.cloudscapeReactTsWebsites || []),
...(options.cloudscapeReactTsWebsite
? [options.cloudscapeReactTsWebsite]
: []),
];
[...typeSafeApis, ...typeSafeWebSocketApis].forEach((tsApi) => {
if (!tsApi.infrastructure.typescript) {
throw new Error(
"Cannot pass in a Type Safe Api without Typescript Infrastructure configured!"
);
}
this.addDeps(
`${tsApi.infrastructure.typescript?.package.packageName!}@${
tsApi.infrastructure.typescript?.package.manifest.version
}`
);
// Ensure handlers are built before infra
tsApi.all.handlers?.forEach((handler) => {
NxProject.ensure(this).addImplicitDependency(handler);
});
});
cloudscapeReactTsWebsites.forEach((csWebsite) => {
// Ensure website is built before infra
this.addDevDeps(
`${csWebsite.package.packageName}@${csWebsite.package.manifest.version}`
);
});
const mustacheConfig = {
stackName: options.stackName || DEFAULT_STACK_NAME,
allowSignup: options.allowSignup ?? false,
typeSafeApis: this.generateTypeSafeMustacheConfig(typeSafeApis),
typeSafeWebSocketApis: this.generateTypeSafeMustacheConfig(
typeSafeWebSocketApis
),
stages: options.stages || [],
cloudscapeReactTsWebsites: cloudscapeReactTsWebsites.map((csWebsite) => {
const websiteName = this.capitalize(
csWebsite.package.packageName
.replace(/[^a-z0-9_]+/gi, "")
.replace(/^[0-9]+/gi, "")
);
return {
websiteName,
websiteNameLowercase: websiteName.toLowerCase(),
websiteDistRelativePath: path.relative(
this.outdir,
`${csWebsite.outdir}/build`
),
typeSafeApis: this.generateTypeSafeMustacheConfig(
csWebsite.typeSafeApis
),
typeSafeWebSocketApis: this.generateTypeSafeMustacheConfig(
csWebsite.typeSafeWebSocketApis
),
};
}),
};
options.sampleCode !== false &&
this.emitSampleFiles(srcDir, ["src"], mustacheConfig);
options.sampleCode !== false &&
this.emitSampleFiles(testDir, ["test"], mustacheConfig);
const eslintTask = this.tasks.tryFind("eslint");
this.testTask.reset();
this.testTask.exec("jest --passWithNoTests ${CI:-'--updateSnapshot'}");
eslintTask && this.testTask.spawn(eslintTask);
}