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(blueprints-cli): add an optional project option to the publish command #445

Merged
merged 3 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
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