humanbehavior-js 0.5.44 → 0.5.45
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/packages/wizard/dist/cli/ai-auto-install.js +136 -112
- package/packages/wizard/dist/cli/ai-auto-install.js.map +1 -1
- package/packages/wizard/dist/cli/auto-install.d.ts.map +1 -1
- package/packages/wizard/dist/cli/auto-install.js +135 -113
- package/packages/wizard/dist/cli/auto-install.js.map +1 -1
- package/packages/wizard/dist/index.js +1 -1
- package/packages/wizard/dist/index.js.map +1 -1
- package/packages/wizard/dist/index.mjs +1 -1
- package/packages/wizard/dist/index.mjs.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-install.d.ts","sourceRoot":"","sources":["../../src/cli/auto-install.ts"],"names":[],"mappings":";AAEA;;;;;;;GAOG;AAOH,UAAU,UAAU;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,cAAM,cAAc;IAClB,OAAO,CAAC,OAAO,CAAa;gBAEhB,OAAO,EAAE,UAAU;IAIzB,GAAG;YAyCK,SAAS;YAsBT,mBAAmB;IAQjC,OAAO,CAAC,cAAc;CA4BvB;
|
|
1
|
+
{"version":3,"file":"auto-install.d.ts","sourceRoot":"","sources":["../../src/cli/auto-install.ts"],"names":[],"mappings":";AAEA;;;;;;;GAOG;AAOH,UAAU,UAAU;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,cAAM,cAAc;IAClB,OAAO,CAAC,OAAO,CAAa;gBAEhB,OAAO,EAAE,UAAU;IAIzB,GAAG;YAyCK,SAAS;YAsBT,mBAAmB;IAQjC,OAAO,CAAC,cAAc;CA4BvB;AAoED,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -1,8 +1,32 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
#!/usr/bin/env node
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
var fs = require('fs');
|
|
6
|
+
var path = require('path');
|
|
7
|
+
var child_process = require('child_process');
|
|
8
|
+
var clack = require('@clack/prompts');
|
|
9
|
+
|
|
10
|
+
function _interopNamespaceDefault(e) {
|
|
11
|
+
var n = Object.create(null);
|
|
12
|
+
if (e) {
|
|
13
|
+
Object.keys(e).forEach(function (k) {
|
|
14
|
+
if (k !== 'default') {
|
|
15
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return e[k]; }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
n.default = e;
|
|
24
|
+
return Object.freeze(n);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
28
|
+
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
29
|
+
var clack__namespace = /*#__PURE__*/_interopNamespaceDefault(clack);
|
|
6
30
|
|
|
7
31
|
/**
|
|
8
32
|
* HumanBehavior SDK Auto-Installation Wizard
|
|
@@ -75,15 +99,15 @@ class AutoInstallationWizard {
|
|
|
75
99
|
* Detect the current framework and project setup
|
|
76
100
|
*/
|
|
77
101
|
async detectFramework() {
|
|
78
|
-
const packageJsonPath =
|
|
79
|
-
if (!
|
|
102
|
+
const packageJsonPath = path__namespace.join(this.projectRoot, 'package.json');
|
|
103
|
+
if (!fs__namespace.existsSync(packageJsonPath)) {
|
|
80
104
|
return {
|
|
81
105
|
name: 'vanilla',
|
|
82
106
|
type: 'vanilla',
|
|
83
107
|
projectRoot: this.projectRoot
|
|
84
108
|
};
|
|
85
109
|
}
|
|
86
|
-
const packageJson = JSON.parse(
|
|
110
|
+
const packageJson = JSON.parse(fs__namespace.readFileSync(packageJsonPath, 'utf8'));
|
|
87
111
|
const dependencies = {
|
|
88
112
|
...packageJson.dependencies,
|
|
89
113
|
...packageJson.devDependencies
|
|
@@ -244,10 +268,10 @@ class AutoInstallationWizard {
|
|
|
244
268
|
framework.bundler = 'rollup';
|
|
245
269
|
}
|
|
246
270
|
// Detect package manager
|
|
247
|
-
if (
|
|
271
|
+
if (fs__namespace.existsSync(path__namespace.join(this.projectRoot, 'yarn.lock'))) {
|
|
248
272
|
framework.packageManager = 'yarn';
|
|
249
273
|
}
|
|
250
|
-
else if (
|
|
274
|
+
else if (fs__namespace.existsSync(path__namespace.join(this.projectRoot, 'pnpm-lock.yaml'))) {
|
|
251
275
|
framework.packageManager = 'pnpm';
|
|
252
276
|
}
|
|
253
277
|
else {
|
|
@@ -270,7 +294,7 @@ class AutoInstallationWizard {
|
|
|
270
294
|
command += ' --legacy-peer-deps';
|
|
271
295
|
}
|
|
272
296
|
try {
|
|
273
|
-
execSync(command, { cwd: this.projectRoot, stdio: 'inherit' });
|
|
297
|
+
child_process.execSync(command, { cwd: this.projectRoot, stdio: 'inherit' });
|
|
274
298
|
}
|
|
275
299
|
catch (error) {
|
|
276
300
|
throw new Error(`Failed to install humanbehavior-js: ${error}`);
|
|
@@ -322,7 +346,7 @@ class AutoInstallationWizard {
|
|
|
322
346
|
// Find main App component or index file
|
|
323
347
|
const appFile = this.findReactAppFile();
|
|
324
348
|
if (appFile) {
|
|
325
|
-
const content =
|
|
349
|
+
const content = fs__namespace.readFileSync(appFile, 'utf8');
|
|
326
350
|
const modifiedContent = this.injectReactProvider(content, appFile);
|
|
327
351
|
modifications.push({
|
|
328
352
|
filePath: appFile,
|
|
@@ -341,12 +365,12 @@ class AutoInstallationWizard {
|
|
|
341
365
|
async generateNextJSModifications() {
|
|
342
366
|
const modifications = [];
|
|
343
367
|
// Check for App Router
|
|
344
|
-
const appLayoutFile =
|
|
345
|
-
const pagesLayoutFile =
|
|
346
|
-
if (
|
|
368
|
+
const appLayoutFile = path__namespace.join(this.projectRoot, 'src', 'app', 'layout.tsx');
|
|
369
|
+
const pagesLayoutFile = path__namespace.join(this.projectRoot, 'src', 'pages', '_app.tsx');
|
|
370
|
+
if (fs__namespace.existsSync(appLayoutFile)) {
|
|
347
371
|
// Create providers.tsx file for App Router
|
|
348
372
|
modifications.push({
|
|
349
|
-
filePath:
|
|
373
|
+
filePath: path__namespace.join(this.projectRoot, 'src', 'app', 'providers.tsx'),
|
|
350
374
|
action: 'create',
|
|
351
375
|
content: `'use client';
|
|
352
376
|
|
|
@@ -362,7 +386,7 @@ export function Providers({ children }: { children: React.ReactNode }) {
|
|
|
362
386
|
description: 'Created providers.tsx file for Next.js App Router'
|
|
363
387
|
});
|
|
364
388
|
// Modify layout.tsx to use the provider
|
|
365
|
-
const content =
|
|
389
|
+
const content = fs__namespace.readFileSync(appLayoutFile, 'utf8');
|
|
366
390
|
const modifiedContent = this.injectNextJSAppRouter(content);
|
|
367
391
|
modifications.push({
|
|
368
392
|
filePath: appLayoutFile,
|
|
@@ -371,10 +395,10 @@ export function Providers({ children }: { children: React.ReactNode }) {
|
|
|
371
395
|
description: 'Added Providers wrapper to Next.js App Router layout'
|
|
372
396
|
});
|
|
373
397
|
}
|
|
374
|
-
else if (
|
|
398
|
+
else if (fs__namespace.existsSync(pagesLayoutFile)) {
|
|
375
399
|
// Create providers.tsx file for Pages Router
|
|
376
400
|
modifications.push({
|
|
377
|
-
filePath:
|
|
401
|
+
filePath: path__namespace.join(this.projectRoot, 'src', 'components', 'providers.tsx'),
|
|
378
402
|
action: 'create',
|
|
379
403
|
content: `'use client';
|
|
380
404
|
|
|
@@ -390,7 +414,7 @@ export function Providers({ children }: { children: React.ReactNode }) {
|
|
|
390
414
|
description: 'Created providers.tsx file for Pages Router'
|
|
391
415
|
});
|
|
392
416
|
// Modify _app.tsx to use the provider
|
|
393
|
-
const content =
|
|
417
|
+
const content = fs__namespace.readFileSync(pagesLayoutFile, 'utf8');
|
|
394
418
|
const modifiedContent = this.injectNextJSPagesRouter(content);
|
|
395
419
|
modifications.push({
|
|
396
420
|
filePath: pagesLayoutFile,
|
|
@@ -409,7 +433,7 @@ export function Providers({ children }: { children: React.ReactNode }) {
|
|
|
409
433
|
async generateAstroModifications() {
|
|
410
434
|
const modifications = [];
|
|
411
435
|
// Create Astro component for HumanBehavior
|
|
412
|
-
const astroComponentPath =
|
|
436
|
+
const astroComponentPath = path__namespace.join(this.projectRoot, 'src', 'components', 'HumanBehavior.astro');
|
|
413
437
|
const astroComponentContent = `---
|
|
414
438
|
// This component will only run on the client side
|
|
415
439
|
---
|
|
@@ -429,19 +453,19 @@ export function Providers({ children }: { children: React.ReactNode }) {
|
|
|
429
453
|
});
|
|
430
454
|
// Find and update layout file
|
|
431
455
|
const layoutFiles = [
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
456
|
+
path__namespace.join(this.projectRoot, 'src', 'layouts', 'Layout.astro'),
|
|
457
|
+
path__namespace.join(this.projectRoot, 'src', 'layouts', 'layout.astro'),
|
|
458
|
+
path__namespace.join(this.projectRoot, 'src', 'layouts', 'BaseLayout.astro')
|
|
435
459
|
];
|
|
436
460
|
let layoutFile = null;
|
|
437
461
|
for (const file of layoutFiles) {
|
|
438
|
-
if (
|
|
462
|
+
if (fs__namespace.existsSync(file)) {
|
|
439
463
|
layoutFile = file;
|
|
440
464
|
break;
|
|
441
465
|
}
|
|
442
466
|
}
|
|
443
467
|
if (layoutFile) {
|
|
444
|
-
const content =
|
|
468
|
+
const content = fs__namespace.readFileSync(layoutFile, 'utf8');
|
|
445
469
|
const modifiedContent = this.injectAstroLayout(content);
|
|
446
470
|
modifications.push({
|
|
447
471
|
filePath: layoutFile,
|
|
@@ -460,7 +484,7 @@ export function Providers({ children }: { children: React.ReactNode }) {
|
|
|
460
484
|
async generateNuxtModifications() {
|
|
461
485
|
const modifications = [];
|
|
462
486
|
// Create plugin file for Nuxt (in app directory)
|
|
463
|
-
const pluginFile =
|
|
487
|
+
const pluginFile = path__namespace.join(this.projectRoot, 'app', 'plugins', 'humanbehavior.client.ts');
|
|
464
488
|
modifications.push({
|
|
465
489
|
filePath: pluginFile,
|
|
466
490
|
action: 'create',
|
|
@@ -478,7 +502,7 @@ export default defineNuxtPlugin(() => {
|
|
|
478
502
|
description: 'Created Nuxt plugin for HumanBehavior SDK in app directory'
|
|
479
503
|
});
|
|
480
504
|
// Create environment configuration
|
|
481
|
-
const nuxtConfigFile =
|
|
505
|
+
const nuxtConfigFile = path__namespace.join(this.projectRoot, 'nuxt.config.ts');
|
|
482
506
|
{
|
|
483
507
|
const mod = this.applyOrNotify(nuxtConfigFile, (c) => this.injectNuxtConfig(c), 'Added HumanBehavior runtime config to Nuxt config', 'Nuxt: Add inside defineNuxtConfig({ … }):\nruntimeConfig: { public: { humanBehaviorApiKey: process.env.NUXT_PUBLIC_HUMANBEHAVIOR_API_KEY } },');
|
|
484
508
|
if (mod)
|
|
@@ -494,9 +518,9 @@ export default defineNuxtPlugin(() => {
|
|
|
494
518
|
async generateRemixModifications() {
|
|
495
519
|
const modifications = [];
|
|
496
520
|
// Find root.tsx file
|
|
497
|
-
const rootFile =
|
|
498
|
-
if (
|
|
499
|
-
const content =
|
|
521
|
+
const rootFile = path__namespace.join(this.projectRoot, 'app', 'root.tsx');
|
|
522
|
+
if (fs__namespace.existsSync(rootFile)) {
|
|
523
|
+
const content = fs__namespace.readFileSync(rootFile, 'utf8');
|
|
500
524
|
const modifiedContent = this.injectRemixProvider(content);
|
|
501
525
|
modifications.push({
|
|
502
526
|
filePath: rootFile,
|
|
@@ -517,8 +541,8 @@ export default defineNuxtPlugin(() => {
|
|
|
517
541
|
// Find main.js or main.ts
|
|
518
542
|
const mainFile = this.findVueMainFile();
|
|
519
543
|
// Create Vue composable per docs (idempotent)
|
|
520
|
-
const composableDir =
|
|
521
|
-
const composablePath =
|
|
544
|
+
const composableDir = path__namespace.join(this.projectRoot, 'src', 'composables');
|
|
545
|
+
const composablePath = path__namespace.join(composableDir, 'useHumanBehavior.ts');
|
|
522
546
|
const composableContent = `import { HumanBehaviorTracker } from 'humanbehavior-js'
|
|
523
547
|
|
|
524
548
|
export function useHumanBehavior() {
|
|
@@ -534,10 +558,10 @@ export function useHumanBehavior() {
|
|
|
534
558
|
}
|
|
535
559
|
`;
|
|
536
560
|
try {
|
|
537
|
-
if (!
|
|
538
|
-
|
|
561
|
+
if (!fs__namespace.existsSync(composableDir)) {
|
|
562
|
+
fs__namespace.mkdirSync(composableDir, { recursive: true });
|
|
539
563
|
}
|
|
540
|
-
if (!
|
|
564
|
+
if (!fs__namespace.existsSync(composablePath)) {
|
|
541
565
|
modifications.push({
|
|
542
566
|
filePath: composablePath,
|
|
543
567
|
action: 'create',
|
|
@@ -548,7 +572,7 @@ export function useHumanBehavior() {
|
|
|
548
572
|
}
|
|
549
573
|
catch { }
|
|
550
574
|
if (mainFile) {
|
|
551
|
-
const content =
|
|
575
|
+
const content = fs__namespace.readFileSync(mainFile, 'utf8');
|
|
552
576
|
const modifiedContent = this.injectVuePlugin(content);
|
|
553
577
|
modifications.push({
|
|
554
578
|
filePath: mainFile,
|
|
@@ -567,8 +591,8 @@ export function useHumanBehavior() {
|
|
|
567
591
|
async generateAngularModifications() {
|
|
568
592
|
const modifications = [];
|
|
569
593
|
// Create Angular service (docs pattern)
|
|
570
|
-
const serviceDir =
|
|
571
|
-
const servicePath =
|
|
594
|
+
const serviceDir = path__namespace.join(this.projectRoot, 'src', 'app', 'services');
|
|
595
|
+
const servicePath = path__namespace.join(serviceDir, 'hb.service.ts');
|
|
572
596
|
const serviceContent = `import { Injectable, NgZone, Inject, PLATFORM_ID } from '@angular/core';
|
|
573
597
|
import { isPlatformBrowser } from '@angular/common';
|
|
574
598
|
import { HumanBehaviorTracker } from 'humanbehavior-js';
|
|
@@ -599,10 +623,10 @@ export class HumanBehavior {
|
|
|
599
623
|
}
|
|
600
624
|
}
|
|
601
625
|
`;
|
|
602
|
-
if (!
|
|
603
|
-
|
|
626
|
+
if (!fs__namespace.existsSync(serviceDir)) {
|
|
627
|
+
fs__namespace.mkdirSync(serviceDir, { recursive: true });
|
|
604
628
|
}
|
|
605
|
-
if (!
|
|
629
|
+
if (!fs__namespace.existsSync(servicePath)) {
|
|
606
630
|
modifications.push({
|
|
607
631
|
filePath: servicePath,
|
|
608
632
|
action: 'create',
|
|
@@ -611,16 +635,16 @@ export class HumanBehavior {
|
|
|
611
635
|
});
|
|
612
636
|
}
|
|
613
637
|
// Handle Angular environment files (proper Angular way)
|
|
614
|
-
const envFile =
|
|
615
|
-
const envProdFile =
|
|
638
|
+
const envFile = path__namespace.join(this.projectRoot, 'src', 'environments', 'environment.ts');
|
|
639
|
+
const envProdFile = path__namespace.join(this.projectRoot, 'src', 'environments', 'environment.prod.ts');
|
|
616
640
|
// Create environments directory if it doesn't exist
|
|
617
|
-
const envDir =
|
|
618
|
-
if (!
|
|
619
|
-
|
|
641
|
+
const envDir = path__namespace.dirname(envFile);
|
|
642
|
+
if (!fs__namespace.existsSync(envDir)) {
|
|
643
|
+
fs__namespace.mkdirSync(envDir, { recursive: true });
|
|
620
644
|
}
|
|
621
645
|
// Create or update development environment
|
|
622
|
-
if (
|
|
623
|
-
const content =
|
|
646
|
+
if (fs__namespace.existsSync(envFile)) {
|
|
647
|
+
const content = fs__namespace.readFileSync(envFile, 'utf8');
|
|
624
648
|
if (!content.includes('humanBehaviorApiKey')) {
|
|
625
649
|
const modifiedContent = content.replace(/export const environment = {([\s\S]*?)};/, `export const environment = {
|
|
626
650
|
$1,
|
|
@@ -647,8 +671,8 @@ export class HumanBehavior {
|
|
|
647
671
|
});
|
|
648
672
|
}
|
|
649
673
|
// Create or update production environment
|
|
650
|
-
if (
|
|
651
|
-
const content =
|
|
674
|
+
if (fs__namespace.existsSync(envProdFile)) {
|
|
675
|
+
const content = fs__namespace.readFileSync(envProdFile, 'utf8');
|
|
652
676
|
if (!content.includes('humanBehaviorApiKey')) {
|
|
653
677
|
const modifiedContent = content.replace(/export const environment = {([\s\S]*?)};/, `export const environment = {
|
|
654
678
|
$1,
|
|
@@ -677,9 +701,9 @@ export class HumanBehavior {
|
|
|
677
701
|
// For Angular, we don't need .env files since we use environment.ts
|
|
678
702
|
// The environment files are already created above
|
|
679
703
|
// Inject service into app component
|
|
680
|
-
const appComponentPath =
|
|
681
|
-
if (
|
|
682
|
-
const appContent =
|
|
704
|
+
const appComponentPath = path__namespace.join(this.projectRoot, 'src', 'app', 'app.ts');
|
|
705
|
+
if (fs__namespace.existsSync(appComponentPath)) {
|
|
706
|
+
const appContent = fs__namespace.readFileSync(appComponentPath, 'utf8');
|
|
683
707
|
// Check if already has HumanBehavior service
|
|
684
708
|
if (!appContent.includes('HumanBehavior')) {
|
|
685
709
|
let modifiedAppContent = appContent
|
|
@@ -704,13 +728,13 @@ import { HumanBehavior } from './services/hb.service';`)
|
|
|
704
728
|
async generateSvelteModifications() {
|
|
705
729
|
const modifications = [];
|
|
706
730
|
// Check for SvelteKit
|
|
707
|
-
const svelteConfigFile =
|
|
708
|
-
const isSvelteKit =
|
|
731
|
+
const svelteConfigFile = path__namespace.join(this.projectRoot, 'svelte.config.js');
|
|
732
|
+
const isSvelteKit = fs__namespace.existsSync(svelteConfigFile);
|
|
709
733
|
if (isSvelteKit) {
|
|
710
734
|
// SvelteKit - create layout file
|
|
711
|
-
const layoutFile =
|
|
712
|
-
if (
|
|
713
|
-
const content =
|
|
735
|
+
const layoutFile = path__namespace.join(this.projectRoot, 'src', 'routes', '+layout.svelte');
|
|
736
|
+
if (fs__namespace.existsSync(layoutFile)) {
|
|
737
|
+
const content = fs__namespace.readFileSync(layoutFile, 'utf8');
|
|
714
738
|
const modifiedContent = this.injectSvelteKitLayout(content);
|
|
715
739
|
modifications.push({
|
|
716
740
|
filePath: layoutFile,
|
|
@@ -724,7 +748,7 @@ import { HumanBehavior } from './services/hb.service';`)
|
|
|
724
748
|
// Regular Svelte - modify main file
|
|
725
749
|
const mainFile = this.findSvelteMainFile();
|
|
726
750
|
if (mainFile) {
|
|
727
|
-
const content =
|
|
751
|
+
const content = fs__namespace.readFileSync(mainFile, 'utf8');
|
|
728
752
|
const modifiedContent = this.injectSvelteStore(content);
|
|
729
753
|
modifications.push({
|
|
730
754
|
filePath: mainFile,
|
|
@@ -746,7 +770,7 @@ import { HumanBehavior } from './services/hb.service';`)
|
|
|
746
770
|
// Find HTML file to inject script
|
|
747
771
|
const htmlFile = this.findHTMLFile();
|
|
748
772
|
if (htmlFile) {
|
|
749
|
-
const content =
|
|
773
|
+
const content = fs__namespace.readFileSync(htmlFile, 'utf8');
|
|
750
774
|
const modifiedContent = this.injectVanillaScript(content);
|
|
751
775
|
modifications.push({
|
|
752
776
|
filePath: htmlFile,
|
|
@@ -765,9 +789,9 @@ import { HumanBehavior } from './services/hb.service';`)
|
|
|
765
789
|
async generateGatsbyModifications() {
|
|
766
790
|
const modifications = [];
|
|
767
791
|
// Modify or create gatsby-browser.js for Gatsby
|
|
768
|
-
const gatsbyBrowserFile =
|
|
769
|
-
if (
|
|
770
|
-
const content =
|
|
792
|
+
const gatsbyBrowserFile = path__namespace.join(this.projectRoot, 'gatsby-browser.js');
|
|
793
|
+
if (fs__namespace.existsSync(gatsbyBrowserFile)) {
|
|
794
|
+
const content = fs__namespace.readFileSync(gatsbyBrowserFile, 'utf8');
|
|
771
795
|
const modifiedContent = this.injectGatsbyBrowser(content);
|
|
772
796
|
modifications.push({
|
|
773
797
|
filePath: gatsbyBrowserFile,
|
|
@@ -802,19 +826,19 @@ export const onClientEntry = () => {
|
|
|
802
826
|
async applyModifications(modifications) {
|
|
803
827
|
for (const modification of modifications) {
|
|
804
828
|
try {
|
|
805
|
-
const dir =
|
|
806
|
-
if (!
|
|
807
|
-
|
|
829
|
+
const dir = path__namespace.dirname(modification.filePath);
|
|
830
|
+
if (!fs__namespace.existsSync(dir)) {
|
|
831
|
+
fs__namespace.mkdirSync(dir, { recursive: true });
|
|
808
832
|
}
|
|
809
833
|
switch (modification.action) {
|
|
810
834
|
case 'create':
|
|
811
|
-
|
|
835
|
+
fs__namespace.writeFileSync(modification.filePath, modification.content);
|
|
812
836
|
break;
|
|
813
837
|
case 'modify':
|
|
814
|
-
|
|
838
|
+
fs__namespace.writeFileSync(modification.filePath, modification.content);
|
|
815
839
|
break;
|
|
816
840
|
case 'append':
|
|
817
|
-
|
|
841
|
+
fs__namespace.appendFileSync(modification.filePath, '\n' + modification.content);
|
|
818
842
|
break;
|
|
819
843
|
}
|
|
820
844
|
}
|
|
@@ -846,11 +870,11 @@ export const onClientEntry = () => {
|
|
|
846
870
|
* Helper: apply a file transform or record a manual instruction if unchanged/missing
|
|
847
871
|
*/
|
|
848
872
|
applyOrNotify(filePath, transform, description, manualNote) {
|
|
849
|
-
if (!
|
|
850
|
-
this.manualNotes.push(`${manualNote} (file missing: ${
|
|
873
|
+
if (!fs__namespace.existsSync(filePath)) {
|
|
874
|
+
this.manualNotes.push(`${manualNote} (file missing: ${path__namespace.relative(this.projectRoot, filePath)})`);
|
|
851
875
|
return null;
|
|
852
876
|
}
|
|
853
|
-
const original =
|
|
877
|
+
const original = fs__namespace.readFileSync(filePath, 'utf8');
|
|
854
878
|
const updated = transform(original);
|
|
855
879
|
if (updated !== original) {
|
|
856
880
|
return {
|
|
@@ -870,8 +894,8 @@ export const onClientEntry = () => {
|
|
|
870
894
|
'src/index.js', 'src/index.tsx', 'src/main.js', 'src/main.tsx'
|
|
871
895
|
];
|
|
872
896
|
for (const file of possibleFiles) {
|
|
873
|
-
const fullPath =
|
|
874
|
-
if (
|
|
897
|
+
const fullPath = path__namespace.join(this.projectRoot, file);
|
|
898
|
+
if (fs__namespace.existsSync(fullPath)) {
|
|
875
899
|
return fullPath;
|
|
876
900
|
}
|
|
877
901
|
}
|
|
@@ -882,8 +906,8 @@ export const onClientEntry = () => {
|
|
|
882
906
|
'src/main.js', 'src/main.ts', 'src/main.jsx', 'src/main.tsx'
|
|
883
907
|
];
|
|
884
908
|
for (const file of possibleFiles) {
|
|
885
|
-
const fullPath =
|
|
886
|
-
if (
|
|
909
|
+
const fullPath = path__namespace.join(this.projectRoot, file);
|
|
910
|
+
if (fs__namespace.existsSync(fullPath)) {
|
|
887
911
|
return fullPath;
|
|
888
912
|
}
|
|
889
913
|
}
|
|
@@ -894,8 +918,8 @@ export const onClientEntry = () => {
|
|
|
894
918
|
'src/main.js', 'src/main.ts', 'src/main.svelte'
|
|
895
919
|
];
|
|
896
920
|
for (const file of possibleFiles) {
|
|
897
|
-
const fullPath =
|
|
898
|
-
if (
|
|
921
|
+
const fullPath = path__namespace.join(this.projectRoot, file);
|
|
922
|
+
if (fs__namespace.existsSync(fullPath)) {
|
|
899
923
|
return fullPath;
|
|
900
924
|
}
|
|
901
925
|
}
|
|
@@ -904,8 +928,8 @@ export const onClientEntry = () => {
|
|
|
904
928
|
findHTMLFile() {
|
|
905
929
|
const possibleFiles = ['index.html', 'public/index.html', 'dist/index.html'];
|
|
906
930
|
for (const file of possibleFiles) {
|
|
907
|
-
const fullPath =
|
|
908
|
-
if (
|
|
931
|
+
const fullPath = path__namespace.join(this.projectRoot, file);
|
|
932
|
+
if (fs__namespace.existsSync(fullPath)) {
|
|
909
933
|
return fullPath;
|
|
910
934
|
}
|
|
911
935
|
}
|
|
@@ -1294,8 +1318,8 @@ if (typeof window !== 'undefined') {
|
|
|
1294
1318
|
const envVarName = getEnvVarName(framework);
|
|
1295
1319
|
// Check for existing files
|
|
1296
1320
|
for (const envFile of possibleEnvFiles) {
|
|
1297
|
-
const fullPath =
|
|
1298
|
-
if (
|
|
1321
|
+
const fullPath = path__namespace.join(this.projectRoot, envFile);
|
|
1322
|
+
if (fs__namespace.existsSync(fullPath)) {
|
|
1299
1323
|
return { filePath: fullPath, envVarName };
|
|
1300
1324
|
}
|
|
1301
1325
|
}
|
|
@@ -1316,7 +1340,7 @@ if (typeof window !== 'undefined') {
|
|
|
1316
1340
|
};
|
|
1317
1341
|
const defaultFile = defaultFiles[framework.type] || '.env';
|
|
1318
1342
|
return {
|
|
1319
|
-
filePath:
|
|
1343
|
+
filePath: path__namespace.join(this.projectRoot, defaultFile),
|
|
1320
1344
|
envVarName
|
|
1321
1345
|
};
|
|
1322
1346
|
}
|
|
@@ -1327,16 +1351,16 @@ if (typeof window !== 'undefined') {
|
|
|
1327
1351
|
const { filePath, envVarName } = this.findBestEnvFile(framework);
|
|
1328
1352
|
// Clean the API key to prevent formatting issues
|
|
1329
1353
|
const cleanApiKey = this.apiKey.trim();
|
|
1330
|
-
if (
|
|
1354
|
+
if (fs__namespace.existsSync(filePath)) {
|
|
1331
1355
|
// Check if the variable already exists
|
|
1332
|
-
const content =
|
|
1356
|
+
const content = fs__namespace.readFileSync(filePath, 'utf8');
|
|
1333
1357
|
if (content.includes(envVarName)) {
|
|
1334
1358
|
// Variable exists, don't modify
|
|
1335
1359
|
return {
|
|
1336
1360
|
filePath,
|
|
1337
1361
|
action: 'modify',
|
|
1338
1362
|
content: content, // No change
|
|
1339
|
-
description: `API key already exists in ${
|
|
1363
|
+
description: `API key already exists in ${path__namespace.basename(filePath)}`
|
|
1340
1364
|
};
|
|
1341
1365
|
}
|
|
1342
1366
|
else {
|
|
@@ -1345,7 +1369,7 @@ if (typeof window !== 'undefined') {
|
|
|
1345
1369
|
filePath,
|
|
1346
1370
|
action: 'append',
|
|
1347
1371
|
content: `\n${envVarName}=${cleanApiKey}`,
|
|
1348
|
-
description: `Added API key to existing ${
|
|
1372
|
+
description: `Added API key to existing ${path__namespace.basename(filePath)}`
|
|
1349
1373
|
};
|
|
1350
1374
|
}
|
|
1351
1375
|
}
|
|
@@ -1355,7 +1379,7 @@ if (typeof window !== 'undefined') {
|
|
|
1355
1379
|
filePath,
|
|
1356
1380
|
action: 'create',
|
|
1357
1381
|
content: `${envVarName}=${cleanApiKey}`,
|
|
1358
|
-
description: `Created ${
|
|
1382
|
+
description: `Created ${path__namespace.basename(filePath)} with API key`
|
|
1359
1383
|
};
|
|
1360
1384
|
}
|
|
1361
1385
|
}
|
|
@@ -1374,12 +1398,12 @@ class AutoInstallCLI {
|
|
|
1374
1398
|
this.options = options;
|
|
1375
1399
|
}
|
|
1376
1400
|
async run() {
|
|
1377
|
-
|
|
1401
|
+
clack__namespace.intro('🚀 HumanBehavior SDK Auto-Installation');
|
|
1378
1402
|
try {
|
|
1379
1403
|
// Get API key
|
|
1380
1404
|
const apiKey = await this.getApiKey();
|
|
1381
1405
|
if (!apiKey) {
|
|
1382
|
-
|
|
1406
|
+
clack__namespace.cancel('API key is required');
|
|
1383
1407
|
process.exit(1);
|
|
1384
1408
|
}
|
|
1385
1409
|
// Get project path
|
|
@@ -1388,12 +1412,12 @@ class AutoInstallCLI {
|
|
|
1388
1412
|
if (!this.options.yes) {
|
|
1389
1413
|
const confirmed = await this.confirmInstallation(projectPath);
|
|
1390
1414
|
if (!confirmed) {
|
|
1391
|
-
|
|
1415
|
+
clack__namespace.cancel('Installation cancelled.');
|
|
1392
1416
|
process.exit(0);
|
|
1393
1417
|
}
|
|
1394
1418
|
}
|
|
1395
1419
|
// Run installation
|
|
1396
|
-
const spinner =
|
|
1420
|
+
const spinner = clack__namespace.spinner();
|
|
1397
1421
|
spinner.start('🔍 Detecting framework and applying integration...');
|
|
1398
1422
|
const wizard = new AutoInstallationWizard(apiKey, projectPath);
|
|
1399
1423
|
const result = await wizard.install();
|
|
@@ -1402,7 +1426,7 @@ class AutoInstallCLI {
|
|
|
1402
1426
|
this.displayResults(result);
|
|
1403
1427
|
}
|
|
1404
1428
|
catch (error) {
|
|
1405
|
-
|
|
1429
|
+
clack__namespace.cancel(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
1406
1430
|
process.exit(1);
|
|
1407
1431
|
}
|
|
1408
1432
|
}
|
|
@@ -1410,7 +1434,7 @@ class AutoInstallCLI {
|
|
|
1410
1434
|
if (this.options.apiKey) {
|
|
1411
1435
|
return this.options.apiKey;
|
|
1412
1436
|
}
|
|
1413
|
-
const apiKey = await
|
|
1437
|
+
const apiKey = await clack__namespace.text({
|
|
1414
1438
|
message: 'Enter your HumanBehavior API key:',
|
|
1415
1439
|
placeholder: 'hb_...',
|
|
1416
1440
|
validate: (value) => {
|
|
@@ -1425,30 +1449,30 @@ class AutoInstallCLI {
|
|
|
1425
1449
|
}
|
|
1426
1450
|
// Framework selection no longer needed; AutoInstallationWizard auto-detects
|
|
1427
1451
|
async confirmInstallation(projectPath) {
|
|
1428
|
-
const confirmed = await
|
|
1452
|
+
const confirmed = await clack__namespace.confirm({
|
|
1429
1453
|
message: `Ready to install HumanBehavior SDK in ${projectPath}?`
|
|
1430
1454
|
});
|
|
1431
1455
|
return confirmed;
|
|
1432
1456
|
}
|
|
1433
1457
|
displayResults(result) {
|
|
1434
1458
|
if (result.success) {
|
|
1435
|
-
|
|
1459
|
+
clack__namespace.outro('🎉 Installation completed successfully!');
|
|
1436
1460
|
// Display framework info
|
|
1437
|
-
|
|
1461
|
+
clack__namespace.note(`Framework detected: ${result.framework.name} (${result.framework.type})`, 'Framework Info');
|
|
1438
1462
|
// Display modifications
|
|
1439
1463
|
if (result.modifications && result.modifications.length > 0) {
|
|
1440
1464
|
const modifications = result.modifications.map((mod) => `${mod.action}: ${mod.filePath} - ${mod.description}`);
|
|
1441
|
-
|
|
1465
|
+
clack__namespace.note(modifications.join('\n'), 'Files Modified');
|
|
1442
1466
|
}
|
|
1443
1467
|
// Display next steps
|
|
1444
1468
|
if (result.nextSteps && result.nextSteps.length > 0) {
|
|
1445
|
-
|
|
1469
|
+
clack__namespace.note(result.nextSteps.join('\n'), 'Next Steps');
|
|
1446
1470
|
}
|
|
1447
1471
|
}
|
|
1448
1472
|
else {
|
|
1449
|
-
|
|
1473
|
+
clack__namespace.cancel('Installation failed');
|
|
1450
1474
|
if (result.errors && result.errors.length > 0) {
|
|
1451
|
-
|
|
1475
|
+
clack__namespace.note(result.errors.join('\n'), 'Errors');
|
|
1452
1476
|
}
|
|
1453
1477
|
}
|
|
1454
1478
|
}
|
|
@@ -1504,17 +1528,15 @@ Examples:
|
|
|
1504
1528
|
npx humanbehavior-js auto-install --project ./my-app --yes
|
|
1505
1529
|
`);
|
|
1506
1530
|
}
|
|
1507
|
-
// Main execution
|
|
1508
|
-
//
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
});
|
|
1517
|
-
}
|
|
1531
|
+
// Main execution
|
|
1532
|
+
// For bin files, always execute when run directly
|
|
1533
|
+
// Rollup will convert this to CommonJS, and the shebang ensures it runs with node
|
|
1534
|
+
const options = parseArgs();
|
|
1535
|
+
const cli = new AutoInstallCLI(options);
|
|
1536
|
+
cli.run().catch((error) => {
|
|
1537
|
+
clack__namespace.cancel(`Unexpected error: ${error.message}`);
|
|
1538
|
+
process.exit(1);
|
|
1539
|
+
});
|
|
1518
1540
|
|
|
1519
|
-
|
|
1541
|
+
exports.AutoInstallCLI = AutoInstallCLI;
|
|
1520
1542
|
//# sourceMappingURL=auto-install.js.map
|