Skip to content

Commit f2674bf

Browse files
authored
refactor(apple-wizard): move configure fastlane to separate file (#912)
1 parent d95c123 commit f2674bf

File tree

2 files changed

+60
-29
lines changed

2 files changed

+60
-29
lines changed

src/apple/apple-wizard.ts

+7-29
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { traceStep, withTelemetry } from '../telemetry';
1111
import * as SentryUtils from '../utils/sentrycli-utils';
1212
import * as cocoapod from './cocoapod';
1313
import * as codeTools from './code-tools';
14-
import * as fastlane from './fastlane';
1514

1615
/* eslint-enable @typescript-eslint/no-unused-vars */
1716

@@ -22,6 +21,7 @@ import {
2221
printWelcome,
2322
} from '../utils/clack';
2423
import { checkInstalledCLI } from './check-installed-cli';
24+
import { configureFastlane } from './configure-fastlane';
2525
import { lookupXcodeProject } from './lookup-xcode-project';
2626
import { AppleWizardOptions } from './options';
2727

@@ -134,34 +134,12 @@ Set the ${chalk.cyan(
134134
);
135135
}
136136

137-
const hasFastlane = fastlane.fastFile(projectDir);
138-
Sentry.setTag('fastlane-exists', hasFastlane);
139-
if (hasFastlane) {
140-
const addLane = await clack.confirm({
141-
message:
142-
'Found a Fastfile in your project. Do you want to configure a lane to upload debug symbols to Sentry?',
143-
});
144-
Sentry.setTag('fastlane-desired', addLane);
145-
if (addLane) {
146-
const added = await traceStep('Configure fastlane', () =>
147-
fastlane.addSentryToFastlane(
148-
projectDir,
149-
selectedProject.organization.slug,
150-
selectedProject.slug,
151-
),
152-
);
153-
Sentry.setTag('fastlane-added', added);
154-
if (added) {
155-
clack.log.step(
156-
'A new step was added to your fastlane file. Now and you build your project with fastlane, debug symbols and source context will be uploaded to Sentry.',
157-
);
158-
} else {
159-
clack.log.warn(
160-
'Could not edit your fastlane file to upload debug symbols to Sentry. Please follow the instructions at https://docs.sentry.io/platforms/apple/guides/ios/dsym/#fastlane',
161-
);
162-
}
163-
}
164-
}
137+
// Step - Fastlane Configuration
138+
await configureFastlane({
139+
projectDir,
140+
orgSlug: selectedProject.organization.slug,
141+
projectSlug: selectedProject.slug,
142+
});
165143

166144
clack.log.success(
167145
'Sentry was successfully added to your project! Run your project to send your first event to Sentry. Go to Sentry.io to see whether everything is working fine.',

src/apple/configure-fastlane.ts

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// @ts-expect-error - clack is ESM and TS complains about that. It works though
2+
import clack from '@clack/prompts';
3+
import * as Sentry from '@sentry/node';
4+
import chalk from 'chalk';
5+
import { traceStep } from '../telemetry';
6+
import { debug } from '../utils/debug';
7+
import * as fastlane from './fastlane';
8+
9+
export async function configureFastlane({
10+
projectDir,
11+
orgSlug,
12+
projectSlug,
13+
}: {
14+
projectDir: string;
15+
orgSlug: string;
16+
projectSlug: string;
17+
}) {
18+
debug(`Checking if Fastfile exists in directory: ${chalk.cyan(projectDir)}`);
19+
const isFastlaneAvailable = fastlane.fastFile(projectDir);
20+
Sentry.setTag('fastlane-exists', isFastlaneAvailable);
21+
if (!isFastlaneAvailable) {
22+
debug(`Fastfile not found, not configuring Fastlane`);
23+
// If fastlane is not available, we don't need to configure it and exit early.
24+
return;
25+
}
26+
27+
debug(`Fastfile found, asking user if they want to configure Fastlane`);
28+
const shouldAddLane = await clack.confirm({
29+
message:
30+
'Found a Fastfile in your project. Do you want to configure a lane to upload debug symbols to Sentry?',
31+
});
32+
debug(`User wants to add lane: ${chalk.cyan(shouldAddLane.toString())}`);
33+
Sentry.setTag('fastlane-desired', shouldAddLane);
34+
35+
if (shouldAddLane) {
36+
debug(`Adding Sentry lane to Fastlane`);
37+
const added = await traceStep('Configure fastlane', () =>
38+
fastlane.addSentryToFastlane(projectDir, orgSlug, projectSlug),
39+
);
40+
Sentry.setTag('fastlane-added', added);
41+
debug(`Fastlane added: ${chalk.cyan(added.toString())}`);
42+
43+
if (added) {
44+
clack.log.step(
45+
'A new step was added to your fastlane file. Now and you build your project with fastlane, debug symbols and source context will be uploaded to Sentry.',
46+
);
47+
} else {
48+
clack.log.warn(
49+
'Could not edit your fastlane file to upload debug symbols to Sentry. Please follow the instructions at https://docs.sentry.io/platforms/apple/guides/ios/dsym/#fastlane',
50+
);
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)