Skip to content

Commit

Permalink
feat(nuxt): Add Nuxt menu option and install SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiborza committed Nov 14, 2024
1 parent b724bb9 commit 77378e7
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
88 changes: 88 additions & 0 deletions src/nuxt/nuxt-wizard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// @ts-ignore - clack is ESM and TS complains about that. It works though
import * as clack from '@clack/prompts';
import * as Sentry from '@sentry/node';
import { lt, minVersion } from 'semver';
import type { WizardOptions } from '../utils/types';
import { withTelemetry } from '../telemetry';
import {
abort,
abortIfCancelled,
addDotEnvSentryBuildPluginFile,
confirmContinueIfNoOrDirtyGitRepo,
ensurePackageIsInstalled,
getOrAskForProjectData,
getPackageDotJson,
installPackage,
printWelcome,
} from '../utils/clack-utils';
import { getPackageVersion, hasPackageInstalled } from '../utils/package-json';

export function runNuxtWizard(options: WizardOptions) {
return withTelemetry(
{
enabled: options.telemetryEnabled,
integration: 'nuxt',
wizardOptions: options,
},
() => runNuxtWizardWithTelemetry(options),
);
}

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

await confirmContinueIfNoOrDirtyGitRepo();

const packageJson = await getPackageDotJson();

await ensurePackageIsInstalled(packageJson, 'nuxt', 'Nuxt');

const nuxtVersion = getPackageVersion('nuxt', packageJson);
Sentry.setTag('nuxt-version', nuxtVersion);

const minVer = minVersion(nuxtVersion || 'none');

if (!nuxtVersion || !minVer || lt(minVer, '3.13.2')) {
clack.log.warn(
"It seems you're using a Nuxt version <3.13.2 which is not supported by Sentry.\nWe recommend upgrading to the latest version before you continue.",
);
const shouldContinue = await abortIfCancelled(
clack.select({
message: 'Do you want to continue anyway?',
options: [
{
label: 'Yes, continue',
hint: 'The SDK might not work correctly',
value: true,
},
{ label: "No, I'll upgrade first", value: false },
],
}),
);
if (!shouldContinue) {
await abort('Exiting Wizard', 0);
return;
}
}

const { authToken } = await getOrAskForProjectData(
options,
'javascript-nuxt',
);

const sdkAlreadyInstalled = hasPackageInstalled('@sentry/nuxt', packageJson);
Sentry.setTag('sdk-already-installed', sdkAlreadyInstalled);

await installPackage({
packageName: '@sentry/nuxt',
alreadyInstalled: sdkAlreadyInstalled,
});

await addDotEnvSentryBuildPluginFile(authToken);
}
7 changes: 7 additions & 0 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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';
Expand All @@ -22,6 +23,7 @@ type WizardIntegration =
| 'cordova'
| 'electron'
| 'nextjs'
| 'nuxt'
| 'remix'
| 'sveltekit'
| 'sourcemaps';
Expand Down Expand Up @@ -103,6 +105,7 @@ export async function run(argv: Args) {
{ 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' },
Expand Down Expand Up @@ -148,6 +151,10 @@ export async function run(argv: Args) {
await runNextjsWizard(wizardOptions);
break;

case 'nuxt':
await runNuxtWizard(wizardOptions);
break;

case 'remix':
await runRemixWizard(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 @@ -850,6 +850,7 @@ export async function getOrAskForProjectData(
options: WizardOptions,
platform?:
| 'javascript-nextjs'
| 'javascript-nuxt'
| 'javascript-remix'
| 'javascript-sveltekit'
| 'apple-ios'
Expand Down Expand Up @@ -1011,6 +1012,7 @@ async function askForWizardLogin(options: {
promoCode?: string;
platform?:
| 'javascript-nextjs'
| 'javascript-nuxt'
| 'javascript-remix'
| 'javascript-sveltekit'
| 'apple-ios'
Expand Down

0 comments on commit 77378e7

Please sign in to comment.