humanbehavior-js 0.5.44 → 0.5.46
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
package/package.json
CHANGED
|
@@ -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
|
}
|
|
@@ -1660,10 +1684,10 @@ class ManualFrameworkInstallationWizard extends AutoInstallationWizard {
|
|
|
1660
1684
|
if (depth > 3)
|
|
1661
1685
|
return; // Limit depth
|
|
1662
1686
|
try {
|
|
1663
|
-
const items =
|
|
1687
|
+
const items = fs__namespace.readdirSync(dir);
|
|
1664
1688
|
for (const item of items) {
|
|
1665
|
-
const fullPath =
|
|
1666
|
-
const stat =
|
|
1689
|
+
const fullPath = path__namespace.join(dir, item);
|
|
1690
|
+
const stat = fs__namespace.statSync(fullPath);
|
|
1667
1691
|
if (stat.isDirectory() && !item.startsWith('.') && item !== 'node_modules') {
|
|
1668
1692
|
scanDir(fullPath, depth + 1);
|
|
1669
1693
|
}
|
|
@@ -1701,8 +1725,8 @@ class ManualFrameworkInstallationWizard extends AutoInstallationWizard {
|
|
|
1701
1725
|
const samples = [];
|
|
1702
1726
|
for (const file of files.slice(0, 20)) { // Limit to 20 files
|
|
1703
1727
|
try {
|
|
1704
|
-
const content =
|
|
1705
|
-
const relativePath =
|
|
1728
|
+
const content = fs__namespace.readFileSync(file, 'utf8');
|
|
1729
|
+
const relativePath = path__namespace.relative(this.projectRoot, file);
|
|
1706
1730
|
samples.push(`File: ${relativePath}\n${content.substring(0, 1000)}`);
|
|
1707
1731
|
}
|
|
1708
1732
|
catch (error) {
|
|
@@ -1785,12 +1809,12 @@ class AIAutoInstallCLI {
|
|
|
1785
1809
|
this.options = options;
|
|
1786
1810
|
}
|
|
1787
1811
|
async run() {
|
|
1788
|
-
|
|
1812
|
+
clack__namespace.intro('🤖 AI-Enhanced HumanBehavior SDK Auto-Installation');
|
|
1789
1813
|
try {
|
|
1790
1814
|
// Get API key
|
|
1791
1815
|
const apiKey = await this.getApiKey();
|
|
1792
1816
|
if (!apiKey) {
|
|
1793
|
-
|
|
1817
|
+
clack__namespace.cancel('API key is required');
|
|
1794
1818
|
process.exit(1);
|
|
1795
1819
|
}
|
|
1796
1820
|
// Get project path
|
|
@@ -1798,19 +1822,19 @@ class AIAutoInstallCLI {
|
|
|
1798
1822
|
// Choose framework
|
|
1799
1823
|
const framework = await this.chooseFramework();
|
|
1800
1824
|
if (!framework) {
|
|
1801
|
-
|
|
1825
|
+
clack__namespace.cancel('Installation cancelled.');
|
|
1802
1826
|
process.exit(0);
|
|
1803
1827
|
}
|
|
1804
1828
|
// Confirm installation
|
|
1805
1829
|
if (!this.options.yes) {
|
|
1806
1830
|
const confirmed = await this.confirmInstallation(projectPath, framework);
|
|
1807
1831
|
if (!confirmed) {
|
|
1808
|
-
|
|
1832
|
+
clack__namespace.cancel('Installation cancelled.');
|
|
1809
1833
|
process.exit(0);
|
|
1810
1834
|
}
|
|
1811
1835
|
}
|
|
1812
1836
|
// Run installation
|
|
1813
|
-
const spinner =
|
|
1837
|
+
const spinner = clack__namespace.spinner();
|
|
1814
1838
|
spinner.start('🔍 Analyzing your project with AI...');
|
|
1815
1839
|
const wizard = new ManualFrameworkInstallationWizard(apiKey, projectPath, framework);
|
|
1816
1840
|
const result = await wizard.install();
|
|
@@ -1819,7 +1843,7 @@ class AIAutoInstallCLI {
|
|
|
1819
1843
|
this.displayResults(result, framework);
|
|
1820
1844
|
}
|
|
1821
1845
|
catch (error) {
|
|
1822
|
-
|
|
1846
|
+
clack__namespace.cancel(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
1823
1847
|
process.exit(1);
|
|
1824
1848
|
}
|
|
1825
1849
|
}
|
|
@@ -1827,7 +1851,7 @@ class AIAutoInstallCLI {
|
|
|
1827
1851
|
if (this.options.apiKey) {
|
|
1828
1852
|
return this.options.apiKey;
|
|
1829
1853
|
}
|
|
1830
|
-
const apiKey = await
|
|
1854
|
+
const apiKey = await clack__namespace.text({
|
|
1831
1855
|
message: 'Enter your HumanBehavior API key:',
|
|
1832
1856
|
placeholder: 'hb_...',
|
|
1833
1857
|
validate: (value) => {
|
|
@@ -1841,13 +1865,13 @@ class AIAutoInstallCLI {
|
|
|
1841
1865
|
return apiKey;
|
|
1842
1866
|
}
|
|
1843
1867
|
async confirmInstallation(projectPath, framework) {
|
|
1844
|
-
const confirmed = await
|
|
1868
|
+
const confirmed = await clack__namespace.confirm({
|
|
1845
1869
|
message: `Ready to install HumanBehavior SDK in ${projectPath} for ${framework}?`
|
|
1846
1870
|
});
|
|
1847
1871
|
return confirmed;
|
|
1848
1872
|
}
|
|
1849
1873
|
async chooseFramework() {
|
|
1850
|
-
const framework = await
|
|
1874
|
+
const framework = await clack__namespace.select({
|
|
1851
1875
|
message: 'Select your framework:',
|
|
1852
1876
|
options: [
|
|
1853
1877
|
{ label: 'React', value: 'react' },
|
|
@@ -1866,30 +1890,30 @@ class AIAutoInstallCLI {
|
|
|
1866
1890
|
}
|
|
1867
1891
|
displayResults(result, framework) {
|
|
1868
1892
|
if (result.success) {
|
|
1869
|
-
|
|
1893
|
+
clack__namespace.outro('🎉 Installation completed successfully!');
|
|
1870
1894
|
// Display framework info
|
|
1871
|
-
|
|
1895
|
+
clack__namespace.note(`Framework detected: ${result.framework.name} (${result.framework.type})`, 'Framework Info');
|
|
1872
1896
|
// Display modifications
|
|
1873
1897
|
if (result.modifications && result.modifications.length > 0) {
|
|
1874
1898
|
const modifications = result.modifications.map((mod) => `${mod.action}: ${mod.filePath} - ${mod.description}`);
|
|
1875
|
-
|
|
1899
|
+
clack__namespace.note(modifications.join('\n'), 'Files Modified');
|
|
1876
1900
|
}
|
|
1877
1901
|
// Display next steps
|
|
1878
1902
|
if (result.nextSteps && result.nextSteps.length > 0) {
|
|
1879
|
-
|
|
1903
|
+
clack__namespace.note(result.nextSteps.join('\n'), 'Next Steps');
|
|
1880
1904
|
}
|
|
1881
1905
|
// Display AI insights if available
|
|
1882
1906
|
if (result.aiAnalysis) {
|
|
1883
|
-
|
|
1907
|
+
clack__namespace.note(`Confidence: ${Math.round(result.aiAnalysis.confidence * 100)}%`, 'AI Analysis');
|
|
1884
1908
|
if (result.aiAnalysis.recommendations && result.aiAnalysis.recommendations.length > 0) {
|
|
1885
|
-
|
|
1909
|
+
clack__namespace.note(result.aiAnalysis.recommendations.join('\n'), 'AI Recommendations');
|
|
1886
1910
|
}
|
|
1887
1911
|
}
|
|
1888
1912
|
}
|
|
1889
1913
|
else {
|
|
1890
|
-
|
|
1914
|
+
clack__namespace.cancel('Installation failed');
|
|
1891
1915
|
if (result.errors && result.errors.length > 0) {
|
|
1892
|
-
|
|
1916
|
+
clack__namespace.note(result.errors.join('\n'), 'Errors');
|
|
1893
1917
|
}
|
|
1894
1918
|
}
|
|
1895
1919
|
}
|
|
@@ -1954,9 +1978,9 @@ Examples:
|
|
|
1954
1978
|
const options = parseArgs();
|
|
1955
1979
|
const cli = new AIAutoInstallCLI(options);
|
|
1956
1980
|
cli.run().catch((error) => {
|
|
1957
|
-
|
|
1981
|
+
clack__namespace.cancel(`Unexpected error: ${error.message}`);
|
|
1958
1982
|
process.exit(1);
|
|
1959
1983
|
});
|
|
1960
1984
|
|
|
1961
|
-
|
|
1985
|
+
exports.AIAutoInstallCLI = AIAutoInstallCLI;
|
|
1962
1986
|
//# sourceMappingURL=ai-auto-install.js.map
|