From 42ce9a0504a9a23be215067d9b76ffa00d682ec5 Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Mon, 22 Dec 2025 12:33:07 +0100 Subject: [PATCH] init the setup command --- packages/cli/src/lib/plugins/remoteCache.ts | 27 ++++++- packages/cli/src/lib/utils/prompts.ts | 87 +++++++++++++++++++++ 2 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 packages/cli/src/lib/utils/prompts.ts diff --git a/packages/cli/src/lib/plugins/remoteCache.ts b/packages/cli/src/lib/plugins/remoteCache.ts index 26a83b126..f18d8d790 100644 --- a/packages/cli/src/lib/plugins/remoteCache.ts +++ b/packages/cli/src/lib/plugins/remoteCache.ts @@ -25,6 +25,10 @@ import { templateIndexHtmlIOS, templateManifestPlist, } from '../adHocTemplates.js'; +import { + promptRemoteCacheProvider, + promptRemoteCacheProviderArgs, +} from '../utils/prompts.js'; type Flags = { platform?: 'ios' | 'android'; @@ -317,6 +321,25 @@ ${deletedArtifacts console.log(remoteBuildCache.name); break; } + case 'setup': { + if (remoteBuildCache) { + console.log( + `You already have a remote build cache setup with ${remoteBuildCache.name}`, + ); + break; + } + + // Prompt duplicates from https://github.com/callstack/rock/blob/626ccf8f585afeec323e17727bc541ddbed829bf/packages/create-app/src/lib/utils/prompts.ts + const provider = await promptRemoteCacheProvider(); + const args = provider + ? await promptRemoteCacheProviderArgs(provider) + : null; + + // Setup remote build cache + // await remoteBuildCache.setup(providerName, args); + console.log(`Remote build cache setup with ${provider}: ${args}`); + break; + } } return null; @@ -503,7 +526,7 @@ export const remoteCachePlugin = { name: '[action]', description: - 'Select action, e.g. list, list-all, download, upload, delete, get-provider-name', + 'Select action, e.g. setup, list, list-all, download, upload, delete, get-provider-name', }, ], options: [ @@ -532,7 +555,7 @@ export const remoteCachePlugin = }, { name: '-t, --traits ', - description: `Comma-separated traits that construct final artifact name. Traits for Android are: variant; for iOS: destination and configuration. + description: `Comma-separated traits that construct final artifact name. Traits for Android are: variant; for iOS: destination and configuration. Example iOS: --traits simulator,Release Example Android: --traits debug Example Harmony: --traits debug`, diff --git a/packages/cli/src/lib/utils/prompts.ts b/packages/cli/src/lib/utils/prompts.ts new file mode 100644 index 000000000..aa81bff67 --- /dev/null +++ b/packages/cli/src/lib/utils/prompts.ts @@ -0,0 +1,87 @@ +import { + color, + note, + promptGroup, + promptSelect, + promptText, + type SupportedRemoteCacheProviders, +} from '@rock-js/tools'; + +export function promptRemoteCacheProvider() { + return promptSelect({ + message: 'What do you want to use as cache for your remote builds?', + initialValue: 'github-actions', + options: [ + { + value: 'github-actions', + label: 'GitHub Actions', + hint: 'The easiest way to start if you store your code on GitHub', + }, + { + value: 's3', + label: 'S3', + hint: 'Work with any S3-compatible storage, including AWS S3 and Cloudflare R2', + }, + { + value: null, + label: 'None', + hint: `Local cache only which isn't shared across team members or CI/CD environments`, + }, + ], + }); +} + +export function promptRemoteCacheProviderArgs( + provider: SupportedRemoteCacheProviders, +) { + const environmentVariablesTitle = + 'Ensure the below environment variables are set'; + + switch (provider) { + case 'github-actions': + note( + [ + `GITHUB_TOKEN Your GitHub personal access token (PAT)`, + '', + `💡 Set this in your ${color.bold('.env')} file or pass it as an argument to ${color.bold('run:*')} commands.`, + ].join('\n'), + environmentVariablesTitle, + ); + + return promptGroup({ + owner: () => promptText({ message: 'GitHub repository owner' }), + repository: () => promptText({ message: 'GitHub repository name' }), + }); + case 's3': + note( + [ + `AWS_ACCESS_KEY_ID Your AWS access key ID`, + `AWS_SECRET_ACCESS_KEY Your AWS secret access key`, + '', + `💡 Set these in your ${color.bold('.env')} file or pass them as arguments to ${color.bold('run:*')} commands.`, + ].join('\n'), + environmentVariablesTitle, + ); + + return promptGroup({ + bucket: () => + promptText({ + message: 'Pass your bucket name:', + placeholder: 'bucket-name', + defaultValue: 'bucket-name', + }), + region: () => + promptText({ + message: 'Pass your bucket region:', + placeholder: 'us-west-1', + defaultValue: 'us-west-1', + }), + endpoint: () => + promptText({ + message: `If you're using self-hosted S3 or Cloudflare R2, pass your endpoint ${color.dim('(Press to skip)')}:`, + placeholder: 'https://.r2.cloudflarestorage.com', + defaultValue: undefined, + }), + }); + } +}