humanbehavior-js 0.4.13 → 0.4.14

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.
@@ -1,6 +1,6 @@
1
1
  import * as fs from 'fs';
2
2
  import * as path from 'path';
3
- import * as readline from 'readline';
3
+ import * as clack from '@clack/prompts';
4
4
 
5
5
  /******************************************************************************
6
6
  Copyright (c) Microsoft Corporation.
@@ -164,6 +164,24 @@ class AutoInstallationWizard {
164
164
  projectRoot: this.projectRoot
165
165
  };
166
166
  }
167
+ else if (dependencies.astro) {
168
+ framework = {
169
+ name: 'astro',
170
+ type: 'astro',
171
+ hasTypeScript: !!dependencies.typescript || !!dependencies['@astrojs/ts-plugin'],
172
+ hasRouter: true,
173
+ projectRoot: this.projectRoot
174
+ };
175
+ }
176
+ else if (dependencies.gatsby) {
177
+ framework = {
178
+ name: 'gatsby',
179
+ type: 'gatsby',
180
+ hasTypeScript: !!dependencies.typescript || !!dependencies['@types/react'],
181
+ hasRouter: true,
182
+ projectRoot: this.projectRoot
183
+ };
184
+ }
167
185
  // Detect bundler
168
186
  if (dependencies.vite) {
169
187
  framework.bundler = 'vite';
@@ -195,13 +213,18 @@ class AutoInstallationWizard {
195
213
  */
196
214
  installPackage() {
197
215
  return __awaiter(this, void 0, void 0, function* () {
198
- var _a, _b;
216
+ var _a, _b, _c, _d;
199
217
  const { execSync } = yield import('child_process');
200
- const command = ((_a = this.framework) === null || _a === void 0 ? void 0 : _a.packageManager) === 'yarn'
218
+ // Build base command
219
+ let command = ((_a = this.framework) === null || _a === void 0 ? void 0 : _a.packageManager) === 'yarn'
201
220
  ? 'yarn add humanbehavior-js'
202
221
  : ((_b = this.framework) === null || _b === void 0 ? void 0 : _b.packageManager) === 'pnpm'
203
222
  ? 'pnpm add humanbehavior-js'
204
223
  : 'npm install humanbehavior-js';
224
+ // Add legacy peer deps flag for npm to handle dependency conflicts
225
+ 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') {
226
+ command += ' --legacy-peer-deps';
227
+ }
205
228
  try {
206
229
  execSync(command, { cwd: this.projectRoot, stdio: 'inherit' });
207
230
  }
@@ -227,6 +250,12 @@ class AutoInstallationWizard {
227
250
  case 'nuxt':
228
251
  modifications.push(...yield this.generateNuxtModifications());
229
252
  break;
253
+ case 'astro':
254
+ modifications.push(...yield this.generateAstroModifications());
255
+ break;
256
+ case 'gatsby':
257
+ modifications.push(...yield this.generateGatsbyModifications());
258
+ break;
230
259
  case 'remix':
231
260
  modifications.push(...yield this.generateRemixModifications());
232
261
  break;
@@ -338,6 +367,84 @@ export function Providers({ children }: { children: React.ReactNode }) {
338
367
  return modifications;
339
368
  });
340
369
  }
370
+ /**
371
+ * Generate Astro-specific modifications
372
+ */
373
+ generateAstroModifications() {
374
+ return __awaiter(this, void 0, void 0, function* () {
375
+ const modifications = [];
376
+ // Create Astro component for HumanBehavior
377
+ const astroComponentPath = path.join(this.projectRoot, 'src', 'components', 'HumanBehavior.astro');
378
+ const astroComponentContent = `---
379
+ // This component will only run on the client side
380
+ ---
381
+
382
+ <script>
383
+ import { HumanBehaviorTracker } from 'humanbehavior-js';
384
+
385
+ // Get API key from environment variable
386
+ const apiKey = import.meta.env.PUBLIC_HUMANBEHAVIOR_API_KEY;
387
+
388
+ console.log('HumanBehavior: API key found:', apiKey ? 'Yes' : 'No');
389
+
390
+ if (apiKey) {
391
+ try {
392
+ const tracker = HumanBehaviorTracker.init(apiKey);
393
+ console.log('HumanBehavior: Tracker initialized successfully');
394
+
395
+ // Test event to verify tracking is working
396
+ setTimeout(() => {
397
+ tracker.customEvent('astro_page_view', {
398
+ page: window.location.pathname,
399
+ framework: 'astro'
400
+ }).then(() => {
401
+ console.log('HumanBehavior: Test event sent successfully');
402
+ }).catch((error) => {
403
+ console.error('HumanBehavior: Failed to send test event:', error);
404
+ });
405
+ }, 1000);
406
+
407
+ } catch (error) {
408
+ console.error('HumanBehavior: Failed to initialize tracker:', error);
409
+ }
410
+ } else {
411
+ console.error('HumanBehavior: No API key found');
412
+ }
413
+ </script>`;
414
+ modifications.push({
415
+ filePath: astroComponentPath,
416
+ action: 'create',
417
+ content: astroComponentContent,
418
+ description: 'Created Astro component for HumanBehavior SDK'
419
+ });
420
+ // Find and update layout file
421
+ const layoutFiles = [
422
+ path.join(this.projectRoot, 'src', 'layouts', 'Layout.astro'),
423
+ path.join(this.projectRoot, 'src', 'layouts', 'layout.astro'),
424
+ path.join(this.projectRoot, 'src', 'layouts', 'BaseLayout.astro')
425
+ ];
426
+ let layoutFile = null;
427
+ for (const file of layoutFiles) {
428
+ if (fs.existsSync(file)) {
429
+ layoutFile = file;
430
+ break;
431
+ }
432
+ }
433
+ if (layoutFile) {
434
+ const content = fs.readFileSync(layoutFile, 'utf8');
435
+ const modifiedContent = this.injectAstroLayout(content);
436
+ modifications.push({
437
+ filePath: layoutFile,
438
+ action: 'modify',
439
+ content: modifiedContent,
440
+ description: 'Added HumanBehavior component to Astro layout'
441
+ });
442
+ }
443
+ // Add environment variable
444
+ modifications.push(this.createEnvironmentModification(this.framework));
445
+ return modifications;
446
+ });
447
+ }
341
448
  /**
342
449
  * Generate Nuxt-specific modifications
343
450
  */
@@ -558,6 +665,50 @@ export default defineNuxtPlugin(() => {
558
665
  return modifications;
559
666
  });
560
667
  }
668
+ /**
669
+ * Generate Gatsby-specific modifications
670
+ */
671
+ generateGatsbyModifications() {
672
+ return __awaiter(this, void 0, void 0, function* () {
673
+ const modifications = [];
674
+ // Modify or create gatsby-browser.js for Gatsby
675
+ const gatsbyBrowserFile = path.join(this.projectRoot, 'gatsby-browser.js');
676
+ if (fs.existsSync(gatsbyBrowserFile)) {
677
+ const content = fs.readFileSync(gatsbyBrowserFile, 'utf8');
678
+ const modifiedContent = this.injectGatsbyBrowser(content);
679
+ modifications.push({
680
+ filePath: gatsbyBrowserFile,
681
+ action: 'modify',
682
+ content: modifiedContent,
683
+ description: 'Added HumanBehavior initialization to Gatsby browser'
684
+ });
685
+ }
686
+ else {
687
+ // Create gatsby-browser.js if it doesn't exist
688
+ modifications.push({
689
+ filePath: gatsbyBrowserFile,
690
+ action: 'create',
691
+ content: `import { HumanBehaviorTracker } from 'humanbehavior-js';
692
+
693
+ export const onClientEntry = () => {
694
+ console.log('Gatsby browser entry point loaded');
695
+ const apiKey = process.env.GATSBY_HUMANBEHAVIOR_API_KEY;
696
+ console.log('API Key found:', apiKey ? 'Yes' : 'No');
697
+ if (apiKey) {
698
+ const tracker = HumanBehaviorTracker.init(apiKey);
699
+ console.log('HumanBehavior SDK initialized for Gatsby');
700
+ } else {
701
+ console.log('No API key found in environment variables');
702
+ }
703
+ };`,
704
+ description: 'Created gatsby-browser.js with HumanBehavior initialization'
705
+ });
706
+ }
707
+ // Create or append to environment file
708
+ modifications.push(this.createEnvironmentModification(this.framework));
709
+ return modifications;
710
+ });
711
+ }
561
712
  /**
562
713
  * Apply modifications to the codebase
563
714
  */
@@ -863,6 +1014,37 @@ if (typeof window !== 'undefined') {
863
1014
  </script>`;
864
1015
  return content.replace(/<\/head>/, ` ${cdnScript}\n ${initScript}\n</head>`);
865
1016
  }
1017
+ /**
1018
+ * Inject Astro layout with HumanBehavior component
1019
+ */
1020
+ injectAstroLayout(content) {
1021
+ // Check if HumanBehavior component is already imported
1022
+ if (content.includes('HumanBehavior') || content.includes('humanbehavior-js')) {
1023
+ return content; // Already has HumanBehavior
1024
+ }
1025
+ // Add import inside frontmatter if not present
1026
+ let modifiedContent = content;
1027
+ if (!content.includes('import HumanBehavior')) {
1028
+ const importStatement = 'import HumanBehavior from \'../components/HumanBehavior.astro\';';
1029
+ const frontmatterEndIndex = content.indexOf('---', 3);
1030
+ if (frontmatterEndIndex !== -1) {
1031
+ // Insert import inside frontmatter, before the closing ---
1032
+ modifiedContent = content.slice(0, frontmatterEndIndex) + '\n' + importStatement + '\n' + content.slice(frontmatterEndIndex);
1033
+ }
1034
+ else {
1035
+ // No frontmatter, add at the very beginning
1036
+ modifiedContent = '---\n' + importStatement + '\n---\n\n' + content;
1037
+ }
1038
+ }
1039
+ // Find the closing </body> tag and add HumanBehavior component before it
1040
+ const bodyCloseIndex = modifiedContent.lastIndexOf('</body>');
1041
+ if (bodyCloseIndex === -1) {
1042
+ // No body tag found, append to end
1043
+ return modifiedContent + '\n\n<HumanBehavior />';
1044
+ }
1045
+ // Add component before closing body tag
1046
+ return modifiedContent.slice(0, bodyCloseIndex) + ' <HumanBehavior />\n' + modifiedContent.slice(bodyCloseIndex);
1047
+ }
866
1048
  injectNuxtConfig(content) {
867
1049
  if (content.includes('humanBehaviorApiKey')) {
868
1050
  return content;
@@ -875,6 +1057,45 @@ if (typeof window !== 'undefined') {
875
1057
  }
876
1058
  },`);
877
1059
  }
1060
+ injectGatsbyLayout(content) {
1061
+ if (content.includes('HumanBehavior')) {
1062
+ return content;
1063
+ }
1064
+ const importStatement = `import HumanBehavior from './HumanBehavior';`;
1065
+ const componentUsage = `<HumanBehavior apiKey={process.env.GATSBY_HUMANBEHAVIOR_API_KEY || ''} />`;
1066
+ // Add import at the top
1067
+ let modifiedContent = content.replace(/import.*from.*['"]\./, `${importStatement}\n$&`);
1068
+ // Add component before closing body tag
1069
+ modifiedContent = modifiedContent.replace(/(\s*<\/body>)/, `\n ${componentUsage}\n$1`);
1070
+ return modifiedContent;
1071
+ }
1072
+ injectGatsbyBrowser(content) {
1073
+ if (content.includes('HumanBehaviorTracker')) {
1074
+ return content;
1075
+ }
1076
+ const importStatement = `import { HumanBehaviorTracker } from 'humanbehavior-js';`;
1077
+ const initCode = `
1078
+ // Initialize HumanBehavior SDK
1079
+ export const onClientEntry = () => {
1080
+ console.log('Gatsby browser entry point loaded');
1081
+ const apiKey = process.env.GATSBY_HUMANBEHAVIOR_API_KEY;
1082
+ console.log('API Key found:', apiKey ? 'Yes' : 'No');
1083
+ if (apiKey) {
1084
+ const tracker = HumanBehaviorTracker.init(apiKey);
1085
+ console.log('HumanBehavior SDK initialized for Gatsby');
1086
+ } else {
1087
+ console.log('No API key found in environment variables');
1088
+ }
1089
+ };`;
1090
+ // If the file already has content, add the import and init code
1091
+ if (content.trim()) {
1092
+ return `${importStatement}${initCode}\n\n${content}`;
1093
+ }
1094
+ else {
1095
+ // If file is empty, just return the new content
1096
+ return `${importStatement}${initCode}`;
1097
+ }
1098
+ }
878
1099
  /**
879
1100
  * Helper method to find the best environment file for a framework
880
1101
  */
@@ -904,6 +1125,8 @@ if (typeof window !== 'undefined') {
904
1125
  nuxt: 'NUXT_PUBLIC_HUMANBEHAVIOR_API_KEY',
905
1126
  remix: 'HUMANBEHAVIOR_API_KEY',
906
1127
  vanilla: 'HUMANBEHAVIOR_API_KEY',
1128
+ astro: 'PUBLIC_HUMANBEHAVIOR_API_KEY',
1129
+ gatsby: 'GATSBY_HUMANBEHAVIOR_API_KEY',
907
1130
  node: 'HUMANBEHAVIOR_API_KEY',
908
1131
  auto: 'HUMANBEHAVIOR_API_KEY'
909
1132
  };
@@ -927,6 +1150,8 @@ if (typeof window !== 'undefined') {
927
1150
  nuxt: '.env',
928
1151
  remix: '.env.local',
929
1152
  vanilla: '.env',
1153
+ astro: '.env',
1154
+ gatsby: '.env.development',
930
1155
  node: '.env',
931
1156
  auto: '.env'
932
1157
  };
@@ -941,6 +1166,8 @@ if (typeof window !== 'undefined') {
941
1166
  */
942
1167
  createEnvironmentModification(framework) {
943
1168
  const { filePath, envVarName } = this.findBestEnvFile(framework);
1169
+ // Clean the API key to prevent formatting issues
1170
+ const cleanApiKey = this.apiKey.trim();
944
1171
  if (fs.existsSync(filePath)) {
945
1172
  // Check if the variable already exists
946
1173
  const content = fs.readFileSync(filePath, 'utf8');
@@ -958,7 +1185,7 @@ if (typeof window !== 'undefined') {
958
1185
  return {
959
1186
  filePath,
960
1187
  action: 'append',
961
- content: `\n${envVarName}=${this.apiKey}`,
1188
+ content: `\n${envVarName}=${cleanApiKey}`,
962
1189
  description: `Added API key to existing ${path.basename(filePath)}`
963
1190
  };
964
1191
  }
@@ -968,7 +1195,7 @@ if (typeof window !== 'undefined') {
968
1195
  return {
969
1196
  filePath,
970
1197
  action: 'create',
971
- content: `${envVarName}=${this.apiKey}`,
1198
+ content: `${envVarName}=${cleanApiKey}`,
972
1199
  description: `Created ${path.basename(filePath)} with API key`
973
1200
  };
974
1201
  }
@@ -1064,6 +1291,10 @@ class DefaultAIService {
1064
1291
  framework = { name: 'nextjs', type: 'nextjs' };
1065
1292
  confidence = 0.95;
1066
1293
  }
1294
+ 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')) {
1295
+ framework = { name: 'gatsby', type: 'gatsby' };
1296
+ confidence = 0.95;
1297
+ }
1067
1298
  else if (patterns.includes('react')) {
1068
1299
  framework = { name: 'react', type: 'react' };
1069
1300
  confidence = 0.9;
@@ -1082,7 +1313,7 @@ class DefaultAIService {
1082
1313
  }
1083
1314
  // Integration strategy
1084
1315
  let integrationStrategy = 'script';
1085
- if (framework.type === 'react' || framework.type === 'nextjs') {
1316
+ if (framework.type === 'react' || framework.type === 'nextjs' || framework.type === 'gatsby') {
1086
1317
  integrationStrategy = 'provider';
1087
1318
  }
1088
1319
  else if (framework.type === 'vue') {
@@ -1877,6 +2108,10 @@ class RemoteAIService {
1877
2108
  framework = { name: 'nextjs', type: 'nextjs' };
1878
2109
  confidence = 0.95;
1879
2110
  }
2111
+ 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')) {
2112
+ framework = { name: 'gatsby', type: 'gatsby' };
2113
+ confidence = 0.95;
2114
+ }
1880
2115
  else if (patterns.includes('react')) {
1881
2116
  framework = { name: 'react', type: 'react' };
1882
2117
  confidence = 0.9;
@@ -1893,9 +2128,13 @@ class RemoteAIService {
1893
2128
  framework = { name: 'svelte', type: 'svelte' };
1894
2129
  confidence = 0.9;
1895
2130
  }
2131
+ else if (patterns.includes('astro')) {
2132
+ framework = { name: 'astro', type: 'astro' };
2133
+ confidence = 0.9;
2134
+ }
1896
2135
  // Integration strategy
1897
2136
  let integrationStrategy = 'script';
1898
- if (framework.type === 'react' || framework.type === 'nextjs') {
2137
+ if (framework.type === 'react' || framework.type === 'nextjs' || framework.type === 'gatsby') {
1899
2138
  integrationStrategy = 'provider';
1900
2139
  }
1901
2140
  else if (framework.type === 'vue') {
@@ -2138,6 +2377,8 @@ class ManualFrameworkInstallationWizard extends AutoInstallationWizard {
2138
2377
  'svelte': { name: 'svelte', type: 'svelte' },
2139
2378
  'sveltekit': { name: 'svelte', type: 'svelte' },
2140
2379
  'remix': { name: 'remix', type: 'remix' },
2380
+ 'astro': { name: 'astro', type: 'astro' },
2381
+ 'gatsby': { name: 'gatsby', type: 'gatsby' },
2141
2382
  'vanilla': { name: 'vanilla', type: 'vanilla' },
2142
2383
  'node': { name: 'node', type: 'node' },
2143
2384
  'auto': { name: 'auto-detected', type: 'auto' }
@@ -2197,67 +2438,46 @@ class ManualFrameworkInstallationWizard extends AutoInstallationWizard {
2197
2438
  class AIAutoInstallCLI {
2198
2439
  constructor(options) {
2199
2440
  this.options = options;
2200
- this.rl = readline.createInterface({
2201
- input: process.stdin,
2202
- output: process.stdout
2203
- });
2204
2441
  }
2205
2442
  run() {
2206
2443
  return __awaiter(this, void 0, void 0, function* () {
2207
- console.log('šŸ¤– AI-Enhanced HumanBehavior SDK Auto-Installation');
2208
- console.log('================================================\n');
2444
+ clack.intro('šŸ¤– AI-Enhanced HumanBehavior SDK Auto-Installation');
2209
2445
  try {
2210
2446
  // Get API key
2211
2447
  const apiKey = yield this.getApiKey();
2212
2448
  if (!apiKey) {
2213
- console.error('āŒ API key is required');
2449
+ clack.cancel('API key is required');
2214
2450
  process.exit(1);
2215
2451
  }
2216
2452
  // Get project path
2217
2453
  const projectPath = this.options.projectPath || process.cwd();
2218
- // Choose installation mode
2219
- const installationMode = yield this.chooseInstallationMode();
2454
+ // Choose framework
2455
+ const framework = yield this.chooseFramework();
2456
+ if (!framework) {
2457
+ clack.cancel('Installation cancelled.');
2458
+ process.exit(0);
2459
+ }
2220
2460
  // Confirm installation
2221
2461
  if (!this.options.yes) {
2222
- const confirmed = yield this.confirmInstallation(projectPath, installationMode);
2462
+ const confirmed = yield this.confirmInstallation(projectPath, framework);
2223
2463
  if (!confirmed) {
2224
- console.log('Installation cancelled.');
2464
+ clack.cancel('Installation cancelled.');
2225
2465
  process.exit(0);
2226
2466
  }
2227
2467
  }
2228
2468
  // Run installation
2229
- console.log('šŸ” Analyzing your project with AI...');
2230
- let result;
2231
- if (this.options.browser) {
2232
- const wizard = new AIBrowserInstallationWizard(apiKey);
2233
- result = yield wizard.install();
2234
- }
2235
- else if (installationMode === 'manual') {
2236
- // Manual AI-Enhanced framework selection
2237
- const framework = yield this.chooseFramework();
2238
- const wizard = new ManualFrameworkInstallationWizard(apiKey, projectPath, framework);
2239
- result = yield wizard.install();
2240
- }
2241
- else if (installationMode.startsWith('manual:')) {
2242
- // Manual framework selection with pre-selected framework
2243
- const framework = installationMode.split(':')[1];
2244
- const wizard = new ManualFrameworkInstallationWizard(apiKey, projectPath, framework);
2245
- result = yield wizard.install();
2246
- }
2247
- else {
2248
- const wizard = new AutoInstallationWizard(apiKey, projectPath);
2249
- result = yield wizard.install();
2250
- }
2469
+ const spinner = clack.spinner();
2470
+ spinner.start('šŸ” Analyzing your project with AI...');
2471
+ const wizard = new ManualFrameworkInstallationWizard(apiKey, projectPath, framework);
2472
+ const result = yield wizard.install();
2473
+ spinner.stop('Analysis complete!');
2251
2474
  // Display results
2252
- this.displayResults(result, installationMode);
2475
+ this.displayResults(result, framework);
2253
2476
  }
2254
2477
  catch (error) {
2255
- console.error('āŒ Error:', error instanceof Error ? error.message : error);
2478
+ clack.cancel(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`);
2256
2479
  process.exit(1);
2257
2480
  }
2258
- finally {
2259
- this.rl.close();
2260
- }
2261
2481
  });
2262
2482
  }
2263
2483
  getApiKey() {
@@ -2265,262 +2485,143 @@ class AIAutoInstallCLI {
2265
2485
  if (this.options.apiKey) {
2266
2486
  return this.options.apiKey;
2267
2487
  }
2268
- return new Promise((resolve) => {
2269
- this.rl.question('Enter your HumanBehavior API key: ', (answer) => {
2270
- resolve(answer.trim());
2271
- });
2272
- });
2273
- });
2274
- }
2275
- chooseInstallationMode() {
2276
- return __awaiter(this, void 0, void 0, function* () {
2277
- if (this.options.manual && this.options.framework) {
2278
- return `manual:${this.options.framework}`;
2279
- }
2280
- if (this.options.useAI !== undefined) {
2281
- return this.options.useAI ? 'ai' : 'traditional';
2282
- }
2283
- console.log('šŸ¤– Choose installation mode:');
2284
- console.log('1. Manual AI-Enhanced (recommended) - Choose your framework and use AI for optimization');
2285
- console.log('2. Traditional - Standard framework detection and installation');
2286
- console.log('3. Browser - Browser-based AI detection and code generation\n');
2287
- return new Promise((resolve) => {
2288
- this.rl.question('Select mode (1-3, default: 1): ', (answer) => {
2289
- const choice = answer.trim() || '1';
2290
- if (choice === '1')
2291
- resolve('manual');
2292
- else if (choice === '2')
2293
- resolve('traditional');
2294
- else if (choice === '3')
2295
- resolve('browser');
2296
- else
2297
- resolve('manual');
2298
- });
2488
+ const apiKey = yield clack.text({
2489
+ message: 'Enter your HumanBehavior API key:',
2490
+ placeholder: 'hb_...',
2491
+ validate: (value) => {
2492
+ if (!value)
2493
+ return 'API key is required';
2494
+ if (!value.startsWith('hb_'))
2495
+ return 'API key should start with "hb_"';
2496
+ return undefined;
2497
+ }
2299
2498
  });
2499
+ return apiKey;
2300
2500
  });
2301
2501
  }
2302
- confirmInstallation(projectPath, installationMode) {
2502
+ confirmInstallation(projectPath, framework) {
2303
2503
  return __awaiter(this, void 0, void 0, function* () {
2304
- console.log(`šŸ“ Project path: ${projectPath}`);
2305
- console.log(`šŸ¤– Installation mode: ${this.getInstallationModeDisplay(installationMode)}`);
2306
- console.log('āš ļø This will modify your codebase to integrate HumanBehavior SDK.');
2307
- console.log(' The following changes will be made:');
2308
- console.log(' - Install humanbehavior-js package');
2309
- console.log(' - Analyze code patterns with AI (if enabled)');
2310
- console.log(' - Modify your main app file');
2311
- console.log(' - Create environment files');
2312
- console.log(' - Add AI-optimized SDK initialization code\n');
2313
- return new Promise((resolve) => {
2314
- this.rl.question('Continue with installation? (y/n): ', (answer) => {
2315
- resolve(answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes');
2316
- });
2504
+ const confirmed = yield clack.confirm({
2505
+ message: `Ready to install HumanBehavior SDK in ${projectPath} for ${framework}?`
2317
2506
  });
2507
+ return confirmed;
2318
2508
  });
2319
2509
  }
2320
- getInstallationModeDisplay(mode) {
2321
- if (mode === 'manual')
2322
- return 'Manual AI-Enhanced';
2323
- if (mode === 'traditional')
2324
- return 'Traditional';
2325
- if (mode.startsWith('manual:')) {
2326
- const framework = mode.split(':')[1];
2327
- return `Manual AI-Enhanced (${framework})`;
2328
- }
2329
- if (mode === 'browser')
2330
- return 'Browser';
2331
- return 'Unknown';
2332
- }
2333
2510
  chooseFramework() {
2334
2511
  return __awaiter(this, void 0, void 0, function* () {
2335
- console.log('\nšŸŽÆ Choose your framework:');
2336
- console.log('1. Vanilla JS (HTML)');
2337
- console.log('2. React');
2338
- console.log('3. Next.js');
2339
- console.log('4. Vue');
2340
- console.log('5. Nuxt');
2341
- console.log('6. Angular');
2342
- console.log('7. Svelte');
2343
- console.log('8. Remix');
2344
- console.log('9. Node.js');
2345
- console.log('10. Other (Auto-detect)\n');
2346
- return new Promise((resolve) => {
2347
- this.rl.question('Select framework (1-10, default: 1): ', (answer) => {
2348
- const choice = answer.trim() || '1';
2349
- const frameworks = ['vanilla', 'react', 'nextjs', 'vue', 'nuxt', 'angular', 'svelte', 'remix', 'node', 'auto'];
2350
- const index = parseInt(choice) - 1;
2351
- resolve(frameworks[index] || 'vanilla');
2352
- });
2512
+ const framework = yield clack.select({
2513
+ message: 'Select your framework:',
2514
+ options: [
2515
+ { label: 'React', value: 'react' },
2516
+ { label: 'Next.js', value: 'nextjs' },
2517
+ { label: 'Vue', value: 'vue' },
2518
+ { label: 'Angular', value: 'angular' },
2519
+ { label: 'Svelte', value: 'svelte' },
2520
+ { label: 'Nuxt.js', value: 'nuxt' },
2521
+ { label: 'Remix', value: 'remix' },
2522
+ { label: 'Astro', value: 'astro' },
2523
+ { label: 'Gatsby', value: 'gatsby' },
2524
+ { label: 'Vanilla JS/TS', value: 'vanilla' }
2525
+ ]
2353
2526
  });
2527
+ return framework;
2354
2528
  });
2355
2529
  }
2356
- displayResults(result, installationMode) {
2530
+ displayResults(result, framework) {
2357
2531
  if (result.success) {
2358
- console.log('\nāœ… Installation completed successfully!');
2359
- if (installationMode === 'ai' && result.aiAnalysis) {
2360
- console.log(`šŸŽÆ AI Analysis Results:`);
2361
- console.log(` Framework: ${result.aiAnalysis.framework.name} (confidence: ${Math.round(result.aiAnalysis.confidence * 100)}%)`);
2362
- console.log(` Integration Strategy: ${result.aiAnalysis.integrationStrategy}`);
2363
- console.log(` Compatibility Mode: ${result.aiAnalysis.compatibilityMode}`);
2364
- if (result.aiAnalysis.patterns.length > 0) {
2365
- console.log(` Detected Patterns: ${result.aiAnalysis.patterns.length} patterns`);
2366
- }
2367
- if (result.aiAnalysis.recommendations.length > 0) {
2368
- console.log(` AI Recommendations:`);
2369
- result.aiAnalysis.recommendations.forEach((rec) => {
2370
- console.log(` • ${rec}`);
2371
- });
2532
+ clack.outro('šŸŽ‰ Installation completed successfully!');
2533
+ // Display framework info
2534
+ clack.note(`Framework detected: ${result.framework.name} (${result.framework.type})`, 'Framework Info');
2535
+ // Display modifications
2536
+ if (result.modifications && result.modifications.length > 0) {
2537
+ const modifications = result.modifications.map((mod) => `${mod.action}: ${mod.filePath} - ${mod.description}`);
2538
+ clack.note(modifications.join('\n'), 'Files Modified');
2539
+ }
2540
+ // Display next steps
2541
+ if (result.nextSteps && result.nextSteps.length > 0) {
2542
+ clack.note(result.nextSteps.join('\n'), 'Next Steps');
2543
+ }
2544
+ // Display AI insights if available
2545
+ if (result.aiAnalysis) {
2546
+ clack.note(`Confidence: ${Math.round(result.aiAnalysis.confidence * 100)}%`, 'AI Analysis');
2547
+ if (result.aiAnalysis.recommendations && result.aiAnalysis.recommendations.length > 0) {
2548
+ clack.note(result.aiAnalysis.recommendations.join('\n'), 'AI Recommendations');
2372
2549
  }
2373
2550
  }
2374
- else {
2375
- console.log(`šŸ“¦ Framework detected: ${result.framework.name}`);
2376
- }
2377
- if (result.framework.bundler) {
2378
- console.log(`šŸ”§ Bundler: ${result.framework.bundler}`);
2379
- }
2380
- if (result.framework.packageManager) {
2381
- console.log(`šŸ“‹ Package Manager: ${result.framework.packageManager}`);
2382
- }
2383
- console.log('\nšŸ“ Changes made:');
2384
- result.modifications.forEach((mod) => {
2385
- console.log(` ${mod.action === 'create' ? 'āž•' : 'āœļø'} ${mod.description}`);
2386
- console.log(` ${mod.filePath}`);
2387
- });
2388
- console.log('\nšŸŽÆ Next steps:');
2389
- result.nextSteps.forEach((step) => {
2390
- console.log(` ${step}`);
2391
- });
2392
- if (installationMode === 'ai' && result.learningData) {
2393
- console.log('\n🧠 Learning Data:');
2394
- console.log(` Framework: ${result.learningData.framework}`);
2395
- console.log(` Patterns: ${result.learningData.patterns.length} detected`);
2396
- console.log(` Success: ${result.learningData.success ? 'Yes' : 'No'}`);
2397
- }
2398
- console.log('\nšŸš€ Your app is now ready to track user behavior!');
2399
- console.log('šŸ“Š View sessions in your HumanBehavior dashboard');
2400
2551
  }
2401
2552
  else {
2402
- console.log('\nāŒ Installation failed:');
2403
- result.errors.forEach((error) => {
2404
- console.log(` ${error}`);
2405
- });
2406
- console.log('\nšŸ’” Try running with --help for more options');
2553
+ clack.cancel('Installation failed');
2554
+ if (result.errors && result.errors.length > 0) {
2555
+ clack.note(result.errors.join('\n'), 'Errors');
2556
+ }
2407
2557
  }
2408
2558
  }
2409
2559
  }
2410
- // CLI argument parsing
2411
2560
  function parseArgs$1() {
2412
2561
  const args = process.argv.slice(2);
2413
2562
  const options = {};
2414
2563
  for (let i = 0; i < args.length; i++) {
2415
2564
  const arg = args[i];
2416
- if (arg === '--yes' || arg === '-y') {
2417
- options.yes = true;
2418
- }
2419
- else if (arg === '--dry-run' || arg === '-d') {
2420
- options.dryRun = true;
2421
- }
2422
- else if (arg === '--project' || arg === '-p') {
2423
- options.projectPath = args[i + 1];
2424
- i++;
2425
- }
2426
- else if (arg === '--traditional' || arg === '-t') {
2427
- options.useAI = false;
2428
- }
2429
- else if (arg === '--browser' || arg === '-b') {
2430
- options.browser = true;
2431
- }
2432
- else if (arg === '--manual' || arg === '-m') {
2433
- options.manual = true;
2434
- }
2435
- else if (arg === '--framework' || arg === '-f') {
2436
- options.framework = args[i + 1];
2437
- i++;
2438
- }
2439
- else if (arg === '--help' || arg === '-h') {
2440
- showHelp$1();
2441
- process.exit(0);
2442
- }
2443
- else if (!options.apiKey) {
2444
- options.apiKey = arg;
2565
+ switch (arg) {
2566
+ case '--help':
2567
+ case '-h':
2568
+ showHelp$1();
2569
+ process.exit(0);
2570
+ break;
2571
+ case '--yes':
2572
+ case '-y':
2573
+ options.yes = true;
2574
+ break;
2575
+ case '--dry-run':
2576
+ options.dryRun = true;
2577
+ break;
2578
+ case '--project':
2579
+ case '-p':
2580
+ options.projectPath = args[++i];
2581
+ break;
2582
+ case '--framework':
2583
+ case '-f':
2584
+ options.framework = args[++i];
2585
+ break;
2586
+ default:
2587
+ if (!options.apiKey && !arg.startsWith('-')) {
2588
+ options.apiKey = arg;
2589
+ }
2590
+ break;
2445
2591
  }
2446
2592
  }
2447
2593
  return options;
2448
2594
  }
2449
2595
  function showHelp$1() {
2450
2596
  console.log(`
2451
- AI-Enhanced HumanBehavior SDK Auto-Installation CLI
2597
+ šŸ¤– HumanBehavior SDK AI Auto-Installation
2452
2598
 
2453
2599
  Usage: npx humanbehavior-js ai-auto-install [api-key] [options]
2454
2600
 
2455
- This tool uses AI to intelligently detect frameworks, analyze code patterns,
2456
- and generate optimal integration code that's both future-proof and backward-compatible.
2457
-
2458
- Arguments:
2459
- api-key Your HumanBehavior API key
2460
-
2461
2601
  Options:
2462
- -y, --yes Skip all prompts and use defaults
2463
- -d, --dry-run Show what would be changed without making changes
2464
- -p, --project <path> Project directory (default: current directory)
2465
- -t, --traditional Force traditional installation mode
2466
- -b, --browser Browser-based AI installation
2467
- -m, --manual Manual framework selection
2468
- -f, --framework <f> Specify framework for manual mode
2469
- -h, --help Show this help message
2602
+ -h, --help Show this help message
2603
+ -y, --yes Skip all prompts and use defaults
2604
+ --dry-run Show what would be changed without making changes
2470
2605
 
2471
- Installation Modes:
2472
- 1. Manual AI-Enhanced (default): Choose your framework and use AI for optimization
2473
- 2. Traditional: Standard framework detection and installation
2474
- 3. Browser: Browser-based AI detection and code generation
2606
+ -p, --project <path> Specify project directory
2607
+ -f, --framework <name> Specify framework manually
2475
2608
 
2476
2609
  Examples:
2477
- npx humanbehavior-js ai-auto-install your-api-key
2478
- npx humanbehavior-js ai-auto-install your-api-key --manual --framework react
2479
- npx humanbehavior-js ai-auto-install your-api-key --traditional
2480
- npx humanbehavior-js ai-auto-install your-api-key --browser
2481
-
2482
- Supported Frameworks:
2483
- āœ… React (CRA, Vite, Webpack)
2484
- āœ… Next.js (App Router, Pages Router)
2485
- āœ… Vue (Vue CLI, Vite)
2486
- āœ… Angular
2487
- āœ… Svelte (SvelteKit, Vite)
2488
- āœ… Remix
2489
- āœ… Vanilla JS/TS
2490
- āœ… Node.js (CommonJS & ESM)
2491
-
2492
- AI Features:
2493
- šŸ” Intelligent framework detection beyond package.json
2494
- šŸ“Š Code pattern analysis and optimization
2495
- šŸ”„ Future-proof integration strategies
2496
- šŸ”™ Backward compatibility with legacy frameworks
2497
- 🧠 Learning from installation patterns
2498
- ⚔ Adaptive code generation for new frameworks
2499
- šŸ”§ Smart conflict resolution
2500
- šŸ“ˆ Performance optimization recommendations
2501
-
2502
- The AI-enhanced tool will:
2503
- 1. šŸ” Analyze your codebase with AI to detect patterns
2504
- 2. šŸŽÆ Determine optimal integration strategy
2505
- 3. šŸ“¦ Install the humanbehavior-js package
2506
- 4. āœļø Generate AI-optimized integration code
2507
- 5. šŸ”§ Apply modifications with conflict resolution
2508
- 6. 🧠 Learn from the installation for future improvements
2509
- 7. šŸš€ Make your app ready to track user behavior
2610
+ npx humanbehavior-js ai-auto-install
2611
+ npx humanbehavior-js ai-auto-install hb_your_api_key_here
2612
+ npx humanbehavior-js ai-auto-install --project ./my-app --ai
2613
+ npx humanbehavior-js ai-auto-install --framework react --yes
2510
2614
  `);
2511
2615
  }
2512
2616
  // Main execution
2513
- const options$1 = parseArgs$1();
2514
- // Check if we have enough arguments (api-key is required)
2515
- if (process.argv.length < 3 || process.argv.includes('--help') || process.argv.includes('-h')) {
2516
- showHelp$1();
2517
- process.exit(0);
2617
+ if (import.meta.url === `file://${process.argv[1]}`) {
2618
+ const options = parseArgs$1();
2619
+ const cli = new AIAutoInstallCLI(options);
2620
+ cli.run().catch((error) => {
2621
+ clack.cancel(`Unexpected error: ${error.message}`);
2622
+ process.exit(1);
2623
+ });
2518
2624
  }
2519
- const cli$1 = new AIAutoInstallCLI(options$1);
2520
- cli$1.run().catch((error) => {
2521
- console.error('āŒ Fatal error:', error);
2522
- process.exit(1);
2523
- });
2524
2625
 
2525
2626
  /**
2526
2627
  * HumanBehavior SDK Auto-Installation CLI
@@ -2533,46 +2634,46 @@ cli$1.run().catch((error) => {
2533
2634
  class AutoInstallCLI {
2534
2635
  constructor(options) {
2535
2636
  this.options = options;
2536
- this.rl = readline.createInterface({
2537
- input: process.stdin,
2538
- output: process.stdout
2539
- });
2540
2637
  }
2541
2638
  run() {
2542
2639
  return __awaiter(this, void 0, void 0, function* () {
2543
- console.log('šŸš€ HumanBehavior SDK Auto-Installation');
2544
- console.log('=====================================\n');
2640
+ clack.intro('šŸš€ HumanBehavior SDK Auto-Installation');
2545
2641
  try {
2546
2642
  // Get API key
2547
2643
  const apiKey = yield this.getApiKey();
2548
2644
  if (!apiKey) {
2549
- console.error('āŒ API key is required');
2645
+ clack.cancel('API key is required');
2550
2646
  process.exit(1);
2551
2647
  }
2552
2648
  // Get project path
2553
2649
  const projectPath = this.options.projectPath || process.cwd();
2650
+ // Choose framework
2651
+ const framework = yield this.chooseFramework();
2652
+ if (!framework) {
2653
+ clack.cancel('Installation cancelled.');
2654
+ process.exit(0);
2655
+ }
2554
2656
  // Confirm installation
2555
2657
  if (!this.options.yes) {
2556
- const confirmed = yield this.confirmInstallation(projectPath);
2658
+ const confirmed = yield this.confirmInstallation(projectPath, framework);
2557
2659
  if (!confirmed) {
2558
- console.log('Installation cancelled.');
2660
+ clack.cancel('Installation cancelled.');
2559
2661
  process.exit(0);
2560
2662
  }
2561
2663
  }
2562
- // Run auto-installation
2563
- console.log('šŸ” Detecting your project setup...');
2564
- const wizard = new AutoInstallationWizard(apiKey, projectPath);
2664
+ // Run installation
2665
+ const spinner = clack.spinner();
2666
+ spinner.start('šŸ” Analyzing your project...');
2667
+ const wizard = new ManualFrameworkInstallationWizard(apiKey, projectPath, framework);
2565
2668
  const result = yield wizard.install();
2669
+ spinner.stop('Detection complete!');
2566
2670
  // Display results
2567
2671
  this.displayResults(result);
2568
2672
  }
2569
2673
  catch (error) {
2570
- console.error('āŒ Error:', error instanceof Error ? error.message : error);
2674
+ clack.cancel(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`);
2571
2675
  process.exit(1);
2572
2676
  }
2573
- finally {
2574
- this.rl.close();
2575
- }
2576
2677
  });
2577
2678
  }
2578
2679
  getApiKey() {
@@ -2580,139 +2681,131 @@ class AutoInstallCLI {
2580
2681
  if (this.options.apiKey) {
2581
2682
  return this.options.apiKey;
2582
2683
  }
2583
- return new Promise((resolve) => {
2584
- this.rl.question('Enter your HumanBehavior API key: ', (answer) => {
2585
- resolve(answer.trim());
2586
- });
2684
+ const apiKey = yield clack.text({
2685
+ message: 'Enter your HumanBehavior API key:',
2686
+ placeholder: 'hb_...',
2687
+ validate: (value) => {
2688
+ if (!value)
2689
+ return 'API key is required';
2690
+ if (!value.startsWith('hb_'))
2691
+ return 'API key should start with "hb_"';
2692
+ return undefined;
2693
+ }
2587
2694
  });
2695
+ return apiKey;
2588
2696
  });
2589
2697
  }
2590
- confirmInstallation(projectPath) {
2698
+ chooseFramework() {
2591
2699
  return __awaiter(this, void 0, void 0, function* () {
2592
- console.log(`šŸ“ Project path: ${projectPath}`);
2593
- console.log('āš ļø This will modify your codebase to integrate HumanBehavior SDK.');
2594
- console.log(' The following changes will be made:');
2595
- console.log(' - Install humanbehavior-js package');
2596
- console.log(' - Modify your main app file');
2597
- console.log(' - Create environment files');
2598
- console.log(' - Add SDK initialization code\n');
2599
- return new Promise((resolve) => {
2600
- this.rl.question('Continue with auto-installation? (y/n): ', (answer) => {
2601
- resolve(answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes');
2602
- });
2700
+ const framework = yield clack.select({
2701
+ message: 'Select your framework:',
2702
+ options: [
2703
+ { label: 'React', value: 'react' },
2704
+ { label: 'Next.js', value: 'nextjs' },
2705
+ { label: 'Vue', value: 'vue' },
2706
+ { label: 'Angular', value: 'angular' },
2707
+ { label: 'Svelte', value: 'svelte' },
2708
+ { label: 'Nuxt.js', value: 'nuxt' },
2709
+ { label: 'Remix', value: 'remix' },
2710
+ { label: 'Astro', value: 'astro' },
2711
+ { label: 'Gatsby', value: 'gatsby' },
2712
+ { label: 'Vanilla JS/TS', value: 'vanilla' }
2713
+ ]
2714
+ });
2715
+ return framework;
2716
+ });
2717
+ }
2718
+ confirmInstallation(projectPath, framework) {
2719
+ return __awaiter(this, void 0, void 0, function* () {
2720
+ const confirmed = yield clack.confirm({
2721
+ message: `Ready to install HumanBehavior SDK in ${projectPath} for ${framework}?`
2603
2722
  });
2723
+ return confirmed;
2604
2724
  });
2605
2725
  }
2606
2726
  displayResults(result) {
2607
2727
  if (result.success) {
2608
- console.log('\nāœ… Installation completed successfully!');
2609
- console.log(`šŸ“¦ Framework detected: ${result.framework.name}`);
2610
- if (result.framework.bundler) {
2611
- console.log(`šŸ”§ Bundler: ${result.framework.bundler}`);
2612
- }
2613
- if (result.framework.packageManager) {
2614
- console.log(`šŸ“‹ Package Manager: ${result.framework.packageManager}`);
2615
- }
2616
- console.log('\nšŸ“ Changes made:');
2617
- result.modifications.forEach((mod) => {
2618
- console.log(` ${mod.action === 'create' ? 'āž•' : 'āœļø'} ${mod.description}`);
2619
- console.log(` ${mod.filePath}`);
2620
- });
2621
- console.log('\nšŸŽÆ Next steps:');
2622
- result.nextSteps.forEach((step) => {
2623
- console.log(` ${step}`);
2624
- });
2625
- console.log('\nšŸš€ Your app is now ready to track user behavior!');
2626
- console.log('šŸ“Š View sessions in your HumanBehavior dashboard');
2728
+ clack.outro('šŸŽ‰ Installation completed successfully!');
2729
+ // Display framework info
2730
+ clack.note(`Framework detected: ${result.framework.name} (${result.framework.type})`, 'Framework Info');
2731
+ // Display modifications
2732
+ if (result.modifications && result.modifications.length > 0) {
2733
+ const modifications = result.modifications.map((mod) => `${mod.action}: ${mod.filePath} - ${mod.description}`);
2734
+ clack.note(modifications.join('\n'), 'Files Modified');
2735
+ }
2736
+ // Display next steps
2737
+ if (result.nextSteps && result.nextSteps.length > 0) {
2738
+ clack.note(result.nextSteps.join('\n'), 'Next Steps');
2739
+ }
2627
2740
  }
2628
2741
  else {
2629
- console.log('\nāŒ Installation failed:');
2630
- result.errors.forEach((error) => {
2631
- console.log(` ${error}`);
2632
- });
2633
- console.log('\nšŸ’” Try running with --help for more options');
2742
+ clack.cancel('Installation failed');
2743
+ if (result.errors && result.errors.length > 0) {
2744
+ clack.note(result.errors.join('\n'), 'Errors');
2745
+ }
2634
2746
  }
2635
2747
  }
2636
2748
  }
2637
- // CLI argument parsing
2638
2749
  function parseArgs() {
2639
2750
  const args = process.argv.slice(2);
2640
2751
  const options = {};
2641
2752
  for (let i = 0; i < args.length; i++) {
2642
2753
  const arg = args[i];
2643
- if (arg === '--yes' || arg === '-y') {
2644
- options.yes = true;
2645
- }
2646
- else if (arg === '--dry-run' || arg === '-d') {
2647
- options.dryRun = true;
2648
- }
2649
- else if (arg === '--project' || arg === '-p') {
2650
- options.projectPath = args[i + 1];
2651
- i++;
2652
- }
2653
- else if (arg === '--help' || arg === '-h') {
2654
- showHelp();
2655
- process.exit(0);
2656
- }
2657
- else if (!options.apiKey) {
2658
- options.apiKey = arg;
2754
+ switch (arg) {
2755
+ case '--help':
2756
+ case '-h':
2757
+ showHelp();
2758
+ process.exit(0);
2759
+ break;
2760
+ case '--yes':
2761
+ case '-y':
2762
+ options.yes = true;
2763
+ break;
2764
+ case '--dry-run':
2765
+ options.dryRun = true;
2766
+ break;
2767
+ case '--project':
2768
+ case '-p':
2769
+ options.projectPath = args[++i];
2770
+ break;
2771
+ default:
2772
+ if (!options.apiKey && !arg.startsWith('-')) {
2773
+ options.apiKey = arg;
2774
+ }
2775
+ break;
2659
2776
  }
2660
2777
  }
2661
2778
  return options;
2662
2779
  }
2663
2780
  function showHelp() {
2664
2781
  console.log(`
2665
- HumanBehavior SDK Auto-Installation CLI
2666
-
2667
- Usage: npx humanbehavior-js [api-key] [options]
2782
+ šŸš€ HumanBehavior SDK Auto-Installation
2668
2783
 
2669
- This tool automatically detects your project's framework and modifies your codebase
2670
- to integrate the HumanBehavior SDK with minimal user intervention.
2784
+ Usage: npx humanbehavior-js auto-install [api-key] [options]
2671
2785
 
2672
- Arguments:
2673
- api-key Your HumanBehavior API key
2786
+ This tool automatically detects your framework and integrates the HumanBehavior SDK.
2674
2787
 
2675
2788
  Options:
2676
- -y, --yes Skip all prompts and use defaults
2677
- -d, --dry-run Show what would be changed without making changes
2678
- -p, --project <path> Project directory (default: current directory)
2679
- -h, --help Show this help message
2789
+ -h, --help Show this help message
2790
+ -y, --yes Skip all prompts and use defaults
2791
+ --dry-run Show what would be changed without making changes
2792
+ -p, --project <path> Specify project directory
2680
2793
 
2681
2794
  Examples:
2682
- npx humanbehavior-js your-api-key
2683
- npx humanbehavior-js your-api-key --yes
2684
- npx humanbehavior-js your-api-key -p /path/to/project
2685
-
2686
- Supported Frameworks:
2687
- āœ… React (CRA, Vite, Webpack)
2688
- āœ… Next.js (App Router, Pages Router)
2689
- āœ… Vue (Vue CLI, Vite)
2690
- āœ… Angular
2691
- āœ… Svelte (SvelteKit, Vite)
2692
- āœ… Remix
2693
- āœ… Vanilla JS/TS
2694
- āœ… Node.js (CommonJS & ESM)
2695
-
2696
- The tool will:
2697
- 1. šŸ” Auto-detect your project's framework and setup
2698
- 2. šŸ“¦ Install the humanbehavior-js package
2699
- 3. āœļø Modify your codebase to integrate the SDK
2700
- 4. šŸ”§ Create environment files with your API key
2701
- 5. šŸš€ Make your app ready to track user behavior
2795
+ npx humanbehavior-js auto-install
2796
+ npx humanbehavior-js auto-install hb_your_api_key_here
2797
+ npx humanbehavior-js auto-install --project ./my-app --yes
2702
2798
  `);
2703
2799
  }
2704
2800
  // Main execution
2705
- const options = parseArgs();
2706
- // Check if we have enough arguments (api-key is required)
2707
- if (process.argv.length < 3 || process.argv.includes('--help') || process.argv.includes('-h')) {
2708
- showHelp();
2709
- process.exit(0);
2801
+ if (import.meta.url === `file://${process.argv[1]}`) {
2802
+ const options = parseArgs();
2803
+ const cli = new AutoInstallCLI(options);
2804
+ cli.run().catch((error) => {
2805
+ clack.cancel(`Unexpected error: ${error.message}`);
2806
+ process.exit(1);
2807
+ });
2710
2808
  }
2711
- const cli = new AutoInstallCLI(options);
2712
- cli.run().catch((error) => {
2713
- console.error('āŒ Fatal error:', error);
2714
- process.exit(1);
2715
- });
2716
2809
 
2717
2810
  /**
2718
2811
  * Centralized AI Service Implementation