@posthog/wizard 0.2.9 → 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -10
- package/dist/src/lib/config.d.ts +21 -0
- package/dist/src/lib/config.js +49 -0
- package/dist/src/lib/config.js.map +1 -0
- package/dist/src/lib/constants.d.ts +2 -1
- package/dist/src/lib/constants.js +3 -0
- package/dist/src/lib/constants.js.map +1 -1
- package/dist/src/lib/prompts.d.ts +16 -0
- package/dist/src/{nextjs → lib}/prompts.js +18 -9
- package/dist/src/lib/prompts.js.map +1 -0
- package/dist/src/nextjs/docs.js +28 -16
- package/dist/src/nextjs/docs.js.map +1 -1
- package/dist/src/nextjs/nextjs-wizard.d.ts +0 -7
- package/dist/src/nextjs/nextjs-wizard.js +23 -306
- package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
- package/dist/src/nextjs/utils.d.ts +1 -4
- package/dist/src/nextjs/utils.js +1 -32
- package/dist/src/nextjs/utils.js.map +1 -1
- package/dist/src/react/docs.d.ts +4 -0
- package/dist/src/react/docs.js +37 -0
- package/dist/src/react/docs.js.map +1 -0
- package/dist/src/react/react-wizard.d.ts +2 -0
- package/dist/src/react/react-wizard.js +94 -0
- package/dist/src/react/react-wizard.js.map +1 -0
- package/dist/src/run.d.ts +1 -0
- package/dist/src/run.js +11 -4
- package/dist/src/run.js.map +1 -1
- package/dist/src/utils/clack-utils.d.ts +3 -1
- package/dist/src/utils/clack-utils.js +56 -9
- package/dist/src/utils/clack-utils.js.map +1 -1
- package/dist/src/utils/environment.d.ts +6 -0
- package/dist/src/utils/environment.js +100 -0
- package/dist/src/utils/environment.js.map +1 -1
- package/dist/src/utils/file-utils.d.ts +27 -0
- package/dist/src/utils/file-utils.js +139 -0
- package/dist/src/utils/file-utils.js.map +1 -1
- package/dist/src/utils/query.js +2 -2
- package/dist/src/utils/query.js.map +1 -1
- package/dist/src/utils/types.d.ts +9 -0
- package/dist/src/utils/types.js.map +1 -1
- package/dist/src/utils/urls.d.ts +4 -0
- package/dist/src/utils/urls.js +35 -0
- package/dist/src/utils/urls.js.map +1 -0
- package/package.json +1 -1
- package/dist/src/nextjs/prompts.d.ts +0 -12
- package/dist/src/nextjs/prompts.js.map +0 -1
package/README.md
CHANGED
|
@@ -22,15 +22,15 @@ Currently the wizard can be used for Next.js only. If you have other platforms y
|
|
|
22
22
|
|
|
23
23
|
The following CLI arguments are available:
|
|
24
24
|
|
|
25
|
-
| Option | Description | Type | Default | Choices
|
|
26
|
-
| ----------------- | -------------------------------------------------------------------------- | ------- | ------------------------------- |
|
|
27
|
-
| `--help` | Show help | boolean | |
|
|
28
|
-
| `--version` | Show version number | boolean | |
|
|
29
|
-
| `--debug` | Enable verbose logging | boolean | `false` |
|
|
30
|
-
| `--integration` | Choose the integration to setup | choices | Select integration during setup | "nextjs"
|
|
31
|
-
| `--force-install` | Force install the SDK NPM package (use with caution!) | boolean | `false` |
|
|
32
|
-
| `--install-dir` | Relative path to install in | string | `.` |
|
|
33
|
-
| `--region` | PostHog region to use | choices | | "us", "eu"
|
|
34
|
-
| `--default` | Select the default option for all questions automatically (where possible) | boolean | `false` |
|
|
25
|
+
| Option | Description | Type | Default | Choices | Environment Variable |
|
|
26
|
+
| ----------------- | -------------------------------------------------------------------------- | ------- | ------------------------------- | ---------- | ---------------------------- |
|
|
27
|
+
| `--help` | Show help | boolean | | | |
|
|
28
|
+
| `--version` | Show version number | boolean | | | |
|
|
29
|
+
| `--debug` | Enable verbose logging | boolean | `false` | | `POSTHOG_WIZARD_DEBUG` |
|
|
30
|
+
| `--integration` | Choose the integration to setup | choices | Select integration during setup | "nextjs" | `POSTHOG_WIZARD_INTEGRATION` |
|
|
31
|
+
| `--force-install` | Force install the SDK NPM package (use with caution!) | boolean | `false` | | |
|
|
32
|
+
| `--install-dir` | Relative path to install in | string | `.` | | `POSTHOG_WIZARD_INSTALL_DIR` |
|
|
33
|
+
| `--region` | PostHog region to use | choices | | "us", "eu" | `POSTHOG_WIZARD_REGION` |
|
|
34
|
+
| `--default` | Select the default option for all questions automatically (where possible) | boolean | `false` | | `POSTHOG_WIZARD_DEFAULT` |
|
|
35
35
|
|
|
36
36
|
> Note: A large amount of the scaffolding for this came from the amazing Sentry wizard, which you can find [here](https://github.com/getsentry/sentry-wizard) 💖
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { WizardOptions } from '../utils/types';
|
|
2
|
+
import { Integration } from './constants';
|
|
3
|
+
export declare const INTEGRATION_CONFIG: {
|
|
4
|
+
readonly nextjs: {
|
|
5
|
+
readonly name: "Next.js";
|
|
6
|
+
readonly filterPatterns: ["**/*.{tsx,ts,jsx,js,mjs,cjs}"];
|
|
7
|
+
readonly ignorePatterns: ["node_modules", "dist", "build", "public", "static", "next-env.d.*"];
|
|
8
|
+
readonly detect: (options: Pick<WizardOptions, "installDir">) => Promise<boolean>;
|
|
9
|
+
readonly generateFilesRules: "";
|
|
10
|
+
readonly filterFilesRules: "";
|
|
11
|
+
};
|
|
12
|
+
readonly react: {
|
|
13
|
+
readonly name: "React";
|
|
14
|
+
readonly filterPatterns: ["**/*.{tsx,ts,jsx,js}"];
|
|
15
|
+
readonly ignorePatterns: ["node_modules", "dist", "build", "public", "static", "assets"];
|
|
16
|
+
readonly detect: (options: Pick<WizardOptions, "installDir">) => Promise<boolean>;
|
|
17
|
+
readonly generateFilesRules: "";
|
|
18
|
+
readonly filterFilesRules: "";
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export declare const INTEGRATION_ORDER: readonly [Integration.nextjs, Integration.react];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.INTEGRATION_ORDER = exports.INTEGRATION_CONFIG = void 0;
|
|
4
|
+
const clack_utils_1 = require("../utils/clack-utils");
|
|
5
|
+
const package_json_1 = require("../utils/package-json");
|
|
6
|
+
const constants_1 = require("./constants");
|
|
7
|
+
exports.INTEGRATION_CONFIG = {
|
|
8
|
+
[constants_1.Integration.nextjs]: {
|
|
9
|
+
name: 'Next.js',
|
|
10
|
+
filterPatterns: ['**/*.{tsx,ts,jsx,js,mjs,cjs}'],
|
|
11
|
+
ignorePatterns: [
|
|
12
|
+
'node_modules',
|
|
13
|
+
'dist',
|
|
14
|
+
'build',
|
|
15
|
+
'public',
|
|
16
|
+
'static',
|
|
17
|
+
'next-env.d.*',
|
|
18
|
+
],
|
|
19
|
+
detect: async (options) => {
|
|
20
|
+
const packageJson = await (0, clack_utils_1.getPackageDotJson)(options);
|
|
21
|
+
return (0, package_json_1.hasPackageInstalled)('next', packageJson);
|
|
22
|
+
},
|
|
23
|
+
generateFilesRules: '',
|
|
24
|
+
filterFilesRules: '',
|
|
25
|
+
},
|
|
26
|
+
[constants_1.Integration.react]: {
|
|
27
|
+
name: 'React',
|
|
28
|
+
filterPatterns: ['**/*.{tsx,ts,jsx,js}'],
|
|
29
|
+
ignorePatterns: [
|
|
30
|
+
'node_modules',
|
|
31
|
+
'dist',
|
|
32
|
+
'build',
|
|
33
|
+
'public',
|
|
34
|
+
'static',
|
|
35
|
+
'assets',
|
|
36
|
+
],
|
|
37
|
+
detect: async (options) => {
|
|
38
|
+
const packageJson = await (0, clack_utils_1.getPackageDotJson)(options);
|
|
39
|
+
return (0, package_json_1.hasPackageInstalled)('react', packageJson);
|
|
40
|
+
},
|
|
41
|
+
generateFilesRules: '',
|
|
42
|
+
filterFilesRules: '',
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
exports.INTEGRATION_ORDER = [
|
|
46
|
+
constants_1.Integration.nextjs,
|
|
47
|
+
constants_1.Integration.react,
|
|
48
|
+
];
|
|
49
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/lib/config.ts"],"names":[],"mappings":";;;AAAA,sDAAyD;AACzD,wDAA4D;AAE5D,2CAA0C;AAW7B,QAAA,kBAAkB,GAAG;IAChC,CAAC,uBAAW,CAAC,MAAM,CAAC,EAAE;QACpB,IAAI,EAAE,SAAS;QACf,cAAc,EAAE,CAAC,8BAA8B,CAAC;QAChD,cAAc,EAAE;YACd,cAAc;YACd,MAAM;YACN,OAAO;YACP,QAAQ;YACR,QAAQ;YACR,cAAc;SACf;QACD,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YACxB,MAAM,WAAW,GAAG,MAAM,IAAA,+BAAiB,EAAC,OAAO,CAAC,CAAC;YACrD,OAAO,IAAA,kCAAmB,EAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QAClD,CAAC;QACD,kBAAkB,EAAE,EAAE;QACtB,gBAAgB,EAAE,EAAE;KACrB;IACD,CAAC,uBAAW,CAAC,KAAK,CAAC,EAAE;QACnB,IAAI,EAAE,OAAO;QACb,cAAc,EAAE,CAAC,sBAAsB,CAAC;QACxC,cAAc,EAAE;YACd,cAAc;YACd,MAAM;YACN,OAAO;YACP,QAAQ;YACR,QAAQ;YACR,QAAQ;SACT;QACD,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YACxB,MAAM,WAAW,GAAG,MAAM,IAAA,+BAAiB,EAAC,OAAO,CAAC,CAAC;YACrD,OAAO,IAAA,kCAAmB,EAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QACnD,CAAC;QACD,kBAAkB,EAAE,EAAE;QACtB,gBAAgB,EAAE,EAAE;KACrB;CACwD,CAAC;AAE/C,QAAA,iBAAiB,GAAG;IAC/B,uBAAW,CAAC,MAAM;IAClB,uBAAW,CAAC,KAAK;CACT,CAAC","sourcesContent":["import { getPackageDotJson } from '../utils/clack-utils';\nimport { hasPackageInstalled } from '../utils/package-json';\nimport type { WizardOptions } from '../utils/types';\nimport { Integration } from './constants';\n\ntype IntegrationConfig = {\n name: string;\n filterPatterns: string[];\n ignorePatterns: string[];\n detect: (options: Pick<WizardOptions, 'installDir'>) => Promise<boolean>;\n generateFilesRules: string;\n filterFilesRules: string;\n};\n\nexport const INTEGRATION_CONFIG = {\n [Integration.nextjs]: {\n name: 'Next.js',\n filterPatterns: ['**/*.{tsx,ts,jsx,js,mjs,cjs}'],\n ignorePatterns: [\n 'node_modules',\n 'dist',\n 'build',\n 'public',\n 'static',\n 'next-env.d.*',\n ],\n detect: async (options) => {\n const packageJson = await getPackageDotJson(options);\n return hasPackageInstalled('next', packageJson);\n },\n generateFilesRules: '',\n filterFilesRules: '',\n },\n [Integration.react]: {\n name: 'React',\n filterPatterns: ['**/*.{tsx,ts,jsx,js}'],\n ignorePatterns: [\n 'node_modules',\n 'dist',\n 'build',\n 'public',\n 'static',\n 'assets',\n ],\n detect: async (options) => {\n const packageJson = await getPackageDotJson(options);\n return hasPackageInstalled('react', packageJson);\n },\n generateFilesRules: '',\n filterFilesRules: '',\n },\n} as const satisfies Record<Integration, IntegrationConfig>;\n\nexport const INTEGRATION_ORDER = [\n Integration.nextjs,\n Integration.react,\n] as const;\n"]}
|
|
@@ -6,11 +6,14 @@ exports.getIntegrationChoices = getIntegrationChoices;
|
|
|
6
6
|
var Integration;
|
|
7
7
|
(function (Integration) {
|
|
8
8
|
Integration["nextjs"] = "nextjs";
|
|
9
|
+
Integration["react"] = "react";
|
|
9
10
|
})(Integration || (exports.Integration = Integration = {}));
|
|
10
11
|
function getIntegrationDescription(type) {
|
|
11
12
|
switch (type) {
|
|
12
13
|
case Integration.nextjs:
|
|
13
14
|
return 'Next.js';
|
|
15
|
+
case Integration.react:
|
|
16
|
+
return 'React';
|
|
14
17
|
default:
|
|
15
18
|
throw new Error(`Unknown integration ${type}`);
|
|
16
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/lib/constants.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/lib/constants.ts"],"names":[],"mappings":";;;AAKA,8DASC;AAOD,sDAKC;AA1BD,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,8BAAe,CAAA;AACjB,CAAC,EAHW,WAAW,2BAAX,WAAW,QAGtB;AAED,SAAgB,yBAAyB,CAAC,IAAY;IACpD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,WAAW,CAAC,MAAM;YACrB,OAAO,SAAS,CAAC;QACnB,KAAK,WAAW,CAAC,KAAK;YACpB,OAAO,OAAO,CAAC;QACjB;YACE,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,EAAE,CAAC,CAAC;IACnD,CAAC;AACH,CAAC;AAOD,SAAgB,qBAAqB;IACnC,OAAO,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC;QACrD,IAAI,EAAE,yBAAyB,CAAC,IAAI,CAAC;QACrC,KAAK,EAAE,IAAI;KACZ,CAAC,CAAC,CAAC;AACN,CAAC;AAOY,QAAA,MAAM,GAAG,KAAK,CAAC;AAEf,QAAA,WAAW,GAAG,cAAM;IAC/B,CAAC,CAAC,uBAAuB;IACzB,CAAC,CAAC,wBAAwB,CAAC;AAChB,QAAA,UAAU,GAAG,0CAA0C,CAAC;AACxD,QAAA,gBAAgB,GAAG,cAAM;IACpC,CAAC,CAAC,uBAAuB;IACzB,CAAC,CAAC,0BAA0B,CAAC;AAClB,QAAA,0CAA0C,GAAG,gBAAgB,CAAC;AAC9D,QAAA,kBAAkB,GAAG,cAAM;IACtC,CAAC,CAAC,uBAAuB;IACzB,CAAC,CAAC,gCAAgC,CAAC;AACxB,QAAA,qBAAqB,GAAG,gCAAgC,CAAC","sourcesContent":["export enum Integration {\n nextjs = 'nextjs',\n react = 'react',\n}\n\nexport function getIntegrationDescription(type: string): string {\n switch (type) {\n case Integration.nextjs:\n return 'Next.js';\n case Integration.react:\n return 'React';\n default:\n throw new Error(`Unknown integration ${type}`);\n }\n}\n\ntype IntegrationChoice = {\n name: string;\n value: string;\n};\n\nexport function getIntegrationChoices(): IntegrationChoice[] {\n return Object.keys(Integration).map((type: string) => ({\n name: getIntegrationDescription(type),\n value: type,\n }));\n}\n\nexport interface Args {\n debug: boolean;\n integration: Integration;\n}\n\nexport const IS_DEV = false;\n\nexport const DEFAULT_URL = IS_DEV\n ? 'http://localhost:8010'\n : 'https://us.posthog.com';\nexport const ISSUES_URL = 'https://github.com/posthog/wizard/issues';\nexport const DEFAULT_HOST_URL = IS_DEV\n ? 'http://localhost:8010'\n : 'https://us.i.posthog.com';\nexport const ANALYTICS_POSTHOG_PUBLIC_PROJECT_WRITE_KEY = 'sTMFPsFhdP1Ssg';\nexport const ANALYTICS_HOST_URL = IS_DEV\n ? 'http://localhost:8010'\n : 'https://internal-t.posthog.com';\nexport const DUMMY_PROJECT_API_KEY = '_YOUR_POSTHOG_PROJECT_API_KEY_';\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PromptTemplate } from '@langchain/core/prompts';
|
|
2
|
+
export declare const baseFilterFilesPromptTemplate: PromptTemplate<{
|
|
3
|
+
documentation: any;
|
|
4
|
+
file_list: any;
|
|
5
|
+
integration_name: any;
|
|
6
|
+
integration_rules: any;
|
|
7
|
+
}, any>;
|
|
8
|
+
export declare const baseGenerateFileChangesPromptTemplate: PromptTemplate<{
|
|
9
|
+
documentation: any;
|
|
10
|
+
integration_name: any;
|
|
11
|
+
integration_rules: any;
|
|
12
|
+
file_content: any;
|
|
13
|
+
file_path: any;
|
|
14
|
+
changed_files: any;
|
|
15
|
+
unchanged_files: any;
|
|
16
|
+
}, any>;
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.baseGenerateFileChangesPromptTemplate = exports.baseFilterFilesPromptTemplate = void 0;
|
|
4
4
|
const prompts_1 = require("@langchain/core/prompts");
|
|
5
|
-
exports.
|
|
6
|
-
inputVariables: [
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
exports.baseFilterFilesPromptTemplate = new prompts_1.PromptTemplate({
|
|
6
|
+
inputVariables: [
|
|
7
|
+
'documentation',
|
|
8
|
+
'file_list',
|
|
9
|
+
'integration_name',
|
|
10
|
+
'integration_rules',
|
|
11
|
+
],
|
|
12
|
+
template: `You are a PostHog installation wizard, a master AI programming assistant that implements PostHog for {integration_name} projects.
|
|
13
|
+
Given the following list of file paths from a project, determine which files are likely to require modifications
|
|
9
14
|
to integrate PostHog. Use the installation documentation as a reference for what files might need modifications, do not include files that are unlikely to require modification based on the documentation.
|
|
10
15
|
|
|
11
16
|
- If you would like to create a new file, you can include the file path in your response.
|
|
@@ -19,8 +24,8 @@ Rules:
|
|
|
19
24
|
- If you are unsure, return the file, since it's better to have more files than less.
|
|
20
25
|
- If you create a new file, it should not conflict with any existing files.
|
|
21
26
|
- If the user is using TypeScript, you should return .ts and .tsx files.
|
|
22
|
-
- You should implement both posthog-js and posthog-node.
|
|
23
27
|
- The file structure of the project may be different than the documentation, you should follow the file structure of the project.
|
|
28
|
+
{integration_rules}
|
|
24
29
|
|
|
25
30
|
Installation documentation:
|
|
26
31
|
{documentation}
|
|
@@ -29,15 +34,17 @@ All current files in the repository:
|
|
|
29
34
|
|
|
30
35
|
{file_list}`,
|
|
31
36
|
});
|
|
32
|
-
exports.
|
|
37
|
+
exports.baseGenerateFileChangesPromptTemplate = new prompts_1.PromptTemplate({
|
|
33
38
|
inputVariables: [
|
|
34
39
|
'file_content',
|
|
35
40
|
'documentation',
|
|
36
41
|
'file_path',
|
|
37
42
|
'changed_files',
|
|
38
43
|
'unchanged_files',
|
|
44
|
+
'integration_name',
|
|
45
|
+
'integration_rules',
|
|
39
46
|
],
|
|
40
|
-
template: `You are a PostHog installation wizard, a master AI programming assistant that implements PostHog for
|
|
47
|
+
template: `You are a PostHog installation wizard, a master AI programming assistant that implements PostHog for {integration_name} projects.
|
|
41
48
|
|
|
42
49
|
Your task is to update the file to integrate PostHog according to the documentation.
|
|
43
50
|
Do not return a diff — you should return the complete updated file content.
|
|
@@ -49,11 +56,13 @@ Rules:
|
|
|
49
56
|
- If the current file is empty, and you think it should be created, you can add the contents of the new file.
|
|
50
57
|
- The file structure of the project may be different than the documentation, you should follow the file structure of the project.
|
|
51
58
|
- Use relative imports if you are unsure what the project import paths are.
|
|
59
|
+
{integration_rules}
|
|
60
|
+
|
|
52
61
|
|
|
53
62
|
CONTEXT
|
|
54
63
|
---
|
|
55
64
|
|
|
56
|
-
Documentation for integrating PostHog with
|
|
65
|
+
Documentation for integrating PostHog with {integration_name}:
|
|
57
66
|
{documentation}
|
|
58
67
|
|
|
59
68
|
The file you are updating is:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../src/lib/prompts.ts"],"names":[],"mappings":";;;AAAA,qDAAyD;AAE5C,QAAA,6BAA6B,GAAG,IAAI,wBAAc,CAAC;IAC9D,cAAc,EAAE;QACd,eAAe;QACf,WAAW;QACX,kBAAkB;QAClB,mBAAmB;KACpB;IACD,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;YAuBA;CACX,CAAC,CAAC;AAEU,QAAA,qCAAqC,GAAG,IAAI,wBAAc,CAAC;IACtE,cAAc,EAAE;QACd,cAAc;QACd,eAAe;QACf,WAAW;QACX,eAAe;QACf,iBAAiB;QACjB,kBAAkB;QAClB,mBAAmB;KACpB;IACD,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eA+BG;CACd,CAAC,CAAC","sourcesContent":["import { PromptTemplate } from '@langchain/core/prompts';\n\nexport const baseFilterFilesPromptTemplate = new PromptTemplate({\n inputVariables: [\n 'documentation',\n 'file_list',\n 'integration_name',\n 'integration_rules',\n ],\n template: `You are a PostHog installation wizard, a master AI programming assistant that implements PostHog for {integration_name} projects.\nGiven the following list of file paths from a project, determine which files are likely to require modifications \nto integrate PostHog. Use the installation documentation as a reference for what files might need modifications, do not include files that are unlikely to require modification based on the documentation.\n\n- If you would like to create a new file, you can include the file path in your response.\n- If you would like to modify an existing file, you can include the file path in your response.\n\nYou should return all files that you think will be required to look at or modify to integrate PostHog. You should return them in the order you would like to see them processed, with new files first, followed by the files that you want to update to integrate PostHog.\n\nRules:\n- Only return files that you think will be required to look at or modify to integrate PostHog.\n- Do not return files that are unlikely to require modification based on the documentation.\n- If you are unsure, return the file, since it's better to have more files than less.\n- If you create a new file, it should not conflict with any existing files.\n- If the user is using TypeScript, you should return .ts and .tsx files.\n- The file structure of the project may be different than the documentation, you should follow the file structure of the project.\n{integration_rules}\n\nInstallation documentation:\n{documentation}\n\nAll current files in the repository:\n\n{file_list}`,\n});\n\nexport const baseGenerateFileChangesPromptTemplate = new PromptTemplate({\n inputVariables: [\n 'file_content',\n 'documentation',\n 'file_path',\n 'changed_files',\n 'unchanged_files',\n 'integration_name',\n 'integration_rules',\n ],\n template: `You are a PostHog installation wizard, a master AI programming assistant that implements PostHog for {integration_name} projects.\n\nYour task is to update the file to integrate PostHog according to the documentation.\nDo not return a diff — you should return the complete updated file content.\n\nRules:\n- Preserve the existing code formatting and style.\n- Only make the changes required by the documentation.\n- If no changes are needed, return the file as-is.\n- If the current file is empty, and you think it should be created, you can add the contents of the new file.\n- The file structure of the project may be different than the documentation, you should follow the file structure of the project.\n- Use relative imports if you are unsure what the project import paths are.\n{integration_rules}\n\n\nCONTEXT\n---\n\nDocumentation for integrating PostHog with {integration_name}:\n{documentation}\n\nThe file you are updating is:\n{file_path}\n\nHere are the changes you have already made to the project:\n{changed_files}\n\nHere are the files that have not been changed yet:\n{unchanged_files}\n\nBelow is the current file contents:\n{file_content}`,\n});\n"]}
|
package/dist/src/nextjs/docs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getNextjsPagesRouterDocs = exports.getNextjsAppRouterDocs = void 0;
|
|
4
|
-
const
|
|
4
|
+
const urls_1 = require("../utils/urls");
|
|
5
5
|
const getNextjsAppRouterDocs = ({ host, language, }) => {
|
|
6
6
|
return `
|
|
7
7
|
==============================
|
|
@@ -24,7 +24,7 @@ export function PostHogProvider({ children }: { children: React.ReactNode }) {
|
|
|
24
24
|
useEffect(() => {
|
|
25
25
|
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
|
|
26
26
|
api_host: "/ingest",
|
|
27
|
-
ui_host: "${(0,
|
|
27
|
+
ui_host: "${(0, urls_1.getUiHostFromHost)(host)}",
|
|
28
28
|
capture_pageview: false, // We capture pageviews manually
|
|
29
29
|
capture_pageleave: true, // Enable pageleave capture
|
|
30
30
|
})
|
|
@@ -122,7 +122,8 @@ LOCATION: Wherever the root next config is
|
|
|
122
122
|
Changes:
|
|
123
123
|
- Add rewrites to the Next.js config to support PostHog, if there are existing rewrites, add the PostHog rewrites to them.
|
|
124
124
|
- Add skipTrailingSlashRedirect to the Next.js config to support PostHog trailing slash API requests.
|
|
125
|
-
- This can be of type js, ts, mjs, cjs etc. You should adapt the file according
|
|
125
|
+
- This can be of type js, ts, mjs, cjs etc. You should adapt the file according to what extension it uses, and if it does not exist yet use '.js'.
|
|
126
|
+
|
|
126
127
|
Example:
|
|
127
128
|
--------------------------------------------------
|
|
128
129
|
const nextConfig = {
|
|
@@ -131,7 +132,7 @@ const nextConfig = {
|
|
|
131
132
|
return [
|
|
132
133
|
{
|
|
133
134
|
source: "/ingest/static/:path*",
|
|
134
|
-
destination: "${(0,
|
|
135
|
+
destination: "${(0, urls_1.getAssetHostFromHost)(host)}/static/:path*",
|
|
135
136
|
},
|
|
136
137
|
{
|
|
137
138
|
source: "/ingest/:path*",
|
|
@@ -172,7 +173,7 @@ export default function App({ Component, pageProps }) {
|
|
|
172
173
|
useEffect(() => {
|
|
173
174
|
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {
|
|
174
175
|
api_host: "/ingest",
|
|
175
|
-
ui_host: "${(0,
|
|
176
|
+
ui_host: "${(0, urls_1.getUiHostFromHost)(host)}",
|
|
176
177
|
loaded: (posthog) => {
|
|
177
178
|
if (process.env.NODE_ENV === "development") posthog.debug()
|
|
178
179
|
},
|
|
@@ -199,18 +200,19 @@ FILE: posthog.${language === 'typescript' ? 'ts' : 'js'}
|
|
|
199
200
|
LOCATION: Wherever works best given the project structure
|
|
200
201
|
==============================
|
|
201
202
|
Changes:
|
|
202
|
-
- Initialize the PostHog Node.js client
|
|
203
|
+
- Initialize the PostHog Node.js client
|
|
203
204
|
|
|
204
205
|
Example:
|
|
205
206
|
--------------------------------------------------
|
|
206
207
|
import { PostHog } from "posthog-node"
|
|
207
208
|
|
|
208
209
|
export default function PostHogClient() {
|
|
209
|
-
|
|
210
|
+
const posthogClient = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
|
|
210
211
|
host: "${host}",
|
|
211
212
|
flushAt: 1,
|
|
212
213
|
flushInterval: 0,
|
|
213
214
|
})
|
|
215
|
+
return posthogClient
|
|
214
216
|
}
|
|
215
217
|
--------------------------------------------------
|
|
216
218
|
|
|
@@ -219,25 +221,35 @@ FILE: next.config.{js,ts,mjs,cjs}
|
|
|
219
221
|
LOCATION: Wherever the root next config is
|
|
220
222
|
==============================
|
|
221
223
|
Changes:
|
|
222
|
-
- Add rewrites to support PostHog
|
|
223
|
-
-
|
|
224
|
+
- Add rewrites to the Next.js config to support PostHog, if there are existing rewrites, add the PostHog rewrites to them.
|
|
225
|
+
- Add skipTrailingSlashRedirect to the Next.js config to support PostHog trailing slash API requests.
|
|
226
|
+
- This can be of type js, ts, mjs, cjs etc. You should adapt the file according to what extension it uses, and if it does not exist yet use '.js'.
|
|
224
227
|
|
|
225
228
|
Example:
|
|
226
229
|
--------------------------------------------------
|
|
227
230
|
const nextConfig = {
|
|
231
|
+
// other config
|
|
228
232
|
async rewrites() {
|
|
229
233
|
return [
|
|
230
|
-
{
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
+
{
|
|
235
|
+
source: "/ingest/static/:path*",
|
|
236
|
+
destination: "${(0, urls_1.getAssetHostFromHost)(host)}/static/:path*",
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
source: "/ingest/:path*",
|
|
240
|
+
destination: "${host}/:path*",
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
source: "/ingest/decide",
|
|
244
|
+
destination: "${host}/decide",
|
|
245
|
+
},
|
|
246
|
+
];
|
|
234
247
|
},
|
|
248
|
+
// This is required to support PostHog trailing slash API requests
|
|
235
249
|
skipTrailingSlashRedirect: true,
|
|
236
250
|
}
|
|
237
|
-
|
|
238
251
|
module.exports = nextConfig
|
|
239
|
-
|
|
240
|
-
`;
|
|
252
|
+
--------------------------------------------------`;
|
|
241
253
|
};
|
|
242
254
|
exports.getNextjsPagesRouterDocs = getNextjsPagesRouterDocs;
|
|
243
255
|
//# sourceMappingURL=docs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"docs.js","sourceRoot":"","sources":["../../../src/nextjs/docs.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"docs.js","sourceRoot":"","sources":["../../../src/nextjs/docs.ts"],"names":[],"mappings":";;;AAAA,wCAAwE;AAEjE,MAAM,sBAAsB,GAAG,CAAC,EACrC,IAAI,EACJ,QAAQ,GAIT,EAAE,EAAE;IACH,OAAO;;wBAEe,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KACxD;;;;;;;;;;;;;;;;;;;kBAmBc,IAAA,wBAAiB,EAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eA4C1B,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;gBA2BxC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;;;;;;;;;;;;aAY1C,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;wBAyBO,IAAA,2BAAoB,EAAC,IAAI,CAAC;;;;wBAI1B,IAAI;;;;wBAIJ,IAAI;;;;;;;;mDAQuB,CAAC;AACpD,CAAC,CAAC;AA1JW,QAAA,sBAAsB,0BA0JjC;AAEK,MAAM,wBAAwB,GAAG,CAAC,EACvC,IAAI,EACJ,QAAQ,GAIT,EAAE,EAAE;IACH,OAAO;;aAEI,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK;mCACnB,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KACnE;;;;;;;;;;;;;;;;;;kBAkBc,IAAA,wBAAiB,EAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;gBAuBzB,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;;;;;;;;;;;;aAY1C,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;wBAyBO,IAAA,2BAAoB,EAAC,IAAI,CAAC;;;;wBAI1B,IAAI;;;;wBAIJ,IAAI;;;;;;;;mDAQuB,CAAC;AACpD,CAAC,CAAC;AA1GW,QAAA,wBAAwB,4BA0GnC","sourcesContent":["import { getAssetHostFromHost, getUiHostFromHost } from '../utils/urls';\n\nexport const getNextjsAppRouterDocs = ({\n host,\n language,\n}: {\n host: string;\n language: 'typescript' | 'javascript';\n}) => {\n return `\n==============================\nFILE: PostHogProvider.${language === 'typescript' ? 'tsx' : 'jsx'\n } (put it somewhere where client files are, like the components folder)\nLOCATION: Wherever other providers are, or the components folder\n==============================\nChanges:\n- Create a PostHogProvider component that will be imported into the layout file.\n\nExample:\n--------------------------------------------------\n\"use client\"\n\nimport posthog from \"posthog-js\"\nimport { PostHogProvider as PHProvider, usePostHog } from \"posthog-js/react\"\nimport { Suspense, useEffect } from \"react\"\nimport { usePathname, useSearchParams } from \"next/navigation\"\n\nexport function PostHogProvider({ children }: { children: React.ReactNode }) {\n useEffect(() => {\n posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {\n api_host: \"/ingest\",\n ui_host: \"${getUiHostFromHost(host)}\",\n capture_pageview: false, // We capture pageviews manually\n capture_pageleave: true, // Enable pageleave capture\n })\n }, [])\n\n return (\n <PHProvider client={posthog}>\n <SuspendedPostHogPageView />\n {children}\n </PHProvider>\n )\n}\n\n\nfunction PostHogPageView() {\n const pathname = usePathname()\n const searchParams = useSearchParams()\n const posthog = usePostHog()\n\n useEffect(() => {\n if (pathname && posthog) {\n let url = window.origin + pathname\n const search = searchParams.toString()\n if (search) {\n url += \"?\" + search\n }\n posthog.capture(\"$pageview\", { \"$current_url\": url })\n }\n }, [pathname, searchParams, posthog])\n\n return null\n}\n\nfunction SuspendedPostHogPageView() {\n return (\n <Suspense fallback={null}>\n <PostHogPageView />\n </Suspense>\n )\n}\n--------------------------------------------------\n\n==============================\nFILE: layout.${language === 'typescript' ? 'tsx' : 'jsx'}\nLOCATION: Wherever the root layout is\n==============================\nChanges:\n- Import the PostHogProvider from the providers file and wrap the app in it.\n\nExample:\n--------------------------------------------------\n// other imports\nimport { PostHogProvider } from \"LOCATION_OF_POSTHOG_PROVIDER\"\n\nexport default function RootLayout({ children }) {\n return (\n <html lang=\"en\">\n <body>\n <PostHogProvider>\n {/* other providers */}\n {children}\n {/* other providers */}\n </PostHogProvider>\n </body>\n </html>\n )\n}\n--------------------------------------------------\n\n==============================\nFILE: posthog.${language === 'typescript' ? 'ts' : 'js'}\nLOCATION: Wherever works best given the project structure\n==============================\nChanges:\n- Initialize the PostHog Node.js client\n\nExample:\n--------------------------------------------------\nimport { PostHog } from \"posthog-node\"\n\nexport default function PostHogClient() {\n const posthogClient = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {\n host: \"${host}\",\n flushAt: 1,\n flushInterval: 0,\n })\n return posthogClient\n}\n--------------------------------------------------\n\n==============================\nFILE: next.config.{js,ts,mjs,cjs}\nLOCATION: Wherever the root next config is\n==============================\nChanges:\n- Add rewrites to the Next.js config to support PostHog, if there are existing rewrites, add the PostHog rewrites to them.\n- Add skipTrailingSlashRedirect to the Next.js config to support PostHog trailing slash API requests.\n- This can be of type js, ts, mjs, cjs etc. You should adapt the file according to what extension it uses, and if it does not exist yet use '.js'.\n\nExample:\n--------------------------------------------------\nconst nextConfig = {\n // other config\n async rewrites() {\n return [\n {\n source: \"/ingest/static/:path*\",\n destination: \"${getAssetHostFromHost(host)}/static/:path*\",\n },\n {\n source: \"/ingest/:path*\",\n destination: \"${host}/:path*\",\n },\n {\n source: \"/ingest/decide\",\n destination: \"${host}/decide\",\n },\n ];\n },\n // This is required to support PostHog trailing slash API requests\n skipTrailingSlashRedirect: true,\n}\nmodule.exports = nextConfig\n--------------------------------------------------`;\n};\n\nexport const getNextjsPagesRouterDocs = ({\n host,\n language,\n}: {\n host: string;\n language: 'typescript' | 'javascript';\n}) => {\n return `\n==============================\nFILE: _app.${language === 'typescript' ? 'tsx' : 'jsx'}\nLOCATION: Wherever the root _app.${language === 'typescript' ? 'tsx' : 'jsx'\n } file is\n==============================\nChanges:\n- Initialize PostHog in _app.js.\n- Wrap the application in PostHogProvider.\n- Manually capture $pageview events.\n\nExample:\n--------------------------------------------------\nimport { useEffect } from \"react\"\nimport { Router } from \"next/router\"\nimport posthog from \"posthog-js\"\nimport { PostHogProvider } from \"posthog-js/react\"\n\nexport default function App({ Component, pageProps }) {\n useEffect(() => {\n posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {\n api_host: \"/ingest\",\n ui_host: \"${getUiHostFromHost(host)}\",\n loaded: (posthog) => {\n if (process.env.NODE_ENV === \"development\") posthog.debug()\n },\n })\n\n const handleRouteChange = () => posthog?.capture(\"$pageview\")\n Router.events.on(\"routeChangeComplete\", handleRouteChange)\n\n return () => {\n Router.events.off(\"routeChangeComplete\", handleRouteChange)\n }\n }, [])\n\n return (\n <PostHogProvider client={posthog}>\n <Component {...pageProps} />\n </PostHogProvider>\n )\n}\n--------------------------------------------------\n\n==============================\nFILE: posthog.${language === 'typescript' ? 'ts' : 'js'}\nLOCATION: Wherever works best given the project structure\n==============================\nChanges:\n- Initialize the PostHog Node.js client\n\nExample:\n--------------------------------------------------\nimport { PostHog } from \"posthog-node\"\n\nexport default function PostHogClient() {\n const posthogClient = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {\n host: \"${host}\",\n flushAt: 1,\n flushInterval: 0,\n })\n return posthogClient\n}\n--------------------------------------------------\n\n==============================\nFILE: next.config.{js,ts,mjs,cjs}\nLOCATION: Wherever the root next config is\n==============================\nChanges:\n- Add rewrites to the Next.js config to support PostHog, if there are existing rewrites, add the PostHog rewrites to them.\n- Add skipTrailingSlashRedirect to the Next.js config to support PostHog trailing slash API requests.\n- This can be of type js, ts, mjs, cjs etc. You should adapt the file according to what extension it uses, and if it does not exist yet use '.js'.\n\nExample:\n--------------------------------------------------\nconst nextConfig = {\n // other config\n async rewrites() {\n return [\n {\n source: \"/ingest/static/:path*\",\n destination: \"${getAssetHostFromHost(host)}/static/:path*\",\n },\n {\n source: \"/ingest/:path*\",\n destination: \"${host}/:path*\",\n },\n {\n source: \"/ingest/decide\",\n destination: \"${host}/decide\",\n },\n ];\n },\n // This is required to support PostHog trailing slash API requests\n skipTrailingSlashRedirect: true,\n}\nmodule.exports = nextConfig\n--------------------------------------------------`;\n};\n"]}
|
|
@@ -1,9 +1,2 @@
|
|
|
1
1
|
import type { WizardOptions } from '../utils/types';
|
|
2
|
-
import { Integration } from '../lib/constants';
|
|
3
2
|
export declare function runNextjsWizard(options: WizardOptions): Promise<void>;
|
|
4
|
-
export declare function detectNextJs(options: Pick<WizardOptions, 'installDir'>): Promise<Integration.nextjs | undefined>;
|
|
5
|
-
export declare function addOrUpdateEnvironmentVariables({ projectApiKey, installDir, }: {
|
|
6
|
-
projectApiKey: string;
|
|
7
|
-
installDir: string;
|
|
8
|
-
}): Promise<void>;
|
|
9
|
-
export declare function getDotGitignore({ installDir, }: Pick<WizardOptions, 'installDir'>): string | undefined;
|