-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathrun.ts
195 lines (171 loc) · 4.85 KB
/
run.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// @ts-ignore - clack is ESM and TS complains about that. It works though
import * as clack from '@clack/prompts';
import { abortIfCancelled } from './utils/clack-utils';
import { runReactNativeWizard } from './react-native/react-native-wizard';
import { run as legacyRun } from '../lib/Setup';
import type { PreselectedProject, WizardOptions } from './utils/types';
import { runAndroidWizard } from './android/android-wizard';
import { runAppleWizard } from './apple/apple-wizard';
import { runNextjsWizard } from './nextjs/nextjs-wizard';
import { runNuxtWizard } from './nuxt/nuxt-wizard';
import { runRemixWizard } from './remix/remix-wizard';
import { runSvelteKitWizard } from './sveltekit/sveltekit-wizard';
import { runSourcemapsWizard } from './sourcemaps/sourcemaps-wizard';
import { readEnvironment } from '../lib/Helper/Env';
import type { Platform } from '../lib/Constants';
import type { PackageDotJson } from './utils/package-json';
type WizardIntegration =
| 'reactNative'
| 'ios'
| 'android'
| 'cordova'
| 'electron'
| 'nextjs'
| 'nuxt'
| 'remix'
| 'sveltekit'
| 'sourcemaps';
type Args = {
integration?: WizardIntegration;
uninstall: boolean;
signup: boolean;
skipConnect: boolean;
debug: boolean;
quiet: boolean;
disableTelemetry: boolean;
promoCode?: string;
preSelectedProject?: {
authToken: string;
selfHosted: boolean;
dsn: string;
projectId: string;
projectSlug: string;
projectName: string;
orgId: string;
orgName: string;
orgSlug: string;
};
url?: string;
platform?: Platform[];
org?: string;
project?: string;
saas?: boolean;
};
function preSelectedProjectArgsToObject(
args: Args,
): PreselectedProject | undefined {
if (!args.preSelectedProject) {
return undefined;
}
return {
authToken: args.preSelectedProject.authToken,
selfHosted: args.preSelectedProject.selfHosted,
project: {
id: args.preSelectedProject.projectId,
keys: [
{
dsn: {
public: args.preSelectedProject.dsn,
},
},
],
organization: {
id: args.preSelectedProject.orgId,
name: args.preSelectedProject.orgName,
slug: args.preSelectedProject.orgSlug,
},
slug: args.preSelectedProject.projectSlug,
},
};
}
export async function run(argv: Args) {
const finalArgs = {
...argv,
...readEnvironment(),
};
let integration = finalArgs.integration;
if (!integration) {
clack.intro(`Sentry Wizard ${tryGetWizardVersion()}`);
integration = await abortIfCancelled(
clack.select({
message: 'What do you want to set up?',
options: [
{ value: 'reactNative', label: 'React Native' },
{ value: 'ios', label: 'iOS' },
{ value: 'android', label: 'Android' },
{ value: 'cordova', label: 'Cordova' },
{ value: 'electron', label: 'Electron' },
{ value: 'nextjs', label: 'Next.js' },
{ value: 'nuxt', label: 'Nuxt' },
{ value: 'remix', label: 'Remix' },
{ value: 'sveltekit', label: 'SvelteKit' },
{ value: 'sourcemaps', label: 'Configure Source Maps Upload' },
],
}),
);
if (!integration) {
clack.log.error('No integration selected. Exiting.');
return;
}
clack.outro(`Starting ${integration} setup`);
}
const wizardOptions: WizardOptions = {
telemetryEnabled: !finalArgs.disableTelemetry,
promoCode: finalArgs.promoCode,
url: finalArgs.url,
orgSlug: finalArgs.org,
projectSlug: finalArgs.project,
saas: finalArgs.saas,
preSelectedProject: preSelectedProjectArgsToObject(finalArgs),
};
switch (integration) {
case 'reactNative':
await runReactNativeWizard({
...wizardOptions,
uninstall: finalArgs.uninstall,
});
break;
case 'ios':
await runAppleWizard(wizardOptions);
break;
case 'android':
await runAndroidWizard(wizardOptions);
break;
case 'nextjs':
await runNextjsWizard(wizardOptions);
break;
case 'nuxt':
await runNuxtWizard(wizardOptions);
break;
case 'remix':
await runRemixWizard(wizardOptions);
break;
case 'sveltekit':
await runSvelteKitWizard(wizardOptions);
break;
case 'sourcemaps':
await runSourcemapsWizard(wizardOptions);
break;
case 'cordova':
argv.integration = 'cordova';
void legacyRun(argv);
break;
case 'electron':
argv.integration = 'electron';
void legacyRun(argv);
break;
default:
clack.log.error('No setup wizard selected!');
}
}
/**
* TODO: replace with rollup replace whenever we switch to rollup
*/
function tryGetWizardVersion(): string {
try {
const wizardPkgJson = require('../package.json') as PackageDotJson;
return wizardPkgJson.version ?? '';
} catch {
return '';
}
}