UNPKG

@posthog/wizard

Version:

The PostHog wizard helps you to configure your project

368 lines 16.8 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.INTEGRATION_ORDER = exports.INTEGRATION_CONFIG = void 0; const clack_utils_1 = require("../utils/clack-utils"); const package_json_1 = require("../utils/package-json"); const constants_1 = require("./constants"); const fast_glob_1 = __importDefault(require("fast-glob")); const fs = __importStar(require("node:fs")); const path = __importStar(require("node:path")); exports.INTEGRATION_CONFIG = { [constants_1.Integration.nextjs]: { name: 'Next.js', filterPatterns: ['**/*.{tsx,ts,jsx,js,mjs,cjs}'], ignorePatterns: [ 'node_modules', 'dist', 'build', 'public', 'static', 'next-env.d.*', ], detect: async (options) => { const packageJson = await (0, clack_utils_1.tryGetPackageJson)(options); return packageJson ? (0, package_json_1.hasPackageInstalled)('next', packageJson) : false; }, generateFilesRules: '', filterFilesRules: '', docsUrl: 'https://posthog.com/docs/libraries/next-js', defaultChanges: '• Installed posthog-js & posthog-node packages\n• Initialized PostHog and added pageview tracking\n• Created a PostHogClient to use PostHog server-side\n• Setup a reverse proxy to avoid ad blockers blocking analytics requests', nextSteps: '• Call posthog.identify() when a user signs into your app\n• Call posthog.capture() to capture custom events in your app', }, [constants_1.Integration.react]: { name: 'React', filterPatterns: ['**/*.{tsx,ts,jsx,js}'], ignorePatterns: [ 'node_modules', 'dist', 'build', 'public', 'static', 'assets', ], detect: async (options) => { const packageJson = await (0, clack_utils_1.tryGetPackageJson)(options); return packageJson ? (0, package_json_1.hasPackageInstalled)('react', packageJson) : false; }, generateFilesRules: '', filterFilesRules: '', docsUrl: 'https://posthog.com/docs/libraries/react', defaultChanges: '• Installed posthog-js package\n• Added PostHogProvider to the root of the app, to initialize PostHog and enable autocapture', nextSteps: '• Call posthog.identify() when a user signs into your app\n• Call posthog.capture() to capture custom events in your app', }, [constants_1.Integration.svelte]: { name: 'Svelte', filterPatterns: ['**/*.{svelte,ts,js,jsx,tsx}'], ignorePatterns: ['node_modules', 'dist', 'build', 'public', 'static'], detect: async (options) => { const packageJson = await (0, clack_utils_1.tryGetPackageJson)(options); return packageJson ? (0, package_json_1.hasPackageInstalled)('@sveltejs/kit', packageJson) : false; }, generateFilesRules: '', filterFilesRules: '', docsUrl: 'https://posthog.com/docs/libraries/svelte', defaultChanges: '• Installed posthog-js & posthog-node packages\n• Added PostHog initialization to your Svelte app\n• Setup pageview & pageleave tracking\n• Setup event auto - capture to capture events as users interact with your app\n• Added a getPostHogClient() function to use PostHog server-side', nextSteps: '• Call posthog.identify() when a user signs into your app\n• Use getPostHogClient() to start capturing events server - side', }, [constants_1.Integration.reactNative]: { name: 'React Native', filterPatterns: ['**/*.{ts,js,jsx,tsx}'], ignorePatterns: ['node_modules', 'dist', 'build', 'public', 'static'], detect: async (options) => { const packageJson = await (0, clack_utils_1.tryGetPackageJson)(options); return packageJson ? (0, package_json_1.hasPackageInstalled)('react-native', packageJson) : false; }, generateFilesRules: '', filterFilesRules: '', docsUrl: 'https://posthog.com/docs/libraries/react-native', defaultChanges: '• Installed required packages\n• Added PostHogProvider to the root of the app\n• Enabled autocapture and session replay', nextSteps: '• Call posthog.identify() when a user signs into your app\n• Call posthog.capture() to capture custom events in your app', }, [constants_1.Integration.astro]: { name: 'Astro', filterPatterns: ['**/*.{astro,ts,js,jsx,tsx}'], ignorePatterns: ['node_modules', 'dist', 'build', 'public', 'static'], detect: async (options) => { const packageJson = await (0, clack_utils_1.tryGetPackageJson)(options); return packageJson ? (0, package_json_1.hasPackageInstalled)('astro', packageJson) : false; }, generateFilesRules: '', filterFilesRules: '', docsUrl: 'https://posthog.com/docs/libraries/js', defaultChanges: '• Added PostHog component with initialization script\n• Created PostHogLayout for consistent analytics tracking', nextSteps: '• Call posthog.identify() when a user signs into your app\n• Call posthog.capture() to capture custom events in your app\n• Use posthog.isFeatureEnabled() for feature flags', }, [constants_1.Integration.reactRouter]: { name: 'React Router', filterPatterns: ['**/*.{tsx,ts,jsx,js}'], ignorePatterns: [ 'node_modules', 'dist', 'build', 'public', 'static', 'assets', ], detect: async (options) => { const packageJson = await (0, clack_utils_1.tryGetPackageJson)(options); return packageJson ? (0, package_json_1.hasPackageInstalled)('react-router', packageJson) : false; }, generateFilesRules: '', filterFilesRules: '', docsUrl: 'https://posthog-git-react-post-hog.vercel.app/docs/libraries/react-router', defaultChanges: '• Installed posthog-js package\n• Added PostHogProvider to the root of the app\n• Integrated PostHog with React Router for pageview tracking', nextSteps: '• Call posthog.identify() when a user signs into your app\n• Call posthog.capture() to capture custom events in your app', }, [constants_1.Integration.django]: { name: 'Django', filterPatterns: ['**/*.py'], ignorePatterns: [ 'node_modules', 'dist', 'build', 'public', 'static', 'venv', '.venv', 'env', '.env', '__pycache__', '*.pyc', 'migrations', ], detect: async (options) => { const { installDir } = options; // Check for manage.py (Django project indicator) const managePyMatches = await (0, fast_glob_1.default)('**/manage.py', { cwd: installDir, ignore: ['**/venv/**', '**/.venv/**', '**/env/**', '**/.env/**'], }); if (managePyMatches.length > 0) { // Verify it's a Django manage.py by checking content for (const match of managePyMatches) { try { const content = fs.readFileSync(path.join(installDir, match), 'utf-8'); if (content.includes('django') || content.includes('DJANGO_SETTINGS_MODULE')) { return true; } } catch { // Skip files that can't be read continue; } } } // Check for Django in requirements files const requirementsFiles = await (0, fast_glob_1.default)(['**/requirements*.txt', '**/pyproject.toml', '**/setup.py'], { cwd: installDir, ignore: ['**/venv/**', '**/.venv/**', '**/env/**', '**/.env/**'], }); for (const reqFile of requirementsFiles) { try { const content = fs.readFileSync(path.join(installDir, reqFile), 'utf-8'); // Check for Django package reference if (content.toLowerCase().includes('django') && !content.toLowerCase().includes('django-') // Avoid false positives from Django plugins only ) { return true; } } catch { // Skip files that can't be read continue; } } return false; }, generateFilesRules: '', filterFilesRules: '', docsUrl: 'https://posthog.com/docs/libraries/django', defaultChanges: '• Installed posthog Python package\n• Added PostHog middleware for automatic event tracking\n• Configured PostHog settings in Django settings file', nextSteps: '• Use identify_context() within new_context() to associate events with users\n• Call posthog.capture() to capture custom events\n• Use feature flags with posthog.feature_enabled()', }, [constants_1.Integration.flask]: { name: 'Flask', filterPatterns: ['**/*.py'], ignorePatterns: [ 'node_modules', 'dist', 'build', 'public', 'static', 'venv', '.venv', 'env', '.env', '__pycache__', '*.pyc', 'migrations', 'instance', ], detect: async (options) => { const { installDir } = options; // Note: Django is checked before Flask in INTEGRATION_ORDER, // so if we get here, the project is not a Django project. // Check for Flask in requirements files const requirementsFiles = await (0, fast_glob_1.default)([ '**/requirements*.txt', '**/pyproject.toml', '**/setup.py', '**/Pipfile', ], { cwd: installDir, ignore: ['**/venv/**', '**/.venv/**', '**/env/**', '**/.env/**'], }); for (const reqFile of requirementsFiles) { try { const content = fs.readFileSync(path.join(installDir, reqFile), 'utf-8'); // Check for flask package (case-insensitive) // Match "flask" as a standalone package, not just as part of plugin names if (/^flask([<>=~!]|$|\s)/im.test(content) || /["']flask["']/i.test(content)) { return true; } } catch { continue; } } // Check for Flask app patterns in Python files const pyFiles = await (0, fast_glob_1.default)(['**/app.py', '**/wsgi.py', '**/application.py', '**/__init__.py'], { cwd: installDir, ignore: [ '**/venv/**', '**/.venv/**', '**/env/**', '**/.env/**', '**/__pycache__/**', ], }); for (const pyFile of pyFiles) { try { const content = fs.readFileSync(path.join(installDir, pyFile), 'utf-8'); if (content.includes('from flask import') || content.includes('import flask') || /Flask\s*\(/.test(content)) { return true; } } catch { continue; } } return false; }, generateFilesRules: '', filterFilesRules: '', docsUrl: 'https://posthog.com/docs/libraries/flask', defaultChanges: '• Installed posthog Python package\n• Added PostHog initialization to your Flask app\n• Configured automatic event tracking', nextSteps: '• Use posthog.identify() to associate events with users\n• Call posthog.capture() to capture custom events\n• Use feature flags with posthog.feature_enabled()', }, [constants_1.Integration.laravel]: { name: 'Laravel', filterPatterns: ['**/*.php'], ignorePatterns: [ 'node_modules', 'vendor', 'storage', 'bootstrap/cache', 'public/build', 'public/hot', '.phpunit.cache', ], detect: async (options) => { const { installDir } = options; // Primary check: artisan file (definitive Laravel indicator) const artisanPath = path.join(installDir, 'artisan'); if (fs.existsSync(artisanPath)) { try { const content = fs.readFileSync(artisanPath, 'utf-8'); if (content.includes('Laravel') || content.includes('Artisan')) { return true; } } catch { // Continue to other checks } } // Secondary check: composer.json with laravel/framework const composerPath = path.join(installDir, 'composer.json'); if (fs.existsSync(composerPath)) { try { const content = fs.readFileSync(composerPath, 'utf-8'); const composer = JSON.parse(content); if (composer.require?.['laravel/framework'] || composer['require-dev']?.['laravel/framework']) { return true; } } catch { // Continue to other checks } } // Tertiary check: Laravel-specific directory structure const hasLaravelStructure = await (0, fast_glob_1.default)(['**/bootstrap/app.php', '**/app/Http/Kernel.php'], { cwd: installDir, ignore: ['**/vendor/**'] }); return hasLaravelStructure.length > 0; }, generateFilesRules: '', filterFilesRules: '', docsUrl: 'https://posthog.com/docs/libraries/php', defaultChanges: '• Installed posthog/posthog-php via Composer\n• Added PostHog service provider\n• Configured automatic event tracking', nextSteps: '• Use PostHog::capture() to track custom events\n• Use PostHog::identify() to associate events with users', }, }; exports.INTEGRATION_ORDER = [ constants_1.Integration.nextjs, constants_1.Integration.astro, constants_1.Integration.svelte, constants_1.Integration.reactNative, constants_1.Integration.reactRouter, constants_1.Integration.django, constants_1.Integration.flask, constants_1.Integration.laravel, constants_1.Integration.react, ]; //# sourceMappingURL=config.js.map