in packages/blueprints/blueprint-builder/src/blueprint.ts [84:188]
constructor(options_: Options) {
super({
...options_,
});
/**
* This is a typecheck to ensure that the defaults passed in are of the correct type.
* There are some cases where the typecheck will fail, but the defaults will still be valid, such when using enums.
* you can override this ex. myEnum: defaults.myEnum as Options['myEnum'],
*/
const typeCheck: Options = {
outdir: this.outdir,
...defaults,
advancedSettings: {
...defaults.advancedSettings,
license: defaults.advancedSettings.license as any,
},
};
const userSelectedOptions = Object.assign(typeCheck, options_);
const spaceName = process.env.CONTEXT_SPACENAME || '<<unknown-space>>';
const dashName = decamelize.default(options_.blueprintName.toString()).replace(/[_ ]/g, '-');
const defaultPackageName = `@amazon-codecatalyst/${spaceName}.${dashName}`.substring(0, 214).toLocaleLowerCase().replace(/[_ ]/g, '-');
const options = {
...userSelectedOptions,
advancedSettings: {
...userSelectedOptions.advancedSettings,
blueprintPackageName: userSelectedOptions.advancedSettings.blueprintPackageName || defaultPackageName,
repository: userSelectedOptions.advancedSettings.repository || dashName,
},
};
this.setInstantiation({
options,
description: options.description,
});
/**
* Create a new Source repo
*/
this.repository = new SourceRepository(this, {
title: options.advancedSettings.repository,
});
/**
* Builds the assets for the basic blueprint npm package
*/
buildBlueprintPackage(this, this.repository, {
bpOptions: options,
space: this.context.spaceName || 'unknown',
packageName: options.advancedSettings.blueprintPackageName,
dashname: dashName,
projectName: this.context.project.name || 'unknown',
spaceName: this.context.spaceName || 'unknown',
});
/**
* If the release option is set, respect that and build a release workflow
*/
if (options.advancedSettings.releaseWorkflow) {
new Workflow(
this,
this.repository,
buildReleaseWorkflow(new WorkflowBuilder(this), {
includePublishStep: options.advancedSettings.includePublishingAction,
}).getDefinition(),
);
this.repository.copyStaticFiles({
from: 'release',
});
}
/**
* this is the first time this blueprint is being applied, and its being applied to a repository that already exists.
* this blueprint is being added as a conversion on an existing codebase.
*/
if (!this.context.project.blueprint.instantiationId && userSelectedOptions.advancedSettings.repository) {
console.log('CONVERTING A BLUEPRINT!!!');
this.isBlueprintConversion = true;
buildInitialStaticAssets(this.repository, {
existingFiles: this.context.project.src.findAll({
repositoryName: this.repository.title,
}),
});
this.repository.copyStaticFiles({
from: 'converted-blueprint',
});
this.repository.setResynthStrategies([
{
identifier: 'inital_conversion',
strategy: (_commonAncestorFile, _existingFile, proposedFile) => proposedFile,
globs: ['**/**'],
},
]);
} else {
/**
* Otherwise use the standard static assets
*/
this.repository.copyStaticFiles({
from: 'standard-static-assets',
to: 'static-assets',
});
this.setStandardResynthStrategies();
}
}