UNPKG

@posthog/wizard

Version:

The PostHog wizard helps you to configure your project

183 lines 8.13 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.runLaravelWizardAgent = runLaravelWizardAgent; const debug_1 = require("../utils/debug"); const agent_runner_1 = require("../lib/agent-runner"); const constants_1 = require("../lib/constants"); const clack_1 = __importDefault(require("../utils/clack")); const chalk_1 = __importDefault(require("chalk")); const semver = __importStar(require("semver")); const utils_1 = require("./utils"); /** * Laravel framework configuration for the universal agent runner */ const MINIMUM_LARAVEL_VERSION = '9.0.0'; const LARAVEL_AGENT_CONFIG = { metadata: { name: 'Laravel', integration: constants_1.Integration.laravel, docsUrl: 'https://posthog.com/docs/libraries/php', unsupportedVersionDocsUrl: 'https://posthog.com/docs/libraries/php', gatherContext: async (options) => { const projectType = await (0, utils_1.getLaravelProjectType)(options); const serviceProvider = await (0, utils_1.findLaravelServiceProvider)(options); const bootstrapFile = (0, utils_1.findLaravelBootstrapFile)(options); const laravelStructure = (0, utils_1.detectLaravelStructure)(options); return { projectType, serviceProvider, bootstrapFile, laravelStructure, }; }, }, detection: { packageName: 'laravel/framework', packageDisplayName: 'Laravel', usesPackageJson: false, getVersion: (_packageJson) => { // For Laravel, we don't use package.json. Version is extracted separately // from composer.json in the wizard entry point return undefined; }, getVersionBucket: utils_1.getLaravelVersionBucket, }, environment: { uploadToHosting: false, getEnvVars: (apiKey, host) => ({ POSTHOG_API_KEY: apiKey, POSTHOG_HOST: host, }), }, analytics: { getTags: (context) => { const projectType = context.projectType; return { projectType: projectType || 'unknown', laravelStructure: context.laravelStructure || 'unknown', }; }, }, prompts: { projectTypeDetection: 'This is a PHP/Laravel project. Look for composer.json, artisan CLI, and app/ directory structure to confirm. Check for Laravel-specific packages like laravel/framework.', packageInstallation: 'Use Composer to install packages. Run `composer require posthog/posthog-php` without pinning a specific version.', getAdditionalContextLines: (context) => { const projectType = context.projectType; const projectTypeName = projectType ? (0, utils_1.getLaravelProjectTypeName)(projectType) : 'unknown'; const lines = [ `Project type: ${projectTypeName}`, `Framework docs ID: php (use posthog://docs/frameworks/php for documentation)`, `Laravel structure: ${context.laravelStructure} (affects where to add configuration)`, ]; if (context.serviceProvider) { lines.push(`Service provider: ${context.serviceProvider}`); } if (context.bootstrapFile) { lines.push(`Bootstrap file: ${context.bootstrapFile}`); } // Add Laravel-specific guidance based on version structure if (context.laravelStructure === 'latest') { lines.push('Note: Laravel 11+ uses simplified bootstrap/app.php for middleware and providers'); } else { lines.push('Note: Use app/Http/Kernel.php for middleware, app/Providers for service providers'); } return lines; }, }, ui: { successMessage: 'PostHog integration complete', estimatedDurationMinutes: 5, getOutroChanges: (context) => { const projectType = context.projectType; const projectTypeName = projectType ? (0, utils_1.getLaravelProjectTypeName)(projectType) : 'Laravel'; const changes = [ `Analyzed your ${projectTypeName} project structure`, `Installed the PostHog PHP package via Composer`, `Configured PostHog in your Laravel application`, ]; if (context.laravelStructure === 'latest') { changes.push('Added PostHog initialization to bootstrap/app.php'); } else { changes.push('Created a PostHog service provider for initialization'); } if (projectType === utils_1.LaravelProjectType.INERTIA) { changes.push('Configured PostHog to work with Inertia.js'); } if (projectType === utils_1.LaravelProjectType.LIVEWIRE) { changes.push('Configured PostHog to work with Livewire'); } return changes; }, getOutroNextSteps: () => [ 'Start your Laravel development server with `php artisan serve`', 'Visit your PostHog dashboard to see incoming events', 'Use PostHog::capture() to track custom events', 'Use PostHog::identify() to associate events with users', ], }, }; /** * Laravel wizard powered by the universal agent runner. */ async function runLaravelWizardAgent(options) { if (options.debug) { (0, debug_1.enableDebugLogs)(); } // Check Laravel version - agent wizard requires >= 9.0.0 const laravelVersion = (0, utils_1.getLaravelVersion)(options); if (laravelVersion) { const coercedVersion = semver.coerce(laravelVersion); if (coercedVersion && semver.lt(coercedVersion, MINIMUM_LARAVEL_VERSION)) { const docsUrl = LARAVEL_AGENT_CONFIG.metadata.unsupportedVersionDocsUrl ?? LARAVEL_AGENT_CONFIG.metadata.docsUrl; clack_1.default.log.warn(`Sorry: the wizard can't help you with Laravel ${laravelVersion}. Upgrade to Laravel ${MINIMUM_LARAVEL_VERSION} or later, or check out the manual setup guide.`); clack_1.default.log.info(`Setup Laravel manually: ${chalk_1.default.cyan(docsUrl)}`); clack_1.default.outro('PostHog wizard will see you next time!'); return; } } await (0, agent_runner_1.runAgentWizard)(LARAVEL_AGENT_CONFIG, options); } //# sourceMappingURL=laravel-wizard-agent.js.map