Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions packages/cli/src/lib/plugins/remoteCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import {
templateIndexHtmlIOS,
templateManifestPlist,
} from '../adHocTemplates.js';
import {
promptRemoteCacheProvider,
promptRemoteCacheProviderArgs,
} from '../utils/prompts.js';

type Flags = {
platform?: 'ios' | 'android';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -532,7 +555,7 @@ export const remoteCachePlugin =
},
{
name: '-t, --traits <list>',
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`,
Expand Down
87 changes: 87 additions & 0 deletions packages/cli/src/lib/utils/prompts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import {
color,
note,
promptGroup,
promptSelect,
promptText,
type SupportedRemoteCacheProviders,
} from '@rock-js/tools';

export function promptRemoteCacheProvider() {
return promptSelect<SupportedRemoteCacheProviders | null>({
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 <enter> to skip)')}:`,
placeholder: 'https://<ACCOUNT_ID>.r2.cloudflarestorage.com',
defaultValue: undefined,
}),
});
}
}
Loading