diff --git a/packages/cli/README.md b/packages/cli/README.md index bb28f5f7..4d3e404a 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -41,7 +41,7 @@ use `bubblewrap [cmd]`. ### Installing Bubblewrap -```shell +```bash npm i -g @bubblewrap/cli ``` @@ -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 ``` @@ -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 ``` @@ -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=`: path to the Trusted Web Activity configuration.', @@ -283,37 +284,46 @@ 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: @@ -321,12 +331,12 @@ Options: - `--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: diff --git a/packages/cli/src/lib/Cli.ts b/packages/cli/src/lib/Cli.ts index e9254549..31532bb0 100644 --- a/packages/cli/src/lib/Cli.ts +++ b/packages/cli/src/lib/Cli.ts @@ -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 { @@ -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`); diff --git a/packages/cli/src/lib/cmds/fingerprint.ts b/packages/cli/src/lib/cmds/fingerprint.ts index 8ecfdc61..4154b2ba 100644 --- a/packages/cli/src/lib/cmds/fingerprint.ts +++ b/packages/cli/src/lib/cmds/fingerprint.ts @@ -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'; diff --git a/packages/cli/src/lib/cmds/help.ts b/packages/cli/src/lib/cmds/help.ts index a34736b9..ad7b056d 100644 --- a/packages/cli/src/lib/cmds/help.ts +++ b/packages/cli/src/lib/cmds/help.ts @@ -168,6 +168,52 @@ const HELP_MESSAGES = new Map( ' --output= .... path from where to load the project configuration.', '', ].join('\n')], + ['play', [ + 'Usage:', + '', + '', + 'bubblewrap play [subcommand]', + '', + ' Global play flags: ', + ' --serviceAccountFile= . Path to the the service account JSON file to set in', + ' the twa-manifest.', + ' --manifest= ....... 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:', + ' --track= ............ A Google Play Store track to publish the bundle to', + ' (defaults to internal track).', + ' --appBundleLocation= . 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:', + ' --add= ....... Bundles to retain for 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 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:', + ' --targetDirectory= . The directory that versionCheck should run in', + ' (defaults to the current directory). This', + ' should be your bubblewrap project directory.', + '', + ].join('\n')], ], ); diff --git a/packages/cli/src/lib/cmds/play.ts b/packages/cli/src/lib/cmds/play.ts index 7789847a..1d0fb68a 100644 --- a/packages/cli/src/lib/cmds/play.ts +++ b/packages/cli/src/lib/cmds/play.ts @@ -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'; @@ -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; @@ -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. */ @@ -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 { + async runRetain(prompt: Prompt): Promise { + // 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); @@ -247,21 +250,26 @@ async function setupGooglePlay(args: PlayArgs): Promise { return new GooglePlay(twaManifest.serviceAccountJsonFile); } -export async function play(parsedArgs: PlayArgs, - command: PlayCommand, prompt: Prompt = new InquirerPrompt()): Promise { - // 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 { + 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}`); } }