Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(blueprint): include an instantiation object on the base blueprint #446

Merged
merged 4 commits into from
Jan 5, 2024
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
30 changes: 29 additions & 1 deletion packages/blueprints/blueprint/src/blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from 'fs';
import * as path from 'path';

import { Project } from 'projen';
import { Context, ResynthesisPhase } from './context/context';
import { BlueprintInstantiation, Context, ResynthesisPhase } from './context/context';
import { TraversalOptions, traverse } from './context/traverse';
import { createLifecyclePullRequest } from './pull-requests/create-lifecycle-pull-request';
import { ContextFile, createContextFile, destructurePath } from './resynthesis/context-file';
Expand Down Expand Up @@ -59,6 +59,9 @@ export class Blueprint extends Project {
name: process.env.CONTEXT_PROJECTNAME,
bundlepath: process.env.EXISTING_BUNDLE_ABS,
options: getOptions(path.join(process.env.EXISTING_BUNDLE_ABS || '', OPTIONS_FILE)),
blueprint: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this be blueprints?

this.context.project.blueprint.instantiations

or

this.context.project.blueprints.instantiations

Copy link
Contributor

Choose a reason for hiding this comment

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

I think what you have makes sense since the ancestor is singular.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay fair enough

instantiations: structureExistingBlueprints(process.env.INSTANTIATIONS_ABS),
},
src: {
listRepositoryNames: (): string[] => {
const repoBundlePath = path.join(this.context.project.bundlepath || '', 'src');
Expand Down Expand Up @@ -249,3 +252,28 @@ function getOptions(location: string): any {
return {};
}
}

function structureExistingBlueprints(location: string | undefined): BlueprintInstantiation[] {
if (!location) {
console.warn('Instantiations location not specified');
return [];
}
if (!fs.existsSync(location || '')) {
console.warn('Could not find instantiations at ' + location);
return [];
}
try {
const result = JSON.parse(fs.readFileSync(location!).toString());
const instantiations = (result as BlueprintInstantiation[]).map(instantiation => {
return {
...instantiation,
options: JSON.parse(instantiation.options),
};
});
return instantiations;
} catch (error) {
console.error(error);
console.error('Could not read instantiations at ' + location);
}
return [];
}
45 changes: 45 additions & 0 deletions packages/blueprints/blueprint/src/context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,37 @@ export interface PackageConfiguration {
readonly name?: string;
readonly version?: string;
}

/**
* This represents an instantiation of a blueprint
*/
export interface BlueprintInstantiation {
/**
* This is a unique identifier of this particular blueprint instantiation. This can be found on the instantiation settings.
*/
id: string;

/**
* This is the identifier of the space that published this blueprint.
*/
publisher?: string;

/**
* This is the package name of this blueprint.
*/
packageName: string;

/**
* This is blueprint version used.
*/
versionId: string;

/**
* This is an object that represents the options used on the blueprint.
*/
options: any;
}

/**
* context about the existing project bundle (if it exists)
*/
Expand All @@ -21,6 +52,20 @@ export interface Project {
* The options used on the previous run of this blueprint.
*/
options?: any;

/**
* Information about Blueprints the existing project
*/
blueprint: {
/**
* A list of all blueprint instantiations already present in your project
*/
instantiations: BlueprintInstantiation[];
};

/**
* The source code from the existing project. Note, this can be across multiple repositories
*/
src: {
/**
* This can be used to list the repositories in the exisiting codebase.
Expand Down
3 changes: 3 additions & 0 deletions packages/blueprints/test-blueprint/src/blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,5 +204,8 @@ export class Blueprint extends ParentBlueprint {
new SourceFile(internalRepo, 'blueprint.d.ts', blueprintInterface);
new SourceFile(internalRepo, 'defaults.json', blueprintDefaults);
new SourceFile(internalRepo, 'internal/ast.json', blueprintAST);
new SourceFile(internalRepo, 'internal/env.json', JSON.stringify(process.env, null, 2));

new SourceFile(internalRepo, 'internal/INSTANTIATIONS_ABS.json', JSON.stringify(this.context.project.blueprint.instantiations, null, 2));
}
}