diff --git a/packages/blueprints/blueprint/src/blueprint.ts b/packages/blueprints/blueprint/src/blueprint.ts index 1a72859bc..025979173 100644 --- a/packages/blueprints/blueprint/src/blueprint.ts +++ b/packages/blueprints/blueprint/src/blueprint.ts @@ -147,7 +147,6 @@ export class Blueprint extends Project { fs.writeFileSync(outputPath, filecontent); } - //2. construct the superset of files between [ancestorBundle, existingBundle, proposedBundle]/src // only consider files under the source code 'src' const supersetSourcePaths: string[] = filepathSet([ancestorBundle, existingBundle, proposedBundle], ['src/**']); diff --git a/packages/utils/blueprint-cli/src/index.ts b/packages/utils/blueprint-cli/src/index.ts index e02eea07c..12bcb4ed3 100644 --- a/packages/utils/blueprint-cli/src/index.ts +++ b/packages/utils/blueprint-cli/src/index.ts @@ -321,6 +321,12 @@ yargs demandOption: false, type: 'string', }) + .option('project', { + description: + 'Generates a preview link as if this blueprint was being added to an existing project. This does not check if the project actually exists.', + demandOption: false, + type: 'string', + }) .option('force', { description: 'Force publish. This will overwrite the exisiting blueprint version (if it exists). This may cause exisiting blueprint consumers unexpected difference sets.', @@ -329,13 +335,14 @@ yargs }, handler: async (argv: PublishOptions): Promise => { argv = useOverrideOptionals(argv); - void (await publish(log, argv.endpoint, { + await publish(log, argv.endpoint, { blueprintPath: argv.blueprint, publishingSpace: argv.publisher, cookie: argv.cookie, region: argv.region || process.env.AWS_REGION || 'us-west-2', force: ((argv.force as boolean) && argv.force == true) || false, - })); + targetProject: argv.project, + }); process.exit(0); }, }) diff --git a/packages/utils/blueprint-cli/src/publish/publish.ts b/packages/utils/blueprint-cli/src/publish/publish.ts index c4718f54b..eee55f685 100644 --- a/packages/utils/blueprint-cli/src/publish/publish.ts +++ b/packages/utils/blueprint-cli/src/publish/publish.ts @@ -12,6 +12,7 @@ export interface PublishOptions extends yargs.Arguments { cookie?: string; endpoint: string; region?: string; + project?: string; } export async function publish( @@ -20,6 +21,7 @@ export async function publish( options: { blueprintPath: string; publishingSpace: string; + targetProject?: string; cookie?: string; region: string; force?: boolean; @@ -90,6 +92,7 @@ export async function publish( blueprint: { publishingSpace: options.publishingSpace, targetSpace: options.publishingSpace, + targetProject: options.targetProject, packageName, version, authentication, diff --git a/packages/utils/blueprint-cli/src/publish/upload-blueprint.ts b/packages/utils/blueprint-cli/src/publish/upload-blueprint.ts index 279ac5ee7..fb0d463a8 100644 --- a/packages/utils/blueprint-cli/src/publish/upload-blueprint.ts +++ b/packages/utils/blueprint-cli/src/publish/upload-blueprint.ts @@ -16,6 +16,7 @@ export async function uploadBlueprint( blueprint: { publishingSpace: string; targetSpace: string; + targetProject?: string; packageName: string; version: string; authentication: CodeCatalystAuthentication; @@ -113,13 +114,19 @@ export async function uploadBlueprint( version: blueprint.version, publishingSpace: blueprint.publishingSpace, targetSpace: blueprint.targetSpace, + targetProject: blueprint.targetProject, http: { endpoint: endpoint, headers: generateHeaders(blueprint.authentication, blueprint.identity), }, }; - log.info(`See this blueprint at: ${await generatePreviewLink(log, previewOptions)}`); log.info(`Enable version ${version} at: ${resolveStageUrl(endpoint)}/spaces/${blueprint.targetSpace}/blueprints`); + const previewlink = await generatePreviewLink(log, previewOptions); + if (previewOptions.targetProject) { + log.info(`Preview applied to [${previewOptions.targetProject}]: ${previewlink}`); + } else { + log.info(`Preview applied to [NEW]: ${previewlink}`); + } return; } else if (fetchStatusResponse.status === 'IN_PROGRESS') { const curWait = baseWaitSec * 1000 + 1000 * attempt; @@ -219,6 +226,7 @@ async function generatePreviewLink( version: string; publishingSpace: string; targetSpace: string; + targetProject?: string; http: { endpoint; headers: { [key: string]: string }; @@ -247,6 +255,26 @@ async function generatePreviewLink( }, ); + /** + * generate a url to a project instead + */ + if (options.targetProject) { + return [ + resolveStageUrl(options.http.endpoint), + 'spaces', + querystring.escape(options.targetSpace), + 'projects', + querystring.escape(options.targetProject), + 'blueprints', + querystring.escape(options.blueprintPackage), + 'publishers', + querystring.escape(publishingSpaceIdResponse.data?.data?.getSpace?.id), + 'versions', + querystring.escape(options.version), + 'add', + ].join('/'); + } + return [ resolveStageUrl(options.http.endpoint), 'spaces',