Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Angular Wizard #767

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- feat: Add Angular Wizard ([#767](https://github.com/getsentry/sentry-wizard/pull/767))

## 3.39.0

- Always send platform query param to auth page ([#757](https://github.com/getsentry/sentry-wizard/pull/757))
Expand Down Expand Up @@ -28,7 +32,7 @@
- feat: Pin JS SDK versions to v8 (#712)
- Remove enableTracing for Cocoa ([#715](https://github.com/getsentry/sentry-wizard/pull/715))
- feat(nuxt): Add nuxt wizard ([#719](https://github.com/getsentry/sentry-wizard/pull/719))

Set up the Sentry Nuxt SDK in your app with one command:

```sh
Expand Down
3 changes: 3 additions & 0 deletions lib/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export enum Integration {
ios = 'ios',
android = 'android',
cordova = 'cordova',
angular = 'angular',
electron = 'electron',
nextjs = 'nextjs',
nuxt = 'nuxt',
Expand Down Expand Up @@ -68,6 +69,8 @@ export function mapIntegrationToPlatform(type: string): string | undefined {
return 'react-native';
case Integration.cordova:
return 'cordova';
case Integration.angular:
return 'javascript-angular';
case Integration.electron:
return 'javascript-electron';
case Integration.nextjs:
Expand Down
114 changes: 114 additions & 0 deletions src/angular/angular-wizard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */

// @ts-expect-error - clack is ESM and TS complains about that. It works though
import clack from '@clack/prompts';

import chalk from 'chalk';
import type { WizardOptions } from '../utils/types';
import { withTelemetry } from '../telemetry';
import {
abortIfCancelled,
confirmContinueIfNoOrDirtyGitRepo,
ensurePackageIsInstalled,
getPackageDotJson,
installPackage,
printWelcome,
} from '../utils/clack-utils';
import { getPackageVersion, hasPackageInstalled } from '../utils/package-json';
import { gte, minVersion, SemVer } from 'semver';

import * as Sentry from '@sentry/node';

const MIN_SUPPORTED_ANGULAR_VERSION = '14.0.0';

export async function runAngularWizard(options: WizardOptions): Promise<void> {
return withTelemetry(
{
enabled: options.telemetryEnabled,
integration: 'angular',
wizardOptions: options,
},
() => runAngularWizardWithTelemetry(options),
);
}

async function runAngularWizardWithTelemetry(
options: WizardOptions,
): Promise<void> {
printWelcome({
wizardName: 'Sentry Angular Wizard',
promoCode: options.promoCode,
telemetryEnabled: options.telemetryEnabled,
});

await confirmContinueIfNoOrDirtyGitRepo();

const packageJson = await getPackageDotJson();

await ensurePackageIsInstalled(packageJson, '@angular/core', 'Angular');

let installedAngularVersion = getPackageVersion('@angular/core', packageJson);

if (!installedAngularVersion) {
clack.log.warn('Could not determine installed Angular version.');

installedAngularVersion = await abortIfCancelled(
clack.text({
message: `Please enter your installed Angular major version (e.g. ${chalk.cyan(
'18',
)} for Angular 18)`,
validate(value) {
if (!value) {
return 'Angular version is required';
}

try {
if (!minVersion(value)) {
return `Invalid Angular version provided: ${value}`;
}
} catch (error) {
return `Invalid Angular version provided: ${value}`;
}
},
}),
);
}

Sentry.setTag('angular-version', installedAngularVersion);

const installedMinVersion = minVersion(installedAngularVersion) as SemVer;

const isSupportedAngularVersion = gte(
installedMinVersion,
MIN_SUPPORTED_ANGULAR_VERSION,
);

if (!isSupportedAngularVersion) {
clack.log.warn(
`Angular version ${chalk.cyan(
MIN_SUPPORTED_ANGULAR_VERSION,
)} or higher is required.`,
);
clack.log.warn(
`Please refer to Sentry's version compatibility table for more information:
${chalk.underline(
'https://docs.sentry.io/platforms/javascript/guides/angular/#angular-version-compatibility',
)}`,
);

return;
}

const sdkAlreadyInstalled = hasPackageInstalled(
'@sentry/angular',
packageJson,
);

Sentry.setTag('sdk-already-installed', sdkAlreadyInstalled);

await installPackage({
packageName: '@sentry/angular@^8',
packageNameDisplayLabel: '@sentry/angular',
alreadyInstalled: sdkAlreadyInstalled,
});
}
7 changes: 7 additions & 0 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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 { runAngularWizard } from './angular/angular-wizard';
import { runAppleWizard } from './apple/apple-wizard';
import { runNextjsWizard } from './nextjs/nextjs-wizard';
import { runNuxtWizard } from './nuxt/nuxt-wizard';
Expand All @@ -17,6 +18,7 @@ import type { Platform } from '../lib/Constants';
import type { PackageDotJson } from './utils/package-json';

type WizardIntegration =
| 'angular'
| 'reactNative'
| 'ios'
| 'android'
Expand Down Expand Up @@ -101,6 +103,7 @@ export async function run(argv: Args) {
options: [
{ value: 'reactNative', label: 'React Native' },
{ value: 'ios', label: 'iOS' },
{ value: 'angular', label: 'Angular' },
{ value: 'android', label: 'Android' },
{ value: 'cordova', label: 'Cordova' },
{ value: 'electron', label: 'Electron' },
Expand Down Expand Up @@ -147,6 +150,10 @@ export async function run(argv: Args) {
await runAndroidWizard(wizardOptions);
break;

case 'angular':
await runAngularWizard(wizardOptions);
break;

case 'nextjs':
await runNextjsWizard(wizardOptions);
break;
Expand Down
2 changes: 2 additions & 0 deletions src/utils/clack-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@ export function isUsingTypeScript() {
export async function getOrAskForProjectData(
options: WizardOptions,
platform?:
| 'javascript-angular'
| 'javascript-nextjs'
| 'javascript-nuxt'
| 'javascript-remix'
Expand Down Expand Up @@ -1037,6 +1038,7 @@ async function askForWizardLogin(options: {
url: string;
promoCode?: string;
platform?:
| 'javascript-angular'
| 'javascript-nextjs'
| 'javascript-nuxt'
| 'javascript-remix'
Expand Down
Loading