Skip to content

Commit 443b77d

Browse files
authored
Upload and publish if no command is specified (#81)
1 parent 4843717 commit 443b77d

File tree

5 files changed

+40
-38
lines changed

5 files changed

+40
-38
lines changed

cli.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,34 @@ import { upload, publish, fetchToken } from './wrapper.js';
99
import {
1010
isUploadSuccess,
1111
handlePublishStatus,
12-
validateInput,
1312
} from './util.js';
1413

1514
const cli = meow(`
1615
Usage
17-
$ chrome-webstore-upload <command>
16+
$ chrome-webstore-upload [command]
1817
19-
where <command> is one of
18+
where [command] can be one of
2019
upload, publish
2120
22-
Options
23-
--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
24-
--extension-id The ID of the Chrome Extension (environment variable EXTENSION_ID)
25-
--client-id OAuth2 Client ID (environment variable CLIENT_ID)
26-
--client-secret OAuth2 Client Secret (environment variable CLIENT_SECRET)
27-
--refresh-token OAuth2 Refresh Token (environment variable REFRESH_TOKEN)
28-
--auto-publish Can be used with the "upload" command
29-
--trusted-testers Can be used with the "publish" command
21+
if the command is missing, it will both upload and publish the extension.
3022
23+
Options
24+
--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
25+
--extension-id The ID of the Chrome Extension (environment variable EXTENSION_ID)
26+
--client-id OAuth2 Client ID (environment variable CLIENT_ID)
27+
--client-secret OAuth2 Client Secret (environment variable CLIENT_SECRET)
28+
--refresh-token OAuth2 Refresh Token (environment variable REFRESH_TOKEN)
29+
--auto-publish Can be used with the "upload" command (deprecated, use \`chrome-webstore-upload\` without a command instead)
30+
--trusted-testers Can be used with the "publish" command
3131
3232
Examples
33+
Upload and publish a new version, using existing environment variables and the default value for --source
34+
$ chrome-webstore-upload
35+
3336
Upload new extension archive to the Chrome Web Store
34-
$ chrome-webstore-upload upload --source extension.zip --extension-id $EXTENSION_ID --client-id $CLIENT_ID --client-secret $CLIENT_SECRET --refresh-token $REFRESH_TOKEN
37+
$ chrome-webstore-upload upload --source my-custom-zip.zip
3538
36-
Publish extension (with CLIENT_ID, CLIENT_SECRET, and REFRESH_TOKEN set as env variables)
39+
Publish the last uploaded version (whether it was uploaded via web UI or via CLI)
3740
$ chrome-webstore-upload publish --extension-id elomekmlfonmdhmpmdfldcjgdoacjcba
3841
`, {
3942
importMeta: import.meta,
@@ -44,9 +47,8 @@ const cli = meow(`
4447
},
4548
});
4649

47-
const preliminaryValidation = validateInput(cli.input, cli.flags);
48-
if (preliminaryValidation.error) {
49-
console.error(preliminaryValidation.error);
50+
if (cli.input.length > 1) {
51+
console.error('Too many parameters');
5052
cli.showHelp(1);
5153
}
5254

@@ -130,7 +132,7 @@ function errorHandler(error) {
130132
'Probably the provided client ID is not valid. Try following the guide again',
131133
);
132134
console.error(
133-
'https://github.com/fregante/chrome-webstore-upload/blob/main/How%20to%20generate%20Google%20API%20keys.md',
135+
'https://github.com/fregante/chrome-webstore-upload-keys',
134136
);
135137
console.error({ clientId });
136138
return;
@@ -142,7 +144,7 @@ function errorHandler(error) {
142144
'Probably the provided refresh token is not valid. Try following the guide again',
143145
);
144146
console.error(
145-
'https://github.com/fregante/chrome-webstore-upload/blob/main/How%20to%20generate%20Google%20API%20keys.md',
147+
'https://github.com/fregante/chrome-webstore-upload-keys',
146148
);
147149
console.error({ clientId, refreshToken });
148150
return;

config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export default async function getConfig(command, flags) {
1212
return {
1313
apiConfig,
1414
zipPath: await findSource(flags.source),
15-
isUpload: command === 'upload',
15+
isUpload: command === 'upload' || !command,
1616
isPublish: command === 'publish',
17-
autoPublish: flags.autoPublish,
17+
autoPublish: flags.autoPublish || !command,
1818
trustedTesters: flags.trustedTesters,
1919
};
2020
}

readme.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,30 @@ $ chrome-webstore-upload --help
2727
CLI Utility to quickly upload + publish extensions to the Chrome Web Store
2828
2929
Usage
30-
$ chrome-webstore-upload <command>
30+
$ chrome-webstore-upload [command]
3131
32-
where <command> is one of
32+
where [command] can be one of
3333
upload, publish
3434
35+
if the command is missing, it will both upload and publish the extension.
36+
3537
Options
36-
--source Path to either a zip file, or a directory to be zipped (Defaults to cwd if not specified)
38+
--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
3739
--extension-id The ID of the Chrome Extension (environment variable EXTENSION_ID)
3840
--client-id OAuth2 Client ID (environment variable CLIENT_ID)
3941
--client-secret OAuth2 Client Secret (environment variable CLIENT_SECRET)
4042
--refresh-token OAuth2 Refresh Token (environment variable REFRESH_TOKEN)
41-
--auto-publish Can be used with the "upload" command
43+
--auto-publish Can be used with the "upload" command (deprecated, use `chrome-webstore-upload` without a command instead)
4244
--trusted-testers Can be used with the "publish" command
4345
4446
Examples
47+
Upload and publish a new version, using existing environment variables and the default value for --source
48+
$ chrome-webstore-upload
49+
4550
Upload new extension archive to the Chrome Web Store
46-
$ chrome-webstore-upload upload --source extension.zip --extension-id $EXTENSION_ID --client-id $CLIENT_ID --client-secret $CLIENT_SECRET --refresh-token $REFRESH_TOKEN
51+
$ chrome-webstore-upload upload --source my-custom-zip.zip
4752
48-
Publish extension (with CLIENT_ID, CLIENT_SECRET, and REFRESH_TOKEN set as env variables)
53+
Publish the last uploaded version (whether it was uploaded via web UI or via CLI)
4954
$ chrome-webstore-upload publish --extension-id elomekmlfonmdhmpmdfldcjgdoacjcba
5055
```
5156

test/config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,10 @@ test('Auto Publish', async t => {
5757

5858
t.true(config.autoPublish);
5959
});
60+
61+
test('Auto upload and publish', async t => {
62+
const config = await createConfig('', {});
63+
t.false(config.isPublish);
64+
t.true(config.isUpload);
65+
t.true(config.autoPublish);
66+
});

util.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,6 @@ export function handlePublishStatus(item) {
1919
throw item;
2020
}
2121

22-
export function validateInput(input) {
23-
if (input.length === 0) {
24-
return { error: 'Must specify "upload" or "publish"' };
25-
}
26-
27-
if (input.length > 1) {
28-
return { error: 'Too many parameters' };
29-
}
30-
31-
return { valid: true };
32-
}
33-
3422
export function zipPath(root, file) {
3523
return relative(root, file);
3624
}

0 commit comments

Comments
 (0)