@posthog/wizard
Version:
The PostHog wizard helps you to configure your project
137 lines • 4.79 kB
JavaScript
#!/usr/bin/env node
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const semver_1 = require("semver");
const logging_1 = require("./src/utils/logging");
const yargs_1 = __importDefault(require("yargs"));
const helpers_1 = require("yargs/helpers");
const NODE_VERSION_RANGE = '>=18.17.0';
// Have to run this above the other imports because they are importing clack that
// has the problematic imports.
if (!(0, semver_1.satisfies)(process.version, NODE_VERSION_RANGE)) {
(0, logging_1.red)(`PostHog wizard requires Node.js ${NODE_VERSION_RANGE}. You are using Node.js ${process.version}. Please upgrade your Node.js version.`);
process.exit(1);
}
const mcp_1 = require("./src/mcp");
const run_1 = require("./src/run");
const event_setup_1 = require("./src/nextjs/event-setup");
const environment_1 = require("./src/utils/environment");
const path_1 = __importDefault(require("path"));
if (process.env.NODE_ENV === 'test') {
void (async () => {
try {
const { server } = await import('./e2e-tests/mocks/server.js');
server.listen({
onUnhandledRequest: 'bypass',
});
}
catch (error) {
// Mock server import failed - this can happen during non-E2E tests
}
})();
}
(0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
.env('POSTHOG_WIZARD')
// global options
.options({
debug: {
default: false,
describe: 'Enable verbose logging\nenv: POSTHOG_WIZARD_DEBUG',
type: 'boolean',
},
region: {
describe: 'PostHog cloud region\nenv: POSTHOG_WIZARD_REGION',
choices: ['us', 'eu'],
type: 'string',
},
default: {
default: true,
describe: 'Use default options for all prompts\nenv: POSTHOG_WIZARD_DEFAULT',
type: 'boolean',
},
signup: {
default: false,
describe: 'Create a new PostHog account during setup\nenv: POSTHOG_WIZARD_SIGNUP',
type: 'boolean',
},
})
.command(['$0'], 'Run the PostHog setup wizard', (yargs) => {
return yargs.options({
'force-install': {
default: false,
describe: 'Force install packages even if peer dependency checks fail\nenv: POSTHOG_WIZARD_FORCE_INSTALL',
type: 'boolean',
},
'install-dir': {
describe: 'Directory to install PostHog in\nenv: POSTHOG_WIZARD_INSTALL_DIR',
type: 'string',
},
integration: {
describe: 'Integration to set up',
choices: ['nextjs', 'astro', 'react', 'svelte', 'react-native'],
type: 'string',
},
});
}, (argv) => {
const options = { ...argv };
void (0, run_1.runWizard)(options);
})
.command('event-setup', 'Run the event setup wizard', (yargs) => {
return yargs.options({
'install-dir': {
describe: 'Directory to run the wizard in\nenv: POSTHOG_WIZARD_INSTALL_DIR',
type: 'string',
},
});
}, (argv) => {
const finalArgs = {
...argv,
...(0, environment_1.readEnvironment)(),
};
let resolvedInstallDir;
if (finalArgs.installDir) {
if (path_1.default.isAbsolute(finalArgs.installDir)) {
resolvedInstallDir = finalArgs.installDir;
}
else {
resolvedInstallDir = path_1.default.join(process.cwd(), finalArgs.installDir);
}
}
else {
resolvedInstallDir = process.cwd();
}
const wizardOptions = {
debug: finalArgs.debug ?? false,
installDir: resolvedInstallDir,
cloudRegion: finalArgs.region,
default: finalArgs.default ?? false,
signup: finalArgs.signup ?? false,
forceInstall: false,
};
void (0, event_setup_1.runEventSetupWizard)(wizardOptions);
})
.command('mcp <command>', 'MCP server management commands', (yargs) => {
return yargs
.command('add', 'Install PostHog MCP server to supported clients', (yargs) => {
return yargs.options({});
}, (argv) => {
const options = { ...argv };
void (0, mcp_1.runMCPInstall)(options);
})
.command('remove', 'Remove PostHog MCP server from supported clients', (yargs) => {
return yargs.options({});
}, () => {
void (0, mcp_1.runMCPRemove)();
})
.demandCommand(1, 'You must specify a subcommand (add or remove)')
.help();
})
.help()
.alias('help', 'h')
.version()
.alias('version', 'v')
.wrap(process.stdout.isTTY ? yargs_1.default.terminalWidth() : 80).argv;
//# sourceMappingURL=bin.js.map