@posthog/wizard 0.6.0 β 0.7.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/package.json +1 -1
- package/dist/bin.d.ts +0 -2
- package/dist/bin.js +0 -28
- package/dist/bin.js.map +0 -1
- package/dist/src/lib/config.d.ts +0 -49
- package/dist/src/lib/config.js +0 -85
- package/dist/src/lib/config.js.map +0 -1
- package/dist/src/lib/constants.d.ts +0 -24
- package/dist/src/lib/constants.js +0 -46
- package/dist/src/lib/constants.js.map +0 -1
- package/dist/src/lib/messages.d.ts +0 -10
- package/dist/src/lib/messages.js +0 -37
- package/dist/src/lib/messages.js.map +0 -1
- package/dist/src/lib/prompts.d.ts +0 -16
- package/dist/src/lib/prompts.js +0 -83
- package/dist/src/lib/prompts.js.map +0 -1
- package/dist/src/nextjs/docs.d.ts +0 -8
- package/dist/src/nextjs/docs.js +0 -257
- package/dist/src/nextjs/docs.js.map +0 -1
- package/dist/src/nextjs/nextjs-wizard.d.ts +0 -2
- package/dist/src/nextjs/nextjs-wizard.js +0 -121
- package/dist/src/nextjs/nextjs-wizard.js.map +0 -1
- package/dist/src/nextjs/utils.d.ts +0 -9
- package/dist/src/nextjs/utils.js +0 -83
- package/dist/src/nextjs/utils.js.map +0 -1
- package/dist/src/react/docs.d.ts +0 -4
- package/dist/src/react/docs.js +0 -46
- package/dist/src/react/docs.js.map +0 -1
- package/dist/src/react/react-wizard.d.ts +0 -2
- package/dist/src/react/react-wizard.js +0 -105
- package/dist/src/react/react-wizard.js.map +0 -1
- package/dist/src/react-native/docs.d.ts +0 -5
- package/dist/src/react-native/docs.js +0 -31
- package/dist/src/react-native/docs.js.map +0 -1
- package/dist/src/react-native/react-native-wizard.d.ts +0 -2
- package/dist/src/react-native/react-native-wizard.js +0 -123
- package/dist/src/react-native/react-native-wizard.js.map +0 -1
- package/dist/src/run.d.ts +0 -13
- package/dist/src/run.js +0 -83
- package/dist/src/run.js.map +0 -1
- package/dist/src/svelte/docs.d.ts +0 -3
- package/dist/src/svelte/docs.js +0 -110
- package/dist/src/svelte/docs.js.map +0 -1
- package/dist/src/svelte/svelte-wizard.d.ts +0 -2
- package/dist/src/svelte/svelte-wizard.js +0 -113
- package/dist/src/svelte/svelte-wizard.js.map +0 -1
- package/dist/src/telemetry.d.ts +0 -2
- package/dist/src/telemetry.js +0 -13
- package/dist/src/telemetry.js.map +0 -1
- package/dist/src/utils/analytics.d.ts +0 -12
- package/dist/src/utils/analytics.js +0 -59
- package/dist/src/utils/analytics.js.map +0 -1
- package/dist/src/utils/bash.d.ts +0 -2
- package/dist/src/utils/bash.js +0 -54
- package/dist/src/utils/bash.js.map +0 -1
- package/dist/src/utils/clack-utils.d.ts +0 -184
- package/dist/src/utils/clack-utils.js +0 -683
- package/dist/src/utils/clack-utils.js.map +0 -1
- package/dist/src/utils/clack.d.ts +0 -2
- package/dist/src/utils/clack.js +0 -9
- package/dist/src/utils/clack.js.map +0 -1
- package/dist/src/utils/debug.d.ts +0 -2
- package/dist/src/utils/debug.js +0 -22
- package/dist/src/utils/debug.js.map +0 -1
- package/dist/src/utils/environment.d.ts +0 -9
- package/dist/src/utils/environment.js +0 -164
- package/dist/src/utils/environment.js.map +0 -1
- package/dist/src/utils/file-utils.d.ts +0 -29
- package/dist/src/utils/file-utils.js +0 -177
- package/dist/src/utils/file-utils.js.map +0 -1
- package/dist/src/utils/logging.d.ts +0 -9
- package/dist/src/utils/logging.js +0 -50
- package/dist/src/utils/logging.js.map +0 -1
- package/dist/src/utils/package-json.d.ts +0 -25
- package/dist/src/utils/package-json.js +0 -27
- package/dist/src/utils/package-json.js.map +0 -1
- package/dist/src/utils/package-manager.d.ts +0 -21
- package/dist/src/utils/package-manager.js +0 -208
- package/dist/src/utils/package-manager.js.map +0 -1
- package/dist/src/utils/query.d.ts +0 -8
- package/dist/src/utils/query.js +0 -27
- package/dist/src/utils/query.js.map +0 -1
- package/dist/src/utils/rules/add-editor-rules.d.ts +0 -9
- package/dist/src/utils/rules/add-editor-rules.js +0 -90
- package/dist/src/utils/rules/add-editor-rules.js.map +0 -1
- package/dist/src/utils/rules/add-editor-rules.ts +0 -86
- package/dist/src/utils/rules/next-rules.md +0 -9
- package/dist/src/utils/rules/react-native-rules.md +0 -7
- package/dist/src/utils/rules/react-rules.md +0 -7
- package/dist/src/utils/rules/svelte-rules.md +0 -7
- package/dist/src/utils/rules/universal.md +0 -20
- package/dist/src/utils/semver.d.ts +0 -5
- package/dist/src/utils/semver.js +0 -25
- package/dist/src/utils/semver.js.map +0 -1
- package/dist/src/utils/string.d.ts +0 -1
- package/dist/src/utils/string.js +0 -9
- package/dist/src/utils/string.js.map +0 -1
- package/dist/src/utils/types.d.ts +0 -48
- package/dist/src/utils/types.js +0 -3
- package/dist/src/utils/types.js.map +0 -1
- package/dist/src/utils/urls.d.ts +0 -4
- package/dist/src/utils/urls.js +0 -35
- package/dist/src/utils/urls.js.map +0 -1
- package/dist/src/utils/vendor/is-unicorn-supported.d.ts +0 -1
- package/dist/src/utils/vendor/is-unicorn-supported.js +0 -24
- package/dist/src/utils/vendor/is-unicorn-supported.js.map +0 -1
|
@@ -1,683 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.abort = abort;
|
|
40
|
-
exports.abortIfCancelled = abortIfCancelled;
|
|
41
|
-
exports.printWelcome = printWelcome;
|
|
42
|
-
exports.confirmContinueIfNoOrDirtyGitRepo = confirmContinueIfNoOrDirtyGitRepo;
|
|
43
|
-
exports.isInGitRepo = isInGitRepo;
|
|
44
|
-
exports.getUncommittedOrUntrackedFiles = getUncommittedOrUntrackedFiles;
|
|
45
|
-
exports.askForItemSelection = askForItemSelection;
|
|
46
|
-
exports.confirmContinueIfPackageVersionNotSupported = confirmContinueIfPackageVersionNotSupported;
|
|
47
|
-
exports.installPackage = installPackage;
|
|
48
|
-
exports.runPrettierIfInstalled = runPrettierIfInstalled;
|
|
49
|
-
exports.ensurePackageIsInstalled = ensurePackageIsInstalled;
|
|
50
|
-
exports.getPackageDotJson = getPackageDotJson;
|
|
51
|
-
exports.updatePackageDotJson = updatePackageDotJson;
|
|
52
|
-
exports.getPackageManager = getPackageManager;
|
|
53
|
-
exports.isUsingTypeScript = isUsingTypeScript;
|
|
54
|
-
exports.getOrAskForProjectData = getOrAskForProjectData;
|
|
55
|
-
exports.askForToolConfigPath = askForToolConfigPath;
|
|
56
|
-
exports.showCopyPasteInstructions = showCopyPasteInstructions;
|
|
57
|
-
exports.makeCodeSnippet = makeCodeSnippet;
|
|
58
|
-
exports.createNewConfigFile = createNewConfigFile;
|
|
59
|
-
exports.featureSelectionPrompt = featureSelectionPrompt;
|
|
60
|
-
exports.askShouldInstallPackage = askShouldInstallPackage;
|
|
61
|
-
exports.askShouldAddPackageOverride = askShouldAddPackageOverride;
|
|
62
|
-
exports.askForAIConsent = askForAIConsent;
|
|
63
|
-
exports.askForCloudRegion = askForCloudRegion;
|
|
64
|
-
const childProcess = __importStar(require("node:child_process"));
|
|
65
|
-
const fs = __importStar(require("node:fs"));
|
|
66
|
-
const os = __importStar(require("node:os"));
|
|
67
|
-
const node_path_1 = require("node:path");
|
|
68
|
-
const node_timers_1 = require("node:timers");
|
|
69
|
-
const node_url_1 = require("node:url");
|
|
70
|
-
const axios_1 = __importDefault(require("axios"));
|
|
71
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
72
|
-
const opn_1 = __importDefault(require("opn"));
|
|
73
|
-
const telemetry_1 = require("../telemetry");
|
|
74
|
-
const debug_1 = require("./debug");
|
|
75
|
-
const package_json_1 = require("./package-json");
|
|
76
|
-
const package_manager_1 = require("./package-manager");
|
|
77
|
-
const semver_1 = require("./semver");
|
|
78
|
-
const constants_1 = require("../lib/constants");
|
|
79
|
-
const analytics_1 = require("./analytics");
|
|
80
|
-
const clack_1 = __importDefault(require("./clack"));
|
|
81
|
-
const urls_1 = require("./urls");
|
|
82
|
-
async function abort(message, status) {
|
|
83
|
-
await analytics_1.analytics.shutdown('cancelled');
|
|
84
|
-
clack_1.default.outro(message ?? 'Wizard setup cancelled.');
|
|
85
|
-
return process.exit(status ?? 1);
|
|
86
|
-
}
|
|
87
|
-
async function abortIfCancelled(input) {
|
|
88
|
-
await analytics_1.analytics.shutdown('cancelled');
|
|
89
|
-
if (clack_1.default.isCancel(await input)) {
|
|
90
|
-
clack_1.default.cancel('Wizard setup cancelled.');
|
|
91
|
-
process.exit(0);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
return input;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
function printWelcome(options) {
|
|
98
|
-
// eslint-disable-next-line no-console
|
|
99
|
-
console.log('');
|
|
100
|
-
clack_1.default.intro(chalk_1.default.inverse(` ${options.wizardName} `));
|
|
101
|
-
const welcomeText = options.message ||
|
|
102
|
-
`The ${options.wizardName} will help you set up PostHog for your application.\nThank you for using PostHog :)`;
|
|
103
|
-
clack_1.default.note(welcomeText);
|
|
104
|
-
}
|
|
105
|
-
async function confirmContinueIfNoOrDirtyGitRepo(options) {
|
|
106
|
-
return (0, telemetry_1.traceStep)('check-git-status', async () => {
|
|
107
|
-
if (!isInGitRepo()) {
|
|
108
|
-
const continueWithoutGit = options.default
|
|
109
|
-
? true
|
|
110
|
-
: await abortIfCancelled(clack_1.default.confirm({
|
|
111
|
-
message: 'You are not inside a git repository. The wizard will create and update files. Do you want to continue anyway?',
|
|
112
|
-
}));
|
|
113
|
-
analytics_1.analytics.setTag('continue-without-git', continueWithoutGit);
|
|
114
|
-
if (!continueWithoutGit) {
|
|
115
|
-
await abort(undefined, 0);
|
|
116
|
-
}
|
|
117
|
-
// return early to avoid checking for uncommitted files
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
const uncommittedOrUntrackedFiles = getUncommittedOrUntrackedFiles();
|
|
121
|
-
if (uncommittedOrUntrackedFiles.length) {
|
|
122
|
-
clack_1.default.log.warn(`You have uncommitted or untracked files in your repo:
|
|
123
|
-
|
|
124
|
-
${uncommittedOrUntrackedFiles.join('\n')}
|
|
125
|
-
|
|
126
|
-
The wizard will create and update files.`);
|
|
127
|
-
const continueWithDirtyRepo = options.default
|
|
128
|
-
? true
|
|
129
|
-
: await abortIfCancelled(clack_1.default.confirm({
|
|
130
|
-
message: 'Do you want to continue anyway?',
|
|
131
|
-
}));
|
|
132
|
-
analytics_1.analytics.setTag('continue-with-dirty-repo', continueWithDirtyRepo);
|
|
133
|
-
if (!continueWithDirtyRepo) {
|
|
134
|
-
await abort(undefined, 0);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
function isInGitRepo() {
|
|
140
|
-
try {
|
|
141
|
-
childProcess.execSync('git rev-parse --is-inside-work-tree', {
|
|
142
|
-
stdio: 'ignore',
|
|
143
|
-
});
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
|
-
catch {
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
function getUncommittedOrUntrackedFiles() {
|
|
151
|
-
try {
|
|
152
|
-
const gitStatus = childProcess
|
|
153
|
-
.execSync('git status --porcelain=v1', {
|
|
154
|
-
// we only care about stdout
|
|
155
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
156
|
-
})
|
|
157
|
-
.toString();
|
|
158
|
-
const files = gitStatus
|
|
159
|
-
.split(os.EOL)
|
|
160
|
-
.map((line) => line.trim())
|
|
161
|
-
.filter(Boolean)
|
|
162
|
-
.map((f) => `- ${f.split(/\s+/)[1]}`);
|
|
163
|
-
return files;
|
|
164
|
-
}
|
|
165
|
-
catch {
|
|
166
|
-
return [];
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
async function askForItemSelection(items, message) {
|
|
170
|
-
const selection = await abortIfCancelled(clack_1.default.select({
|
|
171
|
-
maxItems: 12,
|
|
172
|
-
message: message,
|
|
173
|
-
options: items.map((item, index) => {
|
|
174
|
-
return {
|
|
175
|
-
value: { value: item, index: index },
|
|
176
|
-
label: item,
|
|
177
|
-
};
|
|
178
|
-
}),
|
|
179
|
-
}));
|
|
180
|
-
return selection;
|
|
181
|
-
}
|
|
182
|
-
async function confirmContinueIfPackageVersionNotSupported({ packageId, packageName, packageVersion, acceptableVersions, note, }) {
|
|
183
|
-
return (0, telemetry_1.traceStep)(`check-package-version`, async () => {
|
|
184
|
-
analytics_1.analytics.setTag(`${packageName.toLowerCase()}-version`, packageVersion);
|
|
185
|
-
const isSupportedVersion = (0, semver_1.fulfillsVersionRange)({
|
|
186
|
-
acceptableVersions,
|
|
187
|
-
version: packageVersion,
|
|
188
|
-
canBeLatest: true,
|
|
189
|
-
});
|
|
190
|
-
if (isSupportedVersion) {
|
|
191
|
-
analytics_1.analytics.setTag(`${packageName.toLowerCase()}-supported`, true);
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
clack_1.default.log.warn(`You have an unsupported version of ${packageName} installed:
|
|
195
|
-
|
|
196
|
-
${packageId}@${packageVersion}`);
|
|
197
|
-
clack_1.default.note(note ??
|
|
198
|
-
`Please upgrade to ${acceptableVersions} if you wish to use the PostHog Wizard.`);
|
|
199
|
-
const continueWithUnsupportedVersion = await abortIfCancelled(clack_1.default.confirm({
|
|
200
|
-
message: 'Do you want to continue anyway?',
|
|
201
|
-
}));
|
|
202
|
-
analytics_1.analytics.setTag(`${packageName.toLowerCase()}-continue-with-unsupported-version`, continueWithUnsupportedVersion);
|
|
203
|
-
if (!continueWithUnsupportedVersion) {
|
|
204
|
-
await abort(undefined, 0);
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Installs or updates a package with the user's package manager.
|
|
210
|
-
*
|
|
211
|
-
* IMPORTANT: This function modifies the `package.json`! Be sure to re-read
|
|
212
|
-
* it if you make additional modifications to it after calling this function!
|
|
213
|
-
*/
|
|
214
|
-
async function installPackage({ packageName, alreadyInstalled, askBeforeUpdating = true, packageNameDisplayLabel, packageManager, forceInstall = false, integration, installDir, }) {
|
|
215
|
-
return (0, telemetry_1.traceStep)('install-package', async () => {
|
|
216
|
-
if (alreadyInstalled && askBeforeUpdating) {
|
|
217
|
-
const shouldUpdatePackage = await abortIfCancelled(clack_1.default.confirm({
|
|
218
|
-
message: `The ${chalk_1.default.bold.cyan(packageNameDisplayLabel ?? packageName)} package is already installed. Do you want to update it to the latest version?`,
|
|
219
|
-
}));
|
|
220
|
-
if (!shouldUpdatePackage) {
|
|
221
|
-
return {};
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
const sdkInstallSpinner = clack_1.default.spinner();
|
|
225
|
-
const pkgManager = packageManager || (await getPackageManager({ installDir }));
|
|
226
|
-
sdkInstallSpinner.start(`${alreadyInstalled ? 'Updating' : 'Installing'} ${chalk_1.default.bold.cyan(packageNameDisplayLabel ?? packageName)} with ${chalk_1.default.bold(pkgManager.label)}.`);
|
|
227
|
-
try {
|
|
228
|
-
await new Promise((resolve, reject) => {
|
|
229
|
-
childProcess.exec(`${pkgManager.installCommand} ${packageName} ${pkgManager.flags} ${forceInstall ? pkgManager.forceInstallFlag : ''}`, { cwd: installDir }, (err, stdout, stderr) => {
|
|
230
|
-
if (err) {
|
|
231
|
-
// Write a log file so we can better troubleshoot issues
|
|
232
|
-
fs.writeFileSync((0, node_path_1.join)(process.cwd(), `posthog-wizard-installation-error-${Date.now()}.log`), JSON.stringify({
|
|
233
|
-
stdout,
|
|
234
|
-
stderr,
|
|
235
|
-
}), { encoding: 'utf8' });
|
|
236
|
-
reject(err);
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
resolve();
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
catch (e) {
|
|
245
|
-
sdkInstallSpinner.stop('Installation failed.');
|
|
246
|
-
clack_1.default.log.error(`${chalk_1.default.red('Encountered the following error during installation:')}\n\n${e}\n\n${chalk_1.default.dim(`The wizard has created a \`posthog-wizard-installation-error-*.log\` file. If you think this issue is caused by the PostHog Wizard, create an issue on GitHub and include the log file's content:\n${constants_1.ISSUES_URL}`)}`);
|
|
247
|
-
await abort();
|
|
248
|
-
}
|
|
249
|
-
sdkInstallSpinner.stop(`${alreadyInstalled ? 'Updated' : 'Installed'} ${chalk_1.default.bold.cyan(packageNameDisplayLabel ?? packageName)} with ${chalk_1.default.bold(pkgManager.label)}.`);
|
|
250
|
-
analytics_1.analytics.capture('wizard interaction', {
|
|
251
|
-
action: 'package installed',
|
|
252
|
-
package_name: packageName,
|
|
253
|
-
package_manager: pkgManager.name,
|
|
254
|
-
integration,
|
|
255
|
-
});
|
|
256
|
-
return { packageManager: pkgManager };
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
async function runPrettierIfInstalled({ installDir, integration, }) {
|
|
260
|
-
return (0, telemetry_1.traceStep)('run-prettier', async () => {
|
|
261
|
-
if (!isInGitRepo()) {
|
|
262
|
-
// We only run formatting on changed files. If we're not in a git repo, we can't find
|
|
263
|
-
// changed files. So let's early-return without showing any formatting-related messages.
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
const changedOrUntrackedFiles = getUncommittedOrUntrackedFiles()
|
|
267
|
-
.map((filename) => {
|
|
268
|
-
return filename.startsWith('- ') ? filename.slice(2) : filename;
|
|
269
|
-
})
|
|
270
|
-
.join(' ');
|
|
271
|
-
if (!changedOrUntrackedFiles.length) {
|
|
272
|
-
// Likewise, if we can't find changed or untracked files, there's no point in running Prettier.
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
const packageJson = await getPackageDotJson({ installDir });
|
|
276
|
-
const prettierInstalled = (0, package_json_1.hasPackageInstalled)('prettier', packageJson);
|
|
277
|
-
analytics_1.analytics.setTag('prettier-installed', prettierInstalled);
|
|
278
|
-
if (!prettierInstalled) {
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
const prettierSpinner = clack_1.default.spinner();
|
|
282
|
-
prettierSpinner.start('Running Prettier on your files.');
|
|
283
|
-
try {
|
|
284
|
-
await new Promise((resolve, reject) => {
|
|
285
|
-
childProcess.exec(`npx prettier --ignore-unknown --write ${changedOrUntrackedFiles}`, (err) => {
|
|
286
|
-
if (err) {
|
|
287
|
-
reject(err);
|
|
288
|
-
}
|
|
289
|
-
else {
|
|
290
|
-
resolve();
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
catch (e) {
|
|
296
|
-
prettierSpinner.stop('Prettier failed to run.');
|
|
297
|
-
clack_1.default.log.warn('Prettier failed to run. There may be formatting issues in your updated files.');
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
prettierSpinner.stop('Prettier has formatted your files.');
|
|
301
|
-
analytics_1.analytics.capture('wizard interaction', {
|
|
302
|
-
action: 'ran prettier',
|
|
303
|
-
integration,
|
|
304
|
-
});
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* Checks if @param packageId is listed as a dependency in @param packageJson.
|
|
309
|
-
* If not, it will ask users if they want to continue without the package.
|
|
310
|
-
*
|
|
311
|
-
* Use this function to check if e.g. a the framework of the SDK is installed
|
|
312
|
-
*
|
|
313
|
-
* @param packageJson the package.json object
|
|
314
|
-
* @param packageId the npm name of the package
|
|
315
|
-
* @param packageName a human readable name of the package
|
|
316
|
-
*/
|
|
317
|
-
async function ensurePackageIsInstalled(packageJson, packageId, packageName) {
|
|
318
|
-
return (0, telemetry_1.traceStep)('ensure-package-installed', async () => {
|
|
319
|
-
const installed = (0, package_json_1.hasPackageInstalled)(packageId, packageJson);
|
|
320
|
-
analytics_1.analytics.setTag(`${packageName.toLowerCase()}-installed`, installed);
|
|
321
|
-
if (!installed) {
|
|
322
|
-
analytics_1.analytics.setTag(`${packageName.toLowerCase()}-installed`, false);
|
|
323
|
-
const continueWithoutPackage = await abortIfCancelled(clack_1.default.confirm({
|
|
324
|
-
message: `${packageName} does not seem to be installed. Do you still want to continue?`,
|
|
325
|
-
initialValue: false,
|
|
326
|
-
}));
|
|
327
|
-
if (!continueWithoutPackage) {
|
|
328
|
-
await abort(undefined, 0);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
async function getPackageDotJson({ installDir, }) {
|
|
334
|
-
const packageJsonFileContents = await fs.promises
|
|
335
|
-
.readFile((0, node_path_1.join)(installDir, 'package.json'), 'utf8')
|
|
336
|
-
.catch(() => {
|
|
337
|
-
clack_1.default.log.error('Could not find package.json. Make sure to run the wizard in the root of your app!');
|
|
338
|
-
return abort();
|
|
339
|
-
});
|
|
340
|
-
let packageJson = undefined;
|
|
341
|
-
try {
|
|
342
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
343
|
-
packageJson = JSON.parse(packageJsonFileContents);
|
|
344
|
-
}
|
|
345
|
-
catch {
|
|
346
|
-
clack_1.default.log.error(`Unable to parse your ${chalk_1.default.cyan('package.json')}. Make sure it has a valid format!`);
|
|
347
|
-
await abort();
|
|
348
|
-
}
|
|
349
|
-
return packageJson || {};
|
|
350
|
-
}
|
|
351
|
-
async function updatePackageDotJson(packageDotJson, { installDir }) {
|
|
352
|
-
try {
|
|
353
|
-
await fs.promises.writeFile((0, node_path_1.join)(installDir, 'package.json'),
|
|
354
|
-
// TODO: maybe figure out the original indentation
|
|
355
|
-
JSON.stringify(packageDotJson, null, 2), {
|
|
356
|
-
encoding: 'utf8',
|
|
357
|
-
flag: 'w',
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
catch {
|
|
361
|
-
clack_1.default.log.error(`Unable to update your ${chalk_1.default.cyan('package.json')}.`);
|
|
362
|
-
await abort();
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
async function getPackageManager({ installDir, }) {
|
|
366
|
-
const detectedPackageManager = (0, package_manager_1.detectPackageManger)({ installDir });
|
|
367
|
-
if (detectedPackageManager) {
|
|
368
|
-
return detectedPackageManager;
|
|
369
|
-
}
|
|
370
|
-
const selectedPackageManager = await abortIfCancelled(clack_1.default.select({
|
|
371
|
-
message: 'Please select your package manager.',
|
|
372
|
-
options: package_manager_1.packageManagers.map((packageManager) => ({
|
|
373
|
-
value: packageManager,
|
|
374
|
-
label: packageManager.label,
|
|
375
|
-
})),
|
|
376
|
-
}));
|
|
377
|
-
analytics_1.analytics.setTag('package-manager', selectedPackageManager.name);
|
|
378
|
-
return selectedPackageManager;
|
|
379
|
-
}
|
|
380
|
-
function isUsingTypeScript({ installDir, }) {
|
|
381
|
-
try {
|
|
382
|
-
return fs.existsSync((0, node_path_1.join)(installDir, 'tsconfig.json'));
|
|
383
|
-
}
|
|
384
|
-
catch {
|
|
385
|
-
return false;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
*
|
|
390
|
-
* Use this function to get project data for the wizard.
|
|
391
|
-
*
|
|
392
|
-
* @param options wizard options
|
|
393
|
-
* @returns project data (token, url)
|
|
394
|
-
*/
|
|
395
|
-
async function getOrAskForProjectData(_options) {
|
|
396
|
-
const cloudUrl = (0, urls_1.getCloudUrlFromRegion)(_options.cloudRegion);
|
|
397
|
-
const { host, projectApiKey, wizardHash } = await (0, telemetry_1.traceStep)('login', () => askForWizardLogin({
|
|
398
|
-
url: cloudUrl,
|
|
399
|
-
signup: _options.signup,
|
|
400
|
-
}));
|
|
401
|
-
if (!projectApiKey) {
|
|
402
|
-
clack_1.default.log.error(`Didn't receive a project API key. This shouldn't happen :(
|
|
403
|
-
|
|
404
|
-
Please let us know if you think this is a bug in the wizard:
|
|
405
|
-
${chalk_1.default.cyan(constants_1.ISSUES_URL)}`);
|
|
406
|
-
clack_1.default.log
|
|
407
|
-
.info(`In the meantime, we'll add a dummy project API key (${chalk_1.default.cyan(`"${constants_1.DUMMY_PROJECT_API_KEY}"`)}) for you to replace later.
|
|
408
|
-
You can find your Project API key here:
|
|
409
|
-
${chalk_1.default.cyan(`${cloudUrl}/settings/project#variables`)}`);
|
|
410
|
-
}
|
|
411
|
-
return {
|
|
412
|
-
wizardHash,
|
|
413
|
-
host: host || constants_1.DEFAULT_HOST_URL,
|
|
414
|
-
projectApiKey: projectApiKey || constants_1.DUMMY_PROJECT_API_KEY,
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
async function askForWizardLogin(options) {
|
|
418
|
-
let wizardHash;
|
|
419
|
-
try {
|
|
420
|
-
wizardHash = (await axios_1.default.post(`${options.url}/api/wizard/initialize`)).data.hash;
|
|
421
|
-
}
|
|
422
|
-
catch (e) {
|
|
423
|
-
clack_1.default.log.error('Loading wizard failed.');
|
|
424
|
-
clack_1.default.log.info(JSON.stringify(e, null, 2));
|
|
425
|
-
await abort(chalk_1.default.red(`Please try again in a few minutes and let us know if this issue persists: ${constants_1.ISSUES_URL}`));
|
|
426
|
-
throw e;
|
|
427
|
-
}
|
|
428
|
-
const loginUrl = new node_url_1.URL(`${options.url}/wizard?hash=${wizardHash}`);
|
|
429
|
-
const signupUrl = new node_url_1.URL(`${options.url}/signup?next=${encodeURIComponent(`/wizard?hash=${wizardHash}`)}`);
|
|
430
|
-
const urlToOpen = options.signup ? signupUrl.toString() : loginUrl.toString();
|
|
431
|
-
clack_1.default.log.info(`${chalk_1.default.bold(`If the browser window didn't open automatically, please open the following link to login into PostHog:`)}\n\n${chalk_1.default.cyan(urlToOpen)}${options.signup
|
|
432
|
-
? `\n\nIf you already have an account, you can use this link:\n\n${chalk_1.default.cyan(loginUrl.toString())}`
|
|
433
|
-
: ``}`);
|
|
434
|
-
(0, opn_1.default)(urlToOpen, { wait: false }).catch(() => {
|
|
435
|
-
// opn throws in environments that don't have a browser (e.g. remote shells) so we just noop here
|
|
436
|
-
});
|
|
437
|
-
const loginSpinner = clack_1.default.spinner();
|
|
438
|
-
loginSpinner.start('Waiting for you to log in using the link above');
|
|
439
|
-
const data = await new Promise((resolve) => {
|
|
440
|
-
const pollingInterval = (0, node_timers_1.setInterval)(() => {
|
|
441
|
-
axios_1.default
|
|
442
|
-
.get(`${options.url}/api/wizard/data`, {
|
|
443
|
-
headers: {
|
|
444
|
-
'Accept-Encoding': 'deflate',
|
|
445
|
-
'X-PostHog-Wizard-Hash': wizardHash,
|
|
446
|
-
},
|
|
447
|
-
})
|
|
448
|
-
.then((result) => {
|
|
449
|
-
const data = {
|
|
450
|
-
wizardHash,
|
|
451
|
-
projectApiKey: result.data.project_api_key,
|
|
452
|
-
host: result.data.host,
|
|
453
|
-
distinctId: result.data.user_distinct_id,
|
|
454
|
-
};
|
|
455
|
-
resolve(data);
|
|
456
|
-
clearTimeout(timeout);
|
|
457
|
-
clearInterval(pollingInterval);
|
|
458
|
-
})
|
|
459
|
-
.catch(() => {
|
|
460
|
-
// noop - just try again
|
|
461
|
-
});
|
|
462
|
-
}, 500);
|
|
463
|
-
const timeout = setTimeout(() => {
|
|
464
|
-
clearInterval(pollingInterval);
|
|
465
|
-
loginSpinner.stop('Login timed out. No worries - it happens to the best of us.');
|
|
466
|
-
analytics_1.analytics.setTag('opened-wizard-link', false);
|
|
467
|
-
void abort('Please restart the Wizard and log in to complete the setup.');
|
|
468
|
-
}, 180_000);
|
|
469
|
-
});
|
|
470
|
-
loginSpinner.stop(`Login complete. ${options.signup ? 'Welcome to PostHog! π' : ''}`);
|
|
471
|
-
analytics_1.analytics.setTag('opened-wizard-link', true);
|
|
472
|
-
analytics_1.analytics.setDistinctId(data.distinctId);
|
|
473
|
-
return data;
|
|
474
|
-
}
|
|
475
|
-
/**
|
|
476
|
-
* Asks users if they have a config file for @param tool (e.g. Vite).
|
|
477
|
-
* If yes, asks users to specify the path to their config file.
|
|
478
|
-
*
|
|
479
|
-
* Use this helper function as a fallback mechanism if the lookup for
|
|
480
|
-
* a config file with its most usual location/name fails.
|
|
481
|
-
*
|
|
482
|
-
* @param toolName Name of the tool for which we're looking for the config file
|
|
483
|
-
* @param configFileName Name of the most common config file name (e.g. vite.config.js)
|
|
484
|
-
*
|
|
485
|
-
* @returns a user path to the config file or undefined if the user doesn't have a config file
|
|
486
|
-
*/
|
|
487
|
-
async function askForToolConfigPath(toolName, configFileName) {
|
|
488
|
-
const hasConfig = await abortIfCancelled(clack_1.default.confirm({
|
|
489
|
-
message: `Do you have a ${toolName} config file (e.g. ${chalk_1.default.cyan(configFileName)})?`,
|
|
490
|
-
initialValue: true,
|
|
491
|
-
}));
|
|
492
|
-
if (!hasConfig) {
|
|
493
|
-
return undefined;
|
|
494
|
-
}
|
|
495
|
-
return await abortIfCancelled(clack_1.default.text({
|
|
496
|
-
message: `Please enter the path to your ${toolName} config file:`,
|
|
497
|
-
placeholder: (0, node_path_1.join)('.', configFileName),
|
|
498
|
-
validate: (value) => {
|
|
499
|
-
if (!value) {
|
|
500
|
-
return 'Please enter a path.';
|
|
501
|
-
}
|
|
502
|
-
try {
|
|
503
|
-
fs.accessSync(value);
|
|
504
|
-
}
|
|
505
|
-
catch {
|
|
506
|
-
return 'Could not access the file at this path.';
|
|
507
|
-
}
|
|
508
|
-
},
|
|
509
|
-
}));
|
|
510
|
-
}
|
|
511
|
-
/**
|
|
512
|
-
* Prints copy/paste-able instructions to the console.
|
|
513
|
-
* Afterwards asks the user if they added the code snippet to their file.
|
|
514
|
-
*
|
|
515
|
-
* While there's no point in providing a "no" answer here, it gives users time to fulfill the
|
|
516
|
-
* task before the wizard continues with additional steps.
|
|
517
|
-
*
|
|
518
|
-
* Use this function if you want to show users instructions on how to add/modify
|
|
519
|
-
* code in their file. This is helpful if automatic insertion failed or is not possible/feasible.
|
|
520
|
-
*
|
|
521
|
-
* @param filename the name of the file to which the code snippet should be applied.
|
|
522
|
-
* If a path is provided, only the filename will be used.
|
|
523
|
-
*
|
|
524
|
-
* @param codeSnippet the snippet to be printed. Use {@link makeCodeSnippet} to create the
|
|
525
|
-
* diff-like format for visually highlighting unchanged or modified lines of code.
|
|
526
|
-
*
|
|
527
|
-
* @param hint (optional) a hint to be printed after the main instruction to add
|
|
528
|
-
* the code from @param codeSnippet to their @param filename.
|
|
529
|
-
*
|
|
530
|
-
* TODO: refactor copy paste instructions across different wizards to use this function.
|
|
531
|
-
* this might require adding a custom message parameter to the function
|
|
532
|
-
*/
|
|
533
|
-
async function showCopyPasteInstructions(filename, codeSnippet, hint) {
|
|
534
|
-
clack_1.default.log.step(`Add the following code to your ${chalk_1.default.cyan((0, node_path_1.basename)(filename))} file:${hint ? chalk_1.default.dim(` (${chalk_1.default.dim(hint)})`) : ''}`);
|
|
535
|
-
// Padding the code snippet to be printed with a \n at the beginning and end
|
|
536
|
-
// This makes it easier to distinguish the snippet from the rest of the output
|
|
537
|
-
// Intentionally logging directly to console here so that the code can be copied/pasted directly
|
|
538
|
-
// eslint-disable-next-line no-console
|
|
539
|
-
console.log(`\n${codeSnippet}\n`);
|
|
540
|
-
await abortIfCancelled(clack_1.default.select({
|
|
541
|
-
message: 'Did you apply the snippet above?',
|
|
542
|
-
options: [{ label: 'Yes, continue!', value: true }],
|
|
543
|
-
initialValue: true,
|
|
544
|
-
}));
|
|
545
|
-
}
|
|
546
|
-
/**
|
|
547
|
-
* Crafts a code snippet that can be used to e.g.
|
|
548
|
-
* - print copy/paste instructions to the console
|
|
549
|
-
* - create a new config file.
|
|
550
|
-
*
|
|
551
|
-
* @param colors set this to true if you want the final snippet to be colored.
|
|
552
|
-
* This is useful for printing the snippet to the console as part of copy/paste instructions.
|
|
553
|
-
*
|
|
554
|
-
* @param callback the callback that returns the formatted code snippet.
|
|
555
|
-
* It exposes takes the helper functions for marking code as unchanged, new or removed.
|
|
556
|
-
* These functions no-op if no special formatting should be applied
|
|
557
|
-
* and otherwise apply the appropriate formatting/coloring.
|
|
558
|
-
* (@see {@link CodeSnippetFormatter})
|
|
559
|
-
*
|
|
560
|
-
* @see {@link showCopyPasteInstructions} for the helper with which to display the snippet in the console.
|
|
561
|
-
*
|
|
562
|
-
* @returns a string containing the final, formatted code snippet.
|
|
563
|
-
*/
|
|
564
|
-
function makeCodeSnippet(colors, callback) {
|
|
565
|
-
const unchanged = (txt) => (colors ? chalk_1.default.grey(txt) : txt);
|
|
566
|
-
const plus = (txt) => (colors ? chalk_1.default.greenBright(txt) : txt);
|
|
567
|
-
const minus = (txt) => (colors ? chalk_1.default.redBright(txt) : txt);
|
|
568
|
-
return callback(unchanged, plus, minus);
|
|
569
|
-
}
|
|
570
|
-
/**
|
|
571
|
-
* Creates a new config file with the given @param filepath and @param codeSnippet.
|
|
572
|
-
*
|
|
573
|
-
* Use this function to create a new config file for users. This is useful
|
|
574
|
-
* when users answered that they don't yet have a config file for a tool.
|
|
575
|
-
*
|
|
576
|
-
* (This doesn't mean that they don't yet have some other way of configuring
|
|
577
|
-
* their tool but we can leave it up to them to figure out how to merge configs
|
|
578
|
-
* here.)
|
|
579
|
-
*
|
|
580
|
-
* @param filepath absolute path to the new config file
|
|
581
|
-
* @param codeSnippet the snippet to be inserted into the file
|
|
582
|
-
* @param moreInformation (optional) the message to be printed after the file was created
|
|
583
|
-
* For example, this can be a link to more information about configuring the tool.
|
|
584
|
-
*
|
|
585
|
-
* @returns true on success, false otherwise
|
|
586
|
-
*/
|
|
587
|
-
async function createNewConfigFile(filepath, codeSnippet, { installDir }, moreInformation) {
|
|
588
|
-
if (!(0, node_path_1.isAbsolute)(filepath)) {
|
|
589
|
-
(0, debug_1.debug)(`createNewConfigFile: filepath is not absolute: ${filepath}`);
|
|
590
|
-
return false;
|
|
591
|
-
}
|
|
592
|
-
const prettyFilename = chalk_1.default.cyan((0, node_path_1.relative)(installDir, filepath));
|
|
593
|
-
try {
|
|
594
|
-
await fs.promises.writeFile(filepath, codeSnippet);
|
|
595
|
-
clack_1.default.log.success(`Added new ${prettyFilename} file.`);
|
|
596
|
-
if (moreInformation) {
|
|
597
|
-
clack_1.default.log.info(chalk_1.default.gray(moreInformation));
|
|
598
|
-
}
|
|
599
|
-
return true;
|
|
600
|
-
}
|
|
601
|
-
catch (e) {
|
|
602
|
-
(0, debug_1.debug)(e);
|
|
603
|
-
clack_1.default.log.warn(`Could not create a new ${prettyFilename} file. Please create one manually and follow the instructions below.`);
|
|
604
|
-
}
|
|
605
|
-
return false;
|
|
606
|
-
}
|
|
607
|
-
async function featureSelectionPrompt(features) {
|
|
608
|
-
return (0, telemetry_1.traceStep)('feature-selection', async () => {
|
|
609
|
-
const selectedFeatures = {};
|
|
610
|
-
for (const feature of features) {
|
|
611
|
-
const selected = await abortIfCancelled(clack_1.default.select({
|
|
612
|
-
message: feature.prompt,
|
|
613
|
-
initialValue: true,
|
|
614
|
-
options: [
|
|
615
|
-
{
|
|
616
|
-
value: true,
|
|
617
|
-
label: 'Yes',
|
|
618
|
-
hint: feature.enabledHint,
|
|
619
|
-
},
|
|
620
|
-
{
|
|
621
|
-
value: false,
|
|
622
|
-
label: 'No',
|
|
623
|
-
hint: feature.disabledHint,
|
|
624
|
-
},
|
|
625
|
-
],
|
|
626
|
-
}));
|
|
627
|
-
selectedFeatures[feature.id] = selected;
|
|
628
|
-
}
|
|
629
|
-
return selectedFeatures;
|
|
630
|
-
});
|
|
631
|
-
}
|
|
632
|
-
async function askShouldInstallPackage(pkgName) {
|
|
633
|
-
return (0, telemetry_1.traceStep)(`ask-install-package`, () => abortIfCancelled(clack_1.default.confirm({
|
|
634
|
-
message: `Do you want to install ${chalk_1.default.cyan(pkgName)}?`,
|
|
635
|
-
})));
|
|
636
|
-
}
|
|
637
|
-
async function askShouldAddPackageOverride(pkgName, pkgVersion) {
|
|
638
|
-
return (0, telemetry_1.traceStep)(`ask-add-package-override`, () => abortIfCancelled(clack_1.default.confirm({
|
|
639
|
-
message: `Do you want to add an override for ${chalk_1.default.cyan(pkgName)} version ${chalk_1.default.cyan(pkgVersion)}?`,
|
|
640
|
-
})));
|
|
641
|
-
}
|
|
642
|
-
async function askForAIConsent(options) {
|
|
643
|
-
return await (0, telemetry_1.traceStep)('ask-for-ai-consent', async () => {
|
|
644
|
-
const aiConsent = options.default
|
|
645
|
-
? true
|
|
646
|
-
: await abortIfCancelled(clack_1.default.select({
|
|
647
|
-
message: 'This setup wizard uses AI, are you happy to continue? β¨',
|
|
648
|
-
options: [
|
|
649
|
-
{
|
|
650
|
-
label: 'Yes',
|
|
651
|
-
value: true,
|
|
652
|
-
hint: 'We will use AI to help you setup PostHog quickly',
|
|
653
|
-
},
|
|
654
|
-
{
|
|
655
|
-
label: 'No',
|
|
656
|
-
value: false,
|
|
657
|
-
hint: "I don't like AI",
|
|
658
|
-
},
|
|
659
|
-
],
|
|
660
|
-
initialValue: true,
|
|
661
|
-
}));
|
|
662
|
-
return aiConsent;
|
|
663
|
-
});
|
|
664
|
-
}
|
|
665
|
-
async function askForCloudRegion() {
|
|
666
|
-
return await (0, telemetry_1.traceStep)('ask-for-cloud-region', async () => {
|
|
667
|
-
const cloudRegion = await abortIfCancelled(clack_1.default.select({
|
|
668
|
-
message: 'Select your cloud region',
|
|
669
|
-
options: [
|
|
670
|
-
{
|
|
671
|
-
label: 'US πΊπΈ',
|
|
672
|
-
value: 'us',
|
|
673
|
-
},
|
|
674
|
-
{
|
|
675
|
-
label: 'EU πͺπΊ',
|
|
676
|
-
value: 'eu',
|
|
677
|
-
},
|
|
678
|
-
],
|
|
679
|
-
}));
|
|
680
|
-
return cloudRegion;
|
|
681
|
-
});
|
|
682
|
-
}
|
|
683
|
-
//# sourceMappingURL=clack-utils.js.map
|