Skip to content

Commit

Permalink
feat(sveltekit): Ask for confirmation before creating example page (#516
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Lms24 authored Dec 15, 2023
1 parent e35f92d commit 77c5f29
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 34 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

## Unreleased

- feat(remix): Add instrumentation step for Express server adapters (#504)
- feat(nextjs): Ask for confirmation before creating example page (#515)
- feat(remix): Add instrumentation step for Express server adapters (#504)
- feat(sveltekit): Add instrumentation step for Express server adapters (#516)
- fix(nextjs): Instruct users to restart dev server after setup (#513)
- ref(sveltekit): Improve Outro Message (#514)

Expand Down
79 changes: 46 additions & 33 deletions src/sveltekit/sveltekit-wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
abort,
abortIfCancelled,
addSentryCliConfig,
askShouldCreateExamplePage,
confirmContinueIfNoOrDirtyGitRepo,
ensurePackageIsInstalled,
getOrAskForProjectData,
Expand Down Expand Up @@ -129,43 +130,55 @@ export async function runSvelteKitWizardWithTelemetry(
return;
}

try {
await traceStep('create-example-page', () =>
createExamplePage(svelteConfig, {
selfHosted,
url: sentryUrl,
orgSlug: selectedProject.organization.slug,
projectId: selectedProject.id,
}),
);
} catch (e: unknown) {
clack.log.error('Error while creating an example page to test Sentry:');
clack.log.info(
chalk.dim(
typeof e === 'object' && e != null && 'toString' in e
? e.toString()
: typeof e === 'string'
? e
: 'Unknown error',
),
);
Sentry.captureException(
'Error while creating an example Svelte page to test Sentry',
);
await abort('Exiting Wizard');
return;
const shouldCreateExamplePage = await askShouldCreateExamplePage(
'sentry-example',
);

if (shouldCreateExamplePage) {
try {
await traceStep('create-example-page', () =>
createExamplePage(svelteConfig, {
selfHosted,
url: sentryUrl,
orgSlug: selectedProject.organization.slug,
projectId: selectedProject.id,
}),
);
} catch (e: unknown) {
clack.log.error('Error while creating an example page to test Sentry:');
clack.log.info(
chalk.dim(
typeof e === 'object' && e != null && 'toString' in e
? e.toString()
: typeof e === 'string'
? e
: 'Unknown error',
),
);
Sentry.captureException(
'Error while creating an example Svelte page to test Sentry',
);
await abort('Exiting Wizard');
return;
}
}

clack.outro(buildOutroMessage(shouldCreateExamplePage));
}

function buildOutroMessage(shouldCreateExamplePage: boolean): string {
const packageManager = detectPackageManger() || NPM;

clack.outro(`
${chalk.green('Successfully installed the Sentry SvelteKit SDK!')}
let msg = chalk.green('\nSuccessfully installed the Sentry SvelteKit SDK!');

if (shouldCreateExamplePage) {
msg += `\n\nYou can validate your setup by starting your dev environment (${chalk.cyan(
`\`${packageManager.runScriptCommand} dev\``,
)}) and visiting ${chalk.cyan('"/sentry-example"')}.`;
}

You can validate your setup by starting your dev environment (${chalk.cyan(
`\`${packageManager.runScriptCommand} dev\``,
)}) and visiting ${chalk.cyan('"/sentry-example"')}.
msg += `\n\nCheck out the SDK documentation for further configuration:
https://docs.sentry.io/platforms/javascript/guides/sveltekit/`;

Check out the SDK documentation for further configuration:
https://docs.sentry.io/platforms/javascript/guides/sveltekit/
`);
return msg;
}

0 comments on commit 77c5f29

Please sign in to comment.