humanbehavior-js 0.4.13 ā 0.4.15
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/cjs/install-wizard.cjs +396 -25
- package/dist/cjs/install-wizard.cjs.map +1 -1
- package/dist/cjs/wizard/index.cjs +633 -395
- package/dist/cjs/wizard/index.cjs.map +1 -1
- package/dist/cli/ai-auto-install.cjs +57161 -0
- package/dist/cli/ai-auto-install.cjs.map +1 -0
- package/dist/cli/ai-auto-install.js +520 -575
- package/dist/cli/ai-auto-install.js.map +1 -1
- package/dist/cli/auto-install.cjs +56352 -0
- package/dist/cli/auto-install.cjs.map +1 -0
- package/dist/cli/auto-install.js +925 -140
- package/dist/cli/auto-install.js.map +1 -1
- package/dist/esm/install-wizard.js +396 -25
- package/dist/esm/install-wizard.js.map +1 -1
- package/dist/esm/wizard/index.js +631 -394
- package/dist/esm/wizard/index.js.map +1 -1
- package/dist/types/install-wizard.d.ts +31 -1
- package/dist/types/wizard/index.d.ts +44 -10
- package/package.json +3 -1
- package/rollup.config.js +5 -1
- package/src/types/clack.d.ts +31 -0
- package/src/wizard/ai/ai-install-wizard.ts +4 -1
- package/src/wizard/ai/manual-framework-wizard.ts +2 -0
- package/src/wizard/cli/ai-auto-install.ts +122 -248
- package/src/wizard/cli/auto-install.ts +116 -117
- package/src/wizard/core/install-wizard.ts +498 -60
- package/src/wizard/services/centralized-ai-service.ts +1 -1
- package/src/wizard/services/remote-ai-service.ts +18 -2
- package/tsconfig.json +1 -1
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var fs = require('fs');
|
|
4
4
|
var path = require('path');
|
|
5
|
-
var
|
|
5
|
+
var clack = require('@clack/prompts');
|
|
6
6
|
|
|
7
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
7
8
|
function _interopNamespaceDefault(e) {
|
|
8
9
|
var n = Object.create(null);
|
|
9
10
|
if (e) {
|
|
@@ -23,7 +24,7 @@ function _interopNamespaceDefault(e) {
|
|
|
23
24
|
|
|
24
25
|
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
25
26
|
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
26
|
-
var
|
|
27
|
+
var clack__namespace = /*#__PURE__*/_interopNamespaceDefault(clack);
|
|
27
28
|
|
|
28
29
|
/******************************************************************************
|
|
29
30
|
Copyright (c) Microsoft Corporation.
|
|
@@ -69,6 +70,28 @@ class AutoInstallationWizard {
|
|
|
69
70
|
this.apiKey = apiKey;
|
|
70
71
|
this.projectRoot = projectRoot;
|
|
71
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Simple version comparison utility
|
|
75
|
+
*/
|
|
76
|
+
compareVersions(version1, version2) {
|
|
77
|
+
const v1Parts = version1.split('.').map(Number);
|
|
78
|
+
const v2Parts = version2.split('.').map(Number);
|
|
79
|
+
for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) {
|
|
80
|
+
const v1 = v1Parts[i] || 0;
|
|
81
|
+
const v2 = v2Parts[i] || 0;
|
|
82
|
+
if (v1 > v2)
|
|
83
|
+
return 1;
|
|
84
|
+
if (v1 < v2)
|
|
85
|
+
return -1;
|
|
86
|
+
}
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
89
|
+
isVersionGte(version, target) {
|
|
90
|
+
return this.compareVersions(version, target) >= 0;
|
|
91
|
+
}
|
|
92
|
+
getMajorVersion(version) {
|
|
93
|
+
return parseInt(version.split('.')[0]) || 0;
|
|
94
|
+
}
|
|
72
95
|
/**
|
|
73
96
|
* Main installation method - detects framework and auto-installs
|
|
74
97
|
*/
|
|
@@ -118,73 +141,146 @@ class AutoInstallationWizard {
|
|
|
118
141
|
}
|
|
119
142
|
const packageJson = JSON.parse(fs__namespace.readFileSync(packageJsonPath, 'utf8'));
|
|
120
143
|
const dependencies = Object.assign(Object.assign({}, packageJson.dependencies), packageJson.devDependencies);
|
|
121
|
-
// Detect framework
|
|
144
|
+
// Detect framework with version information
|
|
122
145
|
let framework = {
|
|
123
146
|
name: 'vanilla',
|
|
124
147
|
type: 'vanilla',
|
|
125
|
-
projectRoot: this.projectRoot
|
|
148
|
+
projectRoot: this.projectRoot,
|
|
149
|
+
features: {}
|
|
126
150
|
};
|
|
127
151
|
if (dependencies.nuxt) {
|
|
152
|
+
const nuxtVersion = dependencies.nuxt;
|
|
153
|
+
const isNuxt3 = this.isVersionGte(nuxtVersion, '3.0.0');
|
|
128
154
|
framework = {
|
|
129
155
|
name: 'nuxt',
|
|
130
156
|
type: 'nuxt',
|
|
157
|
+
version: nuxtVersion,
|
|
158
|
+
majorVersion: this.getMajorVersion(nuxtVersion),
|
|
131
159
|
hasTypeScript: !!dependencies.typescript,
|
|
132
160
|
hasRouter: true,
|
|
133
|
-
projectRoot: this.projectRoot
|
|
161
|
+
projectRoot: this.projectRoot,
|
|
162
|
+
features: {
|
|
163
|
+
hasNuxt3: isNuxt3
|
|
164
|
+
}
|
|
134
165
|
};
|
|
135
166
|
}
|
|
136
167
|
else if (dependencies.next) {
|
|
168
|
+
const nextVersion = dependencies.next;
|
|
169
|
+
const isNext13 = this.isVersionGte(nextVersion, '13.0.0');
|
|
137
170
|
framework = {
|
|
138
171
|
name: 'nextjs',
|
|
139
172
|
type: 'nextjs',
|
|
173
|
+
version: nextVersion,
|
|
174
|
+
majorVersion: this.getMajorVersion(nextVersion),
|
|
140
175
|
hasTypeScript: !!dependencies.typescript || !!dependencies['@types/node'],
|
|
141
176
|
hasRouter: true,
|
|
142
|
-
projectRoot: this.projectRoot
|
|
177
|
+
projectRoot: this.projectRoot,
|
|
178
|
+
features: {
|
|
179
|
+
hasNextAppRouter: isNext13
|
|
180
|
+
}
|
|
143
181
|
};
|
|
144
182
|
}
|
|
145
183
|
else if (dependencies['@remix-run/react'] || dependencies['@remix-run/dev']) {
|
|
184
|
+
const remixVersion = dependencies['@remix-run/react'] || dependencies['@remix-run/dev'];
|
|
146
185
|
framework = {
|
|
147
186
|
name: 'remix',
|
|
148
187
|
type: 'remix',
|
|
188
|
+
version: remixVersion,
|
|
189
|
+
majorVersion: this.getMajorVersion(remixVersion),
|
|
149
190
|
hasTypeScript: !!dependencies.typescript || !!dependencies['@types/react'],
|
|
150
191
|
hasRouter: true,
|
|
151
|
-
projectRoot: this.projectRoot
|
|
192
|
+
projectRoot: this.projectRoot,
|
|
193
|
+
features: {}
|
|
152
194
|
};
|
|
153
195
|
}
|
|
154
196
|
else if (dependencies.react) {
|
|
197
|
+
const reactVersion = dependencies.react;
|
|
198
|
+
const isReact18 = this.isVersionGte(reactVersion, '18.0.0');
|
|
155
199
|
framework = {
|
|
156
200
|
name: 'react',
|
|
157
201
|
type: 'react',
|
|
202
|
+
version: reactVersion,
|
|
203
|
+
majorVersion: this.getMajorVersion(reactVersion),
|
|
158
204
|
hasTypeScript: !!dependencies.typescript || !!dependencies['@types/react'],
|
|
159
205
|
hasRouter: !!dependencies['react-router-dom'] || !!dependencies['react-router'],
|
|
160
|
-
projectRoot: this.projectRoot
|
|
206
|
+
projectRoot: this.projectRoot,
|
|
207
|
+
features: {
|
|
208
|
+
hasReact18: isReact18
|
|
209
|
+
}
|
|
161
210
|
};
|
|
162
211
|
}
|
|
163
212
|
else if (dependencies.vue) {
|
|
213
|
+
const vueVersion = dependencies.vue;
|
|
214
|
+
const isVue3 = this.isVersionGte(vueVersion, '3.0.0');
|
|
164
215
|
framework = {
|
|
165
216
|
name: 'vue',
|
|
166
217
|
type: 'vue',
|
|
218
|
+
version: vueVersion,
|
|
219
|
+
majorVersion: this.getMajorVersion(vueVersion),
|
|
167
220
|
hasTypeScript: !!dependencies.typescript || !!dependencies['@vue/cli-service'],
|
|
168
221
|
hasRouter: !!dependencies['vue-router'],
|
|
169
|
-
projectRoot: this.projectRoot
|
|
222
|
+
projectRoot: this.projectRoot,
|
|
223
|
+
features: {
|
|
224
|
+
hasVue3: isVue3
|
|
225
|
+
}
|
|
170
226
|
};
|
|
171
227
|
}
|
|
172
228
|
else if (dependencies['@angular/core']) {
|
|
229
|
+
const angularVersion = dependencies['@angular/core'];
|
|
230
|
+
const isAngular17 = this.isVersionGte(angularVersion, '17.0.0');
|
|
173
231
|
framework = {
|
|
174
232
|
name: 'angular',
|
|
175
233
|
type: 'angular',
|
|
234
|
+
version: angularVersion,
|
|
235
|
+
majorVersion: this.getMajorVersion(angularVersion),
|
|
176
236
|
hasTypeScript: true,
|
|
177
237
|
hasRouter: true,
|
|
178
|
-
projectRoot: this.projectRoot
|
|
238
|
+
projectRoot: this.projectRoot,
|
|
239
|
+
features: {
|
|
240
|
+
hasAngularStandalone: isAngular17
|
|
241
|
+
}
|
|
179
242
|
};
|
|
180
243
|
}
|
|
181
244
|
else if (dependencies.svelte) {
|
|
245
|
+
const svelteVersion = dependencies.svelte;
|
|
246
|
+
const isSvelteKit = !!dependencies['@sveltejs/kit'];
|
|
182
247
|
framework = {
|
|
183
248
|
name: 'svelte',
|
|
184
249
|
type: 'svelte',
|
|
250
|
+
version: svelteVersion,
|
|
251
|
+
majorVersion: this.getMajorVersion(svelteVersion),
|
|
185
252
|
hasTypeScript: !!dependencies.typescript || !!dependencies['svelte-check'],
|
|
186
253
|
hasRouter: !!dependencies['svelte-routing'] || !!dependencies['@sveltejs/kit'],
|
|
187
|
-
projectRoot: this.projectRoot
|
|
254
|
+
projectRoot: this.projectRoot,
|
|
255
|
+
features: {
|
|
256
|
+
hasSvelteKit: isSvelteKit
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
else if (dependencies.astro) {
|
|
261
|
+
const astroVersion = dependencies.astro;
|
|
262
|
+
framework = {
|
|
263
|
+
name: 'astro',
|
|
264
|
+
type: 'astro',
|
|
265
|
+
version: astroVersion,
|
|
266
|
+
majorVersion: this.getMajorVersion(astroVersion),
|
|
267
|
+
hasTypeScript: !!dependencies.typescript || !!dependencies['@astrojs/ts-plugin'],
|
|
268
|
+
hasRouter: true,
|
|
269
|
+
projectRoot: this.projectRoot,
|
|
270
|
+
features: {}
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
else if (dependencies.gatsby) {
|
|
274
|
+
const gatsbyVersion = dependencies.gatsby;
|
|
275
|
+
framework = {
|
|
276
|
+
name: 'gatsby',
|
|
277
|
+
type: 'gatsby',
|
|
278
|
+
version: gatsbyVersion,
|
|
279
|
+
majorVersion: this.getMajorVersion(gatsbyVersion),
|
|
280
|
+
hasTypeScript: !!dependencies.typescript || !!dependencies['@types/react'],
|
|
281
|
+
hasRouter: true,
|
|
282
|
+
projectRoot: this.projectRoot,
|
|
283
|
+
features: {}
|
|
188
284
|
};
|
|
189
285
|
}
|
|
190
286
|
// Detect bundler
|
|
@@ -218,13 +314,18 @@ class AutoInstallationWizard {
|
|
|
218
314
|
*/
|
|
219
315
|
installPackage() {
|
|
220
316
|
return __awaiter(this, void 0, void 0, function* () {
|
|
221
|
-
var _a, _b;
|
|
317
|
+
var _a, _b, _c, _d;
|
|
222
318
|
const { execSync } = yield import('child_process');
|
|
223
|
-
|
|
319
|
+
// Build base command
|
|
320
|
+
let command = ((_a = this.framework) === null || _a === void 0 ? void 0 : _a.packageManager) === 'yarn'
|
|
224
321
|
? 'yarn add humanbehavior-js'
|
|
225
322
|
: ((_b = this.framework) === null || _b === void 0 ? void 0 : _b.packageManager) === 'pnpm'
|
|
226
323
|
? 'pnpm add humanbehavior-js'
|
|
227
324
|
: 'npm install humanbehavior-js';
|
|
325
|
+
// Add legacy peer deps flag for npm to handle dependency conflicts
|
|
326
|
+
if (((_c = this.framework) === null || _c === void 0 ? void 0 : _c.packageManager) !== 'yarn' && ((_d = this.framework) === null || _d === void 0 ? void 0 : _d.packageManager) !== 'pnpm') {
|
|
327
|
+
command += ' --legacy-peer-deps';
|
|
328
|
+
}
|
|
228
329
|
try {
|
|
229
330
|
execSync(command, { cwd: this.projectRoot, stdio: 'inherit' });
|
|
230
331
|
}
|
|
@@ -250,6 +351,12 @@ class AutoInstallationWizard {
|
|
|
250
351
|
case 'nuxt':
|
|
251
352
|
modifications.push(...yield this.generateNuxtModifications());
|
|
252
353
|
break;
|
|
354
|
+
case 'astro':
|
|
355
|
+
modifications.push(...yield this.generateAstroModifications());
|
|
356
|
+
break;
|
|
357
|
+
case 'gatsby':
|
|
358
|
+
modifications.push(...yield this.generateGatsbyModifications());
|
|
359
|
+
break;
|
|
253
360
|
case 'remix':
|
|
254
361
|
modifications.push(...yield this.generateRemixModifications());
|
|
255
362
|
break;
|
|
@@ -361,6 +468,84 @@ export function Providers({ children }: { children: React.ReactNode }) {
|
|
|
361
468
|
return modifications;
|
|
362
469
|
});
|
|
363
470
|
}
|
|
471
|
+
/**
|
|
472
|
+
* Generate Astro-specific modifications
|
|
473
|
+
*/
|
|
474
|
+
generateAstroModifications() {
|
|
475
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
476
|
+
const modifications = [];
|
|
477
|
+
// Create Astro component for HumanBehavior
|
|
478
|
+
const astroComponentPath = path__namespace.join(this.projectRoot, 'src', 'components', 'HumanBehavior.astro');
|
|
479
|
+
const astroComponentContent = `---
|
|
480
|
+
// This component will only run on the client side
|
|
481
|
+
---
|
|
482
|
+
|
|
483
|
+
<script>
|
|
484
|
+
import { HumanBehaviorTracker } from 'humanbehavior-js';
|
|
485
|
+
|
|
486
|
+
// Get API key from environment variable
|
|
487
|
+
const apiKey = import.meta.env.PUBLIC_HUMANBEHAVIOR_API_KEY;
|
|
488
|
+
|
|
489
|
+
console.log('HumanBehavior: API key found:', apiKey ? 'Yes' : 'No');
|
|
490
|
+
|
|
491
|
+
if (apiKey) {
|
|
492
|
+
try {
|
|
493
|
+
const tracker = HumanBehaviorTracker.init(apiKey);
|
|
494
|
+
console.log('HumanBehavior: Tracker initialized successfully');
|
|
495
|
+
|
|
496
|
+
// Test event to verify tracking is working
|
|
497
|
+
setTimeout(() => {
|
|
498
|
+
tracker.customEvent('astro_page_view', {
|
|
499
|
+
page: window.location.pathname,
|
|
500
|
+
framework: 'astro'
|
|
501
|
+
}).then(() => {
|
|
502
|
+
console.log('HumanBehavior: Test event sent successfully');
|
|
503
|
+
}).catch((error) => {
|
|
504
|
+
console.error('HumanBehavior: Failed to send test event:', error);
|
|
505
|
+
});
|
|
506
|
+
}, 1000);
|
|
507
|
+
|
|
508
|
+
} catch (error) {
|
|
509
|
+
console.error('HumanBehavior: Failed to initialize tracker:', error);
|
|
510
|
+
}
|
|
511
|
+
} else {
|
|
512
|
+
console.error('HumanBehavior: No API key found');
|
|
513
|
+
}
|
|
514
|
+
</script>`;
|
|
515
|
+
modifications.push({
|
|
516
|
+
filePath: astroComponentPath,
|
|
517
|
+
action: 'create',
|
|
518
|
+
content: astroComponentContent,
|
|
519
|
+
description: 'Created Astro component for HumanBehavior SDK'
|
|
520
|
+
});
|
|
521
|
+
// Find and update layout file
|
|
522
|
+
const layoutFiles = [
|
|
523
|
+
path__namespace.join(this.projectRoot, 'src', 'layouts', 'Layout.astro'),
|
|
524
|
+
path__namespace.join(this.projectRoot, 'src', 'layouts', 'layout.astro'),
|
|
525
|
+
path__namespace.join(this.projectRoot, 'src', 'layouts', 'BaseLayout.astro')
|
|
526
|
+
];
|
|
527
|
+
let layoutFile = null;
|
|
528
|
+
for (const file of layoutFiles) {
|
|
529
|
+
if (fs__namespace.existsSync(file)) {
|
|
530
|
+
layoutFile = file;
|
|
531
|
+
break;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
if (layoutFile) {
|
|
535
|
+
const content = fs__namespace.readFileSync(layoutFile, 'utf8');
|
|
536
|
+
const modifiedContent = this.injectAstroLayout(content);
|
|
537
|
+
modifications.push({
|
|
538
|
+
filePath: layoutFile,
|
|
539
|
+
action: 'modify',
|
|
540
|
+
content: modifiedContent,
|
|
541
|
+
description: 'Added HumanBehavior component to Astro layout'
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
// Add environment variable
|
|
545
|
+
modifications.push(this.createEnvironmentModification(this.framework));
|
|
546
|
+
return modifications;
|
|
547
|
+
});
|
|
548
|
+
}
|
|
364
549
|
/**
|
|
365
550
|
* Generate Nuxt-specific modifications
|
|
366
551
|
*/
|
|
@@ -581,6 +766,50 @@ export default defineNuxtPlugin(() => {
|
|
|
581
766
|
return modifications;
|
|
582
767
|
});
|
|
583
768
|
}
|
|
769
|
+
/**
|
|
770
|
+
* Generate Gatsby-specific modifications
|
|
771
|
+
*/
|
|
772
|
+
generateGatsbyModifications() {
|
|
773
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
774
|
+
const modifications = [];
|
|
775
|
+
// Modify or create gatsby-browser.js for Gatsby
|
|
776
|
+
const gatsbyBrowserFile = path__namespace.join(this.projectRoot, 'gatsby-browser.js');
|
|
777
|
+
if (fs__namespace.existsSync(gatsbyBrowserFile)) {
|
|
778
|
+
const content = fs__namespace.readFileSync(gatsbyBrowserFile, 'utf8');
|
|
779
|
+
const modifiedContent = this.injectGatsbyBrowser(content);
|
|
780
|
+
modifications.push({
|
|
781
|
+
filePath: gatsbyBrowserFile,
|
|
782
|
+
action: 'modify',
|
|
783
|
+
content: modifiedContent,
|
|
784
|
+
description: 'Added HumanBehavior initialization to Gatsby browser'
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
else {
|
|
788
|
+
// Create gatsby-browser.js if it doesn't exist
|
|
789
|
+
modifications.push({
|
|
790
|
+
filePath: gatsbyBrowserFile,
|
|
791
|
+
action: 'create',
|
|
792
|
+
content: `import { HumanBehaviorTracker } from 'humanbehavior-js';
|
|
793
|
+
|
|
794
|
+
export const onClientEntry = () => {
|
|
795
|
+
console.log('Gatsby browser entry point loaded');
|
|
796
|
+
const apiKey = process.env.GATSBY_HUMANBEHAVIOR_API_KEY;
|
|
797
|
+
console.log('API Key found:', apiKey ? 'Yes' : 'No');
|
|
798
|
+
if (apiKey) {
|
|
799
|
+
const tracker = HumanBehaviorTracker.init(apiKey);
|
|
800
|
+
console.log('HumanBehavior SDK initialized for Gatsby');
|
|
801
|
+
} else {
|
|
802
|
+
console.log('No API key found in environment variables');
|
|
803
|
+
}
|
|
804
|
+
};`,
|
|
805
|
+
description: 'Created gatsby-browser.js with HumanBehavior initialization'
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
// Create or append to environment file
|
|
809
|
+
modifications.push(this.createEnvironmentModification(this.framework));
|
|
810
|
+
return modifications;
|
|
811
|
+
});
|
|
812
|
+
}
|
|
584
813
|
/**
|
|
585
814
|
* Apply modifications to the codebase
|
|
586
815
|
*/
|
|
@@ -675,7 +904,7 @@ export default defineNuxtPlugin(() => {
|
|
|
675
904
|
return null;
|
|
676
905
|
}
|
|
677
906
|
injectReactProvider(content, filePath) {
|
|
678
|
-
var _a;
|
|
907
|
+
var _a, _b, _c;
|
|
679
908
|
filePath.endsWith('.tsx') || filePath.endsWith('.ts');
|
|
680
909
|
// Check if already has HumanBehaviorProvider
|
|
681
910
|
if (content.includes('HumanBehaviorProvider')) {
|
|
@@ -687,14 +916,39 @@ export default defineNuxtPlugin(() => {
|
|
|
687
916
|
? 'import.meta.env.VITE_HUMANBEHAVIOR_API_KEY!'
|
|
688
917
|
: 'process.env.HUMANBEHAVIOR_API_KEY!';
|
|
689
918
|
const importStatement = `import { HumanBehaviorProvider } from 'humanbehavior-js/react';`;
|
|
690
|
-
//
|
|
919
|
+
// Enhanced parsing for React 18+ features
|
|
920
|
+
const hasReact18 = (_c = (_b = this.framework) === null || _b === void 0 ? void 0 : _b.features) === null || _c === void 0 ? void 0 : _c.hasReact18;
|
|
921
|
+
// Handle different React patterns
|
|
691
922
|
if (content.includes('function App()') || content.includes('const App =')) {
|
|
692
|
-
|
|
923
|
+
// Add import statement
|
|
924
|
+
let modifiedContent = content.replace(/(import.*?from.*?['"]react['"];?)/, `$1\n${importStatement}`);
|
|
925
|
+
// If no React import found, add it at the top
|
|
926
|
+
if (!modifiedContent.includes(importStatement)) {
|
|
927
|
+
modifiedContent = `${importStatement}\n\n${modifiedContent}`;
|
|
928
|
+
}
|
|
929
|
+
// Wrap the App component return with HumanBehaviorProvider
|
|
930
|
+
modifiedContent = modifiedContent.replace(/(return\s*\([\s\S]*?\)\s*;)/, `return (
|
|
693
931
|
<HumanBehaviorProvider apiKey={${envVar}}>
|
|
694
932
|
$1
|
|
695
933
|
</HumanBehaviorProvider>
|
|
696
934
|
);`);
|
|
935
|
+
return modifiedContent;
|
|
697
936
|
}
|
|
937
|
+
// Handle React 18+ createRoot pattern
|
|
938
|
+
if (hasReact18 && content.includes('createRoot')) {
|
|
939
|
+
let modifiedContent = content.replace(/(import.*?from.*?['"]react['"];?)/, `$1\n${importStatement}`);
|
|
940
|
+
if (!modifiedContent.includes(importStatement)) {
|
|
941
|
+
modifiedContent = `${importStatement}\n\n${modifiedContent}`;
|
|
942
|
+
}
|
|
943
|
+
// Wrap the root render with HumanBehaviorProvider
|
|
944
|
+
modifiedContent = modifiedContent.replace(/(root\.render\s*\([\s\S]*?\)\s*;)/, `root.render(
|
|
945
|
+
<HumanBehaviorProvider apiKey={${envVar}}>
|
|
946
|
+
$1
|
|
947
|
+
</HumanBehaviorProvider>
|
|
948
|
+
);`);
|
|
949
|
+
return modifiedContent;
|
|
950
|
+
}
|
|
951
|
+
// Fallback: simple injection
|
|
698
952
|
return `${importStatement}\n\n${content}`;
|
|
699
953
|
}
|
|
700
954
|
injectNextJSAppRouter(content) {
|
|
@@ -791,21 +1045,51 @@ export default function App()`);
|
|
|
791
1045
|
return modifiedContent;
|
|
792
1046
|
}
|
|
793
1047
|
injectVuePlugin(content) {
|
|
1048
|
+
var _a, _b;
|
|
794
1049
|
if (content.includes('HumanBehaviorPlugin')) {
|
|
795
1050
|
return content;
|
|
796
1051
|
}
|
|
797
1052
|
const importStatement = `import { HumanBehaviorPlugin } from 'humanbehavior-js/vue';`;
|
|
798
|
-
|
|
1053
|
+
// Enhanced Vue 3 support with version detection
|
|
1054
|
+
const hasVue3 = (_b = (_a = this.framework) === null || _a === void 0 ? void 0 : _a.features) === null || _b === void 0 ? void 0 : _b.hasVue3;
|
|
1055
|
+
if (hasVue3) {
|
|
1056
|
+
// Vue 3 with Composition API
|
|
1057
|
+
const pluginUsage = `app.use(HumanBehaviorPlugin, {
|
|
799
1058
|
apiKey: import.meta.env.VITE_HUMANBEHAVIOR_API_KEY
|
|
800
1059
|
});`;
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
1060
|
+
let modifiedContent = content;
|
|
1061
|
+
// Add import statement
|
|
1062
|
+
if (!content.includes(importStatement)) {
|
|
1063
|
+
modifiedContent = content.replace(/(import.*?from.*?['"]vue['"];?)/, `$1\n${importStatement}`);
|
|
1064
|
+
// If no Vue import found, add it at the top
|
|
1065
|
+
if (!modifiedContent.includes(importStatement)) {
|
|
1066
|
+
modifiedContent = `${importStatement}\n\n${modifiedContent}`;
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
// Handle createApp pattern
|
|
1070
|
+
if (content.includes('createApp')) {
|
|
1071
|
+
modifiedContent = modifiedContent.replace(/(app\.mount\(.*?\))/, `${pluginUsage}\n\n$1`);
|
|
1072
|
+
}
|
|
1073
|
+
return modifiedContent;
|
|
805
1074
|
}
|
|
806
1075
|
else {
|
|
807
|
-
// Vue 2
|
|
808
|
-
|
|
1076
|
+
// Vue 2 with Options API
|
|
1077
|
+
const pluginUsage = `Vue.use(HumanBehaviorPlugin, {
|
|
1078
|
+
apiKey: process.env.VUE_APP_HUMANBEHAVIOR_API_KEY
|
|
1079
|
+
});`;
|
|
1080
|
+
let modifiedContent = content;
|
|
1081
|
+
// Add import statement
|
|
1082
|
+
if (!content.includes(importStatement)) {
|
|
1083
|
+
modifiedContent = content.replace(/(import.*?from.*?['"]vue['"];?)/, `$1\n${importStatement}`);
|
|
1084
|
+
if (!modifiedContent.includes(importStatement)) {
|
|
1085
|
+
modifiedContent = `${importStatement}\n\n${modifiedContent}`;
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
// Handle new Vue pattern
|
|
1089
|
+
if (content.includes('new Vue')) {
|
|
1090
|
+
modifiedContent = modifiedContent.replace(/(new Vue\(.*?\))/, `${pluginUsage}\n\n$1`);
|
|
1091
|
+
}
|
|
1092
|
+
return modifiedContent;
|
|
809
1093
|
}
|
|
810
1094
|
}
|
|
811
1095
|
injectAngularModule(content) {
|
|
@@ -886,17 +1170,99 @@ if (typeof window !== 'undefined') {
|
|
|
886
1170
|
</script>`;
|
|
887
1171
|
return content.replace(/<\/head>/, ` ${cdnScript}\n ${initScript}\n</head>`);
|
|
888
1172
|
}
|
|
1173
|
+
/**
|
|
1174
|
+
* Inject Astro layout with HumanBehavior component
|
|
1175
|
+
*/
|
|
1176
|
+
injectAstroLayout(content) {
|
|
1177
|
+
// Check if HumanBehavior component is already imported
|
|
1178
|
+
if (content.includes('HumanBehavior') || content.includes('humanbehavior-js')) {
|
|
1179
|
+
return content; // Already has HumanBehavior
|
|
1180
|
+
}
|
|
1181
|
+
// Add import inside frontmatter if not present
|
|
1182
|
+
let modifiedContent = content;
|
|
1183
|
+
if (!content.includes('import HumanBehavior')) {
|
|
1184
|
+
const importStatement = 'import HumanBehavior from \'../components/HumanBehavior.astro\';';
|
|
1185
|
+
const frontmatterEndIndex = content.indexOf('---', 3);
|
|
1186
|
+
if (frontmatterEndIndex !== -1) {
|
|
1187
|
+
// Insert import inside frontmatter, before the closing ---
|
|
1188
|
+
modifiedContent = content.slice(0, frontmatterEndIndex) + '\n' + importStatement + '\n' + content.slice(frontmatterEndIndex);
|
|
1189
|
+
}
|
|
1190
|
+
else {
|
|
1191
|
+
// No frontmatter, add at the very beginning
|
|
1192
|
+
modifiedContent = '---\n' + importStatement + '\n---\n\n' + content;
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
// Find the closing </body> tag and add HumanBehavior component before it
|
|
1196
|
+
const bodyCloseIndex = modifiedContent.lastIndexOf('</body>');
|
|
1197
|
+
if (bodyCloseIndex === -1) {
|
|
1198
|
+
// No body tag found, append to end
|
|
1199
|
+
return modifiedContent + '\n\n<HumanBehavior />';
|
|
1200
|
+
}
|
|
1201
|
+
// Add component before closing body tag
|
|
1202
|
+
return modifiedContent.slice(0, bodyCloseIndex) + ' <HumanBehavior />\n' + modifiedContent.slice(bodyCloseIndex);
|
|
1203
|
+
}
|
|
889
1204
|
injectNuxtConfig(content) {
|
|
1205
|
+
var _a, _b;
|
|
890
1206
|
if (content.includes('humanBehaviorApiKey')) {
|
|
891
1207
|
return content;
|
|
892
1208
|
}
|
|
893
|
-
//
|
|
894
|
-
|
|
1209
|
+
// Enhanced Nuxt 3 support with version detection
|
|
1210
|
+
const hasNuxt3 = (_b = (_a = this.framework) === null || _a === void 0 ? void 0 : _a.features) === null || _b === void 0 ? void 0 : _b.hasNuxt3;
|
|
1211
|
+
if (hasNuxt3) {
|
|
1212
|
+
// Nuxt 3 with runtime config
|
|
1213
|
+
return content.replace(/export default defineNuxtConfig\(\{/, `export default defineNuxtConfig({
|
|
895
1214
|
runtimeConfig: {
|
|
896
1215
|
public: {
|
|
897
1216
|
humanBehaviorApiKey: process.env.NUXT_PUBLIC_HUMANBEHAVIOR_API_KEY
|
|
898
1217
|
}
|
|
899
1218
|
},`);
|
|
1219
|
+
}
|
|
1220
|
+
else {
|
|
1221
|
+
// Nuxt 2 with env config
|
|
1222
|
+
return content.replace(/export default \{/, `export default {
|
|
1223
|
+
env: {
|
|
1224
|
+
humanBehaviorApiKey: process.env.HUMANBEHAVIOR_API_KEY
|
|
1225
|
+
},`);
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
injectGatsbyLayout(content) {
|
|
1229
|
+
if (content.includes('HumanBehavior')) {
|
|
1230
|
+
return content;
|
|
1231
|
+
}
|
|
1232
|
+
const importStatement = `import HumanBehavior from './HumanBehavior';`;
|
|
1233
|
+
const componentUsage = `<HumanBehavior apiKey={process.env.GATSBY_HUMANBEHAVIOR_API_KEY || ''} />`;
|
|
1234
|
+
// Add import at the top
|
|
1235
|
+
let modifiedContent = content.replace(/import.*from.*['"]\./, `${importStatement}\n$&`);
|
|
1236
|
+
// Add component before closing body tag
|
|
1237
|
+
modifiedContent = modifiedContent.replace(/(\s*<\/body>)/, `\n ${componentUsage}\n$1`);
|
|
1238
|
+
return modifiedContent;
|
|
1239
|
+
}
|
|
1240
|
+
injectGatsbyBrowser(content) {
|
|
1241
|
+
if (content.includes('HumanBehaviorTracker')) {
|
|
1242
|
+
return content;
|
|
1243
|
+
}
|
|
1244
|
+
const importStatement = `import { HumanBehaviorTracker } from 'humanbehavior-js';`;
|
|
1245
|
+
const initCode = `
|
|
1246
|
+
// Initialize HumanBehavior SDK
|
|
1247
|
+
export const onClientEntry = () => {
|
|
1248
|
+
console.log('Gatsby browser entry point loaded');
|
|
1249
|
+
const apiKey = process.env.GATSBY_HUMANBEHAVIOR_API_KEY;
|
|
1250
|
+
console.log('API Key found:', apiKey ? 'Yes' : 'No');
|
|
1251
|
+
if (apiKey) {
|
|
1252
|
+
const tracker = HumanBehaviorTracker.init(apiKey);
|
|
1253
|
+
console.log('HumanBehavior SDK initialized for Gatsby');
|
|
1254
|
+
} else {
|
|
1255
|
+
console.log('No API key found in environment variables');
|
|
1256
|
+
}
|
|
1257
|
+
};`;
|
|
1258
|
+
// If the file already has content, add the import and init code
|
|
1259
|
+
if (content.trim()) {
|
|
1260
|
+
return `${importStatement}${initCode}\n\n${content}`;
|
|
1261
|
+
}
|
|
1262
|
+
else {
|
|
1263
|
+
// If file is empty, just return the new content
|
|
1264
|
+
return `${importStatement}${initCode}`;
|
|
1265
|
+
}
|
|
900
1266
|
}
|
|
901
1267
|
/**
|
|
902
1268
|
* Helper method to find the best environment file for a framework
|
|
@@ -927,6 +1293,8 @@ if (typeof window !== 'undefined') {
|
|
|
927
1293
|
nuxt: 'NUXT_PUBLIC_HUMANBEHAVIOR_API_KEY',
|
|
928
1294
|
remix: 'HUMANBEHAVIOR_API_KEY',
|
|
929
1295
|
vanilla: 'HUMANBEHAVIOR_API_KEY',
|
|
1296
|
+
astro: 'PUBLIC_HUMANBEHAVIOR_API_KEY',
|
|
1297
|
+
gatsby: 'GATSBY_HUMANBEHAVIOR_API_KEY',
|
|
930
1298
|
node: 'HUMANBEHAVIOR_API_KEY',
|
|
931
1299
|
auto: 'HUMANBEHAVIOR_API_KEY'
|
|
932
1300
|
};
|
|
@@ -950,6 +1318,8 @@ if (typeof window !== 'undefined') {
|
|
|
950
1318
|
nuxt: '.env',
|
|
951
1319
|
remix: '.env.local',
|
|
952
1320
|
vanilla: '.env',
|
|
1321
|
+
astro: '.env',
|
|
1322
|
+
gatsby: '.env.development',
|
|
953
1323
|
node: '.env',
|
|
954
1324
|
auto: '.env'
|
|
955
1325
|
};
|
|
@@ -964,6 +1334,8 @@ if (typeof window !== 'undefined') {
|
|
|
964
1334
|
*/
|
|
965
1335
|
createEnvironmentModification(framework) {
|
|
966
1336
|
const { filePath, envVarName } = this.findBestEnvFile(framework);
|
|
1337
|
+
// Clean the API key to prevent formatting issues
|
|
1338
|
+
const cleanApiKey = this.apiKey.trim();
|
|
967
1339
|
if (fs__namespace.existsSync(filePath)) {
|
|
968
1340
|
// Check if the variable already exists
|
|
969
1341
|
const content = fs__namespace.readFileSync(filePath, 'utf8');
|
|
@@ -981,7 +1353,7 @@ if (typeof window !== 'undefined') {
|
|
|
981
1353
|
return {
|
|
982
1354
|
filePath,
|
|
983
1355
|
action: 'append',
|
|
984
|
-
content: `\n${envVarName}=${
|
|
1356
|
+
content: `\n${envVarName}=${cleanApiKey}`,
|
|
985
1357
|
description: `Added API key to existing ${path__namespace.basename(filePath)}`
|
|
986
1358
|
};
|
|
987
1359
|
}
|
|
@@ -991,7 +1363,7 @@ if (typeof window !== 'undefined') {
|
|
|
991
1363
|
return {
|
|
992
1364
|
filePath,
|
|
993
1365
|
action: 'create',
|
|
994
|
-
content: `${envVarName}=${
|
|
1366
|
+
content: `${envVarName}=${cleanApiKey}`,
|
|
995
1367
|
description: `Created ${path__namespace.basename(filePath)} with API key`
|
|
996
1368
|
};
|
|
997
1369
|
}
|
|
@@ -1087,6 +1459,10 @@ class DefaultAIService {
|
|
|
1087
1459
|
framework = { name: 'nextjs', type: 'nextjs' };
|
|
1088
1460
|
confidence = 0.95;
|
|
1089
1461
|
}
|
|
1462
|
+
else if (patterns.includes('gatsby') || patterns.includes('gatsby-browser') || patterns.includes('gatsby-ssr') || patterns.includes('gatsby-node') || patterns.includes('gatsby-config') || patterns.includes('useStaticQuery') || patterns.includes('graphql')) {
|
|
1463
|
+
framework = { name: 'gatsby', type: 'gatsby' };
|
|
1464
|
+
confidence = 0.95;
|
|
1465
|
+
}
|
|
1090
1466
|
else if (patterns.includes('react')) {
|
|
1091
1467
|
framework = { name: 'react', type: 'react' };
|
|
1092
1468
|
confidence = 0.9;
|
|
@@ -1105,7 +1481,7 @@ class DefaultAIService {
|
|
|
1105
1481
|
}
|
|
1106
1482
|
// Integration strategy
|
|
1107
1483
|
let integrationStrategy = 'script';
|
|
1108
|
-
if (framework.type === 'react' || framework.type === 'nextjs') {
|
|
1484
|
+
if (framework.type === 'react' || framework.type === 'nextjs' || framework.type === 'gatsby') {
|
|
1109
1485
|
integrationStrategy = 'provider';
|
|
1110
1486
|
}
|
|
1111
1487
|
else if (framework.type === 'vue') {
|
|
@@ -1900,6 +2276,10 @@ class RemoteAIService {
|
|
|
1900
2276
|
framework = { name: 'nextjs', type: 'nextjs' };
|
|
1901
2277
|
confidence = 0.95;
|
|
1902
2278
|
}
|
|
2279
|
+
else if (patterns.includes('gatsby') || patterns.includes('gatsby-browser') || patterns.includes('gatsby-ssr') || patterns.includes('gatsby-node') || patterns.includes('gatsby-config') || patterns.includes('useStaticQuery') || patterns.includes('graphql')) {
|
|
2280
|
+
framework = { name: 'gatsby', type: 'gatsby' };
|
|
2281
|
+
confidence = 0.95;
|
|
2282
|
+
}
|
|
1903
2283
|
else if (patterns.includes('react')) {
|
|
1904
2284
|
framework = { name: 'react', type: 'react' };
|
|
1905
2285
|
confidence = 0.9;
|
|
@@ -1916,9 +2296,13 @@ class RemoteAIService {
|
|
|
1916
2296
|
framework = { name: 'svelte', type: 'svelte' };
|
|
1917
2297
|
confidence = 0.9;
|
|
1918
2298
|
}
|
|
2299
|
+
else if (patterns.includes('astro')) {
|
|
2300
|
+
framework = { name: 'astro', type: 'astro' };
|
|
2301
|
+
confidence = 0.9;
|
|
2302
|
+
}
|
|
1919
2303
|
// Integration strategy
|
|
1920
2304
|
let integrationStrategy = 'script';
|
|
1921
|
-
if (framework.type === 'react' || framework.type === 'nextjs') {
|
|
2305
|
+
if (framework.type === 'react' || framework.type === 'nextjs' || framework.type === 'gatsby') {
|
|
1922
2306
|
integrationStrategy = 'provider';
|
|
1923
2307
|
}
|
|
1924
2308
|
else if (framework.type === 'vue') {
|
|
@@ -2161,6 +2545,8 @@ class ManualFrameworkInstallationWizard extends AutoInstallationWizard {
|
|
|
2161
2545
|
'svelte': { name: 'svelte', type: 'svelte' },
|
|
2162
2546
|
'sveltekit': { name: 'svelte', type: 'svelte' },
|
|
2163
2547
|
'remix': { name: 'remix', type: 'remix' },
|
|
2548
|
+
'astro': { name: 'astro', type: 'astro' },
|
|
2549
|
+
'gatsby': { name: 'gatsby', type: 'gatsby' },
|
|
2164
2550
|
'vanilla': { name: 'vanilla', type: 'vanilla' },
|
|
2165
2551
|
'node': { name: 'node', type: 'node' },
|
|
2166
2552
|
'auto': { name: 'auto-detected', type: 'auto' }
|
|
@@ -2220,67 +2606,46 @@ class ManualFrameworkInstallationWizard extends AutoInstallationWizard {
|
|
|
2220
2606
|
class AIAutoInstallCLI {
|
|
2221
2607
|
constructor(options) {
|
|
2222
2608
|
this.options = options;
|
|
2223
|
-
this.rl = readline__namespace.createInterface({
|
|
2224
|
-
input: process.stdin,
|
|
2225
|
-
output: process.stdout
|
|
2226
|
-
});
|
|
2227
2609
|
}
|
|
2228
2610
|
run() {
|
|
2229
2611
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2230
|
-
|
|
2231
|
-
console.log('================================================\n');
|
|
2612
|
+
clack__namespace.intro('š¤ AI-Enhanced HumanBehavior SDK Auto-Installation');
|
|
2232
2613
|
try {
|
|
2233
2614
|
// Get API key
|
|
2234
2615
|
const apiKey = yield this.getApiKey();
|
|
2235
2616
|
if (!apiKey) {
|
|
2236
|
-
|
|
2617
|
+
clack__namespace.cancel('API key is required');
|
|
2237
2618
|
process.exit(1);
|
|
2238
2619
|
}
|
|
2239
2620
|
// Get project path
|
|
2240
2621
|
const projectPath = this.options.projectPath || process.cwd();
|
|
2241
|
-
// Choose
|
|
2242
|
-
const
|
|
2622
|
+
// Choose framework
|
|
2623
|
+
const framework = yield this.chooseFramework();
|
|
2624
|
+
if (!framework) {
|
|
2625
|
+
clack__namespace.cancel('Installation cancelled.');
|
|
2626
|
+
process.exit(0);
|
|
2627
|
+
}
|
|
2243
2628
|
// Confirm installation
|
|
2244
2629
|
if (!this.options.yes) {
|
|
2245
|
-
const confirmed = yield this.confirmInstallation(projectPath,
|
|
2630
|
+
const confirmed = yield this.confirmInstallation(projectPath, framework);
|
|
2246
2631
|
if (!confirmed) {
|
|
2247
|
-
|
|
2632
|
+
clack__namespace.cancel('Installation cancelled.');
|
|
2248
2633
|
process.exit(0);
|
|
2249
2634
|
}
|
|
2250
2635
|
}
|
|
2251
2636
|
// Run installation
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
}
|
|
2258
|
-
else if (installationMode === 'manual') {
|
|
2259
|
-
// Manual AI-Enhanced framework selection
|
|
2260
|
-
const framework = yield this.chooseFramework();
|
|
2261
|
-
const wizard = new ManualFrameworkInstallationWizard(apiKey, projectPath, framework);
|
|
2262
|
-
result = yield wizard.install();
|
|
2263
|
-
}
|
|
2264
|
-
else if (installationMode.startsWith('manual:')) {
|
|
2265
|
-
// Manual framework selection with pre-selected framework
|
|
2266
|
-
const framework = installationMode.split(':')[1];
|
|
2267
|
-
const wizard = new ManualFrameworkInstallationWizard(apiKey, projectPath, framework);
|
|
2268
|
-
result = yield wizard.install();
|
|
2269
|
-
}
|
|
2270
|
-
else {
|
|
2271
|
-
const wizard = new AutoInstallationWizard(apiKey, projectPath);
|
|
2272
|
-
result = yield wizard.install();
|
|
2273
|
-
}
|
|
2637
|
+
const spinner = clack__namespace.spinner();
|
|
2638
|
+
spinner.start('š Analyzing your project with AI...');
|
|
2639
|
+
const wizard = new ManualFrameworkInstallationWizard(apiKey, projectPath, framework);
|
|
2640
|
+
const result = yield wizard.install();
|
|
2641
|
+
spinner.stop('Analysis complete!');
|
|
2274
2642
|
// Display results
|
|
2275
|
-
this.displayResults(result,
|
|
2643
|
+
this.displayResults(result, framework);
|
|
2276
2644
|
}
|
|
2277
2645
|
catch (error) {
|
|
2278
|
-
|
|
2646
|
+
clack__namespace.cancel(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
2279
2647
|
process.exit(1);
|
|
2280
2648
|
}
|
|
2281
|
-
finally {
|
|
2282
|
-
this.rl.close();
|
|
2283
|
-
}
|
|
2284
2649
|
});
|
|
2285
2650
|
}
|
|
2286
2651
|
getApiKey() {
|
|
@@ -2288,262 +2653,143 @@ class AIAutoInstallCLI {
|
|
|
2288
2653
|
if (this.options.apiKey) {
|
|
2289
2654
|
return this.options.apiKey;
|
|
2290
2655
|
}
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
return `manual:${this.options.framework}`;
|
|
2302
|
-
}
|
|
2303
|
-
if (this.options.useAI !== undefined) {
|
|
2304
|
-
return this.options.useAI ? 'ai' : 'traditional';
|
|
2305
|
-
}
|
|
2306
|
-
console.log('š¤ Choose installation mode:');
|
|
2307
|
-
console.log('1. Manual AI-Enhanced (recommended) - Choose your framework and use AI for optimization');
|
|
2308
|
-
console.log('2. Traditional - Standard framework detection and installation');
|
|
2309
|
-
console.log('3. Browser - Browser-based AI detection and code generation\n');
|
|
2310
|
-
return new Promise((resolve) => {
|
|
2311
|
-
this.rl.question('Select mode (1-3, default: 1): ', (answer) => {
|
|
2312
|
-
const choice = answer.trim() || '1';
|
|
2313
|
-
if (choice === '1')
|
|
2314
|
-
resolve('manual');
|
|
2315
|
-
else if (choice === '2')
|
|
2316
|
-
resolve('traditional');
|
|
2317
|
-
else if (choice === '3')
|
|
2318
|
-
resolve('browser');
|
|
2319
|
-
else
|
|
2320
|
-
resolve('manual');
|
|
2321
|
-
});
|
|
2656
|
+
const apiKey = yield clack__namespace.text({
|
|
2657
|
+
message: 'Enter your HumanBehavior API key:',
|
|
2658
|
+
placeholder: 'hb_...',
|
|
2659
|
+
validate: (value) => {
|
|
2660
|
+
if (!value)
|
|
2661
|
+
return 'API key is required';
|
|
2662
|
+
if (!value.startsWith('hb_'))
|
|
2663
|
+
return 'API key should start with "hb_"';
|
|
2664
|
+
return undefined;
|
|
2665
|
+
}
|
|
2322
2666
|
});
|
|
2667
|
+
return apiKey;
|
|
2323
2668
|
});
|
|
2324
2669
|
}
|
|
2325
|
-
confirmInstallation(projectPath,
|
|
2670
|
+
confirmInstallation(projectPath, framework) {
|
|
2326
2671
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
console.log('ā ļø This will modify your codebase to integrate HumanBehavior SDK.');
|
|
2330
|
-
console.log(' The following changes will be made:');
|
|
2331
|
-
console.log(' - Install humanbehavior-js package');
|
|
2332
|
-
console.log(' - Analyze code patterns with AI (if enabled)');
|
|
2333
|
-
console.log(' - Modify your main app file');
|
|
2334
|
-
console.log(' - Create environment files');
|
|
2335
|
-
console.log(' - Add AI-optimized SDK initialization code\n');
|
|
2336
|
-
return new Promise((resolve) => {
|
|
2337
|
-
this.rl.question('Continue with installation? (y/n): ', (answer) => {
|
|
2338
|
-
resolve(answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes');
|
|
2339
|
-
});
|
|
2672
|
+
const confirmed = yield clack__namespace.confirm({
|
|
2673
|
+
message: `Ready to install HumanBehavior SDK in ${projectPath} for ${framework}?`
|
|
2340
2674
|
});
|
|
2675
|
+
return confirmed;
|
|
2341
2676
|
});
|
|
2342
2677
|
}
|
|
2343
|
-
getInstallationModeDisplay(mode) {
|
|
2344
|
-
if (mode === 'manual')
|
|
2345
|
-
return 'Manual AI-Enhanced';
|
|
2346
|
-
if (mode === 'traditional')
|
|
2347
|
-
return 'Traditional';
|
|
2348
|
-
if (mode.startsWith('manual:')) {
|
|
2349
|
-
const framework = mode.split(':')[1];
|
|
2350
|
-
return `Manual AI-Enhanced (${framework})`;
|
|
2351
|
-
}
|
|
2352
|
-
if (mode === 'browser')
|
|
2353
|
-
return 'Browser';
|
|
2354
|
-
return 'Unknown';
|
|
2355
|
-
}
|
|
2356
2678
|
chooseFramework() {
|
|
2357
2679
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
const frameworks = ['vanilla', 'react', 'nextjs', 'vue', 'nuxt', 'angular', 'svelte', 'remix', 'node', 'auto'];
|
|
2373
|
-
const index = parseInt(choice) - 1;
|
|
2374
|
-
resolve(frameworks[index] || 'vanilla');
|
|
2375
|
-
});
|
|
2680
|
+
const framework = yield clack__namespace.select({
|
|
2681
|
+
message: 'Select your framework:',
|
|
2682
|
+
options: [
|
|
2683
|
+
{ label: 'React', value: 'react' },
|
|
2684
|
+
{ label: 'Next.js', value: 'nextjs' },
|
|
2685
|
+
{ label: 'Vue', value: 'vue' },
|
|
2686
|
+
{ label: 'Angular', value: 'angular' },
|
|
2687
|
+
{ label: 'Svelte', value: 'svelte' },
|
|
2688
|
+
{ label: 'Nuxt.js', value: 'nuxt' },
|
|
2689
|
+
{ label: 'Remix', value: 'remix' },
|
|
2690
|
+
{ label: 'Astro', value: 'astro' },
|
|
2691
|
+
{ label: 'Gatsby', value: 'gatsby' },
|
|
2692
|
+
{ label: 'Vanilla JS/TS', value: 'vanilla' }
|
|
2693
|
+
]
|
|
2376
2694
|
});
|
|
2695
|
+
return framework;
|
|
2377
2696
|
});
|
|
2378
2697
|
}
|
|
2379
|
-
displayResults(result,
|
|
2698
|
+
displayResults(result, framework) {
|
|
2380
2699
|
if (result.success) {
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2700
|
+
clack__namespace.outro('š Installation completed successfully!');
|
|
2701
|
+
// Display framework info
|
|
2702
|
+
clack__namespace.note(`Framework detected: ${result.framework.name} (${result.framework.type})`, 'Framework Info');
|
|
2703
|
+
// Display modifications
|
|
2704
|
+
if (result.modifications && result.modifications.length > 0) {
|
|
2705
|
+
const modifications = result.modifications.map((mod) => `${mod.action}: ${mod.filePath} - ${mod.description}`);
|
|
2706
|
+
clack__namespace.note(modifications.join('\n'), 'Files Modified');
|
|
2707
|
+
}
|
|
2708
|
+
// Display next steps
|
|
2709
|
+
if (result.nextSteps && result.nextSteps.length > 0) {
|
|
2710
|
+
clack__namespace.note(result.nextSteps.join('\n'), 'Next Steps');
|
|
2711
|
+
}
|
|
2712
|
+
// Display AI insights if available
|
|
2713
|
+
if (result.aiAnalysis) {
|
|
2714
|
+
clack__namespace.note(`Confidence: ${Math.round(result.aiAnalysis.confidence * 100)}%`, 'AI Analysis');
|
|
2715
|
+
if (result.aiAnalysis.recommendations && result.aiAnalysis.recommendations.length > 0) {
|
|
2716
|
+
clack__namespace.note(result.aiAnalysis.recommendations.join('\n'), 'AI Recommendations');
|
|
2395
2717
|
}
|
|
2396
2718
|
}
|
|
2397
|
-
else {
|
|
2398
|
-
console.log(`š¦ Framework detected: ${result.framework.name}`);
|
|
2399
|
-
}
|
|
2400
|
-
if (result.framework.bundler) {
|
|
2401
|
-
console.log(`š§ Bundler: ${result.framework.bundler}`);
|
|
2402
|
-
}
|
|
2403
|
-
if (result.framework.packageManager) {
|
|
2404
|
-
console.log(`š Package Manager: ${result.framework.packageManager}`);
|
|
2405
|
-
}
|
|
2406
|
-
console.log('\nš Changes made:');
|
|
2407
|
-
result.modifications.forEach((mod) => {
|
|
2408
|
-
console.log(` ${mod.action === 'create' ? 'ā' : 'āļø'} ${mod.description}`);
|
|
2409
|
-
console.log(` ${mod.filePath}`);
|
|
2410
|
-
});
|
|
2411
|
-
console.log('\nšÆ Next steps:');
|
|
2412
|
-
result.nextSteps.forEach((step) => {
|
|
2413
|
-
console.log(` ${step}`);
|
|
2414
|
-
});
|
|
2415
|
-
if (installationMode === 'ai' && result.learningData) {
|
|
2416
|
-
console.log('\nš§ Learning Data:');
|
|
2417
|
-
console.log(` Framework: ${result.learningData.framework}`);
|
|
2418
|
-
console.log(` Patterns: ${result.learningData.patterns.length} detected`);
|
|
2419
|
-
console.log(` Success: ${result.learningData.success ? 'Yes' : 'No'}`);
|
|
2420
|
-
}
|
|
2421
|
-
console.log('\nš Your app is now ready to track user behavior!');
|
|
2422
|
-
console.log('š View sessions in your HumanBehavior dashboard');
|
|
2423
2719
|
}
|
|
2424
2720
|
else {
|
|
2425
|
-
|
|
2426
|
-
result.errors.
|
|
2427
|
-
|
|
2428
|
-
}
|
|
2429
|
-
console.log('\nš” Try running with --help for more options');
|
|
2721
|
+
clack__namespace.cancel('Installation failed');
|
|
2722
|
+
if (result.errors && result.errors.length > 0) {
|
|
2723
|
+
clack__namespace.note(result.errors.join('\n'), 'Errors');
|
|
2724
|
+
}
|
|
2430
2725
|
}
|
|
2431
2726
|
}
|
|
2432
2727
|
}
|
|
2433
|
-
// CLI argument parsing
|
|
2434
2728
|
function parseArgs$1() {
|
|
2435
2729
|
const args = process.argv.slice(2);
|
|
2436
2730
|
const options = {};
|
|
2437
2731
|
for (let i = 0; i < args.length; i++) {
|
|
2438
2732
|
const arg = args[i];
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
}
|
|
2466
|
-
else if (!options.apiKey) {
|
|
2467
|
-
options.apiKey = arg;
|
|
2733
|
+
switch (arg) {
|
|
2734
|
+
case '--help':
|
|
2735
|
+
case '-h':
|
|
2736
|
+
showHelp$1();
|
|
2737
|
+
process.exit(0);
|
|
2738
|
+
break;
|
|
2739
|
+
case '--yes':
|
|
2740
|
+
case '-y':
|
|
2741
|
+
options.yes = true;
|
|
2742
|
+
break;
|
|
2743
|
+
case '--dry-run':
|
|
2744
|
+
options.dryRun = true;
|
|
2745
|
+
break;
|
|
2746
|
+
case '--project':
|
|
2747
|
+
case '-p':
|
|
2748
|
+
options.projectPath = args[++i];
|
|
2749
|
+
break;
|
|
2750
|
+
case '--framework':
|
|
2751
|
+
case '-f':
|
|
2752
|
+
options.framework = args[++i];
|
|
2753
|
+
break;
|
|
2754
|
+
default:
|
|
2755
|
+
if (!options.apiKey && !arg.startsWith('-')) {
|
|
2756
|
+
options.apiKey = arg;
|
|
2757
|
+
}
|
|
2758
|
+
break;
|
|
2468
2759
|
}
|
|
2469
2760
|
}
|
|
2470
2761
|
return options;
|
|
2471
2762
|
}
|
|
2472
2763
|
function showHelp$1() {
|
|
2473
2764
|
console.log(`
|
|
2474
|
-
|
|
2765
|
+
š¤ HumanBehavior SDK AI Auto-Installation
|
|
2475
2766
|
|
|
2476
2767
|
Usage: npx humanbehavior-js ai-auto-install [api-key] [options]
|
|
2477
2768
|
|
|
2478
|
-
This tool uses AI to intelligently detect frameworks, analyze code patterns,
|
|
2479
|
-
and generate optimal integration code that's both future-proof and backward-compatible.
|
|
2480
|
-
|
|
2481
|
-
Arguments:
|
|
2482
|
-
api-key Your HumanBehavior API key
|
|
2483
|
-
|
|
2484
2769
|
Options:
|
|
2485
|
-
-
|
|
2486
|
-
-
|
|
2487
|
-
-
|
|
2488
|
-
-t, --traditional Force traditional installation mode
|
|
2489
|
-
-b, --browser Browser-based AI installation
|
|
2490
|
-
-m, --manual Manual framework selection
|
|
2491
|
-
-f, --framework <f> Specify framework for manual mode
|
|
2492
|
-
-h, --help Show this help message
|
|
2770
|
+
-h, --help Show this help message
|
|
2771
|
+
-y, --yes Skip all prompts and use defaults
|
|
2772
|
+
--dry-run Show what would be changed without making changes
|
|
2493
2773
|
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
2. Traditional: Standard framework detection and installation
|
|
2497
|
-
3. Browser: Browser-based AI detection and code generation
|
|
2774
|
+
-p, --project <path> Specify project directory
|
|
2775
|
+
-f, --framework <name> Specify framework manually
|
|
2498
2776
|
|
|
2499
2777
|
Examples:
|
|
2500
|
-
npx humanbehavior-js ai-auto-install
|
|
2501
|
-
npx humanbehavior-js ai-auto-install
|
|
2502
|
-
npx humanbehavior-js ai-auto-install
|
|
2503
|
-
npx humanbehavior-js ai-auto-install
|
|
2504
|
-
|
|
2505
|
-
Supported Frameworks:
|
|
2506
|
-
ā
React (CRA, Vite, Webpack)
|
|
2507
|
-
ā
Next.js (App Router, Pages Router)
|
|
2508
|
-
ā
Vue (Vue CLI, Vite)
|
|
2509
|
-
ā
Angular
|
|
2510
|
-
ā
Svelte (SvelteKit, Vite)
|
|
2511
|
-
ā
Remix
|
|
2512
|
-
ā
Vanilla JS/TS
|
|
2513
|
-
ā
Node.js (CommonJS & ESM)
|
|
2514
|
-
|
|
2515
|
-
AI Features:
|
|
2516
|
-
š Intelligent framework detection beyond package.json
|
|
2517
|
-
š Code pattern analysis and optimization
|
|
2518
|
-
š Future-proof integration strategies
|
|
2519
|
-
š Backward compatibility with legacy frameworks
|
|
2520
|
-
š§ Learning from installation patterns
|
|
2521
|
-
ā” Adaptive code generation for new frameworks
|
|
2522
|
-
š§ Smart conflict resolution
|
|
2523
|
-
š Performance optimization recommendations
|
|
2524
|
-
|
|
2525
|
-
The AI-enhanced tool will:
|
|
2526
|
-
1. š Analyze your codebase with AI to detect patterns
|
|
2527
|
-
2. šÆ Determine optimal integration strategy
|
|
2528
|
-
3. š¦ Install the humanbehavior-js package
|
|
2529
|
-
4. āļø Generate AI-optimized integration code
|
|
2530
|
-
5. š§ Apply modifications with conflict resolution
|
|
2531
|
-
6. š§ Learn from the installation for future improvements
|
|
2532
|
-
7. š Make your app ready to track user behavior
|
|
2778
|
+
npx humanbehavior-js ai-auto-install
|
|
2779
|
+
npx humanbehavior-js ai-auto-install hb_your_api_key_here
|
|
2780
|
+
npx humanbehavior-js ai-auto-install --project ./my-app --ai
|
|
2781
|
+
npx humanbehavior-js ai-auto-install --framework react --yes
|
|
2533
2782
|
`);
|
|
2534
2783
|
}
|
|
2535
2784
|
// Main execution
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2785
|
+
if ((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)) === `file://${process.argv[1]}`) {
|
|
2786
|
+
const options = parseArgs$1();
|
|
2787
|
+
const cli = new AIAutoInstallCLI(options);
|
|
2788
|
+
cli.run().catch((error) => {
|
|
2789
|
+
clack__namespace.cancel(`Unexpected error: ${error.message}`);
|
|
2790
|
+
process.exit(1);
|
|
2791
|
+
});
|
|
2541
2792
|
}
|
|
2542
|
-
const cli$1 = new AIAutoInstallCLI(options$1);
|
|
2543
|
-
cli$1.run().catch((error) => {
|
|
2544
|
-
console.error('ā Fatal error:', error);
|
|
2545
|
-
process.exit(1);
|
|
2546
|
-
});
|
|
2547
2793
|
|
|
2548
2794
|
/**
|
|
2549
2795
|
* HumanBehavior SDK Auto-Installation CLI
|
|
@@ -2556,46 +2802,46 @@ cli$1.run().catch((error) => {
|
|
|
2556
2802
|
class AutoInstallCLI {
|
|
2557
2803
|
constructor(options) {
|
|
2558
2804
|
this.options = options;
|
|
2559
|
-
this.rl = readline__namespace.createInterface({
|
|
2560
|
-
input: process.stdin,
|
|
2561
|
-
output: process.stdout
|
|
2562
|
-
});
|
|
2563
2805
|
}
|
|
2564
2806
|
run() {
|
|
2565
2807
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2566
|
-
|
|
2567
|
-
console.log('=====================================\n');
|
|
2808
|
+
clack__namespace.intro('š HumanBehavior SDK Auto-Installation');
|
|
2568
2809
|
try {
|
|
2569
2810
|
// Get API key
|
|
2570
2811
|
const apiKey = yield this.getApiKey();
|
|
2571
2812
|
if (!apiKey) {
|
|
2572
|
-
|
|
2813
|
+
clack__namespace.cancel('API key is required');
|
|
2573
2814
|
process.exit(1);
|
|
2574
2815
|
}
|
|
2575
2816
|
// Get project path
|
|
2576
2817
|
const projectPath = this.options.projectPath || process.cwd();
|
|
2818
|
+
// Choose framework
|
|
2819
|
+
const framework = yield this.chooseFramework();
|
|
2820
|
+
if (!framework) {
|
|
2821
|
+
clack__namespace.cancel('Installation cancelled.');
|
|
2822
|
+
process.exit(0);
|
|
2823
|
+
}
|
|
2577
2824
|
// Confirm installation
|
|
2578
2825
|
if (!this.options.yes) {
|
|
2579
|
-
const confirmed = yield this.confirmInstallation(projectPath);
|
|
2826
|
+
const confirmed = yield this.confirmInstallation(projectPath, framework);
|
|
2580
2827
|
if (!confirmed) {
|
|
2581
|
-
|
|
2828
|
+
clack__namespace.cancel('Installation cancelled.');
|
|
2582
2829
|
process.exit(0);
|
|
2583
2830
|
}
|
|
2584
2831
|
}
|
|
2585
|
-
// Run
|
|
2586
|
-
|
|
2587
|
-
|
|
2832
|
+
// Run installation
|
|
2833
|
+
const spinner = clack__namespace.spinner();
|
|
2834
|
+
spinner.start('š Analyzing your project...');
|
|
2835
|
+
const wizard = new ManualFrameworkInstallationWizard(apiKey, projectPath, framework);
|
|
2588
2836
|
const result = yield wizard.install();
|
|
2837
|
+
spinner.stop('Detection complete!');
|
|
2589
2838
|
// Display results
|
|
2590
2839
|
this.displayResults(result);
|
|
2591
2840
|
}
|
|
2592
2841
|
catch (error) {
|
|
2593
|
-
|
|
2842
|
+
clack__namespace.cancel(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
2594
2843
|
process.exit(1);
|
|
2595
2844
|
}
|
|
2596
|
-
finally {
|
|
2597
|
-
this.rl.close();
|
|
2598
|
-
}
|
|
2599
2845
|
});
|
|
2600
2846
|
}
|
|
2601
2847
|
getApiKey() {
|
|
@@ -2603,139 +2849,131 @@ class AutoInstallCLI {
|
|
|
2603
2849
|
if (this.options.apiKey) {
|
|
2604
2850
|
return this.options.apiKey;
|
|
2605
2851
|
}
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2852
|
+
const apiKey = yield clack__namespace.text({
|
|
2853
|
+
message: 'Enter your HumanBehavior API key:',
|
|
2854
|
+
placeholder: 'hb_...',
|
|
2855
|
+
validate: (value) => {
|
|
2856
|
+
if (!value)
|
|
2857
|
+
return 'API key is required';
|
|
2858
|
+
if (!value.startsWith('hb_'))
|
|
2859
|
+
return 'API key should start with "hb_"';
|
|
2860
|
+
return undefined;
|
|
2861
|
+
}
|
|
2610
2862
|
});
|
|
2863
|
+
return apiKey;
|
|
2611
2864
|
});
|
|
2612
2865
|
}
|
|
2613
|
-
|
|
2866
|
+
chooseFramework() {
|
|
2614
2867
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2868
|
+
const framework = yield clack__namespace.select({
|
|
2869
|
+
message: 'Select your framework:',
|
|
2870
|
+
options: [
|
|
2871
|
+
{ label: 'React', value: 'react' },
|
|
2872
|
+
{ label: 'Next.js', value: 'nextjs' },
|
|
2873
|
+
{ label: 'Vue', value: 'vue' },
|
|
2874
|
+
{ label: 'Angular', value: 'angular' },
|
|
2875
|
+
{ label: 'Svelte', value: 'svelte' },
|
|
2876
|
+
{ label: 'Nuxt.js', value: 'nuxt' },
|
|
2877
|
+
{ label: 'Remix', value: 'remix' },
|
|
2878
|
+
{ label: 'Astro', value: 'astro' },
|
|
2879
|
+
{ label: 'Gatsby', value: 'gatsby' },
|
|
2880
|
+
{ label: 'Vanilla JS/TS', value: 'vanilla' }
|
|
2881
|
+
]
|
|
2882
|
+
});
|
|
2883
|
+
return framework;
|
|
2884
|
+
});
|
|
2885
|
+
}
|
|
2886
|
+
confirmInstallation(projectPath, framework) {
|
|
2887
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2888
|
+
const confirmed = yield clack__namespace.confirm({
|
|
2889
|
+
message: `Ready to install HumanBehavior SDK in ${projectPath} for ${framework}?`
|
|
2626
2890
|
});
|
|
2891
|
+
return confirmed;
|
|
2627
2892
|
});
|
|
2628
2893
|
}
|
|
2629
2894
|
displayResults(result) {
|
|
2630
2895
|
if (result.success) {
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
}
|
|
2639
|
-
|
|
2640
|
-
result.
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
});
|
|
2644
|
-
console.log('\nšÆ Next steps:');
|
|
2645
|
-
result.nextSteps.forEach((step) => {
|
|
2646
|
-
console.log(` ${step}`);
|
|
2647
|
-
});
|
|
2648
|
-
console.log('\nš Your app is now ready to track user behavior!');
|
|
2649
|
-
console.log('š View sessions in your HumanBehavior dashboard');
|
|
2896
|
+
clack__namespace.outro('š Installation completed successfully!');
|
|
2897
|
+
// Display framework info
|
|
2898
|
+
clack__namespace.note(`Framework detected: ${result.framework.name} (${result.framework.type})`, 'Framework Info');
|
|
2899
|
+
// Display modifications
|
|
2900
|
+
if (result.modifications && result.modifications.length > 0) {
|
|
2901
|
+
const modifications = result.modifications.map((mod) => `${mod.action}: ${mod.filePath} - ${mod.description}`);
|
|
2902
|
+
clack__namespace.note(modifications.join('\n'), 'Files Modified');
|
|
2903
|
+
}
|
|
2904
|
+
// Display next steps
|
|
2905
|
+
if (result.nextSteps && result.nextSteps.length > 0) {
|
|
2906
|
+
clack__namespace.note(result.nextSteps.join('\n'), 'Next Steps');
|
|
2907
|
+
}
|
|
2650
2908
|
}
|
|
2651
2909
|
else {
|
|
2652
|
-
|
|
2653
|
-
result.errors.
|
|
2654
|
-
|
|
2655
|
-
}
|
|
2656
|
-
console.log('\nš” Try running with --help for more options');
|
|
2910
|
+
clack__namespace.cancel('Installation failed');
|
|
2911
|
+
if (result.errors && result.errors.length > 0) {
|
|
2912
|
+
clack__namespace.note(result.errors.join('\n'), 'Errors');
|
|
2913
|
+
}
|
|
2657
2914
|
}
|
|
2658
2915
|
}
|
|
2659
2916
|
}
|
|
2660
|
-
// CLI argument parsing
|
|
2661
2917
|
function parseArgs() {
|
|
2662
2918
|
const args = process.argv.slice(2);
|
|
2663
2919
|
const options = {};
|
|
2664
2920
|
for (let i = 0; i < args.length; i++) {
|
|
2665
2921
|
const arg = args[i];
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2922
|
+
switch (arg) {
|
|
2923
|
+
case '--help':
|
|
2924
|
+
case '-h':
|
|
2925
|
+
showHelp();
|
|
2926
|
+
process.exit(0);
|
|
2927
|
+
break;
|
|
2928
|
+
case '--yes':
|
|
2929
|
+
case '-y':
|
|
2930
|
+
options.yes = true;
|
|
2931
|
+
break;
|
|
2932
|
+
case '--dry-run':
|
|
2933
|
+
options.dryRun = true;
|
|
2934
|
+
break;
|
|
2935
|
+
case '--project':
|
|
2936
|
+
case '-p':
|
|
2937
|
+
options.projectPath = args[++i];
|
|
2938
|
+
break;
|
|
2939
|
+
default:
|
|
2940
|
+
if (!options.apiKey && !arg.startsWith('-')) {
|
|
2941
|
+
options.apiKey = arg;
|
|
2942
|
+
}
|
|
2943
|
+
break;
|
|
2682
2944
|
}
|
|
2683
2945
|
}
|
|
2684
2946
|
return options;
|
|
2685
2947
|
}
|
|
2686
2948
|
function showHelp() {
|
|
2687
2949
|
console.log(`
|
|
2688
|
-
HumanBehavior SDK Auto-Installation
|
|
2950
|
+
š HumanBehavior SDK Auto-Installation
|
|
2689
2951
|
|
|
2690
|
-
Usage: npx humanbehavior-js [api-key] [options]
|
|
2952
|
+
Usage: npx humanbehavior-js auto-install [api-key] [options]
|
|
2691
2953
|
|
|
2692
|
-
This tool automatically detects your
|
|
2693
|
-
to integrate the HumanBehavior SDK with minimal user intervention.
|
|
2694
|
-
|
|
2695
|
-
Arguments:
|
|
2696
|
-
api-key Your HumanBehavior API key
|
|
2954
|
+
This tool automatically detects your framework and integrates the HumanBehavior SDK.
|
|
2697
2955
|
|
|
2698
2956
|
Options:
|
|
2699
|
-
-
|
|
2700
|
-
-
|
|
2701
|
-
-
|
|
2702
|
-
-
|
|
2957
|
+
-h, --help Show this help message
|
|
2958
|
+
-y, --yes Skip all prompts and use defaults
|
|
2959
|
+
--dry-run Show what would be changed without making changes
|
|
2960
|
+
-p, --project <path> Specify project directory
|
|
2703
2961
|
|
|
2704
2962
|
Examples:
|
|
2705
|
-
npx humanbehavior-js
|
|
2706
|
-
npx humanbehavior-js
|
|
2707
|
-
npx humanbehavior-js
|
|
2708
|
-
|
|
2709
|
-
Supported Frameworks:
|
|
2710
|
-
ā
React (CRA, Vite, Webpack)
|
|
2711
|
-
ā
Next.js (App Router, Pages Router)
|
|
2712
|
-
ā
Vue (Vue CLI, Vite)
|
|
2713
|
-
ā
Angular
|
|
2714
|
-
ā
Svelte (SvelteKit, Vite)
|
|
2715
|
-
ā
Remix
|
|
2716
|
-
ā
Vanilla JS/TS
|
|
2717
|
-
ā
Node.js (CommonJS & ESM)
|
|
2718
|
-
|
|
2719
|
-
The tool will:
|
|
2720
|
-
1. š Auto-detect your project's framework and setup
|
|
2721
|
-
2. š¦ Install the humanbehavior-js package
|
|
2722
|
-
3. āļø Modify your codebase to integrate the SDK
|
|
2723
|
-
4. š§ Create environment files with your API key
|
|
2724
|
-
5. š Make your app ready to track user behavior
|
|
2963
|
+
npx humanbehavior-js auto-install
|
|
2964
|
+
npx humanbehavior-js auto-install hb_your_api_key_here
|
|
2965
|
+
npx humanbehavior-js auto-install --project ./my-app --yes
|
|
2725
2966
|
`);
|
|
2726
2967
|
}
|
|
2727
2968
|
// Main execution
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2969
|
+
if ((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)) === `file://${process.argv[1]}`) {
|
|
2970
|
+
const options = parseArgs();
|
|
2971
|
+
const cli = new AutoInstallCLI(options);
|
|
2972
|
+
cli.run().catch((error) => {
|
|
2973
|
+
clack__namespace.cancel(`Unexpected error: ${error.message}`);
|
|
2974
|
+
process.exit(1);
|
|
2975
|
+
});
|
|
2733
2976
|
}
|
|
2734
|
-
const cli = new AutoInstallCLI(options);
|
|
2735
|
-
cli.run().catch((error) => {
|
|
2736
|
-
console.error('ā Fatal error:', error);
|
|
2737
|
-
process.exit(1);
|
|
2738
|
-
});
|
|
2739
2977
|
|
|
2740
2978
|
/**
|
|
2741
2979
|
* Centralized AI Service Implementation
|