Skip to content

Commit

Permalink
feat(blueprints-cli): add an optional project option to the publish c…
Browse files Browse the repository at this point in the history
…ommand (#445)

* feat(blueprints-cli): add an optional project option to the publish command

* reverse unrelated changes
  • Loading branch information
alexforsyth authored Jan 5, 2024
1 parent 140510a commit 72b9c6b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
1 change: 0 additions & 1 deletion packages/blueprints/blueprint/src/blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/**']);
Expand Down
11 changes: 9 additions & 2 deletions packages/utils/blueprint-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand All @@ -329,13 +335,14 @@ yargs
},
handler: async (argv: PublishOptions): Promise<void> => {
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);
},
})
Expand Down
3 changes: 3 additions & 0 deletions packages/utils/blueprint-cli/src/publish/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface PublishOptions extends yargs.Arguments {
cookie?: string;
endpoint: string;
region?: string;
project?: string;
}

export async function publish(
Expand All @@ -20,6 +21,7 @@ export async function publish(
options: {
blueprintPath: string;
publishingSpace: string;
targetProject?: string;
cookie?: string;
region: string;
force?: boolean;
Expand Down Expand Up @@ -90,6 +92,7 @@ export async function publish(
blueprint: {
publishingSpace: options.publishingSpace,
targetSpace: options.publishingSpace,
targetProject: options.targetProject,
packageName,
version,
authentication,
Expand Down
30 changes: 29 additions & 1 deletion packages/utils/blueprint-cli/src/publish/upload-blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export async function uploadBlueprint(
blueprint: {
publishingSpace: string;
targetSpace: string;
targetProject?: string;
packageName: string;
version: string;
authentication: CodeCatalystAuthentication;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -219,6 +226,7 @@ async function generatePreviewLink(
version: string;
publishingSpace: string;
targetSpace: string;
targetProject?: string;
http: {
endpoint;
headers: { [key: string]: string };
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 72b9c6b

Please sign in to comment.