@datalyr/wizard 1.0.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/index.js ADDED
@@ -0,0 +1,1312 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ detectFramework: () => detectFramework,
34
+ generateInstallationPlan: () => generateInstallationPlan,
35
+ runWizard: () => runWizard
36
+ });
37
+ module.exports = __toCommonJS(src_exports);
38
+ var import_path5 = __toESM(require("path"));
39
+
40
+ // src/detection/detector.ts
41
+ var import_path2 = __toESM(require("path"));
42
+
43
+ // src/utils/fs.ts
44
+ var import_fs_extra = __toESM(require("fs-extra"));
45
+ var import_path = __toESM(require("path"));
46
+ var import_glob = require("glob");
47
+ async function fileExists(filePath) {
48
+ try {
49
+ await import_fs_extra.default.access(filePath);
50
+ return true;
51
+ } catch {
52
+ return false;
53
+ }
54
+ }
55
+ async function readFile(filePath) {
56
+ try {
57
+ return await import_fs_extra.default.readFile(filePath, "utf-8");
58
+ } catch {
59
+ return null;
60
+ }
61
+ }
62
+ async function writeFile(filePath, content) {
63
+ await import_fs_extra.default.ensureDir(import_path.default.dirname(filePath));
64
+ await import_fs_extra.default.writeFile(filePath, content, "utf-8");
65
+ }
66
+ async function readJson(filePath) {
67
+ try {
68
+ return await import_fs_extra.default.readJson(filePath);
69
+ } catch {
70
+ return null;
71
+ }
72
+ }
73
+ async function readPackageJson(cwd) {
74
+ return readJson(import_path.default.join(cwd, "package.json"));
75
+ }
76
+ async function findFile(cwd, patterns) {
77
+ for (const pattern of patterns) {
78
+ const matches = await (0, import_glob.glob)(pattern, { cwd, nodir: true });
79
+ if (matches.length > 0) {
80
+ return import_path.default.join(cwd, matches[0]);
81
+ }
82
+ }
83
+ return null;
84
+ }
85
+ async function findFiles(cwd, pattern) {
86
+ const matches = await (0, import_glob.glob)(pattern, {
87
+ cwd,
88
+ ignore: ["node_modules/**", ".git/**"]
89
+ });
90
+ return matches.map((f) => import_path.default.join(cwd, f));
91
+ }
92
+
93
+ // src/detection/detector.ts
94
+ async function detectFramework(cwd) {
95
+ const signals = [];
96
+ const pkg = await readPackageJson(cwd);
97
+ const deps = { ...pkg?.dependencies, ...pkg?.devDependencies };
98
+ if (await fileExists(import_path2.default.join(cwd, "Package.swift"))) {
99
+ signals.push({ framework: "ios", score: 100, signal: "Package.swift found" });
100
+ }
101
+ const xcodeprojs = await findFile(cwd, ["*.xcodeproj", "*.xcworkspace"]);
102
+ if (xcodeprojs) {
103
+ signals.push({ framework: "ios", score: 90, signal: "Xcode project found" });
104
+ }
105
+ if (!pkg) {
106
+ const iosScore = signals.filter((s) => s.framework === "ios").reduce((a, b) => a + b.score, 0);
107
+ if (iosScore > 0) {
108
+ return buildResult("ios", signals, null);
109
+ }
110
+ return buildResult("unknown", [], null);
111
+ }
112
+ if (deps.next) {
113
+ signals.push({ framework: "nextjs", score: 100, signal: "next in dependencies" });
114
+ if (await fileExists(import_path2.default.join(cwd, "app", "layout.tsx")) || await fileExists(import_path2.default.join(cwd, "app", "layout.js"))) {
115
+ signals.push({ framework: "nextjs", score: 20, signal: "App Router detected" });
116
+ }
117
+ if (await fileExists(import_path2.default.join(cwd, "pages", "_app.tsx")) || await fileExists(import_path2.default.join(cwd, "pages", "_app.js"))) {
118
+ signals.push({ framework: "nextjs", score: 15, signal: "Pages Router detected" });
119
+ }
120
+ }
121
+ if (deps.expo) {
122
+ signals.push({ framework: "expo", score: 100, signal: "expo in dependencies" });
123
+ }
124
+ if (deps["react-native"] && !deps.expo) {
125
+ signals.push({ framework: "react-native", score: 100, signal: "react-native in dependencies" });
126
+ }
127
+ if (deps["@remix-run/react"] || deps["@remix-run/node"]) {
128
+ signals.push({ framework: "remix", score: 100, signal: "@remix-run packages found" });
129
+ }
130
+ if (deps.astro) {
131
+ signals.push({ framework: "astro", score: 100, signal: "astro in dependencies" });
132
+ }
133
+ if (deps["@sveltejs/kit"]) {
134
+ signals.push({ framework: "sveltekit", score: 100, signal: "@sveltejs/kit in dependencies" });
135
+ } else if (deps.svelte) {
136
+ signals.push({ framework: "svelte", score: 80, signal: "svelte in dependencies" });
137
+ }
138
+ if (deps.nuxt) {
139
+ signals.push({ framework: "nuxt", score: 100, signal: "nuxt in dependencies" });
140
+ } else if (deps.vue) {
141
+ signals.push({ framework: "vue", score: 80, signal: "vue in dependencies" });
142
+ }
143
+ if (deps.react && deps["react-dom"]) {
144
+ if (!deps.next && !deps["@remix-run/react"] && !deps["react-native"] && !deps.expo) {
145
+ if (deps.vite || deps["@vitejs/plugin-react"]) {
146
+ signals.push({ framework: "react-vite", score: 90, signal: "React + Vite" });
147
+ } else if (deps["react-scripts"]) {
148
+ signals.push({ framework: "react", score: 85, signal: "Create React App" });
149
+ } else {
150
+ signals.push({ framework: "react", score: 70, signal: "React project" });
151
+ }
152
+ }
153
+ }
154
+ if (deps.express || deps.fastify || deps.koa || deps.hapi) {
155
+ if (!deps.react && !deps.vue && !deps.svelte) {
156
+ signals.push({ framework: "node", score: 80, signal: "Node.js server framework" });
157
+ }
158
+ }
159
+ const frameworkScores = /* @__PURE__ */ new Map();
160
+ signals.forEach((s) => {
161
+ const current = frameworkScores.get(s.framework) || 0;
162
+ frameworkScores.set(s.framework, current + s.score);
163
+ });
164
+ let bestFramework = "unknown";
165
+ let bestScore = 0;
166
+ frameworkScores.forEach((score, framework) => {
167
+ if (score > bestScore) {
168
+ bestScore = score;
169
+ bestFramework = framework;
170
+ }
171
+ });
172
+ return buildResult(bestFramework, signals, pkg);
173
+ }
174
+ function buildResult(framework, signals, pkg) {
175
+ const relevantSignals = signals.filter((s) => s.framework === framework).map((s) => s.signal);
176
+ const confidence = Math.min(100, signals.filter((s) => s.framework === framework).reduce((a, b) => a + b.score, 0));
177
+ const language = detectLanguage(pkg);
178
+ const sdks = getSDKsForFramework(framework);
179
+ const hasAppRouter = framework === "nextjs" && relevantSignals.some((s) => s.includes("App Router"));
180
+ return {
181
+ framework,
182
+ confidence,
183
+ signals: relevantSignals,
184
+ sdks,
185
+ language,
186
+ hasAppRouter,
187
+ isExpo: framework === "expo"
188
+ };
189
+ }
190
+ function detectLanguage(pkg) {
191
+ if (!pkg) return "javascript";
192
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies };
193
+ return deps.typescript ? "typescript" : "javascript";
194
+ }
195
+ function getSDKsForFramework(framework) {
196
+ switch (framework) {
197
+ case "nextjs":
198
+ case "remix":
199
+ case "sveltekit":
200
+ case "nuxt":
201
+ case "astro":
202
+ return ["@datalyr/web", "@datalyr/api"];
203
+ case "react":
204
+ case "react-vite":
205
+ case "svelte":
206
+ case "vue":
207
+ return ["@datalyr/web"];
208
+ case "react-native":
209
+ case "expo":
210
+ return ["@datalyr/react-native"];
211
+ case "ios":
212
+ return ["DatalyrSDK"];
213
+ case "node":
214
+ return ["@datalyr/api"];
215
+ default:
216
+ return ["@datalyr/web"];
217
+ }
218
+ }
219
+ function getFrameworkDisplayName(framework) {
220
+ const names = {
221
+ nextjs: "Next.js",
222
+ react: "React (Create React App)",
223
+ "react-vite": "React (Vite)",
224
+ svelte: "Svelte",
225
+ sveltekit: "SvelteKit",
226
+ vue: "Vue",
227
+ nuxt: "Nuxt",
228
+ remix: "Remix",
229
+ astro: "Astro",
230
+ "react-native": "React Native",
231
+ expo: "Expo",
232
+ ios: "iOS (Swift)",
233
+ node: "Node.js",
234
+ unknown: "Unknown"
235
+ };
236
+ return names[framework];
237
+ }
238
+
239
+ // src/utils/package-manager.ts
240
+ var import_path3 = __toESM(require("path"));
241
+ async function detectPackageManager(cwd) {
242
+ if (await fileExists(import_path3.default.join(cwd, "bun.lockb"))) {
243
+ return "bun";
244
+ }
245
+ if (await fileExists(import_path3.default.join(cwd, "pnpm-lock.yaml"))) {
246
+ return "pnpm";
247
+ }
248
+ if (await fileExists(import_path3.default.join(cwd, "yarn.lock"))) {
249
+ return "yarn";
250
+ }
251
+ if (await fileExists(import_path3.default.join(cwd, "package-lock.json"))) {
252
+ return "npm";
253
+ }
254
+ return "npm";
255
+ }
256
+ function getInstallCommand(pm, packages, dev = false) {
257
+ const pkgList = packages.join(" ");
258
+ switch (pm) {
259
+ case "npm":
260
+ return dev ? `npm install -D ${pkgList}` : `npm install ${pkgList}`;
261
+ case "yarn":
262
+ return dev ? `yarn add -D ${pkgList}` : `yarn add ${pkgList}`;
263
+ case "pnpm":
264
+ return dev ? `pnpm add -D ${pkgList}` : `pnpm add ${pkgList}`;
265
+ case "bun":
266
+ return dev ? `bun add -d ${pkgList}` : `bun add ${pkgList}`;
267
+ }
268
+ }
269
+
270
+ // src/generators/templates/nextjs.ts
271
+ function generateNextJSFiles(options) {
272
+ const { language, hasAppRouter } = options;
273
+ const ext = language === "typescript" ? "tsx" : "jsx";
274
+ const tsExt = language === "typescript" ? "ts" : "js";
275
+ const files = [];
276
+ if (hasAppRouter) {
277
+ files.push({
278
+ path: `app/providers.${ext}`,
279
+ action: "create",
280
+ description: "Datalyr provider component",
281
+ content: generateAppRouterProvider(language)
282
+ });
283
+ files.push({
284
+ path: `lib/datalyr.${tsExt}`,
285
+ action: "create",
286
+ description: "Server-side Datalyr instance",
287
+ content: generateServerInstance(language)
288
+ });
289
+ } else {
290
+ files.push({
291
+ path: `lib/datalyr.${tsExt}`,
292
+ action: "create",
293
+ description: "Datalyr initialization",
294
+ content: generatePagesRouterInit(language)
295
+ });
296
+ files.push({
297
+ path: `lib/datalyr-server.${tsExt}`,
298
+ action: "create",
299
+ description: "Server-side Datalyr instance",
300
+ content: generateServerInstance(language)
301
+ });
302
+ }
303
+ return files;
304
+ }
305
+ function generateAppRouterProvider(language) {
306
+ if (language === "typescript") {
307
+ return `'use client';
308
+
309
+ import datalyr from '@datalyr/web';
310
+ import { useEffect } from 'react';
311
+
312
+ interface DatalyrProviderProps {
313
+ children: React.ReactNode;
314
+ }
315
+
316
+ export function DatalyrProvider({ children }: DatalyrProviderProps) {
317
+ useEffect(() => {
318
+ datalyr.init({
319
+ workspaceId: process.env.NEXT_PUBLIC_DATALYR_WORKSPACE_ID!,
320
+ debug: process.env.NODE_ENV === 'development',
321
+ trackSPA: true,
322
+ });
323
+ }, []);
324
+
325
+ return <>{children}</>;
326
+ }
327
+ `;
328
+ }
329
+ return `'use client';
330
+
331
+ import datalyr from '@datalyr/web';
332
+ import { useEffect } from 'react';
333
+
334
+ export function DatalyrProvider({ children }) {
335
+ useEffect(() => {
336
+ datalyr.init({
337
+ workspaceId: process.env.NEXT_PUBLIC_DATALYR_WORKSPACE_ID,
338
+ debug: process.env.NODE_ENV === 'development',
339
+ trackSPA: true,
340
+ });
341
+ }, []);
342
+
343
+ return <>{children}</>;
344
+ }
345
+ `;
346
+ }
347
+ function generateServerInstance(language) {
348
+ if (language === "typescript") {
349
+ return `import Datalyr from '@datalyr/api';
350
+
351
+ // Server-side Datalyr instance
352
+ export const datalyr = new Datalyr(process.env.DATALYR_API_KEY!);
353
+
354
+ // Helper to track server-side events
355
+ export async function trackServerEvent(
356
+ event: string,
357
+ properties?: Record<string, unknown>,
358
+ userId?: string,
359
+ ) {
360
+ await datalyr.track({
361
+ event,
362
+ properties,
363
+ userId,
364
+ timestamp: new Date().toISOString(),
365
+ });
366
+ }
367
+ `;
368
+ }
369
+ return `import Datalyr from '@datalyr/api';
370
+
371
+ // Server-side Datalyr instance
372
+ export const datalyr = new Datalyr(process.env.DATALYR_API_KEY);
373
+
374
+ // Helper to track server-side events
375
+ export async function trackServerEvent(event, properties, userId) {
376
+ await datalyr.track({
377
+ event,
378
+ properties,
379
+ userId,
380
+ timestamp: new Date().toISOString(),
381
+ });
382
+ }
383
+ `;
384
+ }
385
+ function generatePagesRouterInit(language) {
386
+ if (language === "typescript") {
387
+ return `import datalyr from '@datalyr/web';
388
+
389
+ let initialized = false;
390
+
391
+ export function initDatalyr(): void {
392
+ if (initialized || typeof window === 'undefined') return;
393
+
394
+ datalyr.init({
395
+ workspaceId: process.env.NEXT_PUBLIC_DATALYR_WORKSPACE_ID!,
396
+ debug: process.env.NODE_ENV === 'development',
397
+ trackSPA: true,
398
+ });
399
+
400
+ initialized = true;
401
+ }
402
+
403
+ export { datalyr };
404
+ `;
405
+ }
406
+ return `import datalyr from '@datalyr/web';
407
+
408
+ let initialized = false;
409
+
410
+ export function initDatalyr() {
411
+ if (initialized || typeof window === 'undefined') return;
412
+
413
+ datalyr.init({
414
+ workspaceId: process.env.NEXT_PUBLIC_DATALYR_WORKSPACE_ID,
415
+ debug: process.env.NODE_ENV === 'development',
416
+ trackSPA: true,
417
+ });
418
+
419
+ initialized = true;
420
+ }
421
+
422
+ export { datalyr };
423
+ `;
424
+ }
425
+
426
+ // src/generators/templates/react.ts
427
+ function generateReactFiles(options) {
428
+ const { language, isVite } = options;
429
+ const ext = language === "typescript" ? "ts" : "js";
430
+ return [
431
+ {
432
+ path: `src/lib/datalyr.${ext}`,
433
+ action: "create",
434
+ description: "Datalyr initialization",
435
+ content: generateReactInit(language)
436
+ }
437
+ ];
438
+ }
439
+ function generateReactInit(language) {
440
+ if (language === "typescript") {
441
+ return `import datalyr from '@datalyr/web';
442
+
443
+ let initialized = false;
444
+
445
+ export function initDatalyr(): void {
446
+ if (initialized || typeof window === 'undefined') return;
447
+
448
+ datalyr.init({
449
+ workspaceId: import.meta.env.VITE_DATALYR_WORKSPACE_ID,
450
+ debug: import.meta.env.DEV,
451
+ trackSPA: true,
452
+ });
453
+
454
+ initialized = true;
455
+ }
456
+
457
+ // Re-export for convenience
458
+ export { datalyr };
459
+
460
+ // Usage in your main.tsx/App.tsx:
461
+ // import { initDatalyr } from './lib/datalyr';
462
+ // initDatalyr();
463
+ `;
464
+ }
465
+ return `import datalyr from '@datalyr/web';
466
+
467
+ let initialized = false;
468
+
469
+ export function initDatalyr() {
470
+ if (initialized || typeof window === 'undefined') return;
471
+
472
+ datalyr.init({
473
+ workspaceId: import.meta.env.VITE_DATALYR_WORKSPACE_ID,
474
+ debug: import.meta.env.DEV,
475
+ trackSPA: true,
476
+ });
477
+
478
+ initialized = true;
479
+ }
480
+
481
+ // Re-export for convenience
482
+ export { datalyr };
483
+
484
+ // Usage in your main.jsx/App.jsx:
485
+ // import { initDatalyr } from './lib/datalyr';
486
+ // initDatalyr();
487
+ `;
488
+ }
489
+
490
+ // src/generators/templates/react-native.ts
491
+ function generateReactNativeFiles(options) {
492
+ const { language, isExpo, apiKey } = options;
493
+ const ext = language === "typescript" ? "ts" : "js";
494
+ return [
495
+ {
496
+ path: `src/utils/datalyr.${ext}`,
497
+ action: "create",
498
+ description: "Datalyr initialization",
499
+ content: generateReactNativeInit(language, isExpo, apiKey)
500
+ }
501
+ ];
502
+ }
503
+ function generateReactNativeInit(language, isExpo, apiKey) {
504
+ const importPath = isExpo ? "@datalyr/react-native/expo" : "@datalyr/react-native";
505
+ if (language === "typescript") {
506
+ return `import { Datalyr } from '${importPath}';
507
+
508
+ let initialized = false;
509
+
510
+ export async function initDatalyr(): Promise<void> {
511
+ if (initialized) return;
512
+
513
+ await Datalyr.initialize({
514
+ apiKey: '${apiKey}',
515
+ enableAutoEvents: true,
516
+ enableAttribution: true,
517
+ debug: __DEV__,
518
+ });
519
+
520
+ initialized = true;
521
+ }
522
+
523
+ // Re-export for convenience
524
+ export { Datalyr };
525
+
526
+ // Track custom events
527
+ export function trackEvent(event: string, properties?: Record<string, unknown>): void {
528
+ Datalyr.track(event, properties);
529
+ }
530
+
531
+ // Identify users
532
+ export function identifyUser(userId: string, traits?: Record<string, unknown>): void {
533
+ Datalyr.identify(userId, traits);
534
+ }
535
+ `;
536
+ }
537
+ return `import { Datalyr } from '${importPath}';
538
+
539
+ let initialized = false;
540
+
541
+ export async function initDatalyr() {
542
+ if (initialized) return;
543
+
544
+ await Datalyr.initialize({
545
+ apiKey: '${apiKey}',
546
+ enableAutoEvents: true,
547
+ enableAttribution: true,
548
+ debug: __DEV__,
549
+ });
550
+
551
+ initialized = true;
552
+ }
553
+
554
+ // Re-export for convenience
555
+ export { Datalyr };
556
+
557
+ // Track custom events
558
+ export function trackEvent(event, properties) {
559
+ Datalyr.track(event, properties);
560
+ }
561
+
562
+ // Identify users
563
+ export function identifyUser(userId, traits) {
564
+ Datalyr.identify(userId, traits);
565
+ }
566
+ `;
567
+ }
568
+
569
+ // src/installers/env.ts
570
+ var import_path4 = __toESM(require("path"));
571
+
572
+ // src/cli/ui.ts
573
+ var import_ora = __toESM(require("ora"));
574
+ var import_chalk = __toESM(require("chalk"));
575
+ var currentSpinner = null;
576
+ function startSpinner(text) {
577
+ if (currentSpinner) {
578
+ currentSpinner.stop();
579
+ }
580
+ currentSpinner = (0, import_ora.default)({ text, color: "cyan" }).start();
581
+ return currentSpinner;
582
+ }
583
+ function succeedSpinner(text) {
584
+ if (currentSpinner) {
585
+ currentSpinner.succeed(text);
586
+ currentSpinner = null;
587
+ }
588
+ }
589
+ function failSpinner(text) {
590
+ if (currentSpinner) {
591
+ currentSpinner.fail(text);
592
+ currentSpinner = null;
593
+ }
594
+ }
595
+ function stopSpinner() {
596
+ if (currentSpinner) {
597
+ currentSpinner.stop();
598
+ currentSpinner = null;
599
+ }
600
+ }
601
+ function printWelcome() {
602
+ console.log();
603
+ console.log(import_chalk.default.cyan("\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557"));
604
+ console.log(import_chalk.default.cyan("\u2551") + import_chalk.default.bold(" Welcome to Datalyr Wizard! ") + import_chalk.default.cyan("\u2551"));
605
+ console.log(import_chalk.default.cyan("\u2551") + " AI-powered SDK installation for Datalyr " + import_chalk.default.cyan("\u2551"));
606
+ console.log(import_chalk.default.cyan("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D"));
607
+ console.log();
608
+ }
609
+ function printSuccess() {
610
+ console.log();
611
+ console.log(import_chalk.default.green.bold("Installation complete!"));
612
+ console.log();
613
+ console.log(import_chalk.default.bold("Next steps:"));
614
+ console.log();
615
+ console.log(" 1. Add your workspace ID to .env.local:");
616
+ console.log(import_chalk.default.cyan(" NEXT_PUBLIC_DATALYR_WORKSPACE_ID=your_workspace_id"));
617
+ console.log();
618
+ console.log(" 2. Start tracking events:");
619
+ console.log(import_chalk.default.cyan(" datalyr.track('button_clicked', { button: 'signup' })"));
620
+ console.log();
621
+ console.log(" 3. View your data:");
622
+ console.log(import_chalk.default.cyan(" https://app.datalyr.com/dashboard"));
623
+ console.log();
624
+ console.log(import_chalk.default.gray("Documentation: https://docs.datalyr.com"));
625
+ console.log(import_chalk.default.gray("Support: hello@datalyr.com"));
626
+ console.log();
627
+ }
628
+ function printPlan(plan) {
629
+ console.log();
630
+ console.log(import_chalk.default.bold("Installation Plan:"));
631
+ console.log();
632
+ if (plan.packages.length > 0) {
633
+ console.log(import_chalk.default.cyan(" \u{1F4E6} Packages:"));
634
+ plan.packages.forEach((pkg) => {
635
+ console.log(` \u2022 ${pkg}`);
636
+ });
637
+ console.log();
638
+ }
639
+ if (plan.files.length > 0) {
640
+ console.log(import_chalk.default.cyan(" \u{1F4DD} Files to create/update:"));
641
+ plan.files.forEach((file) => {
642
+ const actionIcon = file.action === "create" ? import_chalk.default.green("(create)") : import_chalk.default.yellow("(update)");
643
+ console.log(` \u2022 ${file.path} ${actionIcon}`);
644
+ });
645
+ console.log();
646
+ }
647
+ }
648
+ function printDetection(result) {
649
+ console.log();
650
+ console.log(import_chalk.default.bold("Detected Configuration:"));
651
+ console.log(` Framework: ${import_chalk.default.cyan(result.framework)}`);
652
+ console.log(` Language: ${import_chalk.default.cyan(result.language)}`);
653
+ console.log(` SDK Needs: ${import_chalk.default.cyan(result.sdks.join(" + "))}`);
654
+ console.log();
655
+ }
656
+ function printError(message, details) {
657
+ console.log();
658
+ console.log(import_chalk.default.red.bold("Error:"), message);
659
+ if (details) {
660
+ console.log(import_chalk.default.gray(details));
661
+ }
662
+ console.log();
663
+ }
664
+ function printDryRun(plan) {
665
+ console.log();
666
+ console.log(import_chalk.default.yellow.bold("[DRY RUN] No changes will be made"));
667
+ console.log();
668
+ if (plan.commands.length > 0) {
669
+ console.log(import_chalk.default.bold("Would run:"));
670
+ plan.commands.forEach((cmd) => console.log(import_chalk.default.cyan(` $ ${cmd}`)));
671
+ console.log();
672
+ }
673
+ if (plan.files.length > 0) {
674
+ console.log(import_chalk.default.bold("Would create/update files:"));
675
+ plan.files.forEach((file) => {
676
+ console.log(import_chalk.default.cyan(` ${file.path} (${file.action})`));
677
+ });
678
+ console.log();
679
+ }
680
+ }
681
+
682
+ // src/installers/env.ts
683
+ async function updateEnvFile(cwd, envVars, options = {}) {
684
+ if (envVars.length === 0) return true;
685
+ const envFileName = options.envFile || ".env.local";
686
+ const envPath = import_path4.default.join(cwd, envFileName);
687
+ const examplePath = import_path4.default.join(cwd, ".env.example");
688
+ if (options.dryRun) {
689
+ return true;
690
+ }
691
+ const spinner = startSpinner(`Updating ${envFileName}...`);
692
+ try {
693
+ let existingContent = "";
694
+ if (await fileExists(envPath)) {
695
+ existingContent = await readFile(envPath) || "";
696
+ }
697
+ const existingVars = parseEnvFile(existingContent);
698
+ const lines = [];
699
+ if (existingContent) {
700
+ lines.push(existingContent.trim());
701
+ lines.push("");
702
+ }
703
+ const newVars = envVars.filter((v) => !existingVars.has(v.key));
704
+ if (newVars.length > 0) {
705
+ lines.push("# Datalyr Analytics");
706
+ for (const envVar of newVars) {
707
+ if (envVar.description) {
708
+ lines.push(`# ${envVar.description}`);
709
+ }
710
+ lines.push(`${envVar.key}=${envVar.value}`);
711
+ }
712
+ }
713
+ await writeFile(envPath, lines.join("\n") + "\n");
714
+ if (await fileExists(examplePath)) {
715
+ await updateEnvExample(examplePath, envVars);
716
+ }
717
+ succeedSpinner(`Updated ${envFileName}`);
718
+ return true;
719
+ } catch (error) {
720
+ console.error(error);
721
+ return false;
722
+ }
723
+ }
724
+ async function updateEnvExample(examplePath, envVars) {
725
+ let content = await readFile(examplePath) || "";
726
+ const existingVars = parseEnvFile(content);
727
+ const newVars = envVars.filter((v) => !existingVars.has(v.key));
728
+ if (newVars.length === 0) return;
729
+ const lines = content.trim().split("\n");
730
+ lines.push("");
731
+ lines.push("# Datalyr Analytics");
732
+ for (const envVar of newVars) {
733
+ const exampleValue = envVar.isPublic ? "your_workspace_id" : "dk_your_api_key";
734
+ lines.push(`${envVar.key}=${exampleValue}`);
735
+ }
736
+ await writeFile(examplePath, lines.join("\n") + "\n");
737
+ }
738
+ function parseEnvFile(content) {
739
+ const vars = /* @__PURE__ */ new Set();
740
+ const lines = content.split("\n");
741
+ for (const line of lines) {
742
+ const trimmed = line.trim();
743
+ if (trimmed && !trimmed.startsWith("#")) {
744
+ const match = trimmed.match(/^([A-Z_][A-Z0-9_]*)=/);
745
+ if (match) {
746
+ vars.add(match[1]);
747
+ }
748
+ }
749
+ }
750
+ return vars;
751
+ }
752
+ function getEnvVarsForFramework(framework, apiKey) {
753
+ const vars = [];
754
+ if (["nextjs", "react", "react-vite", "svelte", "sveltekit", "vue", "nuxt", "remix", "astro"].includes(framework)) {
755
+ vars.push({
756
+ key: "NEXT_PUBLIC_DATALYR_WORKSPACE_ID",
757
+ value: "",
758
+ description: "Your Datalyr workspace ID (get from dashboard)",
759
+ isPublic: true
760
+ });
761
+ }
762
+ if (["nextjs", "sveltekit", "nuxt", "remix", "astro", "node"].includes(framework)) {
763
+ vars.push({
764
+ key: "DATALYR_API_KEY",
765
+ value: apiKey,
766
+ description: "Datalyr API key for server-side tracking",
767
+ isPublic: false
768
+ });
769
+ }
770
+ return vars;
771
+ }
772
+
773
+ // src/generators/index.ts
774
+ function generateInstallationPlan(context, apiKey) {
775
+ const packages = context.sdks.filter((sdk) => sdk !== "DatalyrSDK");
776
+ const files = generateFilesForFramework(context, apiKey);
777
+ const envVars = getEnvVarsForFramework(context.framework, apiKey);
778
+ const postInstallSteps = getPostInstallSteps(context);
779
+ return {
780
+ packages,
781
+ files,
782
+ envVars,
783
+ postInstallSteps
784
+ };
785
+ }
786
+ function generateFilesForFramework(context, apiKey) {
787
+ const { framework, language } = context;
788
+ switch (framework) {
789
+ case "nextjs":
790
+ return generateNextJSFiles({
791
+ language,
792
+ hasAppRouter: context.entryPoints.some((p) => p.includes("app/layout")),
793
+ apiKey
794
+ });
795
+ case "react":
796
+ case "react-vite":
797
+ return generateReactFiles({
798
+ language,
799
+ isVite: framework === "react-vite"
800
+ });
801
+ case "react-native":
802
+ case "expo":
803
+ return generateReactNativeFiles({
804
+ language,
805
+ isExpo: framework === "expo",
806
+ apiKey
807
+ });
808
+ case "sveltekit":
809
+ return generateSvelteKitFiles(language, apiKey);
810
+ case "svelte":
811
+ return generateSvelteFiles(language);
812
+ case "node":
813
+ return generateNodeFiles(language, apiKey);
814
+ case "ios":
815
+ return generateIOSFiles(apiKey);
816
+ default:
817
+ return generateGenericWebFiles(language);
818
+ }
819
+ }
820
+ function generateSvelteKitFiles(language, apiKey) {
821
+ const ext = language === "typescript" ? "ts" : "js";
822
+ return [
823
+ {
824
+ path: `src/lib/datalyr.${ext}`,
825
+ action: "create",
826
+ description: "Client-side Datalyr initialization",
827
+ content: `import datalyr from '@datalyr/web';
828
+ import { browser } from '$app/environment';
829
+
830
+ let initialized = false;
831
+
832
+ export function initDatalyr()${language === "typescript" ? ": void" : ""} {
833
+ if (initialized || !browser) return;
834
+
835
+ datalyr.init({
836
+ workspaceId: import.meta.env.VITE_DATALYR_WORKSPACE_ID,
837
+ debug: import.meta.env.DEV,
838
+ trackSPA: true,
839
+ });
840
+
841
+ initialized = true;
842
+ }
843
+
844
+ export { datalyr };
845
+ `
846
+ },
847
+ {
848
+ path: `src/lib/datalyr.server.${ext}`,
849
+ action: "create",
850
+ description: "Server-side Datalyr instance",
851
+ content: `import Datalyr from '@datalyr/api';
852
+ import { DATALYR_API_KEY } from '$env/static/private';
853
+
854
+ export const datalyr = new Datalyr(DATALYR_API_KEY);
855
+ `
856
+ }
857
+ ];
858
+ }
859
+ function generateSvelteFiles(language) {
860
+ const ext = language === "typescript" ? "ts" : "js";
861
+ return [
862
+ {
863
+ path: `src/lib/datalyr.${ext}`,
864
+ action: "create",
865
+ description: "Datalyr initialization",
866
+ content: `import datalyr from '@datalyr/web';
867
+
868
+ let initialized = false;
869
+
870
+ export function initDatalyr()${language === "typescript" ? ": void" : ""} {
871
+ if (initialized || typeof window === 'undefined') return;
872
+
873
+ datalyr.init({
874
+ workspaceId: import.meta.env.VITE_DATALYR_WORKSPACE_ID,
875
+ debug: import.meta.env.DEV,
876
+ trackSPA: true,
877
+ });
878
+
879
+ initialized = true;
880
+ }
881
+
882
+ export { datalyr };
883
+ `
884
+ }
885
+ ];
886
+ }
887
+ function generateNodeFiles(language, apiKey) {
888
+ const ext = language === "typescript" ? "ts" : "js";
889
+ return [
890
+ {
891
+ path: `src/lib/datalyr.${ext}`,
892
+ action: "create",
893
+ description: "Datalyr server instance",
894
+ content: language === "typescript" ? `import Datalyr from '@datalyr/api';
895
+
896
+ const apiKey = process.env.DATALYR_API_KEY;
897
+ if (!apiKey) {
898
+ throw new Error('DATALYR_API_KEY environment variable is required');
899
+ }
900
+
901
+ export const datalyr = new Datalyr(apiKey);
902
+
903
+ export async function trackEvent(
904
+ event: string,
905
+ properties?: Record<string, unknown>,
906
+ userId?: string,
907
+ ): Promise<void> {
908
+ await datalyr.track({
909
+ event,
910
+ properties,
911
+ userId,
912
+ timestamp: new Date().toISOString(),
913
+ });
914
+ }
915
+ ` : `import Datalyr from '@datalyr/api';
916
+
917
+ const apiKey = process.env.DATALYR_API_KEY;
918
+ if (!apiKey) {
919
+ throw new Error('DATALYR_API_KEY environment variable is required');
920
+ }
921
+
922
+ export const datalyr = new Datalyr(apiKey);
923
+
924
+ export async function trackEvent(event, properties, userId) {
925
+ await datalyr.track({
926
+ event,
927
+ properties,
928
+ userId,
929
+ timestamp: new Date().toISOString(),
930
+ });
931
+ }
932
+ `
933
+ }
934
+ ];
935
+ }
936
+ function generateIOSFiles(_apiKey) {
937
+ return [
938
+ {
939
+ path: "DatalyrConfig.swift",
940
+ action: "create",
941
+ description: "Datalyr iOS configuration",
942
+ content: `import DatalyrSDK
943
+ import Foundation
944
+
945
+ struct DatalyrConfig {
946
+ /// Initialize Datalyr SDK
947
+ /// Reads configuration from Info.plist for security
948
+ static func initialize() {
949
+ guard let apiKey = Bundle.main.object(forInfoDictionaryKey: "DATALYR_API_KEY") as? String,
950
+ let workspaceId = Bundle.main.object(forInfoDictionaryKey: "DATALYR_WORKSPACE_ID") as? String else {
951
+ #if DEBUG
952
+ fatalError("Datalyr API key or workspace ID not found in Info.plist. Add DATALYR_API_KEY and DATALYR_WORKSPACE_ID to your Info.plist.")
953
+ #else
954
+ print("[Datalyr] Warning: API key or workspace ID not configured")
955
+ return
956
+ #endif
957
+ }
958
+
959
+ Datalyr.shared.configure(
960
+ apiKey: apiKey,
961
+ workspaceId: workspaceId,
962
+ options: DatalyrOptions(
963
+ debug: false, // Set to true during development
964
+ enableAutoEvents: true,
965
+ enableAttribution: true
966
+ )
967
+ )
968
+ }
969
+ }
970
+
971
+ // SETUP INSTRUCTIONS:
972
+ // 1. Add to Info.plist:
973
+ // <key>DATALYR_API_KEY</key>
974
+ // <string>$(DATALYR_API_KEY)</string>
975
+ // <key>DATALYR_WORKSPACE_ID</key>
976
+ // <string>$(DATALYR_WORKSPACE_ID)</string>
977
+ //
978
+ // 2. Add to your .xcconfig file (recommended) or scheme environment:
979
+ // DATALYR_API_KEY = dk_your_api_key_here
980
+ // DATALYR_WORKSPACE_ID = your_workspace_id_here
981
+ //
982
+ // 3. Call DatalyrConfig.initialize() in your App's init or AppDelegate
983
+ `
984
+ },
985
+ {
986
+ path: "Datalyr.xcconfig",
987
+ action: "create",
988
+ description: "Datalyr configuration file (add your API key here)",
989
+ content: `// Datalyr Configuration
990
+ // Do NOT commit this file with real credentials to version control
991
+ // Add to .gitignore: *.xcconfig
992
+
993
+ DATALYR_API_KEY = YOUR_API_KEY_HERE
994
+ DATALYR_WORKSPACE_ID = YOUR_WORKSPACE_ID_HERE
995
+ `
996
+ }
997
+ ];
998
+ }
999
+ function generateGenericWebFiles(language) {
1000
+ const ext = language === "typescript" ? "ts" : "js";
1001
+ return [
1002
+ {
1003
+ path: `src/lib/datalyr.${ext}`,
1004
+ action: "create",
1005
+ description: "Datalyr initialization",
1006
+ content: `import datalyr from '@datalyr/web';
1007
+
1008
+ export function initDatalyr()${language === "typescript" ? ": void" : ""} {
1009
+ datalyr.init({
1010
+ workspaceId: 'YOUR_WORKSPACE_ID',
1011
+ debug: true,
1012
+ });
1013
+ }
1014
+
1015
+ export { datalyr };
1016
+ `
1017
+ }
1018
+ ];
1019
+ }
1020
+ function getPostInstallSteps(context) {
1021
+ const steps = [];
1022
+ switch (context.framework) {
1023
+ case "nextjs":
1024
+ steps.push("Add your workspace ID to .env.local");
1025
+ steps.push("Import DatalyrProvider in your app/layout.tsx");
1026
+ break;
1027
+ case "react":
1028
+ case "react-vite":
1029
+ steps.push("Add VITE_DATALYR_WORKSPACE_ID to your .env file");
1030
+ steps.push("Call initDatalyr() in your main.tsx");
1031
+ break;
1032
+ case "react-native":
1033
+ case "expo":
1034
+ steps.push("Run: cd ios && pod install");
1035
+ steps.push("Call initDatalyr() in your App.tsx useEffect");
1036
+ break;
1037
+ case "ios":
1038
+ steps.push("Add DatalyrSDK via Swift Package Manager");
1039
+ steps.push("Add DATALYR_API_KEY and DATALYR_WORKSPACE_ID to Datalyr.xcconfig");
1040
+ steps.push("Configure Info.plist to use the xcconfig variables");
1041
+ steps.push("Call DatalyrConfig.initialize() in your App");
1042
+ break;
1043
+ default:
1044
+ steps.push("Add your workspace ID to your environment");
1045
+ }
1046
+ return steps;
1047
+ }
1048
+
1049
+ // src/installers/npm.ts
1050
+ var import_execa = require("execa");
1051
+ async function installPackages(cwd, packages, options = {}) {
1052
+ if (packages.length === 0) return true;
1053
+ if (options.dryRun) return true;
1054
+ const pm = await detectPackageManager(cwd);
1055
+ const command = getInstallCommand(pm, packages, options.dev);
1056
+ const spinner = startSpinner(`Installing ${packages.join(", ")}...`);
1057
+ try {
1058
+ const [cmd, ...args] = command.split(" ");
1059
+ await (0, import_execa.execa)(cmd, args, { cwd, stdio: "pipe" });
1060
+ succeedSpinner(`Installed ${packages.join(", ")}`);
1061
+ return true;
1062
+ } catch (error) {
1063
+ failSpinner(`Failed to install packages`);
1064
+ console.error(error instanceof Error ? error.message : error);
1065
+ return false;
1066
+ }
1067
+ }
1068
+
1069
+ // src/cli/prompts.ts
1070
+ var import_prompts = require("@inquirer/prompts");
1071
+ var import_chalk2 = __toESM(require("chalk"));
1072
+ async function promptApiKey(existingKey) {
1073
+ if (existingKey) {
1074
+ return existingKey;
1075
+ }
1076
+ const apiKey = await (0, import_prompts.input)({
1077
+ message: "Enter your Datalyr API key (starts with dk_):",
1078
+ validate: (value) => {
1079
+ if (!value.startsWith("dk_")) {
1080
+ return 'API key must start with "dk_"';
1081
+ }
1082
+ if (value.length < 10) {
1083
+ return "API key seems too short";
1084
+ }
1085
+ return true;
1086
+ }
1087
+ });
1088
+ return apiKey;
1089
+ }
1090
+ async function promptFramework() {
1091
+ return (0, import_prompts.select)({
1092
+ message: "Select your framework:",
1093
+ choices: [
1094
+ { name: "Next.js", value: "nextjs" },
1095
+ { name: "React (Vite)", value: "react-vite" },
1096
+ { name: "React (Create React App)", value: "react" },
1097
+ { name: "Svelte/SvelteKit", value: "sveltekit" },
1098
+ { name: "Vue/Nuxt", value: "nuxt" },
1099
+ { name: "Remix", value: "remix" },
1100
+ { name: "Astro", value: "astro" },
1101
+ { name: "React Native", value: "react-native" },
1102
+ { name: "Expo", value: "expo" },
1103
+ { name: "iOS (Swift)", value: "ios" },
1104
+ { name: "Node.js (Server only)", value: "node" }
1105
+ ]
1106
+ });
1107
+ }
1108
+ async function promptProceed() {
1109
+ return (0, import_prompts.confirm)({
1110
+ message: "Proceed with installation?",
1111
+ default: true
1112
+ });
1113
+ }
1114
+
1115
+ // src/utils/logger.ts
1116
+ var import_chalk3 = __toESM(require("chalk"));
1117
+ var logger = {
1118
+ info: (message) => console.log(import_chalk3.default.blue("\u2139"), message),
1119
+ success: (message) => console.log(import_chalk3.default.green("\u2713"), message),
1120
+ warn: (message) => console.log(import_chalk3.default.yellow("\u26A0"), message),
1121
+ error: (message) => console.log(import_chalk3.default.red("\u2717"), message),
1122
+ debug: (message, enabled = false) => {
1123
+ if (enabled) console.log(import_chalk3.default.gray("[debug]"), message);
1124
+ },
1125
+ header: (title) => {
1126
+ console.log();
1127
+ console.log(import_chalk3.default.bold.cyan(title));
1128
+ console.log(import_chalk3.default.gray("\u2500".repeat(40)));
1129
+ },
1130
+ step: (step, total, message) => {
1131
+ console.log();
1132
+ console.log(import_chalk3.default.bold(`Step ${step}/${total}: ${message}`));
1133
+ console.log(import_chalk3.default.gray("\u2500".repeat(40)));
1134
+ },
1135
+ box: (lines) => {
1136
+ const maxLen = Math.max(...lines.map((l) => l.length));
1137
+ const border = "\u2550".repeat(maxLen + 4);
1138
+ console.log(import_chalk3.default.cyan(`\u2554${border}\u2557`));
1139
+ lines.forEach((line) => {
1140
+ const padding = " ".repeat(maxLen - line.length);
1141
+ console.log(import_chalk3.default.cyan("\u2551") + ` ${line}${padding} ` + import_chalk3.default.cyan("\u2551"));
1142
+ });
1143
+ console.log(import_chalk3.default.cyan(`\u255A${border}\u255D`));
1144
+ },
1145
+ list: (items, indent = 2) => {
1146
+ const spaces = " ".repeat(indent);
1147
+ items.forEach((item) => console.log(`${spaces}\u2022 ${item}`));
1148
+ },
1149
+ blank: () => console.log()
1150
+ };
1151
+
1152
+ // src/index.ts
1153
+ async function runWizard(options = {}) {
1154
+ const cwd = options.cwd || process.cwd();
1155
+ const isInteractive = !options.yes && !options.json && !options.dryRun;
1156
+ try {
1157
+ if (isInteractive) {
1158
+ printWelcome();
1159
+ }
1160
+ let apiKey = options.apiKey || "dk_placeholder";
1161
+ if (isInteractive) {
1162
+ logger.step(1, 5, "Enter your Datalyr API Key");
1163
+ apiKey = await promptApiKey(options.apiKey);
1164
+ logger.success("API key validated");
1165
+ }
1166
+ if (!options.json) {
1167
+ logger.step(2, 5, "Analyzing your project...");
1168
+ }
1169
+ const spinner = options.json ? null : startSpinner("Scanning project structure...");
1170
+ let detection = await detectFramework(cwd);
1171
+ if (spinner) {
1172
+ succeedSpinner(`Detected ${getFrameworkDisplayName(detection.framework)}`);
1173
+ }
1174
+ if (detection.framework === "unknown" || options.framework) {
1175
+ stopSpinner();
1176
+ if (options.framework) {
1177
+ detection = { ...detection, framework: options.framework };
1178
+ } else if (isInteractive) {
1179
+ logger.warn("Could not auto-detect framework");
1180
+ detection.framework = await promptFramework();
1181
+ } else {
1182
+ printError("Could not detect framework", "Use --framework to specify");
1183
+ return false;
1184
+ }
1185
+ }
1186
+ const packageManager = await detectPackageManager(cwd);
1187
+ const entryPoints = await findEntryPoints(cwd, detection.framework);
1188
+ const context = {
1189
+ cwd,
1190
+ framework: detection.framework,
1191
+ sdks: detection.sdks,
1192
+ language: detection.language,
1193
+ packageManager,
1194
+ entryPoints,
1195
+ existingFiles: []
1196
+ };
1197
+ if (isInteractive) {
1198
+ printDetection({
1199
+ framework: getFrameworkDisplayName(detection.framework),
1200
+ language: detection.language === "typescript" ? "TypeScript" : "JavaScript",
1201
+ sdks: detection.sdks
1202
+ });
1203
+ }
1204
+ if (!options.json && !options.dryRun) {
1205
+ logger.step(3, 5, "Installation Plan");
1206
+ }
1207
+ const plan = generateInstallationPlan(context, apiKey);
1208
+ if (options.dryRun) {
1209
+ const commands = [
1210
+ `${packageManager} add ${plan.packages.join(" ")}`
1211
+ ];
1212
+ printDryRun({
1213
+ packages: plan.packages,
1214
+ files: plan.files,
1215
+ commands
1216
+ });
1217
+ return true;
1218
+ }
1219
+ if (options.json) {
1220
+ console.log(JSON.stringify({
1221
+ framework: detection.framework,
1222
+ language: detection.language,
1223
+ sdks: detection.sdks,
1224
+ packages: plan.packages,
1225
+ files: plan.files.map((f) => ({ path: f.path, action: f.action })),
1226
+ envVars: plan.envVars.map((v) => v.key)
1227
+ }, null, 2));
1228
+ return true;
1229
+ }
1230
+ printPlan({
1231
+ packages: plan.packages,
1232
+ files: plan.files
1233
+ });
1234
+ if (isInteractive) {
1235
+ const proceed = await promptProceed();
1236
+ if (!proceed) {
1237
+ logger.info("Installation cancelled");
1238
+ return false;
1239
+ }
1240
+ }
1241
+ logger.step(4, 5, "Installing...");
1242
+ if (plan.packages.length > 0) {
1243
+ const success = await installPackages(cwd, plan.packages);
1244
+ if (!success) {
1245
+ printError("Failed to install packages");
1246
+ return false;
1247
+ }
1248
+ }
1249
+ for (const file of plan.files) {
1250
+ const filePath = import_path5.default.join(cwd, file.path);
1251
+ const exists = await fileExists(filePath);
1252
+ if (exists && file.action === "create") {
1253
+ logger.warn(`Skipping ${file.path} (already exists)`);
1254
+ continue;
1255
+ }
1256
+ const fileSpinner = startSpinner(`Creating ${file.path}...`);
1257
+ await writeFile(filePath, file.content);
1258
+ succeedSpinner(`Created ${file.path}`);
1259
+ }
1260
+ if (plan.envVars.length > 0) {
1261
+ await updateEnvFile(cwd, plan.envVars);
1262
+ }
1263
+ logger.step(5, 5, "Success!");
1264
+ printSuccess();
1265
+ if (plan.postInstallSteps.length > 0) {
1266
+ logger.header("Next steps:");
1267
+ plan.postInstallSteps.forEach((step, i) => {
1268
+ console.log(` ${i + 1}. ${step}`);
1269
+ });
1270
+ console.log();
1271
+ }
1272
+ return true;
1273
+ } catch (error) {
1274
+ stopSpinner();
1275
+ printError(
1276
+ error instanceof Error ? error.message : "Unknown error occurred",
1277
+ options.debug ? error.stack : void 0
1278
+ );
1279
+ return false;
1280
+ }
1281
+ }
1282
+ async function findEntryPoints(cwd, framework) {
1283
+ const entryPoints = [];
1284
+ switch (framework) {
1285
+ case "nextjs":
1286
+ const appLayouts = await findFiles(cwd, "app/layout.{tsx,jsx,ts,js}");
1287
+ entryPoints.push(...appLayouts);
1288
+ const pagesApps = await findFiles(cwd, "pages/_app.{tsx,jsx,ts,js}");
1289
+ entryPoints.push(...pagesApps);
1290
+ break;
1291
+ case "react":
1292
+ case "react-vite":
1293
+ const mains = await findFiles(cwd, "src/main.{tsx,jsx,ts,js}");
1294
+ entryPoints.push(...mains);
1295
+ const apps = await findFiles(cwd, "src/App.{tsx,jsx,ts,js}");
1296
+ entryPoints.push(...apps);
1297
+ break;
1298
+ case "react-native":
1299
+ case "expo":
1300
+ const appFiles = await findFiles(cwd, "App.{tsx,jsx,ts,js}");
1301
+ entryPoints.push(...appFiles);
1302
+ break;
1303
+ }
1304
+ return entryPoints;
1305
+ }
1306
+ // Annotate the CommonJS export names for ESM import in node:
1307
+ 0 && (module.exports = {
1308
+ detectFramework,
1309
+ generateInstallationPlan,
1310
+ runWizard
1311
+ });
1312
+ //# sourceMappingURL=index.js.map