Skip to content

Commit

Permalink
Merge pull request #885 from FRSgit/feat/publish-play-related-cli-com…
Browse files Browse the repository at this point in the history
…mands

feat: publish play-related CLI command
  • Loading branch information
OlegNitz authored Sep 9, 2024
2 parents 7d3f005 + 59758de commit df883b0
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 43 deletions.
46 changes: 28 additions & 18 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use `bubblewrap [cmd]`.

### Installing Bubblewrap

```shell
```bash
npm i -g @bubblewrap/cli
```

Expand All @@ -53,7 +53,7 @@ can create different kinds of problems and should be avoided (see
### Initializing an Android Project
Generate an Android project from an existing Web Manifest:

```shell
```bash
bubblewrap init --manifest https://my-twa.com/manifest.json
```

Expand All @@ -70,7 +70,8 @@ and built using [Android Studio](https://developer.android.com/studio/). Please,
applications using Android Studio.

### Building the Android Project
```shell

```bash
bubblewrap build
```

Expand Down Expand Up @@ -232,9 +233,9 @@ Manages the list of fingerprints used to generate the Digital Asset Links file f

Usage:

```
```bash
bubblewrap fingerprint [subcommand]
```
```

Global flags:
- `--manifest=<manifest>`: path to the Trusted Web Activity configuration.',
Expand Down Expand Up @@ -283,50 +284,59 @@ Flags:

## `play`

:warning: This is an experimental feature.

Manages the artifacts for your Google Play Project.

Usage:

```bash
bubblewrap play [subcommand]
```

**Note**:
These feature requires a service account file to work correctly. Please see [this documentation](https://github.com/chromeos/pwa-play-billing#setup-a-service-account) for setting up a service account.

The following options can be applied to all of the features commands:
- `--serviceAccountJsonFile`: sets the service account json file location in the twa-manifest.
Global flags (can be applied to all of the features commands):
- `--serviceAccountFile`: sets the service account json file location in the twa-manifest.
- `--manifest`: specifies the manifest file to use if not in the current directory.


### Subcommands

#### `playPublish`
#### `publish`

Publishes provided bundle to the Play Store.

Usage:

```
bubblewrap playPublish --serviceAccountFile="/path/to/service/account.json" --track="beta" --appBundleLocation="/home/appBundle.aab"
```bash
bubblewrap play publish --serviceAccountFile="/path/to/service/account.json" --track="beta" --appBundleLocation="/home/appBundle.aab"
```

Options:
- `--track`: publishes the prebuilt file to the Google Play Store specificed track (defaults to internal track).
- `--appBundleLocation`: specifies the location of the appbundle to upload to Google Play (defaults to current directory).

#### `playRetain`
#### `retain`

:warning: This is an experimental feature.

Usage:

```
bubblewrap playRetain --add=86
```bash
bubblewrap play retain --add=86
```

Options:
- `--add`: specifies the bundles to retain for release (this would be Android only bundles if releasing a Chrome OS only release).
- `--remove`: removes the specified bundle if no longer relevant.
- `--list`: shows a list of existing retained bundles in the twa-manifest.json, not what is listed as retained from play.

#### `playVersionCheck`
#### `versionCheck`

Usage:

```
bubblewrap playVersionCheck --serviceAccountFile="/path/to/service/account.json" --targetDirectory="/home/my/app/dir"
```bash
bubblewrap play versionCheck --serviceAccountFile="/path/to/service/account.json" --targetDirectory="/home/my/app/dir"
```

Options:
Expand Down
13 changes: 3 additions & 10 deletions packages/cli/src/lib/Cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ import {updateConfig} from './cmds/updateConfig';
import {doctor} from './cmds/doctor';
import {merge} from './cmds/merge';
import {fingerprint} from './cmds/fingerprint';
// import {play, PlayArgs} from './cmds/play';
import {fetchUtils} from '@bubblewrap/core';
// import { play, PlayArgs, playPublish } from './cmds/play';
import {play, PlayArgs} from './cmds/play';

export class Cli {
async run(args: string[]): Promise<boolean> {
Expand Down Expand Up @@ -89,14 +88,8 @@ export class Cli {
return await merge(parsedArgs);
case 'fingerprint':
return await fingerprint(parsedArgs);
// case 'play':
// return await play(parsedArgs as unknown as PlayArgs);
// case 'playPublish':
// return await play(parsedArgs as unknown as PlayArgs, 'publish');
// case 'playVersionCheck':
// return await play(parsedArgs as unknown as PlayArgs, 'versionCheck');
// case 'playRetain':
// return await play(parsedArgs as unknown as PlayArgs, 'retain');
case 'play':
return await play(parsedArgs as unknown as PlayArgs);
default:
throw new Error(
`"${command}" is not a valid command! Use 'bubblewrap help' for a list of commands`);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/cmds/fingerprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {ParsedArgs} from 'minimist';
import type {ParsedArgs} from 'minimist';
import {TwaManifest, DigitalAssetLinks, Fingerprint} from '@bubblewrap/core';
import {TWA_MANIFEST_FILE_NAME, ASSETLINKS_OUTPUT_FILE} from '../constants';
import {Prompt, InquirerPrompt} from '../Prompt';
Expand Down
46 changes: 46 additions & 0 deletions packages/cli/src/lib/cmds/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,52 @@ const HELP_MESSAGES = new Map<string, string>(
' --output=<name> .... path from where to load the project configuration.',
'',
].join('\n')],
['play', [
'Usage:',
'',
'',
'bubblewrap play [subcommand]',
'',
' Global play flags: ',
' --serviceAccountFile=<path> . Path to the the service account JSON file to set in',
' the twa-manifest.',
' --manifest=<manifestPath> ....... Path to the manifest file to use if not in',
' the current directory.',
'',
' - publish: publishes provided bundle to the Play Store.',
' Usage:',
' bubblewrap play publish <flags>',
'',
' Flags:',
' --track=<track> ............ A Google Play Store track to publish the bundle to',
' (defaults to internal track).',
' --appBundleLocation=<path> . Location of the appbundle to upload to Google Play',
' (defaults to current directory).',
'',
'',
' - retain: handles retaining of packages that are published on Google Play Store.',
' Usage:',
' bubblewrap play retain <flags>',
'',
' Flags:',
' --add=<add> ....... Bundles to retain for release',
' --remove=<remove> . Removes the specified bundle if no longer relevant.',
' --list ............ Shows a list of existing retained bundles in the',
' twa-manifest.json (not what is listed as retained in',
' Google Play Store).',
'',
' - versionCheck: runs the version check workflow. If the published version is higher than',
' that of the twaManifest, we assume that the version that exists locally',
' needs to be updated to a higher version.',
' Usage:',
' bubblewrap play versionCheck <flags>',
'',
' Flags:',
' --targetDirectory=<targetDirectory> . The directory that versionCheck should run in',
' (defaults to the current directory). This',
' should be your bubblewrap project directory.',
'',
].join('\n')],
],
);

Expand Down
36 changes: 22 additions & 14 deletions packages/cli/src/lib/cmds/play.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import type {ParsedArgs} from 'minimist';
import {GooglePlay, TwaManifest, asPlayStoreTrack} from '@bubblewrap/core';
import * as fs from 'fs';
import * as path from 'path';
Expand All @@ -22,7 +23,7 @@ import {Prompt, InquirerPrompt} from '../Prompt';
import {updateProject} from './shared';
import {enUS} from '../strings';

export interface PlayArgs {
export interface PlayArgs extends ParsedArgs {
track?: string;
serviceAccountFile?: string;
manifest?: string;
Expand All @@ -37,8 +38,6 @@ export interface PlayArgs {
// Default file path
const defaultSignedAppBundleFileName = 'app-release-bundle.aab';

type PlayCommand = 'publish' | 'retain' | 'versionCheck';

/**
* The Play class is the class that is used to communicate with the Google Play Store.
*/
Expand Down Expand Up @@ -114,7 +113,11 @@ class Play {
* Runs the playRetain command. This handles the retaining of packages that are published on Play.
* @return {boolean} Returns whether or not the run command completed successfully.
*/
async runRetain(): Promise<boolean> {
async runRetain(prompt: Prompt): Promise<boolean> {
// TODO Remove when it's not experimental anymore
if (!await prompt.promptConfirm(enUS.promptExperimentalFeature, false)) {
return true;
}
const manifestFile = this.args.manifest || path.join(process.cwd(), TWA_MANIFEST_FILE_NAME);
const twaManifest = await TwaManifest.fromFile(manifestFile);

Expand Down Expand Up @@ -247,21 +250,26 @@ async function setupGooglePlay(args: PlayArgs): Promise<GooglePlay> {
return new GooglePlay(twaManifest.serviceAccountJsonFile);
}

export async function play(parsedArgs: PlayArgs,
command: PlayCommand, prompt: Prompt = new InquirerPrompt()): Promise<boolean> {
// TODO(@nohe427): Remove after experimental
if (!await prompt.promptConfirm(enUS.promptExperimentalFeature, false)) {
return true;
export async function play(
args: PlayArgs,
prompt: Prompt = new InquirerPrompt(),
): Promise<boolean> {
if (args._.length < 2) {
throw new Error(enUS.errorMissingArgument(2, args._.length));
}
const googlePlay = await setupGooglePlay(parsedArgs);
const play = new Play(parsedArgs, googlePlay, prompt);
switch (command) {

const googlePlay = await setupGooglePlay(args);
const play = new Play(args, googlePlay, prompt);
const subcommand = args._[1];
switch (subcommand) {
case 'publish':
return await play.runPlayPublish();
return play.runPlayPublish();
case 'versionCheck':
await play.runVersionCheck();
return true;
case 'retain':
return await play.runRetain();
return play.runRetain(prompt);
default:
throw new Error(`Unknown subcommand: ${subcommand}`);
}
}

0 comments on commit df883b0

Please sign in to comment.