From 08e97d751620ad7867bb0c9b94633e94f2c01c68 Mon Sep 17 00:00:00 2001 From: Mikkel Gravgaard Date: Mon, 6 Jan 2025 10:50:22 +0100 Subject: [PATCH] Add deployment: allow specifying deployment key (#60) When migrating an existing app to the stand-alone server, it makes sense to re-use existing deployment keys. The Rest API already allows for explicitly specifying deployment key, so this PR just adds an optional argument to the `deployment add` command. Example usage: ```bash code-push-standalone deployment add my-app prod existing-key-abc123 ``` --------- Co-authored-by: Mikkel Gravgaard --- cli/README.md | 6 ++++++ cli/script/command-executor.ts | 2 +- cli/script/command-parser.ts | 13 ++++++++++++- cli/script/management-sdk.ts | 4 ++-- cli/script/types/cli.ts | 1 + 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/cli/README.md b/cli/README.md index a11a33e..1b82597 100644 --- a/cli/README.md +++ b/cli/README.md @@ -204,6 +204,12 @@ If having a staging and production version of your app is enough to meet your ne code-push-standalone deployment add ``` +If you want to re-use an existing deployment key, you can do this with: + +``` +code-push-standalone deployment add -k +``` + Just like with apps, you can remove and rename deployments as well, using the following commands respectively: ``` diff --git a/cli/script/command-executor.ts b/cli/script/command-executor.ts index 30b7521..5e37358 100644 --- a/cli/script/command-executor.ts +++ b/cli/script/command-executor.ts @@ -290,7 +290,7 @@ function deleteFolder(folderPath: string): Promise { } function deploymentAdd(command: cli.IDeploymentAddCommand): Promise { - return sdk.addDeployment(command.appName, command.deploymentName).then((deployment: Deployment): void => { + return sdk.addDeployment(command.appName, command.deploymentName, command.key).then((deployment: Deployment): void => { log( 'Successfully added the "' + command.deploymentName + diff --git a/cli/script/command-parser.ts b/cli/script/command-parser.ts index 61fd940..43b8b39 100644 --- a/cli/script/command-parser.ts +++ b/cli/script/command-parser.ts @@ -377,7 +377,14 @@ yargs yargs .usage(USAGE_PREFIX + " deployment add ") .demand(/*count*/ 2, /*max*/ 2) // Require exactly two non-option arguments - .example("deployment add MyApp MyDeployment", 'Adds deployment "MyDeployment" to app "MyApp"'); + .example("deployment add MyApp MyDeployment", 'Adds deployment "MyDeployment" to app "MyApp"') + .example("deployment add MyApp MyDeployment -k abc123", 'Adds deployment key "abc123"') + .option("key", { + alias: "k", + demand: false, + description: "Specify deployment key", + type: "string", + }); addCommonConfiguration(yargs); }) @@ -1046,6 +1053,10 @@ export function createCommand(): cli.ICommand { deploymentAddCommand.appName = arg2; deploymentAddCommand.deploymentName = arg3; + if(argv["key"]){ + deploymentAddCommand.key = argv["key"] as any; + } + } break; diff --git a/cli/script/management-sdk.ts b/cli/script/management-sdk.ts index 0d5af7a..6b620a0 100644 --- a/cli/script/management-sdk.ts +++ b/cli/script/management-sdk.ts @@ -253,8 +253,8 @@ class AccountManager { } // Deployments - public addDeployment(appName: string, deploymentName: string): Promise { - const deployment = { name: deploymentName }; + public addDeployment(appName: string, deploymentName: string, deploymentKey?: string): Promise { + const deployment = { name: deploymentName, key: deploymentKey }; return this.post(urlEncode([`/apps/${appName}/deployments/`]), JSON.stringify(deployment), /*expectResponseBody=*/ true).then( (res: JsonResponse) => res.body.deployment ); diff --git a/cli/script/types/cli.ts b/cli/script/types/cli.ts index fe55520..359ce1f 100644 --- a/cli/script/types/cli.ts +++ b/cli/script/types/cli.ts @@ -107,6 +107,7 @@ export interface IDebugCommand extends ICommand { export interface IDeploymentAddCommand extends ICommand { appName: string; deploymentName: string; + key?: string; default: boolean; }