-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nuxt): Add Nuxt menu option and install SDK
- Loading branch information
1 parent
b724bb9
commit 77378e7
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters