UNPKG

@posthog/wizard

Version:

The PostHog wizard helps you to configure your project

159 lines 7.01 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.runDjangoWizardAgent = runDjangoWizardAgent; 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"); /** * Django framework configuration for the universal agent runner */ const MINIMUM_DJANGO_VERSION = '3.0.0'; const DJANGO_AGENT_CONFIG = { metadata: { name: 'Django', integration: constants_1.Integration.django, docsUrl: 'https://posthog.com/docs/libraries/django', unsupportedVersionDocsUrl: 'https://posthog.com/docs/libraries/python', gatherContext: async (options) => { const projectType = await (0, utils_1.getDjangoProjectType)(options); const settingsFile = await (0, utils_1.findDjangoSettingsFile)(options); return { projectType, settingsFile }; }, }, detection: { packageName: 'django', packageDisplayName: 'Django', usesPackageJson: false, getVersion: (_packageJson) => { // For Django, we don't use package.json. Version is extracted separately // from requirements.txt or pyproject.toml in the wizard entry point return undefined; }, getVersionBucket: utils_1.getDjangoVersionBucket, }, environment: { uploadToHosting: false, getEnvVars: (apiKey, host) => ({ POSTHOG_API_KEY: apiKey, POSTHOG_HOST: host, }), }, analytics: { getTags: (context) => { const projectType = context.projectType; return { projectType: projectType || 'unknown', }; }, }, prompts: { projectTypeDetection: 'This is a Python/Django project. Look for requirements.txt, pyproject.toml, setup.py, Pipfile, or manage.py to confirm.', packageInstallation: 'Use pip, poetry, or pipenv based on existing config files (requirements.txt, pyproject.toml, Pipfile). Do not pin the posthog version - just add "posthog" without version constraints.', getAdditionalContextLines: (context) => { const projectType = context.projectType; const projectTypeName = projectType ? (0, utils_1.getDjangoProjectTypeName)(projectType) : 'unknown'; // Map project type to framework ID for MCP docs resource const frameworkIdMap = { [utils_1.DjangoProjectType.STANDARD]: 'django', [utils_1.DjangoProjectType.DRF]: 'django', [utils_1.DjangoProjectType.WAGTAIL]: 'django', [utils_1.DjangoProjectType.CHANNELS]: 'django', }; const frameworkId = projectType ? frameworkIdMap[projectType] : 'django'; const lines = [ `Project type: ${projectTypeName}`, `Framework docs ID: ${frameworkId} (use posthog://docs/frameworks/${frameworkId} for documentation)`, ]; if (context.settingsFile) { lines.push(`Settings file: ${context.settingsFile}`); } return lines; }, }, ui: { successMessage: 'PostHog integration complete', estimatedDurationMinutes: 5, getOutroChanges: (context) => { const projectType = context.projectType; const projectTypeName = projectType ? (0, utils_1.getDjangoProjectTypeName)(projectType) : 'Django'; return [ `Analyzed your ${projectTypeName} project structure`, `Installed the PostHog Python package`, `Configured PostHog in your Django settings`, `Added PostHog middleware for automatic event tracking`, ]; }, getOutroNextSteps: () => [ 'Start your Django development server to see PostHog in action', 'Visit your PostHog dashboard to see incoming events', 'Use identify_context() within new_context() to associate events with users', ], }, }; /** * Django wizard powered by the universal agent runner. */ async function runDjangoWizardAgent(options) { if (options.debug) { (0, debug_1.enableDebugLogs)(); } // Check Django version - agent wizard requires >= 3.0.0 const djangoVersion = await (0, utils_1.getDjangoVersion)(options); if (djangoVersion) { const coercedVersion = semver.coerce(djangoVersion); if (coercedVersion && semver.lt(coercedVersion, MINIMUM_DJANGO_VERSION)) { const docsUrl = DJANGO_AGENT_CONFIG.metadata.unsupportedVersionDocsUrl ?? DJANGO_AGENT_CONFIG.metadata.docsUrl; clack_1.default.log.warn(`Sorry: the wizard can't help you with Django ${djangoVersion}. Upgrade to Django ${MINIMUM_DJANGO_VERSION} or later, or check out the manual setup guide.`); clack_1.default.log.info(`Setup Django manually: ${chalk_1.default.cyan(docsUrl)}`); clack_1.default.outro('PostHog wizard will see you next time!'); return; } } await (0, agent_runner_1.runAgentWizard)(DJANGO_AGENT_CONFIG, options); } //# sourceMappingURL=django-wizard-agent.js.map