diff --git a/package.json b/package.json index 96a465be..4aade59d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@posthog/wizard", - "version": "0.8.0", + "version": "0.8.1", "homepage": "https://github.com/posthog/wizard", "repository": "https://github.com/posthog/wizard", "description": "The PostHog wizard helps you to configure your project", diff --git a/src/nextjs/utils.ts b/src/nextjs/utils.ts index bbf6e016..72168a4f 100644 --- a/src/nextjs/utils.ts +++ b/src/nextjs/utils.ts @@ -3,6 +3,7 @@ import fg from 'fast-glob'; import { abortIfCancelled } from '../utils/clack-utils'; import clack from '../utils/clack'; import type { WizardOptions } from '../utils/types'; +import { Integration } from '../lib/constants'; export function getNextJsVersionBucket(version: string | undefined) { if (!version) { @@ -82,6 +83,7 @@ export async function getNextJsRouter({ }, ], }), + Integration.nextjs, ); return result; diff --git a/src/run.ts b/src/run.ts index 4e86a245..16e2ca85 100644 --- a/src/run.ts +++ b/src/run.ts @@ -13,6 +13,7 @@ import { analytics } from './utils/analytics'; import { runSvelteWizard } from './svelte/svelte-wizard'; import { runReactNativeWizard } from './react-native/react-native-wizard'; import { EventEmitter } from 'events'; +import chalk from 'chalk'; EventEmitter.defaultMaxListeners = 50; @@ -54,21 +55,30 @@ async function runWizard(argv: Args) { analytics.setTag('integration', integration); - switch (integration) { - case Integration.nextjs: - await runNextjsWizard(wizardOptions); - break; - case Integration.react: - await runReactWizard(wizardOptions); - break; - case Integration.svelte: - await runSvelteWizard(wizardOptions); - break; - case Integration.reactNative: - await runReactNativeWizard(wizardOptions); - break; - default: - clack.log.error('No setup wizard selected!'); + try { + switch (integration) { + case Integration.nextjs: + await runNextjsWizard(wizardOptions); + break; + case Integration.react: + await runReactWizard(wizardOptions); + break; + case Integration.svelte: + await runSvelteWizard(wizardOptions); + break; + case Integration.reactNative: + await runReactNativeWizard(wizardOptions); + break; + default: + clack.log.error('No setup wizard selected!'); + } + } catch (error) { + clack.log.error( + `Something went wrong. You can read the documentation for PostHog at ${chalk.cyan( + `${INTEGRATION_CONFIG[integration].docsUrl}`, + )} to setup PostHog manually.`, + ); + process.exit(1); } } diff --git a/src/steps/add-editor-rules.ts b/src/steps/add-editor-rules.ts index 8a1ed2a4..13f563e8 100644 --- a/src/steps/add-editor-rules.ts +++ b/src/steps/add-editor-rules.ts @@ -41,6 +41,7 @@ export const addEditorRulesStep = async ({ }, ], }), + integration, ); if (!addEditorRules) { diff --git a/src/steps/create-pr.ts b/src/steps/create-pr.ts index ad194105..eb233b0a 100644 --- a/src/steps/create-pr.ts +++ b/src/steps/create-pr.ts @@ -232,6 +232,7 @@ export async function createPRStep({ }, ], }), + integration, ); if (!createPR) { diff --git a/src/steps/upload-environment-variables/index.ts b/src/steps/upload-environment-variables/index.ts index ec1036db..713cff20 100644 --- a/src/steps/upload-environment-variables/index.ts +++ b/src/steps/upload-environment-variables/index.ts @@ -55,6 +55,7 @@ export const uploadEnvironmentVariablesStep = async ( }, ], }), + integration, ); if (!upload) { diff --git a/src/utils/clack-utils.ts b/src/utils/clack-utils.ts index e64c6ec3..ea5b9ebe 100644 --- a/src/utils/clack-utils.ts +++ b/src/utils/clack-utils.ts @@ -21,10 +21,12 @@ import { DEFAULT_HOST_URL, DUMMY_PROJECT_API_KEY, ISSUES_URL, + type Integration, } from '../lib/constants'; import { analytics } from './analytics'; import clack from './clack'; import { getCloudUrlFromRegion } from './urls'; +import { INTEGRATION_CONFIG } from '../lib/config'; interface ProjectData { projectApiKey: string; @@ -64,11 +66,20 @@ export async function abort(message?: string, status?: number): Promise { export async function abortIfCancelled( input: T | Promise, + integration?: Integration, ): Promise> { await analytics.shutdown('cancelled'); if (clack.isCancel(await input)) { - clack.cancel('Wizard setup cancelled.'); + const docsUrl = integration + ? INTEGRATION_CONFIG[integration].docsUrl + : 'https://posthog.com/docs'; + + clack.cancel( + `Wizard setup cancelled. You can read the documentation for ${ + integration ?? 'PostHog' + } at ${chalk.cyan(docsUrl)} to continue with the setup manually.`, + ); process.exit(0); } else { return input as Exclude;