Skip to content

Commit

Permalink
Upload and publish if no command is specified (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante authored Jun 7, 2024
1 parent 4843717 commit 443b77d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 38 deletions.
38 changes: 20 additions & 18 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,34 @@ import { upload, publish, fetchToken } from './wrapper.js';
import {
isUploadSuccess,
handlePublishStatus,
validateInput,
} from './util.js';

const cli = meow(`
Usage
$ chrome-webstore-upload <command>
$ chrome-webstore-upload [command]
where <command> is one of
where [command] can be one of
upload, publish
Options
--source Path to either a zip file, or a directory to be zipped. Defaults to the value of webExt.sourceDir in package.json or the current directory if not specified
--extension-id The ID of the Chrome Extension (environment variable EXTENSION_ID)
--client-id OAuth2 Client ID (environment variable CLIENT_ID)
--client-secret OAuth2 Client Secret (environment variable CLIENT_SECRET)
--refresh-token OAuth2 Refresh Token (environment variable REFRESH_TOKEN)
--auto-publish Can be used with the "upload" command
--trusted-testers Can be used with the "publish" command
if the command is missing, it will both upload and publish the extension.
Options
--source Path to either a zip file or a directory to be zipped. Defaults to the value of webExt.sourceDir in package.json or the current directory if not specified
--extension-id The ID of the Chrome Extension (environment variable EXTENSION_ID)
--client-id OAuth2 Client ID (environment variable CLIENT_ID)
--client-secret OAuth2 Client Secret (environment variable CLIENT_SECRET)
--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
Examples
Upload and publish a new version, using existing environment variables and the default value for --source
$ chrome-webstore-upload
Upload new extension archive to the Chrome Web Store
$ chrome-webstore-upload upload --source extension.zip --extension-id $EXTENSION_ID --client-id $CLIENT_ID --client-secret $CLIENT_SECRET --refresh-token $REFRESH_TOKEN
$ chrome-webstore-upload upload --source my-custom-zip.zip
Publish extension (with CLIENT_ID, CLIENT_SECRET, and REFRESH_TOKEN set as env variables)
Publish the last uploaded version (whether it was uploaded via web UI or via CLI)
$ chrome-webstore-upload publish --extension-id elomekmlfonmdhmpmdfldcjgdoacjcba
`, {
importMeta: import.meta,
Expand All @@ -44,9 +47,8 @@ const cli = meow(`
},
});

const preliminaryValidation = validateInput(cli.input, cli.flags);
if (preliminaryValidation.error) {
console.error(preliminaryValidation.error);
if (cli.input.length > 1) {
console.error('Too many parameters');
cli.showHelp(1);
}

Expand Down Expand Up @@ -130,7 +132,7 @@ function errorHandler(error) {
'Probably the provided client ID is not valid. Try following the guide again',
);
console.error(
'https://github.com/fregante/chrome-webstore-upload/blob/main/How%20to%20generate%20Google%20API%20keys.md',
'https://github.com/fregante/chrome-webstore-upload-keys',
);
console.error({ clientId });
return;
Expand All @@ -142,7 +144,7 @@ function errorHandler(error) {
'Probably the provided refresh token is not valid. Try following the guide again',
);
console.error(
'https://github.com/fregante/chrome-webstore-upload/blob/main/How%20to%20generate%20Google%20API%20keys.md',
'https://github.com/fregante/chrome-webstore-upload-keys',
);
console.error({ clientId, refreshToken });
return;
Expand Down
4 changes: 2 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export default async function getConfig(command, flags) {
return {
apiConfig,
zipPath: await findSource(flags.source),
isUpload: command === 'upload',
isUpload: command === 'upload' || !command,
isPublish: command === 'publish',
autoPublish: flags.autoPublish,
autoPublish: flags.autoPublish || !command,
trustedTesters: flags.trustedTesters,
};
}
17 changes: 11 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,30 @@ $ chrome-webstore-upload --help
CLI Utility to quickly upload + publish extensions to the Chrome Web Store
Usage
$ chrome-webstore-upload <command>
$ chrome-webstore-upload [command]
where <command> is one of
where [command] can be one of
upload, publish
if the command is missing, it will both upload and publish the extension.
Options
--source Path to either a zip file, or a directory to be zipped (Defaults to cwd if not specified)
--source Path to either a zip file or a directory to be zipped. Defaults to the value of webExt.sourceDir in package.json or the current directory if not specified
--extension-id The ID of the Chrome Extension (environment variable EXTENSION_ID)
--client-id OAuth2 Client ID (environment variable CLIENT_ID)
--client-secret OAuth2 Client Secret (environment variable CLIENT_SECRET)
--refresh-token OAuth2 Refresh Token (environment variable REFRESH_TOKEN)
--auto-publish Can be used with the "upload" command
--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
Examples
Upload and publish a new version, using existing environment variables and the default value for --source
$ chrome-webstore-upload
Upload new extension archive to the Chrome Web Store
$ chrome-webstore-upload upload --source extension.zip --extension-id $EXTENSION_ID --client-id $CLIENT_ID --client-secret $CLIENT_SECRET --refresh-token $REFRESH_TOKEN
$ chrome-webstore-upload upload --source my-custom-zip.zip
Publish extension (with CLIENT_ID, CLIENT_SECRET, and REFRESH_TOKEN set as env variables)
Publish the last uploaded version (whether it was uploaded via web UI or via CLI)
$ chrome-webstore-upload publish --extension-id elomekmlfonmdhmpmdfldcjgdoacjcba
```

Expand Down
7 changes: 7 additions & 0 deletions test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,10 @@ test('Auto Publish', async t => {

t.true(config.autoPublish);
});

test('Auto upload and publish', async t => {
const config = await createConfig('', {});
t.false(config.isPublish);
t.true(config.isUpload);
t.true(config.autoPublish);
});
12 changes: 0 additions & 12 deletions util.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@ export function handlePublishStatus(item) {
throw item;
}

export function validateInput(input) {
if (input.length === 0) {
return { error: 'Must specify "upload" or "publish"' };
}

if (input.length > 1) {
return { error: 'Too many parameters' };
}

return { valid: true };
}

export function zipPath(root, file) {
return relative(root, file);
}

0 comments on commit 443b77d

Please sign in to comment.