Skip to content
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/nextjs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -82,6 +83,7 @@ export async function getNextJsRouter({
},
],
}),
Integration.nextjs,
);

return result;
Expand Down
40 changes: 25 additions & 15 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/steps/add-editor-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const addEditorRulesStep = async ({
},
],
}),
integration,
);

if (!addEditorRules) {
Expand Down
1 change: 1 addition & 0 deletions src/steps/create-pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export async function createPRStep({
},
],
}),
integration,
);

if (!createPR) {
Expand Down
1 change: 1 addition & 0 deletions src/steps/upload-environment-variables/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const uploadEnvironmentVariablesStep = async (
},
],
}),
integration,
);

if (!upload) {
Expand Down
13 changes: 12 additions & 1 deletion src/utils/clack-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,11 +66,20 @@ export async function abort(message?: string, status?: number): Promise<never> {

export async function abortIfCancelled<T>(
input: T | Promise<T>,
integration?: Integration,
): Promise<Exclude<T, symbol>> {
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<T, symbol>;
Expand Down
Loading