@posthog/wizard 0.7.0 → 0.8.0
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/dist/bin.d.ts +2 -0
- package/dist/bin.js +28 -0
- package/dist/bin.js.map +1 -0
- package/dist/src/lib/config.d.ts +49 -0
- package/dist/src/lib/config.js +85 -0
- package/dist/src/lib/config.js.map +1 -0
- package/dist/src/lib/constants.d.ts +25 -0
- package/dist/src/lib/constants.js +45 -0
- package/dist/src/lib/constants.js.map +1 -0
- package/dist/src/lib/messages.d.ts +17 -0
- package/dist/src/lib/messages.js +68 -0
- package/dist/src/lib/messages.js.map +1 -0
- package/dist/src/lib/prompts.d.ts +16 -0
- package/dist/src/lib/prompts.js +83 -0
- package/dist/src/lib/prompts.js.map +1 -0
- package/dist/src/nextjs/docs.d.ts +8 -0
- package/dist/src/nextjs/docs.js +257 -0
- package/dist/src/nextjs/docs.js.map +1 -0
- package/dist/src/nextjs/nextjs-wizard.d.ts +2 -0
- package/dist/src/nextjs/nextjs-wizard.js +136 -0
- package/dist/src/nextjs/nextjs-wizard.js.map +1 -0
- package/dist/src/nextjs/utils.d.ts +9 -0
- package/dist/src/nextjs/utils.js +83 -0
- package/dist/src/nextjs/utils.js.map +1 -0
- package/dist/src/react/docs.d.ts +4 -0
- package/dist/src/react/docs.js +46 -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 +115 -0
- package/dist/src/react/react-wizard.js.map +1 -0
- package/dist/src/react-native/docs.d.ts +5 -0
- package/dist/src/react-native/docs.js +31 -0
- package/dist/src/react-native/docs.js.map +1 -0
- package/dist/src/react-native/react-native-wizard.d.ts +2 -0
- package/dist/src/react-native/react-native-wizard.js +124 -0
- package/dist/src/react-native/react-native-wizard.js.map +1 -0
- package/dist/src/run.d.ts +13 -0
- package/dist/src/run.js +85 -0
- package/dist/src/run.js.map +1 -0
- package/dist/src/steps/__tests__/add-editor-rules.test.d.ts +1 -0
- package/dist/src/steps/__tests__/add-editor-rules.test.js +218 -0
- package/dist/src/steps/__tests__/add-editor-rules.test.js.map +1 -0
- package/dist/src/steps/__tests__/create-pr.test.d.ts +1 -0
- package/dist/src/steps/__tests__/create-pr.test.js +193 -0
- package/dist/src/steps/__tests__/create-pr.test.js.map +1 -0
- package/dist/src/steps/add-editor-rules.d.ts +9 -0
- package/dist/src/steps/add-editor-rules.js +92 -0
- package/dist/src/steps/add-editor-rules.js.map +1 -0
- package/dist/src/steps/add-or-update-environment-variables.d.ts +10 -0
- package/dist/src/steps/add-or-update-environment-variables.js +194 -0
- package/dist/src/steps/add-or-update-environment-variables.js.map +1 -0
- package/dist/src/steps/create-pr.d.ts +27 -0
- package/dist/src/steps/create-pr.js +305 -0
- package/dist/src/steps/create-pr.js.map +1 -0
- package/dist/src/steps/index.d.ts +4 -0
- package/dist/src/steps/index.js +21 -0
- package/dist/src/steps/index.js.map +1 -0
- package/dist/src/steps/run-prettier.d.ts +5 -0
- package/dist/src/steps/run-prettier.js +93 -0
- package/dist/src/steps/run-prettier.js.map +1 -0
- package/dist/src/steps/upload-environment-variables/EnvironmentProvider.d.ts +8 -0
- package/dist/src/steps/upload-environment-variables/EnvironmentProvider.js +12 -0
- package/dist/src/steps/upload-environment-variables/EnvironmentProvider.js.map +1 -0
- package/dist/src/steps/upload-environment-variables/index.d.ts +6 -0
- package/dist/src/steps/upload-environment-variables/index.js +66 -0
- package/dist/src/steps/upload-environment-variables/index.js.map +1 -0
- package/dist/src/steps/upload-environment-variables/providers/__tests__/vercel.test.d.ts +1 -0
- package/dist/src/steps/upload-environment-variables/providers/__tests__/vercel.test.js +117 -0
- package/dist/src/steps/upload-environment-variables/providers/__tests__/vercel.test.js.map +1 -0
- package/dist/src/steps/upload-environment-variables/providers/vercel.d.ts +14 -0
- package/dist/src/steps/upload-environment-variables/providers/vercel.js +146 -0
- package/dist/src/steps/upload-environment-variables/providers/vercel.js.map +1 -0
- package/dist/src/svelte/docs.d.ts +3 -0
- package/dist/src/svelte/docs.js +110 -0
- package/dist/src/svelte/docs.js.map +1 -0
- package/dist/src/svelte/svelte-wizard.d.ts +2 -0
- package/dist/src/svelte/svelte-wizard.js +115 -0
- package/dist/src/svelte/svelte-wizard.js.map +1 -0
- package/dist/src/telemetry.d.ts +2 -0
- package/dist/src/telemetry.js +13 -0
- package/dist/src/telemetry.js.map +1 -0
- package/dist/src/utils/__tests__/clack-utils.test.d.ts +1 -0
- package/dist/src/utils/__tests__/clack-utils.test.js +128 -0
- package/dist/src/utils/__tests__/clack-utils.test.js.map +1 -0
- package/dist/src/utils/analytics.d.ts +12 -0
- package/dist/src/utils/analytics.js +59 -0
- package/dist/src/utils/analytics.js.map +1 -0
- package/dist/src/utils/bash.d.ts +2 -0
- package/dist/src/utils/bash.js +54 -0
- package/dist/src/utils/bash.js.map +1 -0
- package/dist/src/utils/clack-utils.d.ts +180 -0
- package/dist/src/utils/clack-utils.js +634 -0
- package/dist/src/utils/clack-utils.js.map +1 -0
- package/dist/src/utils/clack.d.ts +2 -0
- package/dist/src/utils/clack.js +9 -0
- package/dist/src/utils/clack.js.map +1 -0
- package/dist/src/utils/debug.d.ts +2 -0
- package/dist/src/utils/debug.js +22 -0
- package/dist/src/utils/debug.js.map +1 -0
- package/dist/src/utils/environment.d.ts +3 -0
- package/dist/src/utils/environment.js +64 -0
- package/dist/src/utils/environment.js.map +1 -0
- package/dist/src/utils/file-utils.d.ts +29 -0
- package/dist/src/utils/file-utils.js +177 -0
- package/dist/src/utils/file-utils.js.map +1 -0
- package/dist/src/utils/logging.d.ts +9 -0
- package/dist/src/utils/logging.js +50 -0
- package/dist/src/utils/logging.js.map +1 -0
- package/dist/src/utils/package-json.d.ts +25 -0
- package/dist/src/utils/package-json.js +27 -0
- package/dist/src/utils/package-json.js.map +1 -0
- package/dist/src/utils/package-manager.d.ts +21 -0
- package/dist/src/utils/package-manager.js +208 -0
- package/dist/src/utils/package-manager.js.map +1 -0
- package/dist/src/utils/query.d.ts +8 -0
- package/dist/src/utils/query.js +27 -0
- package/dist/src/utils/query.js.map +1 -0
- package/dist/src/utils/rules/next-rules.md +9 -0
- package/dist/src/utils/rules/react-native-rules.md +7 -0
- package/dist/src/utils/rules/react-rules.md +7 -0
- package/dist/src/utils/rules/svelte-rules.md +7 -0
- package/dist/src/utils/rules/universal.md +20 -0
- package/dist/src/utils/semver.d.ts +5 -0
- package/dist/src/utils/semver.js +25 -0
- package/dist/src/utils/semver.js.map +1 -0
- package/dist/src/utils/string.d.ts +1 -0
- package/dist/src/utils/string.js +9 -0
- package/dist/src/utils/string.js.map +1 -0
- package/dist/src/utils/types.d.ts +48 -0
- package/dist/src/utils/types.js +3 -0
- package/dist/src/utils/types.js.map +1 -0
- 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/dist/src/utils/vendor/is-unicorn-supported.d.ts +1 -0
- package/dist/src/utils/vendor/is-unicorn-supported.js +24 -0
- package/dist/src/utils/vendor/is-unicorn-supported.js.map +1 -0
- package/package.json +5 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docs.js","sourceRoot":"","sources":["../../../src/svelte/docs.ts"],"names":[],"mappings":";;;AAAO,MAAM,sBAAsB,GAAG,CAAC,EACrC,QAAQ,GAGT,EAAE,EAAE;IACH,OAAO;;oBAGL,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IACrC,6BAA6B,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;0EAElE,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IACrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oEAkDE,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KACtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mDAkDiD,CAAC;AACpD,CAAC,CAAC;AAlHW,QAAA,sBAAsB,0BAkHjC","sourcesContent":["export const getSvelteDocumentation = ({\n language,\n}: {\n language: 'typescript' | 'javascript';\n}) => {\n return `\n==============================\nFILE: Root layout.${\n language === 'typescript' ? 'ts' : 'js'\n } file (e.g routes/+layout.${language === 'typescript' ? 'ts' : 'js'})\nLOCATION: Usually placed at the root of the app (e.g src/routes/+layout.${\n language === 'typescript' ? 'ts' : 'js'\n })\n==============================\nChanges:\n- Add a load function to initialize PostHog, checking if the browser is available to make sure it only initializes on the client\nExample:\n--------------------------------------------------\nimport posthog from 'posthog-js'\nimport { browser } from '$app/environment';\nimport { PUBLIC_POSTHOG_KEY } from '$env/static/public';\n\nexport const load = async () => {\n\n if (browser) {\n posthog.init(\n PUBLIC_POSTHOG_KEY,\n {\n api_host: PUBLIC_POSTHOG_HOST,\n capture_pageview: false,\n capture_pageleave: false\n }\n )\n }\n return\n};\n--------------------------------------------------\n\n==============================\nFile: Root layout .svelte file (e.g routes/+layout.svelte)\nLOCATION: Usually placed at the root of the app (e.g src/routes/+layout.svelte)\n==============================\nChanges:\n- Add pageview & pageleave tracking to the layout\n\nExample:\n--------------------------------------------------\n<script>\n import { browser } from '$app/environment';\n import { beforeNavigate, afterNavigate } from '$app/navigation';\n import posthog from 'posthog-js'\n\n if (browser) {\n beforeNavigate(() => posthog.capture('$pageleave'));\n afterNavigate(() => posthog.capture('$pageview'));\n }\n</script>\n--------------------------------------------------\n\n==============================\nFile: PostHog server initializion\nLOCATION: With other server-side code, e.g. src/lib/server/posthog${\n language === 'typescript' ? '.ts' : '.js'\n }\n==============================\nChanges:\n- Initialize a PostHog client for the server using posthog-node that can be used in other server-side code\nExample:\n--------------------------------------------------\nimport posthog, { PostHog } from 'posthog-node';\nimport { PUBLIC_POSTHOG_KEY, PUBLIC_POSTHOG_HOST } from '$env/static/public';\n\nlet _client: PostHog | null = null;\n\nexport function getPostHogClient() {\n if (!_client) {\n _client = new posthog.PostHog(PUBLIC_POSTHOG_KEY, {\n host: PUBLIC_POSTHOG_HOST,\n });\n }\n return _client;\n}\n--------------------------------------------------\n\n==============================\nFILE: Svelte Config (e.g svelte.config.js)\nLOCATION: Wherever the root of the app is\n==============================\nChanges:\n- Set config to not use relative asset paths\n\nExample:\n--------------------------------------------------\nimport adapter from '@sveltejs/adapter-auto';\nimport { vitePreprocess } from '@sveltejs/vite-plugin-svelte';\n\n/** @type {import('@sveltejs/kit').Config} */\nconst config = {\n\t// Consult https://svelte.dev/docs/kit/integrations\n\t// for more information about preprocessors\n\tpreprocess: vitePreprocess(),\n\n\tkit: {\n // ...\n paths: {\n relative: false, // Required for PostHog session replay to work correctly\n },\n // ...\n\t}\n};\n\nexport default config;\n\n--------------------------------------------------`;\n};\n"]}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable max-lines */
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.runSvelteWizard = runSvelteWizard;
|
|
8
|
+
const clack_utils_1 = require("../utils/clack-utils");
|
|
9
|
+
const package_json_1 = require("../utils/package-json");
|
|
10
|
+
const clack_1 = __importDefault(require("../utils/clack"));
|
|
11
|
+
const constants_1 = require("../lib/constants");
|
|
12
|
+
const docs_1 = require("./docs");
|
|
13
|
+
const analytics_1 = require("../utils/analytics");
|
|
14
|
+
const file_utils_1 = require("../utils/file-utils");
|
|
15
|
+
const clack_utils_2 = require("../utils/clack-utils");
|
|
16
|
+
const add_editor_rules_1 = require("../steps/add-editor-rules");
|
|
17
|
+
const messages_1 = require("../lib/messages");
|
|
18
|
+
const steps_1 = require("../steps");
|
|
19
|
+
async function runSvelteWizard(options) {
|
|
20
|
+
(0, clack_utils_1.printWelcome)({
|
|
21
|
+
wizardName: 'PostHog Svelte Wizard',
|
|
22
|
+
});
|
|
23
|
+
const aiConsent = await (0, clack_utils_1.askForAIConsent)(options);
|
|
24
|
+
if (!aiConsent) {
|
|
25
|
+
await (0, clack_utils_1.abort)('The Svelte wizard requires AI to get setup right now. Please view the docs to setup Svelte manually instead: https://posthog.com/docs/libraries/svelte', 0);
|
|
26
|
+
}
|
|
27
|
+
const cloudRegion = options.cloudRegion ?? (await (0, clack_utils_2.askForCloudRegion)());
|
|
28
|
+
const typeScriptDetected = (0, clack_utils_1.isUsingTypeScript)(options);
|
|
29
|
+
await (0, clack_utils_1.confirmContinueIfNoOrDirtyGitRepo)(options);
|
|
30
|
+
const packageJson = await (0, clack_utils_1.getPackageDotJson)(options);
|
|
31
|
+
await (0, clack_utils_1.ensurePackageIsInstalled)(packageJson, '@sveltejs/kit', '@sveltejs/kit');
|
|
32
|
+
const svelteVersion = (0, package_json_1.getPackageVersion)('@sveltejs/kit', packageJson);
|
|
33
|
+
if (svelteVersion) {
|
|
34
|
+
analytics_1.analytics.setTag('svelte-version', svelteVersion);
|
|
35
|
+
}
|
|
36
|
+
const { projectApiKey, wizardHash, host } = await (0, clack_utils_1.getOrAskForProjectData)({
|
|
37
|
+
...options,
|
|
38
|
+
cloudRegion,
|
|
39
|
+
});
|
|
40
|
+
const sdkAlreadyInstalled = (0, package_json_1.hasPackageInstalled)('posthog-js', packageJson);
|
|
41
|
+
analytics_1.analytics.setTag('sdk-already-installed', sdkAlreadyInstalled);
|
|
42
|
+
const { packageManager: packageManagerFromInstallStep } = await (0, clack_utils_1.installPackage)({
|
|
43
|
+
packageName: 'posthog-js',
|
|
44
|
+
packageNameDisplayLabel: 'posthog-js',
|
|
45
|
+
alreadyInstalled: !!packageJson?.dependencies?.['posthog-js'],
|
|
46
|
+
forceInstall: options.forceInstall,
|
|
47
|
+
askBeforeUpdating: false,
|
|
48
|
+
installDir: options.installDir,
|
|
49
|
+
integration: constants_1.Integration.svelte,
|
|
50
|
+
});
|
|
51
|
+
await (0, clack_utils_1.installPackage)({
|
|
52
|
+
packageName: 'posthog-node',
|
|
53
|
+
packageNameDisplayLabel: 'posthog-node',
|
|
54
|
+
packageManager: packageManagerFromInstallStep,
|
|
55
|
+
alreadyInstalled: !!packageJson?.dependencies?.['posthog-node'],
|
|
56
|
+
forceInstall: options.forceInstall,
|
|
57
|
+
askBeforeUpdating: false,
|
|
58
|
+
installDir: options.installDir,
|
|
59
|
+
integration: constants_1.Integration.svelte,
|
|
60
|
+
});
|
|
61
|
+
const relevantFiles = await (0, file_utils_1.getRelevantFilesForIntegration)({
|
|
62
|
+
installDir: options.installDir,
|
|
63
|
+
integration: constants_1.Integration.svelte,
|
|
64
|
+
});
|
|
65
|
+
const installationDocumentation = (0, docs_1.getSvelteDocumentation)({
|
|
66
|
+
language: typeScriptDetected ? 'typescript' : 'javascript',
|
|
67
|
+
});
|
|
68
|
+
clack_1.default.log.info(`Reviewing PostHog documentation for Svelte`);
|
|
69
|
+
const filesToChange = await (0, file_utils_1.getFilesToChange)({
|
|
70
|
+
integration: constants_1.Integration.svelte,
|
|
71
|
+
relevantFiles,
|
|
72
|
+
documentation: installationDocumentation,
|
|
73
|
+
wizardHash,
|
|
74
|
+
cloudRegion,
|
|
75
|
+
});
|
|
76
|
+
await (0, file_utils_1.generateFileChangesForIntegration)({
|
|
77
|
+
integration: constants_1.Integration.svelte,
|
|
78
|
+
filesToChange,
|
|
79
|
+
wizardHash,
|
|
80
|
+
installDir: options.installDir,
|
|
81
|
+
documentation: installationDocumentation,
|
|
82
|
+
cloudRegion,
|
|
83
|
+
});
|
|
84
|
+
const { relativeEnvFilePath, addedEnvVariables } = await (0, steps_1.addOrUpdateEnvironmentVariablesStep)({
|
|
85
|
+
variables: {
|
|
86
|
+
['PUBLIC_POSTHOG_KEY']: projectApiKey,
|
|
87
|
+
['PUBLIC_POSTHOG_HOST']: host,
|
|
88
|
+
},
|
|
89
|
+
installDir: options.installDir,
|
|
90
|
+
integration: constants_1.Integration.svelte,
|
|
91
|
+
});
|
|
92
|
+
const packageManagerForOutro = packageManagerFromInstallStep ?? (await (0, clack_utils_1.getPackageManager)(options));
|
|
93
|
+
await (0, steps_1.runPrettierStep)({
|
|
94
|
+
installDir: options.installDir,
|
|
95
|
+
integration: constants_1.Integration.svelte,
|
|
96
|
+
});
|
|
97
|
+
const addedEditorRules = await (0, add_editor_rules_1.addEditorRulesStep)({
|
|
98
|
+
installDir: options.installDir,
|
|
99
|
+
rulesName: 'svelte-rules.md',
|
|
100
|
+
integration: constants_1.Integration.svelte,
|
|
101
|
+
default: options.default,
|
|
102
|
+
});
|
|
103
|
+
const outroMessage = (0, messages_1.getOutroMessage)({
|
|
104
|
+
options,
|
|
105
|
+
integration: constants_1.Integration.svelte,
|
|
106
|
+
cloudRegion,
|
|
107
|
+
addedEditorRules,
|
|
108
|
+
packageManager: packageManagerForOutro,
|
|
109
|
+
envFileChanged: addedEnvVariables ? relativeEnvFilePath : undefined,
|
|
110
|
+
uploadedEnvVars: [],
|
|
111
|
+
});
|
|
112
|
+
clack_1.default.outro(outroMessage);
|
|
113
|
+
await analytics_1.analytics.shutdown('success');
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=svelte-wizard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svelte-wizard.js","sourceRoot":"","sources":["../../../src/svelte/svelte-wizard.ts"],"names":[],"mappings":";AAAA,8BAA8B;;;;;AA8B9B,0CA+HC;AA3JD,sDAW8B;AAC9B,wDAA+E;AAC/E,2DAAmC;AACnC,gDAA+C;AAC/C,iCAAgD;AAChD,kDAA+C;AAC/C,oDAI6B;AAE7B,sDAAyD;AACzD,gEAA+D;AAC/D,8CAAkD;AAClD,oCAAgF;AAEzE,KAAK,UAAU,eAAe,CAAC,OAAsB;IAC1D,IAAA,0BAAY,EAAC;QACX,UAAU,EAAE,uBAAuB;KACpC,CAAC,CAAC;IAEH,MA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AAC;QACxC,SAAS,EAAE;YACT,CAAC,oBAAoB,CAAC,EAAE,aAAa;YACrC,CAAC,qBAAqB,CAAC,EAAE,IAAI;SAC9B;QACD,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,WAAW,EAAE,uBAAW,CAAC,MAAM;KAChC,CAAC,CAAC;IAEL,MAAM,sBAAsB,GAC1B,6BAA6B,IAAI,CAAC,MAAM,IAAA,+BAAiB,EAAC,OAAO,CAAC,CAAC,CAAC;IAEtE,MAAM,IAAA,uBAAe,EAAC;QACpB,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,WAAW,EAAE,uBAAW,CAAC,MAAM;KAChC,CAAC,CAAC;IAEH,MAAM,gBAAgB,GAAG,MAAM,IAAA,qCAAkB,EAAC;QAChD,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,SAAS,EAAE,iBAAiB;QAC5B,WAAW,EAAE,uBAAW,CAAC,MAAM;QAC/B,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,IAAA,0BAAe,EAAC;QACnC,OAAO;QACP,WAAW,EAAE,uBAAW,CAAC,MAAM;QAC/B,WAAW;QACX,gBAAgB;QAChB,cAAc,EAAE,sBAAsB;QACtC,cAAc,EAAE,iBAAiB,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,SAAS;QACnE,eAAe,EAAE,EAAE;KACpB,CAAC,CAAC;IAEH,eAAK,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAE1B,MAAM,qBAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AACtC,CAAC","sourcesContent":["/* eslint-disable max-lines */\n\nimport {\n abort,\n askForAIConsent,\n confirmContinueIfNoOrDirtyGitRepo,\n ensurePackageIsInstalled,\n getOrAskForProjectData,\n getPackageDotJson,\n getPackageManager,\n installPackage,\n isUsingTypeScript,\n printWelcome,\n} from '../utils/clack-utils';\nimport { getPackageVersion, hasPackageInstalled } from '../utils/package-json';\nimport clack from '../utils/clack';\nimport { Integration } from '../lib/constants';\nimport { getSvelteDocumentation } from './docs';\nimport { analytics } from '../utils/analytics';\nimport {\n generateFileChangesForIntegration,\n getFilesToChange,\n getRelevantFilesForIntegration,\n} from '../utils/file-utils';\nimport type { WizardOptions } from '../utils/types';\nimport { askForCloudRegion } from '../utils/clack-utils';\nimport { addEditorRulesStep } from '../steps/add-editor-rules';\nimport { getOutroMessage } from '../lib/messages';\nimport { addOrUpdateEnvironmentVariablesStep, runPrettierStep } from '../steps';\n\nexport async function runSvelteWizard(options: WizardOptions): Promise<void> {\n printWelcome({\n wizardName: 'PostHog Svelte Wizard',\n });\n\n const aiConsent = await askForAIConsent(options);\n\n if (!aiConsent) {\n await abort(\n 'The Svelte wizard requires AI to get setup right now. Please view the docs to setup Svelte manually instead: https://posthog.com/docs/libraries/svelte',\n 0,\n );\n }\n\n const cloudRegion = options.cloudRegion ?? (await askForCloudRegion());\n\n const typeScriptDetected = isUsingTypeScript(options);\n\n await confirmContinueIfNoOrDirtyGitRepo(options);\n\n const packageJson = await getPackageDotJson(options);\n\n await ensurePackageIsInstalled(packageJson, '@sveltejs/kit', '@sveltejs/kit');\n\n const svelteVersion = getPackageVersion('@sveltejs/kit', packageJson);\n\n if (svelteVersion) {\n analytics.setTag('svelte-version', svelteVersion);\n }\n\n const { projectApiKey, wizardHash, host } = await getOrAskForProjectData({\n ...options,\n cloudRegion,\n });\n\n const sdkAlreadyInstalled = hasPackageInstalled('posthog-js', packageJson);\n\n analytics.setTag('sdk-already-installed', sdkAlreadyInstalled);\n\n const { packageManager: packageManagerFromInstallStep } =\n await installPackage({\n packageName: 'posthog-js',\n packageNameDisplayLabel: 'posthog-js',\n alreadyInstalled: !!packageJson?.dependencies?.['posthog-js'],\n forceInstall: options.forceInstall,\n askBeforeUpdating: false,\n installDir: options.installDir,\n integration: Integration.svelte,\n });\n\n await installPackage({\n packageName: 'posthog-node',\n packageNameDisplayLabel: 'posthog-node',\n packageManager: packageManagerFromInstallStep,\n alreadyInstalled: !!packageJson?.dependencies?.['posthog-node'],\n forceInstall: options.forceInstall,\n askBeforeUpdating: false,\n installDir: options.installDir,\n integration: Integration.svelte,\n });\n\n const relevantFiles = await getRelevantFilesForIntegration({\n installDir: options.installDir,\n integration: Integration.svelte,\n });\n\n const installationDocumentation = getSvelteDocumentation({\n language: typeScriptDetected ? 'typescript' : 'javascript',\n });\n\n clack.log.info(`Reviewing PostHog documentation for Svelte`);\n\n const filesToChange = await getFilesToChange({\n integration: Integration.svelte,\n relevantFiles,\n documentation: installationDocumentation,\n wizardHash,\n cloudRegion,\n });\n\n await generateFileChangesForIntegration({\n integration: Integration.svelte,\n filesToChange,\n wizardHash,\n installDir: options.installDir,\n documentation: installationDocumentation,\n cloudRegion,\n });\n\n const { relativeEnvFilePath, addedEnvVariables } =\n await addOrUpdateEnvironmentVariablesStep({\n variables: {\n ['PUBLIC_POSTHOG_KEY']: projectApiKey,\n ['PUBLIC_POSTHOG_HOST']: host,\n },\n installDir: options.installDir,\n integration: Integration.svelte,\n });\n\n const packageManagerForOutro =\n packageManagerFromInstallStep ?? (await getPackageManager(options));\n\n await runPrettierStep({\n installDir: options.installDir,\n integration: Integration.svelte,\n });\n\n const addedEditorRules = await addEditorRulesStep({\n installDir: options.installDir,\n rulesName: 'svelte-rules.md',\n integration: Integration.svelte,\n default: options.default,\n });\n\n const outroMessage = getOutroMessage({\n options,\n integration: Integration.svelte,\n cloudRegion,\n addedEditorRules,\n packageManager: packageManagerForOutro,\n envFileChanged: addedEnvVariables ? relativeEnvFilePath : undefined,\n uploadedEnvVars: [],\n });\n\n clack.outro(outroMessage);\n\n await analytics.shutdown('success');\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.traceStep = traceStep;
|
|
4
|
+
exports.updateProgress = updateProgress;
|
|
5
|
+
const analytics_1 = require("./utils/analytics");
|
|
6
|
+
function traceStep(step, callback) {
|
|
7
|
+
updateProgress(step);
|
|
8
|
+
return callback();
|
|
9
|
+
}
|
|
10
|
+
function updateProgress(step) {
|
|
11
|
+
analytics_1.analytics.setTag('progress', step);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=telemetry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../../src/telemetry.ts"],"names":[],"mappings":";;AAEA,8BAGC;AAED,wCAEC;AATD,iDAA8C;AAE9C,SAAgB,SAAS,CAAI,IAAY,EAAE,QAAiB;IAC1D,cAAc,CAAC,IAAI,CAAC,CAAC;IACrB,OAAO,QAAQ,EAAE,CAAC;AACpB,CAAC;AAED,SAAgB,cAAc,CAAC,IAAY;IACzC,qBAAS,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC","sourcesContent":["import { analytics } from './utils/analytics';\n\nexport function traceStep<T>(step: string, callback: () => T): T {\n updateProgress(step);\n return callback();\n}\n\nexport function updateProgress(step: string) {\n analytics.setTag('progress', step);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const clack_utils_1 = require("../clack-utils");
|
|
37
|
+
const ChildProcess = __importStar(require("node:child_process"));
|
|
38
|
+
jest.mock('node:child_process', () => ({
|
|
39
|
+
__esModule: true,
|
|
40
|
+
...jest.requireActual('node:child_process'),
|
|
41
|
+
}));
|
|
42
|
+
jest.mock('@clack/prompts', () => ({
|
|
43
|
+
log: {
|
|
44
|
+
info: jest.fn(),
|
|
45
|
+
success: jest.fn(),
|
|
46
|
+
warn: jest.fn(),
|
|
47
|
+
error: jest.fn(),
|
|
48
|
+
},
|
|
49
|
+
text: jest.fn(),
|
|
50
|
+
confirm: jest.fn(),
|
|
51
|
+
cancel: jest.fn(),
|
|
52
|
+
outro: jest.fn(),
|
|
53
|
+
// passthrough for abortIfCancelled
|
|
54
|
+
isCancel: jest.fn().mockReturnValue(false),
|
|
55
|
+
spinner: jest
|
|
56
|
+
.fn()
|
|
57
|
+
.mockImplementation(() => ({ start: jest.fn(), stop: jest.fn() })),
|
|
58
|
+
}));
|
|
59
|
+
describe.skip('installPackage', () => {
|
|
60
|
+
afterEach(() => {
|
|
61
|
+
jest.clearAllMocks();
|
|
62
|
+
});
|
|
63
|
+
it('force-installs a package if the forceInstall flag is set', async () => {
|
|
64
|
+
const packageManagerMock = {
|
|
65
|
+
name: 'npm',
|
|
66
|
+
label: 'NPM',
|
|
67
|
+
installCommand: 'npm install',
|
|
68
|
+
buildCommand: 'npm run build',
|
|
69
|
+
runScriptCommand: 'npm run',
|
|
70
|
+
flags: '',
|
|
71
|
+
forceInstallFlag: '--force',
|
|
72
|
+
detect: jest.fn(),
|
|
73
|
+
addOverride: jest.fn(),
|
|
74
|
+
};
|
|
75
|
+
const execSpy = jest
|
|
76
|
+
.spyOn(ChildProcess, 'exec')
|
|
77
|
+
// @ts-expect-error - don't care about the return value
|
|
78
|
+
.mockImplementationOnce((cmd, cb) => {
|
|
79
|
+
if (cb) {
|
|
80
|
+
// @ts-expect-error - don't care about the options value
|
|
81
|
+
cb(null, '', '');
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
await (0, clack_utils_1.installPackage)({
|
|
85
|
+
alreadyInstalled: false,
|
|
86
|
+
packageName: 'posthog-js',
|
|
87
|
+
packageNameDisplayLabel: 'posthog-js',
|
|
88
|
+
forceInstall: true,
|
|
89
|
+
askBeforeUpdating: false,
|
|
90
|
+
packageManager: packageManagerMock,
|
|
91
|
+
installDir: process.cwd(),
|
|
92
|
+
});
|
|
93
|
+
expect(execSpy).toHaveBeenCalledWith('npm install posthog-js --force', expect.any(Function));
|
|
94
|
+
});
|
|
95
|
+
it.each([false, undefined])("doesn't force-install a package if the forceInstall flag is %s", async (flag) => {
|
|
96
|
+
const packageManagerMock = {
|
|
97
|
+
name: 'npm',
|
|
98
|
+
label: 'NPM',
|
|
99
|
+
installCommand: 'npm install',
|
|
100
|
+
buildCommand: 'npm run build',
|
|
101
|
+
runScriptCommand: 'npm run',
|
|
102
|
+
flags: '',
|
|
103
|
+
forceInstallFlag: '--force',
|
|
104
|
+
detect: jest.fn(),
|
|
105
|
+
addOverride: jest.fn(),
|
|
106
|
+
};
|
|
107
|
+
const execSpy = jest
|
|
108
|
+
.spyOn(ChildProcess, 'exec')
|
|
109
|
+
// @ts-expect-error - don't care about the return value
|
|
110
|
+
.mockImplementationOnce((cmd, cb) => {
|
|
111
|
+
if (cb) {
|
|
112
|
+
// @ts-expect-error - don't care about the options value
|
|
113
|
+
cb(null, '', '');
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
await (0, clack_utils_1.installPackage)({
|
|
117
|
+
alreadyInstalled: false,
|
|
118
|
+
packageName: 'posthog-js',
|
|
119
|
+
packageNameDisplayLabel: 'posthog-js',
|
|
120
|
+
forceInstall: flag,
|
|
121
|
+
askBeforeUpdating: false,
|
|
122
|
+
packageManager: packageManagerMock,
|
|
123
|
+
installDir: process.cwd(),
|
|
124
|
+
});
|
|
125
|
+
expect(execSpy).toHaveBeenCalledWith('npm install posthog-js ', expect.any(Function));
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
//# sourceMappingURL=clack-utils.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clack-utils.test.js","sourceRoot":"","sources":["../../../../src/utils/__tests__/clack-utils.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAgD;AAEhD,iEAAmD;AAGnD,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,GAAG,EAAE,CAAC,CAAC;IACrC,UAAU,EAAE,IAAI;IAChB,GAAG,IAAI,CAAC,aAAa,CAAC,oBAAoB,CAAC;CAC5C,CAAC,CAAC,CAAC;AAEJ,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,GAAG,EAAE,CAAC,CAAC;IACjC,GAAG,EAAE;QACH,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;QACf,OAAO,EAA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AAA,4BAAc,EAAC;YACnB,gBAAgB,EAAE,KAAK;YACvB,WAAW,EAAE,YAAY;YACzB,uBAAuB,EAAE,YAAY;YACrC,YAAY,EAAE,IAAI;YAClB,iBAAiB,EAAE,KAAK;YACxB,cAAc,EAAE,kBAAkB;YAClC,UAAU,EAAE,OAAO,CAAC,GAAG,EAAE;SAC1B,CAAC,CAAC;QAEH,MAAM,CAAC,OAAO,CAAC,CAAC,oBAAoB,CAClC,0BAA0B,EAC1B,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CACrB,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import { installPackage } from '../clack-utils';\n\nimport * as ChildProcess from 'node:child_process';\nimport type { PackageManager } from '../package-manager';\n\njest.mock('node:child_process', () => ({\n __esModule: true,\n ...jest.requireActual('node:child_process'),\n}));\n\njest.mock('@clack/prompts', () => ({\n log: {\n info: jest.fn(),\n success: jest.fn(),\n warn: jest.fn(),\n error: jest.fn(),\n },\n text: jest.fn(),\n confirm: jest.fn(),\n cancel: jest.fn(),\n outro: jest.fn(),\n // passthrough for abortIfCancelled\n isCancel: jest.fn().mockReturnValue(false),\n spinner: jest\n .fn()\n .mockImplementation(() => ({ start: jest.fn(), stop: jest.fn() })),\n}));\n\ndescribe.skip('installPackage', () => {\n afterEach(() => {\n jest.clearAllMocks();\n });\n\n it('force-installs a package if the forceInstall flag is set', async () => {\n const packageManagerMock: PackageManager = {\n name: 'npm',\n label: 'NPM',\n installCommand: 'npm install',\n buildCommand: 'npm run build',\n runScriptCommand: 'npm run',\n flags: '',\n forceInstallFlag: '--force',\n detect: jest.fn(),\n addOverride: jest.fn(),\n };\n\n const execSpy = jest\n .spyOn(ChildProcess, 'exec')\n // @ts-expect-error - don't care about the return value\n .mockImplementationOnce((cmd, cb) => {\n if (cb) {\n // @ts-expect-error - don't care about the options value\n cb(null, '', '');\n }\n });\n\n await installPackage({\n alreadyInstalled: false,\n packageName: 'posthog-js',\n packageNameDisplayLabel: 'posthog-js',\n forceInstall: true,\n askBeforeUpdating: false,\n packageManager: packageManagerMock,\n installDir: process.cwd(),\n });\n\n expect(execSpy).toHaveBeenCalledWith(\n 'npm install posthog-js --force',\n expect.any(Function),\n );\n });\n\n it.each([false, undefined])(\n \"doesn't force-install a package if the forceInstall flag is %s\",\n async (flag) => {\n const packageManagerMock: PackageManager = {\n name: 'npm',\n label: 'NPM',\n installCommand: 'npm install',\n buildCommand: 'npm run build',\n runScriptCommand: 'npm run',\n flags: '',\n forceInstallFlag: '--force',\n detect: jest.fn(),\n addOverride: jest.fn(),\n };\n\n const execSpy = jest\n .spyOn(ChildProcess, 'exec')\n // @ts-expect-error - don't care about the return value\n .mockImplementationOnce((cmd, cb) => {\n if (cb) {\n // @ts-expect-error - don't care about the options value\n cb(null, '', '');\n }\n });\n\n await installPackage({\n alreadyInstalled: false,\n packageName: 'posthog-js',\n packageNameDisplayLabel: 'posthog-js',\n forceInstall: flag,\n askBeforeUpdating: false,\n packageManager: packageManagerMock,\n installDir: process.cwd(),\n });\n\n expect(execSpy).toHaveBeenCalledWith(\n 'npm install posthog-js ',\n expect.any(Function),\n );\n },\n );\n});\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class Analytics {
|
|
2
|
+
private client;
|
|
3
|
+
private tags;
|
|
4
|
+
private distinctId?;
|
|
5
|
+
private anonymousId;
|
|
6
|
+
constructor();
|
|
7
|
+
setDistinctId(distinctId: string): void;
|
|
8
|
+
setTag(key: string, value: string | boolean | number | null | undefined): void;
|
|
9
|
+
capture(eventName: string, properties?: Record<string, unknown>): void;
|
|
10
|
+
shutdown(status: 'success' | 'error' | 'cancelled'): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export declare const analytics: Analytics;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.analytics = exports.Analytics = void 0;
|
|
4
|
+
const posthog_node_1 = require("posthog-node");
|
|
5
|
+
const constants_1 = require("../lib/constants");
|
|
6
|
+
const uuid_1 = require("uuid");
|
|
7
|
+
class Analytics {
|
|
8
|
+
client;
|
|
9
|
+
tags = {};
|
|
10
|
+
distinctId;
|
|
11
|
+
anonymousId;
|
|
12
|
+
constructor() {
|
|
13
|
+
this.client = new posthog_node_1.PostHog(constants_1.ANALYTICS_POSTHOG_PUBLIC_PROJECT_WRITE_KEY, {
|
|
14
|
+
host: constants_1.ANALYTICS_HOST_URL,
|
|
15
|
+
flushAt: 1,
|
|
16
|
+
flushInterval: 0,
|
|
17
|
+
});
|
|
18
|
+
this.tags = {};
|
|
19
|
+
this.anonymousId = (0, uuid_1.v4)();
|
|
20
|
+
this.distinctId = undefined;
|
|
21
|
+
}
|
|
22
|
+
setDistinctId(distinctId) {
|
|
23
|
+
this.distinctId = distinctId;
|
|
24
|
+
this.client.alias({
|
|
25
|
+
distinctId,
|
|
26
|
+
alias: this.anonymousId,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
setTag(key, value) {
|
|
30
|
+
this.tags[key] = value;
|
|
31
|
+
}
|
|
32
|
+
capture(eventName, properties) {
|
|
33
|
+
this.client.capture({
|
|
34
|
+
distinctId: this.distinctId ?? this.anonymousId,
|
|
35
|
+
event: eventName,
|
|
36
|
+
properties: {
|
|
37
|
+
...this.tags,
|
|
38
|
+
...properties,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async shutdown(status) {
|
|
43
|
+
if (Object.keys(this.tags).length === 0) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
this.client.capture({
|
|
47
|
+
distinctId: this.distinctId ?? this.anonymousId,
|
|
48
|
+
event: 'setup wizard finished',
|
|
49
|
+
properties: {
|
|
50
|
+
status,
|
|
51
|
+
tags: this.tags,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
await this.client.shutdown();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.Analytics = Analytics;
|
|
58
|
+
exports.analytics = new Analytics();
|
|
59
|
+
//# sourceMappingURL=analytics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics.js","sourceRoot":"","sources":["../../../src/utils/analytics.ts"],"names":[],"mappings":";;;AAAA,+CAAuC;AACvC,gDAG0B;AAC1B,+BAAoC;AACpC,MAAa,SAAS;IACZ,MAAM,CAAU;IAChB,IAAI,GACV,EAAE,CAAC;IACG,UAAU,CAAU;IACpB,WAAW,CAAS;IAE5B;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,sBAAO,CAAC,sDAA0C,EAAE;YACpE,IAAI,EAAE,8BAAkB;YACxB,OAAO,EAAE,CAAC;YACV,aAAa,EAAE,CAAC;SACjB,CAAC,CAAC;QAEH,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QAEf,IAAI,CAAC,WAAW,GAAG,IAAA,SAAM,GAAE,CAAC;QAE5B,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;IAED,aAAa,CAAC,UAAkB;QAC9B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;YAChB,UAAU;YACV,KAAK,EAAE,IAAI,CAAC,WAAW;SACxB,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,GAAW,EAAE,KAAmD;QACrE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACzB,CAAC;IAED,OAAO,CAAC,SAAiB,EAAE,UAAoC;QAC7D,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;YAClB,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,WAAW;YAC/C,KAAK,EAAE,SAAS;YAChB,UAAU,EAAE;gBACV,GAAG,IAAI,CAAC,IAAI;gBACZ,GAAG,UAAU;aACd;SACF,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAyC;QACtD,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxC,OAAO;QACT,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;YAClB,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,WAAW;YAC/C,KAAK,EAAE,uBAAuB;YAC9B,UAAU,EAAE;gBACV,MAAM;gBACN,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB;SACF,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;IAC/B,CAAC;CACF;AA5DD,8BA4DC;AAEY,QAAA,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC","sourcesContent":["import { PostHog } from 'posthog-node';\nimport {\n ANALYTICS_HOST_URL,\n ANALYTICS_POSTHOG_PUBLIC_PROJECT_WRITE_KEY,\n} from '../lib/constants';\nimport { v4 as uuidv4 } from 'uuid';\nexport class Analytics {\n private client: PostHog;\n private tags: Record<string, string | boolean | number | null | undefined> =\n {};\n private distinctId?: string;\n private anonymousId: string;\n\n constructor() {\n this.client = new PostHog(ANALYTICS_POSTHOG_PUBLIC_PROJECT_WRITE_KEY, {\n host: ANALYTICS_HOST_URL,\n flushAt: 1,\n flushInterval: 0,\n });\n\n this.tags = {};\n\n this.anonymousId = uuidv4();\n\n this.distinctId = undefined;\n }\n\n setDistinctId(distinctId: string) {\n this.distinctId = distinctId;\n this.client.alias({\n distinctId,\n alias: this.anonymousId,\n });\n }\n\n setTag(key: string, value: string | boolean | number | null | undefined) {\n this.tags[key] = value;\n }\n\n capture(eventName: string, properties?: Record<string, unknown>) {\n this.client.capture({\n distinctId: this.distinctId ?? this.anonymousId,\n event: eventName,\n properties: {\n ...this.tags,\n ...properties,\n },\n });\n }\n\n async shutdown(status: 'success' | 'error' | 'cancelled') {\n if (Object.keys(this.tags).length === 0) {\n return;\n }\n\n this.client.capture({\n distinctId: this.distinctId ?? this.anonymousId,\n event: 'setup wizard finished',\n properties: {\n status,\n tags: this.tags,\n },\n });\n\n await this.client.shutdown();\n }\n}\n\nexport const analytics = new Analytics();\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.executeSync = executeSync;
|
|
37
|
+
exports.execute = execute;
|
|
38
|
+
const child_process = __importStar(require("child_process"));
|
|
39
|
+
function executeSync(command) {
|
|
40
|
+
const output = child_process.execSync(command);
|
|
41
|
+
return output.toString();
|
|
42
|
+
}
|
|
43
|
+
function execute(command) {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
child_process.exec(command, (error, stdout, _) => {
|
|
46
|
+
if (error) {
|
|
47
|
+
reject(error);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
resolve(stdout);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=bash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bash.js","sourceRoot":"","sources":["../../../src/utils/bash.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,kCAGC;AAED,0BAWC;AAlBD,6DAA+C;AAE/C,SAAgB,WAAW,CAAC,OAAe;IACzC,MAAM,MAAM,GAAG,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC/C,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAC;AAC3B,CAAC;AAED,SAAgB,OAAO,CAAC,OAAe;IACrC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE;YAC/C,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,CAAC,KAAK,CAAC,CAAC;gBACd,OAAO;YACT,CAAC;YAED,OAAO,CAAC,MAAM,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import * as child_process from 'child_process';\n\nexport function executeSync(command: string): string {\n const output = child_process.execSync(command);\n return output.toString();\n}\n\nexport function execute(command: string): Promise<string> {\n return new Promise((resolve, reject) => {\n child_process.exec(command, (error, stdout, _) => {\n if (error) {\n reject(error);\n return;\n }\n\n resolve(stdout);\n });\n });\n}\n"]}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { type PackageDotJson } from './package-json';
|
|
2
|
+
import { type PackageManager } from './package-manager';
|
|
3
|
+
import type { CloudRegion, Feature, WizardOptions } from './types';
|
|
4
|
+
export interface CliSetupConfig {
|
|
5
|
+
filename: string;
|
|
6
|
+
name: string;
|
|
7
|
+
gitignore: boolean;
|
|
8
|
+
likelyAlreadyHasAuthToken(contents: string): boolean;
|
|
9
|
+
tokenContent(authToken: string): string;
|
|
10
|
+
likelyAlreadyHasOrgAndProject(contents: string): boolean;
|
|
11
|
+
orgAndProjContent(org: string, project: string): string;
|
|
12
|
+
likelyAlreadyHasUrl?(contents: string): boolean;
|
|
13
|
+
urlContent?(url: string): string;
|
|
14
|
+
}
|
|
15
|
+
export interface CliSetupConfigContent {
|
|
16
|
+
authToken: string;
|
|
17
|
+
org?: string;
|
|
18
|
+
project?: string;
|
|
19
|
+
url?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function abort(message?: string, status?: number): Promise<never>;
|
|
22
|
+
export declare function abortIfCancelled<T>(input: T | Promise<T>): Promise<Exclude<T, symbol>>;
|
|
23
|
+
export declare function printWelcome(options: {
|
|
24
|
+
wizardName: string;
|
|
25
|
+
message?: string;
|
|
26
|
+
}): void;
|
|
27
|
+
export declare function confirmContinueIfNoOrDirtyGitRepo(options: Pick<WizardOptions, 'default'>): Promise<void>;
|
|
28
|
+
export declare function isInGitRepo(): boolean;
|
|
29
|
+
export declare function getUncommittedOrUntrackedFiles(): string[];
|
|
30
|
+
export declare function askForItemSelection(items: string[], message: string): Promise<{
|
|
31
|
+
value: string;
|
|
32
|
+
index: number;
|
|
33
|
+
}>;
|
|
34
|
+
export declare function confirmContinueIfPackageVersionNotSupported({ packageId, packageName, packageVersion, acceptableVersions, note, }: {
|
|
35
|
+
packageId: string;
|
|
36
|
+
packageName: string;
|
|
37
|
+
packageVersion: string;
|
|
38
|
+
acceptableVersions: string;
|
|
39
|
+
note?: string;
|
|
40
|
+
}): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Installs or updates a package with the user's package manager.
|
|
43
|
+
*
|
|
44
|
+
* IMPORTANT: This function modifies the `package.json`! Be sure to re-read
|
|
45
|
+
* it if you make additional modifications to it after calling this function!
|
|
46
|
+
*/
|
|
47
|
+
export declare function installPackage({ packageName, alreadyInstalled, askBeforeUpdating, packageNameDisplayLabel, packageManager, forceInstall, integration, installDir, }: {
|
|
48
|
+
/** The string that is passed to the package manager CLI as identifier to install (e.g. `posthog-js`, or `posthog-js@^1.100.0`) */
|
|
49
|
+
packageName: string;
|
|
50
|
+
alreadyInstalled: boolean;
|
|
51
|
+
askBeforeUpdating?: boolean;
|
|
52
|
+
/** Overrides what is shown in the installation logs in place of the `packageName` option. Useful if the `packageName` is ugly */
|
|
53
|
+
packageNameDisplayLabel?: string;
|
|
54
|
+
packageManager?: PackageManager;
|
|
55
|
+
/** Add force install flag to command to skip install precondition fails */
|
|
56
|
+
forceInstall?: boolean;
|
|
57
|
+
/** The integration that is being used */
|
|
58
|
+
integration?: string;
|
|
59
|
+
/** The directory to install the package in */
|
|
60
|
+
installDir: string;
|
|
61
|
+
}): Promise<{
|
|
62
|
+
packageManager?: PackageManager;
|
|
63
|
+
}>;
|
|
64
|
+
/**
|
|
65
|
+
* Checks if @param packageId is listed as a dependency in @param packageJson.
|
|
66
|
+
* If not, it will ask users if they want to continue without the package.
|
|
67
|
+
*
|
|
68
|
+
* Use this function to check if e.g. a the framework of the SDK is installed
|
|
69
|
+
*
|
|
70
|
+
* @param packageJson the package.json object
|
|
71
|
+
* @param packageId the npm name of the package
|
|
72
|
+
* @param packageName a human readable name of the package
|
|
73
|
+
*/
|
|
74
|
+
export declare function ensurePackageIsInstalled(packageJson: PackageDotJson, packageId: string, packageName: string): Promise<void>;
|
|
75
|
+
export declare function getPackageDotJson({ installDir, }: Pick<WizardOptions, 'installDir'>): Promise<PackageDotJson>;
|
|
76
|
+
export declare function updatePackageDotJson(packageDotJson: PackageDotJson, { installDir }: Pick<WizardOptions, 'installDir'>): Promise<void>;
|
|
77
|
+
export declare function getPackageManager({ installDir, }: Pick<WizardOptions, 'installDir'>): Promise<PackageManager>;
|
|
78
|
+
export declare function isUsingTypeScript({ installDir, }: Pick<WizardOptions, 'installDir'>): boolean;
|
|
79
|
+
/**
|
|
80
|
+
*
|
|
81
|
+
* Use this function to get project data for the wizard.
|
|
82
|
+
*
|
|
83
|
+
* @param options wizard options
|
|
84
|
+
* @returns project data (token, url)
|
|
85
|
+
*/
|
|
86
|
+
export declare function getOrAskForProjectData(_options: WizardOptions & {
|
|
87
|
+
cloudRegion: CloudRegion;
|
|
88
|
+
}): Promise<{
|
|
89
|
+
wizardHash: string;
|
|
90
|
+
host: string;
|
|
91
|
+
projectApiKey: string;
|
|
92
|
+
}>;
|
|
93
|
+
/**
|
|
94
|
+
* Asks users if they have a config file for @param tool (e.g. Vite).
|
|
95
|
+
* If yes, asks users to specify the path to their config file.
|
|
96
|
+
*
|
|
97
|
+
* Use this helper function as a fallback mechanism if the lookup for
|
|
98
|
+
* a config file with its most usual location/name fails.
|
|
99
|
+
*
|
|
100
|
+
* @param toolName Name of the tool for which we're looking for the config file
|
|
101
|
+
* @param configFileName Name of the most common config file name (e.g. vite.config.js)
|
|
102
|
+
*
|
|
103
|
+
* @returns a user path to the config file or undefined if the user doesn't have a config file
|
|
104
|
+
*/
|
|
105
|
+
export declare function askForToolConfigPath(toolName: string, configFileName: string): Promise<string | undefined>;
|
|
106
|
+
/**
|
|
107
|
+
* Prints copy/paste-able instructions to the console.
|
|
108
|
+
* Afterwards asks the user if they added the code snippet to their file.
|
|
109
|
+
*
|
|
110
|
+
* While there's no point in providing a "no" answer here, it gives users time to fulfill the
|
|
111
|
+
* task before the wizard continues with additional steps.
|
|
112
|
+
*
|
|
113
|
+
* Use this function if you want to show users instructions on how to add/modify
|
|
114
|
+
* code in their file. This is helpful if automatic insertion failed or is not possible/feasible.
|
|
115
|
+
*
|
|
116
|
+
* @param filename the name of the file to which the code snippet should be applied.
|
|
117
|
+
* If a path is provided, only the filename will be used.
|
|
118
|
+
*
|
|
119
|
+
* @param codeSnippet the snippet to be printed. Use {@link makeCodeSnippet} to create the
|
|
120
|
+
* diff-like format for visually highlighting unchanged or modified lines of code.
|
|
121
|
+
*
|
|
122
|
+
* @param hint (optional) a hint to be printed after the main instruction to add
|
|
123
|
+
* the code from @param codeSnippet to their @param filename.
|
|
124
|
+
*
|
|
125
|
+
* TODO: refactor copy paste instructions across different wizards to use this function.
|
|
126
|
+
* this might require adding a custom message parameter to the function
|
|
127
|
+
*/
|
|
128
|
+
export declare function showCopyPasteInstructions(filename: string, codeSnippet: string, hint?: string): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Callback that exposes formatting helpers for a code snippet.
|
|
131
|
+
* @param unchanged - Formats text as old code.
|
|
132
|
+
* @param plus - Formats text as new code.
|
|
133
|
+
* @param minus - Formats text as removed code.
|
|
134
|
+
*/
|
|
135
|
+
type CodeSnippetFormatter = (unchanged: (txt: string) => string, plus: (txt: string) => string, minus: (txt: string) => string) => string;
|
|
136
|
+
/**
|
|
137
|
+
* Crafts a code snippet that can be used to e.g.
|
|
138
|
+
* - print copy/paste instructions to the console
|
|
139
|
+
* - create a new config file.
|
|
140
|
+
*
|
|
141
|
+
* @param colors set this to true if you want the final snippet to be colored.
|
|
142
|
+
* This is useful for printing the snippet to the console as part of copy/paste instructions.
|
|
143
|
+
*
|
|
144
|
+
* @param callback the callback that returns the formatted code snippet.
|
|
145
|
+
* It exposes takes the helper functions for marking code as unchanged, new or removed.
|
|
146
|
+
* These functions no-op if no special formatting should be applied
|
|
147
|
+
* and otherwise apply the appropriate formatting/coloring.
|
|
148
|
+
* (@see {@link CodeSnippetFormatter})
|
|
149
|
+
*
|
|
150
|
+
* @see {@link showCopyPasteInstructions} for the helper with which to display the snippet in the console.
|
|
151
|
+
*
|
|
152
|
+
* @returns a string containing the final, formatted code snippet.
|
|
153
|
+
*/
|
|
154
|
+
export declare function makeCodeSnippet(colors: boolean, callback: CodeSnippetFormatter): string;
|
|
155
|
+
/**
|
|
156
|
+
* Creates a new config file with the given @param filepath and @param codeSnippet.
|
|
157
|
+
*
|
|
158
|
+
* Use this function to create a new config file for users. This is useful
|
|
159
|
+
* when users answered that they don't yet have a config file for a tool.
|
|
160
|
+
*
|
|
161
|
+
* (This doesn't mean that they don't yet have some other way of configuring
|
|
162
|
+
* their tool but we can leave it up to them to figure out how to merge configs
|
|
163
|
+
* here.)
|
|
164
|
+
*
|
|
165
|
+
* @param filepath absolute path to the new config file
|
|
166
|
+
* @param codeSnippet the snippet to be inserted into the file
|
|
167
|
+
* @param moreInformation (optional) the message to be printed after the file was created
|
|
168
|
+
* For example, this can be a link to more information about configuring the tool.
|
|
169
|
+
*
|
|
170
|
+
* @returns true on success, false otherwise
|
|
171
|
+
*/
|
|
172
|
+
export declare function createNewConfigFile(filepath: string, codeSnippet: string, { installDir }: Pick<WizardOptions, 'installDir'>, moreInformation?: string): Promise<boolean>;
|
|
173
|
+
export declare function featureSelectionPrompt<F extends ReadonlyArray<Feature>>(features: F): Promise<{
|
|
174
|
+
[key in F[number]['id']]: boolean;
|
|
175
|
+
}>;
|
|
176
|
+
export declare function askShouldInstallPackage(pkgName: string): Promise<boolean>;
|
|
177
|
+
export declare function askShouldAddPackageOverride(pkgName: string, pkgVersion: string): Promise<boolean>;
|
|
178
|
+
export declare function askForAIConsent(options: Pick<WizardOptions, 'default'>): Promise<boolean>;
|
|
179
|
+
export declare function askForCloudRegion(): Promise<CloudRegion>;
|
|
180
|
+
export {};
|