From d8de0c31f9a94092288920fdbed3f7acf950171c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20P?= <126772659+remdash@users.noreply.github.com> Date: Tue, 11 Jun 2024 12:42:03 +0200 Subject: [PATCH] Add support for deploy percentage (#83) --- cli.js | 4 ++++ config.js | 1 + package.json | 2 +- readme.md | 1 + test/config.js | 12 ++++++++++++ wrapper.js | 4 ++-- 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/cli.js b/cli.js index e134d16..8ecf3ea 100755 --- a/cli.js +++ b/cli.js @@ -28,6 +28,7 @@ const cli = meow(` --refresh-token OAuth2 Refresh Token (environment variable REFRESH_TOKEN) --auto-publish Can be used with the "upload" command (deprecated, use \`chrome-webstore-upload\` without a command instead) --trusted-testers Can be used with the "publish" command + --deploy-percentage Can be used with the "publish" command. Defaults to 100 Examples Upload and publish a new version, using existing environment variables and the default value for --source @@ -59,6 +60,7 @@ const { isPublish, autoPublish, trustedTesters, + deployPercentage, } = await createConfig(cli.input[0], cli.flags); const spinner = ora(); @@ -87,6 +89,7 @@ async function doAutoPublish() { const publishResponse = await publish( { apiConfig, token }, trustedTesters && 'trustedTesters', + deployPercentage, ); spinner.stop(); handlePublishStatus(publishResponse); @@ -113,6 +116,7 @@ async function doPublish() { const response = await publish( { apiConfig }, trustedTesters && 'trustedTesters', + deployPercentage, ); spinner.stop(); handlePublishStatus(response); diff --git a/config.js b/config.js index 3555feb..1a57d12 100644 --- a/config.js +++ b/config.js @@ -16,5 +16,6 @@ export default async function getConfig(command, flags) { isPublish: command === 'publish', autoPublish: flags.autoPublish || !command, trustedTesters: flags.trustedTesters, + deployPercentage: flags.deployPercentage, }; } diff --git a/package.json b/package.json index 5aa950c..f908bde 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ ] }, "dependencies": { - "chrome-webstore-upload": "^3.0.0", + "chrome-webstore-upload": "^3.1.0", "junk": "^4.0.1", "meow": "^12.1.1", "ora": "^7.0.1", diff --git a/readme.md b/readme.md index 16eb330..174f576 100644 --- a/readme.md +++ b/readme.md @@ -42,6 +42,7 @@ $ chrome-webstore-upload --help --refresh-token OAuth2 Refresh Token (environment variable REFRESH_TOKEN) --auto-publish Can be used with the "upload" command (deprecated, use `chrome-webstore-upload` without a command instead) --trusted-testers Can be used with the "publish" command + --deploy-percentage Can be used with the "publish" command. Defaults to 100 Examples Upload and publish a new version, using existing environment variables and the default value for --source diff --git a/test/config.js b/test/config.js index 5950c5c..887af73 100644 --- a/test/config.js +++ b/test/config.js @@ -58,6 +58,18 @@ test('Auto Publish', async t => { t.true(config.autoPublish); }); +test('Publish with deploy percentage', async t => { + const config = await createConfig(null, { deployPercentage: 5 }); + + t.is(config.deployPercentage, 5); +}); + +test('Publish without deploy percentage', async t => { + const config = await createConfig(null, {}); + + t.is(config.deployPercentage, undefined); +}); + test('Auto upload and publish', async t => { const config = await createConfig('', {}); t.false(config.isPublish); diff --git a/wrapper.js b/wrapper.js index 6ce9994..6cc8ceb 100644 --- a/wrapper.js +++ b/wrapper.js @@ -13,9 +13,9 @@ export async function upload({ apiConfig, zipPath, token }) { return client.uploadExisting(zipStream, token); } -export async function publish({ apiConfig, token }, publishTarget) { +export async function publish({ apiConfig, token }, publishTarget, deployPercentage) { const client = getClient(apiConfig); - return client.publish(publishTarget, token); + return client.publish(publishTarget, token, deployPercentage); } export async function fetchToken(apiConfig) {