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.
@@ -2,8 +2,9 @@
2
2
 
3
3
  var fs = require('fs');
4
4
  var path = require('path');
5
- var readline = require('readline');
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 readline__namespace = /*#__PURE__*/_interopNamespaceDefault(readline);
27
+ var clack__namespace = /*#__PURE__*/_interopNamespaceDefault(clack);
27
28
 
28
29
  /******************************************************************************
29
30
  Copyright (c) Microsoft Corporation.
@@ -187,6 +188,24 @@ class AutoInstallationWizard {
187
188
  projectRoot: this.projectRoot
188
189
  };
189
190
  }
191
+ else if (dependencies.astro) {
192
+ framework = {
193
+ name: 'astro',
194
+ type: 'astro',
195
+ hasTypeScript: !!dependencies.typescript || !!dependencies['@astrojs/ts-plugin'],
196
+ hasRouter: true,
197
+ projectRoot: this.projectRoot
198
+ };
199
+ }
200
+ else if (dependencies.gatsby) {
201
+ framework = {
202
+ name: 'gatsby',
203
+ type: 'gatsby',
204
+ hasTypeScript: !!dependencies.typescript || !!dependencies['@types/react'],
205
+ hasRouter: true,
206
+ projectRoot: this.projectRoot
207
+ };
208
+ }
190
209
  // Detect bundler
191
210
  if (dependencies.vite) {
192
211
  framework.bundler = 'vite';
@@ -218,13 +237,18 @@ class AutoInstallationWizard {
218
237
  */
219
238
  installPackage() {
220
239
  return __awaiter(this, void 0, void 0, function* () {
221
- var _a, _b;
240
+ var _a, _b, _c, _d;
222
241
  const { execSync } = yield import('child_process');
223
- const command = ((_a = this.framework) === null || _a === void 0 ? void 0 : _a.packageManager) === 'yarn'
242
+ // Build base command
243
+ let command = ((_a = this.framework) === null || _a === void 0 ? void 0 : _a.packageManager) === 'yarn'
224
244
  ? 'yarn add humanbehavior-js'
225
245
  : ((_b = this.framework) === null || _b === void 0 ? void 0 : _b.packageManager) === 'pnpm'
226
246
  ? 'pnpm add humanbehavior-js'
227
247
  : 'npm install humanbehavior-js';
248
+ // Add legacy peer deps flag for npm to handle dependency conflicts
249
+ 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') {
250
+ command += ' --legacy-peer-deps';
251
+ }
228
252
  try {
229
253
  execSync(command, { cwd: this.projectRoot, stdio: 'inherit' });
230
254
  }
@@ -250,6 +274,12 @@ class AutoInstallationWizard {
250
274
  case 'nuxt':
251
275
  modifications.push(...yield this.generateNuxtModifications());
252
276
  break;
277
+ case 'astro':
278
+ modifications.push(...yield this.generateAstroModifications());
279
+ break;
280
+ case 'gatsby':
281
+ modifications.push(...yield this.generateGatsbyModifications());
282
+ break;
253
283
  case 'remix':
254
284
  modifications.push(...yield this.generateRemixModifications());
255
285
  break;
@@ -361,6 +391,84 @@ export function Providers({ children }: { children: React.ReactNode }) {
361
391
  return modifications;
362
392
  });
363
393
  }
394
+ /**
395
+ * Generate Astro-specific modifications
396
+ */
397
+ generateAstroModifications() {
398
+ return __awaiter(this, void 0, void 0, function* () {
399
+ const modifications = [];
400
+ // Create Astro component for HumanBehavior
401
+ const astroComponentPath = path__namespace.join(this.projectRoot, 'src', 'components', 'HumanBehavior.astro');
402
+ const astroComponentContent = `---
403
+ // This component will only run on the client side
404
+ ---
405
+
406
+ <script>
407
+ import { HumanBehaviorTracker } from 'humanbehavior-js';
408
+
409
+ // Get API key from environment variable
410
+ const apiKey = import.meta.env.PUBLIC_HUMANBEHAVIOR_API_KEY;
411
+
412
+ console.log('HumanBehavior: API key found:', apiKey ? 'Yes' : 'No');
413
+
414
+ if (apiKey) {
415
+ try {
416
+ const tracker = HumanBehaviorTracker.init(apiKey);
417
+ console.log('HumanBehavior: Tracker initialized successfully');
418
+
419
+ // Test event to verify tracking is working
420
+ setTimeout(() => {
421
+ tracker.customEvent('astro_page_view', {
422
+ page: window.location.pathname,
423
+ framework: 'astro'
424
+ }).then(() => {
425
+ console.log('HumanBehavior: Test event sent successfully');
426
+ }).catch((error) => {
427
+ console.error('HumanBehavior: Failed to send test event:', error);
428
+ });
429
+ }, 1000);
430
+
431
+ } catch (error) {
432
+ console.error('HumanBehavior: Failed to initialize tracker:', error);
433
+ }
434
+ } else {
435
+ console.error('HumanBehavior: No API key found');
436
+ }
437
+ </script>`;
438
+ modifications.push({
439
+ filePath: astroComponentPath,
440
+ action: 'create',
441
+ content: astroComponentContent,
442
+ description: 'Created Astro component for HumanBehavior SDK'
443
+ });
444
+ // Find and update layout file
445
+ const layoutFiles = [
446
+ path__namespace.join(this.projectRoot, 'src', 'layouts', 'Layout.astro'),
447
+ path__namespace.join(this.projectRoot, 'src', 'layouts', 'layout.astro'),
448
+ path__namespace.join(this.projectRoot, 'src', 'layouts', 'BaseLayout.astro')
449
+ ];
450
+ let layoutFile = null;
451
+ for (const file of layoutFiles) {
452
+ if (fs__namespace.existsSync(file)) {
453
+ layoutFile = file;
454
+ break;
455
+ }
456
+ }
457
+ if (layoutFile) {
458
+ const content = fs__namespace.readFileSync(layoutFile, 'utf8');
459
+ const modifiedContent = this.injectAstroLayout(content);
460
+ modifications.push({
461
+ filePath: layoutFile,
462
+ action: 'modify',
463
+ content: modifiedContent,
464
+ description: 'Added HumanBehavior component to Astro layout'
465
+ });
466
+ }
467
+ // Add environment variable
468
+ modifications.push(this.createEnvironmentModification(this.framework));
469
+ return modifications;
470
+ });
471
+ }
364
472
  /**
365
473
  * Generate Nuxt-specific modifications
366
474
  */
@@ -581,6 +689,50 @@ export default defineNuxtPlugin(() => {
581
689
  return modifications;
582
690
  });
583
691
  }
692
+ /**
693
+ * Generate Gatsby-specific modifications
694
+ */
695
+ generateGatsbyModifications() {
696
+ return __awaiter(this, void 0, void 0, function* () {
697
+ const modifications = [];
698
+ // Modify or create gatsby-browser.js for Gatsby
699
+ const gatsbyBrowserFile = path__namespace.join(this.projectRoot, 'gatsby-browser.js');
700
+ if (fs__namespace.existsSync(gatsbyBrowserFile)) {
701
+ const content = fs__namespace.readFileSync(gatsbyBrowserFile, 'utf8');
702
+ const modifiedContent = this.injectGatsbyBrowser(content);
703
+ modifications.push({
704
+ filePath: gatsbyBrowserFile,
705
+ action: 'modify',
706
+ content: modifiedContent,
707
+ description: 'Added HumanBehavior initialization to Gatsby browser'
708
+ });
709
+ }
710
+ else {
711
+ // Create gatsby-browser.js if it doesn't exist
712
+ modifications.push({
713
+ filePath: gatsbyBrowserFile,
714
+ action: 'create',
715
+ content: `import { HumanBehaviorTracker } from 'humanbehavior-js';
716
+
717
+ export const onClientEntry = () => {
718
+ console.log('Gatsby browser entry point loaded');
719
+ const apiKey = process.env.GATSBY_HUMANBEHAVIOR_API_KEY;
720
+ console.log('API Key found:', apiKey ? 'Yes' : 'No');
721
+ if (apiKey) {
722
+ const tracker = HumanBehaviorTracker.init(apiKey);
723
+ console.log('HumanBehavior SDK initialized for Gatsby');
724
+ } else {
725
+ console.log('No API key found in environment variables');
726
+ }
727
+ };`,
728
+ description: 'Created gatsby-browser.js with HumanBehavior initialization'
729
+ });
730
+ }
731
+ // Create or append to environment file
732
+ modifications.push(this.createEnvironmentModification(this.framework));
733
+ return modifications;
734
+ });
735
+ }
584
736
  /**
585
737
  * Apply modifications to the codebase
586
738
  */
@@ -886,6 +1038,37 @@ if (typeof window !== 'undefined') {
886
1038
  </script>`;
887
1039
  return content.replace(/<\/head>/, ` ${cdnScript}\n ${initScript}\n</head>`);
888
1040
  }
1041
+ /**
1042
+ * Inject Astro layout with HumanBehavior component
1043
+ */
1044
+ injectAstroLayout(content) {
1045
+ // Check if HumanBehavior component is already imported
1046
+ if (content.includes('HumanBehavior') || content.includes('humanbehavior-js')) {
1047
+ return content; // Already has HumanBehavior
1048
+ }
1049
+ // Add import inside frontmatter if not present
1050
+ let modifiedContent = content;
1051
+ if (!content.includes('import HumanBehavior')) {
1052
+ const importStatement = 'import HumanBehavior from \'../components/HumanBehavior.astro\';';
1053
+ const frontmatterEndIndex = content.indexOf('---', 3);
1054
+ if (frontmatterEndIndex !== -1) {
1055
+ // Insert import inside frontmatter, before the closing ---
1056
+ modifiedContent = content.slice(0, frontmatterEndIndex) + '\n' + importStatement + '\n' + content.slice(frontmatterEndIndex);
1057
+ }
1058
+ else {
1059
+ // No frontmatter, add at the very beginning
1060
+ modifiedContent = '---\n' + importStatement + '\n---\n\n' + content;
1061
+ }
1062
+ }
1063
+ // Find the closing </body> tag and add HumanBehavior component before it
1064
+ const bodyCloseIndex = modifiedContent.lastIndexOf('</body>');
1065
+ if (bodyCloseIndex === -1) {
1066
+ // No body tag found, append to end
1067
+ return modifiedContent + '\n\n<HumanBehavior />';
1068
+ }
1069
+ // Add component before closing body tag
1070
+ return modifiedContent.slice(0, bodyCloseIndex) + ' <HumanBehavior />\n' + modifiedContent.slice(bodyCloseIndex);
1071
+ }
889
1072
  injectNuxtConfig(content) {
890
1073
  if (content.includes('humanBehaviorApiKey')) {
891
1074
  return content;
@@ -898,6 +1081,45 @@ if (typeof window !== 'undefined') {
898
1081
  }
899
1082
  },`);
900
1083
  }
1084
+ injectGatsbyLayout(content) {
1085
+ if (content.includes('HumanBehavior')) {
1086
+ return content;
1087
+ }
1088
+ const importStatement = `import HumanBehavior from './HumanBehavior';`;
1089
+ const componentUsage = `<HumanBehavior apiKey={process.env.GATSBY_HUMANBEHAVIOR_API_KEY || ''} />`;
1090
+ // Add import at the top
1091
+ let modifiedContent = content.replace(/import.*from.*['"]\./, `${importStatement}\n$&`);
1092
+ // Add component before closing body tag
1093
+ modifiedContent = modifiedContent.replace(/(\s*<\/body>)/, `\n ${componentUsage}\n$1`);
1094
+ return modifiedContent;
1095
+ }
1096
+ injectGatsbyBrowser(content) {
1097
+ if (content.includes('HumanBehaviorTracker')) {
1098
+ return content;
1099
+ }
1100
+ const importStatement = `import { HumanBehaviorTracker } from 'humanbehavior-js';`;
1101
+ const initCode = `
1102
+ // Initialize HumanBehavior SDK
1103
+ export const onClientEntry = () => {
1104
+ console.log('Gatsby browser entry point loaded');
1105
+ const apiKey = process.env.GATSBY_HUMANBEHAVIOR_API_KEY;
1106
+ console.log('API Key found:', apiKey ? 'Yes' : 'No');
1107
+ if (apiKey) {
1108
+ const tracker = HumanBehaviorTracker.init(apiKey);
1109
+ console.log('HumanBehavior SDK initialized for Gatsby');
1110
+ } else {
1111
+ console.log('No API key found in environment variables');
1112
+ }
1113
+ };`;
1114
+ // If the file already has content, add the import and init code
1115
+ if (content.trim()) {
1116
+ return `${importStatement}${initCode}\n\n${content}`;
1117
+ }
1118
+ else {
1119
+ // If file is empty, just return the new content
1120
+ return `${importStatement}${initCode}`;
1121
+ }
1122
+ }
901
1123
  /**
902
1124
  * Helper method to find the best environment file for a framework
903
1125
  */
@@ -927,6 +1149,8 @@ if (typeof window !== 'undefined') {
927
1149
  nuxt: 'NUXT_PUBLIC_HUMANBEHAVIOR_API_KEY',
928
1150
  remix: 'HUMANBEHAVIOR_API_KEY',
929
1151
  vanilla: 'HUMANBEHAVIOR_API_KEY',
1152
+ astro: 'PUBLIC_HUMANBEHAVIOR_API_KEY',
1153
+ gatsby: 'GATSBY_HUMANBEHAVIOR_API_KEY',
930
1154
  node: 'HUMANBEHAVIOR_API_KEY',
931
1155
  auto: 'HUMANBEHAVIOR_API_KEY'
932
1156
  };
@@ -950,6 +1174,8 @@ if (typeof window !== 'undefined') {
950
1174
  nuxt: '.env',
951
1175
  remix: '.env.local',
952
1176
  vanilla: '.env',
1177
+ astro: '.env',
1178
+ gatsby: '.env.development',
953
1179
  node: '.env',
954
1180
  auto: '.env'
955
1181
  };
@@ -964,6 +1190,8 @@ if (typeof window !== 'undefined') {
964
1190
  */
965
1191
  createEnvironmentModification(framework) {
966
1192
  const { filePath, envVarName } = this.findBestEnvFile(framework);
1193
+ // Clean the API key to prevent formatting issues
1194
+ const cleanApiKey = this.apiKey.trim();
967
1195
  if (fs__namespace.existsSync(filePath)) {
968
1196
  // Check if the variable already exists
969
1197
  const content = fs__namespace.readFileSync(filePath, 'utf8');
@@ -981,7 +1209,7 @@ if (typeof window !== 'undefined') {
981
1209
  return {
982
1210
  filePath,
983
1211
  action: 'append',
984
- content: `\n${envVarName}=${this.apiKey}`,
1212
+ content: `\n${envVarName}=${cleanApiKey}`,
985
1213
  description: `Added API key to existing ${path__namespace.basename(filePath)}`
986
1214
  };
987
1215
  }
@@ -991,7 +1219,7 @@ if (typeof window !== 'undefined') {
991
1219
  return {
992
1220
  filePath,
993
1221
  action: 'create',
994
- content: `${envVarName}=${this.apiKey}`,
1222
+ content: `${envVarName}=${cleanApiKey}`,
995
1223
  description: `Created ${path__namespace.basename(filePath)} with API key`
996
1224
  };
997
1225
  }
@@ -1087,6 +1315,10 @@ class DefaultAIService {
1087
1315
  framework = { name: 'nextjs', type: 'nextjs' };
1088
1316
  confidence = 0.95;
1089
1317
  }
1318
+ 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')) {
1319
+ framework = { name: 'gatsby', type: 'gatsby' };
1320
+ confidence = 0.95;
1321
+ }
1090
1322
  else if (patterns.includes('react')) {
1091
1323
  framework = { name: 'react', type: 'react' };
1092
1324
  confidence = 0.9;
@@ -1105,7 +1337,7 @@ class DefaultAIService {
1105
1337
  }
1106
1338
  // Integration strategy
1107
1339
  let integrationStrategy = 'script';
1108
- if (framework.type === 'react' || framework.type === 'nextjs') {
1340
+ if (framework.type === 'react' || framework.type === 'nextjs' || framework.type === 'gatsby') {
1109
1341
  integrationStrategy = 'provider';
1110
1342
  }
1111
1343
  else if (framework.type === 'vue') {
@@ -1900,6 +2132,10 @@ class RemoteAIService {
1900
2132
  framework = { name: 'nextjs', type: 'nextjs' };
1901
2133
  confidence = 0.95;
1902
2134
  }
2135
+ 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')) {
2136
+ framework = { name: 'gatsby', type: 'gatsby' };
2137
+ confidence = 0.95;
2138
+ }
1903
2139
  else if (patterns.includes('react')) {
1904
2140
  framework = { name: 'react', type: 'react' };
1905
2141
  confidence = 0.9;
@@ -1916,9 +2152,13 @@ class RemoteAIService {
1916
2152
  framework = { name: 'svelte', type: 'svelte' };
1917
2153
  confidence = 0.9;
1918
2154
  }
2155
+ else if (patterns.includes('astro')) {
2156
+ framework = { name: 'astro', type: 'astro' };
2157
+ confidence = 0.9;
2158
+ }
1919
2159
  // Integration strategy
1920
2160
  let integrationStrategy = 'script';
1921
- if (framework.type === 'react' || framework.type === 'nextjs') {
2161
+ if (framework.type === 'react' || framework.type === 'nextjs' || framework.type === 'gatsby') {
1922
2162
  integrationStrategy = 'provider';
1923
2163
  }
1924
2164
  else if (framework.type === 'vue') {
@@ -2161,6 +2401,8 @@ class ManualFrameworkInstallationWizard extends AutoInstallationWizard {
2161
2401
  'svelte': { name: 'svelte', type: 'svelte' },
2162
2402
  'sveltekit': { name: 'svelte', type: 'svelte' },
2163
2403
  'remix': { name: 'remix', type: 'remix' },
2404
+ 'astro': { name: 'astro', type: 'astro' },
2405
+ 'gatsby': { name: 'gatsby', type: 'gatsby' },
2164
2406
  'vanilla': { name: 'vanilla', type: 'vanilla' },
2165
2407
  'node': { name: 'node', type: 'node' },
2166
2408
  'auto': { name: 'auto-detected', type: 'auto' }
@@ -2220,67 +2462,46 @@ class ManualFrameworkInstallationWizard extends AutoInstallationWizard {
2220
2462
  class AIAutoInstallCLI {
2221
2463
  constructor(options) {
2222
2464
  this.options = options;
2223
- this.rl = readline__namespace.createInterface({
2224
- input: process.stdin,
2225
- output: process.stdout
2226
- });
2227
2465
  }
2228
2466
  run() {
2229
2467
  return __awaiter(this, void 0, void 0, function* () {
2230
- console.log('šŸ¤– AI-Enhanced HumanBehavior SDK Auto-Installation');
2231
- console.log('================================================\n');
2468
+ clack__namespace.intro('šŸ¤– AI-Enhanced HumanBehavior SDK Auto-Installation');
2232
2469
  try {
2233
2470
  // Get API key
2234
2471
  const apiKey = yield this.getApiKey();
2235
2472
  if (!apiKey) {
2236
- console.error('āŒ API key is required');
2473
+ clack__namespace.cancel('API key is required');
2237
2474
  process.exit(1);
2238
2475
  }
2239
2476
  // Get project path
2240
2477
  const projectPath = this.options.projectPath || process.cwd();
2241
- // Choose installation mode
2242
- const installationMode = yield this.chooseInstallationMode();
2478
+ // Choose framework
2479
+ const framework = yield this.chooseFramework();
2480
+ if (!framework) {
2481
+ clack__namespace.cancel('Installation cancelled.');
2482
+ process.exit(0);
2483
+ }
2243
2484
  // Confirm installation
2244
2485
  if (!this.options.yes) {
2245
- const confirmed = yield this.confirmInstallation(projectPath, installationMode);
2486
+ const confirmed = yield this.confirmInstallation(projectPath, framework);
2246
2487
  if (!confirmed) {
2247
- console.log('Installation cancelled.');
2488
+ clack__namespace.cancel('Installation cancelled.');
2248
2489
  process.exit(0);
2249
2490
  }
2250
2491
  }
2251
2492
  // Run installation
2252
- console.log('šŸ” Analyzing your project with AI...');
2253
- let result;
2254
- if (this.options.browser) {
2255
- const wizard = new AIBrowserInstallationWizard(apiKey);
2256
- result = yield wizard.install();
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
- }
2493
+ const spinner = clack__namespace.spinner();
2494
+ spinner.start('šŸ” Analyzing your project with AI...');
2495
+ const wizard = new ManualFrameworkInstallationWizard(apiKey, projectPath, framework);
2496
+ const result = yield wizard.install();
2497
+ spinner.stop('Analysis complete!');
2274
2498
  // Display results
2275
- this.displayResults(result, installationMode);
2499
+ this.displayResults(result, framework);
2276
2500
  }
2277
2501
  catch (error) {
2278
- console.error('āŒ Error:', error instanceof Error ? error.message : error);
2502
+ clack__namespace.cancel(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`);
2279
2503
  process.exit(1);
2280
2504
  }
2281
- finally {
2282
- this.rl.close();
2283
- }
2284
2505
  });
2285
2506
  }
2286
2507
  getApiKey() {
@@ -2288,262 +2509,143 @@ class AIAutoInstallCLI {
2288
2509
  if (this.options.apiKey) {
2289
2510
  return this.options.apiKey;
2290
2511
  }
2291
- return new Promise((resolve) => {
2292
- this.rl.question('Enter your HumanBehavior API key: ', (answer) => {
2293
- resolve(answer.trim());
2294
- });
2295
- });
2296
- });
2297
- }
2298
- chooseInstallationMode() {
2299
- return __awaiter(this, void 0, void 0, function* () {
2300
- if (this.options.manual && this.options.framework) {
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
- });
2512
+ const apiKey = yield clack__namespace.text({
2513
+ message: 'Enter your HumanBehavior API key:',
2514
+ placeholder: 'hb_...',
2515
+ validate: (value) => {
2516
+ if (!value)
2517
+ return 'API key is required';
2518
+ if (!value.startsWith('hb_'))
2519
+ return 'API key should start with "hb_"';
2520
+ return undefined;
2521
+ }
2322
2522
  });
2523
+ return apiKey;
2323
2524
  });
2324
2525
  }
2325
- confirmInstallation(projectPath, installationMode) {
2526
+ confirmInstallation(projectPath, framework) {
2326
2527
  return __awaiter(this, void 0, void 0, function* () {
2327
- console.log(`šŸ“ Project path: ${projectPath}`);
2328
- console.log(`šŸ¤– Installation mode: ${this.getInstallationModeDisplay(installationMode)}`);
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
- });
2528
+ const confirmed = yield clack__namespace.confirm({
2529
+ message: `Ready to install HumanBehavior SDK in ${projectPath} for ${framework}?`
2340
2530
  });
2531
+ return confirmed;
2341
2532
  });
2342
2533
  }
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
2534
  chooseFramework() {
2357
2535
  return __awaiter(this, void 0, void 0, function* () {
2358
- console.log('\nšŸŽÆ Choose your framework:');
2359
- console.log('1. Vanilla JS (HTML)');
2360
- console.log('2. React');
2361
- console.log('3. Next.js');
2362
- console.log('4. Vue');
2363
- console.log('5. Nuxt');
2364
- console.log('6. Angular');
2365
- console.log('7. Svelte');
2366
- console.log('8. Remix');
2367
- console.log('9. Node.js');
2368
- console.log('10. Other (Auto-detect)\n');
2369
- return new Promise((resolve) => {
2370
- this.rl.question('Select framework (1-10, default: 1): ', (answer) => {
2371
- const choice = answer.trim() || '1';
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
- });
2536
+ const framework = yield clack__namespace.select({
2537
+ message: 'Select your framework:',
2538
+ options: [
2539
+ { label: 'React', value: 'react' },
2540
+ { label: 'Next.js', value: 'nextjs' },
2541
+ { label: 'Vue', value: 'vue' },
2542
+ { label: 'Angular', value: 'angular' },
2543
+ { label: 'Svelte', value: 'svelte' },
2544
+ { label: 'Nuxt.js', value: 'nuxt' },
2545
+ { label: 'Remix', value: 'remix' },
2546
+ { label: 'Astro', value: 'astro' },
2547
+ { label: 'Gatsby', value: 'gatsby' },
2548
+ { label: 'Vanilla JS/TS', value: 'vanilla' }
2549
+ ]
2376
2550
  });
2551
+ return framework;
2377
2552
  });
2378
2553
  }
2379
- displayResults(result, installationMode) {
2554
+ displayResults(result, framework) {
2380
2555
  if (result.success) {
2381
- console.log('\nāœ… Installation completed successfully!');
2382
- if (installationMode === 'ai' && result.aiAnalysis) {
2383
- console.log(`šŸŽÆ AI Analysis Results:`);
2384
- console.log(` Framework: ${result.aiAnalysis.framework.name} (confidence: ${Math.round(result.aiAnalysis.confidence * 100)}%)`);
2385
- console.log(` Integration Strategy: ${result.aiAnalysis.integrationStrategy}`);
2386
- console.log(` Compatibility Mode: ${result.aiAnalysis.compatibilityMode}`);
2387
- if (result.aiAnalysis.patterns.length > 0) {
2388
- console.log(` Detected Patterns: ${result.aiAnalysis.patterns.length} patterns`);
2389
- }
2390
- if (result.aiAnalysis.recommendations.length > 0) {
2391
- console.log(` AI Recommendations:`);
2392
- result.aiAnalysis.recommendations.forEach((rec) => {
2393
- console.log(` • ${rec}`);
2394
- });
2556
+ clack__namespace.outro('šŸŽ‰ Installation completed successfully!');
2557
+ // Display framework info
2558
+ clack__namespace.note(`Framework detected: ${result.framework.name} (${result.framework.type})`, 'Framework Info');
2559
+ // Display modifications
2560
+ if (result.modifications && result.modifications.length > 0) {
2561
+ const modifications = result.modifications.map((mod) => `${mod.action}: ${mod.filePath} - ${mod.description}`);
2562
+ clack__namespace.note(modifications.join('\n'), 'Files Modified');
2563
+ }
2564
+ // Display next steps
2565
+ if (result.nextSteps && result.nextSteps.length > 0) {
2566
+ clack__namespace.note(result.nextSteps.join('\n'), 'Next Steps');
2567
+ }
2568
+ // Display AI insights if available
2569
+ if (result.aiAnalysis) {
2570
+ clack__namespace.note(`Confidence: ${Math.round(result.aiAnalysis.confidence * 100)}%`, 'AI Analysis');
2571
+ if (result.aiAnalysis.recommendations && result.aiAnalysis.recommendations.length > 0) {
2572
+ clack__namespace.note(result.aiAnalysis.recommendations.join('\n'), 'AI Recommendations');
2395
2573
  }
2396
2574
  }
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
2575
  }
2424
2576
  else {
2425
- console.log('\nāŒ Installation failed:');
2426
- result.errors.forEach((error) => {
2427
- console.log(` ${error}`);
2428
- });
2429
- console.log('\nšŸ’” Try running with --help for more options');
2577
+ clack__namespace.cancel('Installation failed');
2578
+ if (result.errors && result.errors.length > 0) {
2579
+ clack__namespace.note(result.errors.join('\n'), 'Errors');
2580
+ }
2430
2581
  }
2431
2582
  }
2432
2583
  }
2433
- // CLI argument parsing
2434
2584
  function parseArgs$1() {
2435
2585
  const args = process.argv.slice(2);
2436
2586
  const options = {};
2437
2587
  for (let i = 0; i < args.length; i++) {
2438
2588
  const arg = args[i];
2439
- if (arg === '--yes' || arg === '-y') {
2440
- options.yes = true;
2441
- }
2442
- else if (arg === '--dry-run' || arg === '-d') {
2443
- options.dryRun = true;
2444
- }
2445
- else if (arg === '--project' || arg === '-p') {
2446
- options.projectPath = args[i + 1];
2447
- i++;
2448
- }
2449
- else if (arg === '--traditional' || arg === '-t') {
2450
- options.useAI = false;
2451
- }
2452
- else if (arg === '--browser' || arg === '-b') {
2453
- options.browser = true;
2454
- }
2455
- else if (arg === '--manual' || arg === '-m') {
2456
- options.manual = true;
2457
- }
2458
- else if (arg === '--framework' || arg === '-f') {
2459
- options.framework = args[i + 1];
2460
- i++;
2461
- }
2462
- else if (arg === '--help' || arg === '-h') {
2463
- showHelp$1();
2464
- process.exit(0);
2465
- }
2466
- else if (!options.apiKey) {
2467
- options.apiKey = arg;
2589
+ switch (arg) {
2590
+ case '--help':
2591
+ case '-h':
2592
+ showHelp$1();
2593
+ process.exit(0);
2594
+ break;
2595
+ case '--yes':
2596
+ case '-y':
2597
+ options.yes = true;
2598
+ break;
2599
+ case '--dry-run':
2600
+ options.dryRun = true;
2601
+ break;
2602
+ case '--project':
2603
+ case '-p':
2604
+ options.projectPath = args[++i];
2605
+ break;
2606
+ case '--framework':
2607
+ case '-f':
2608
+ options.framework = args[++i];
2609
+ break;
2610
+ default:
2611
+ if (!options.apiKey && !arg.startsWith('-')) {
2612
+ options.apiKey = arg;
2613
+ }
2614
+ break;
2468
2615
  }
2469
2616
  }
2470
2617
  return options;
2471
2618
  }
2472
2619
  function showHelp$1() {
2473
2620
  console.log(`
2474
- AI-Enhanced HumanBehavior SDK Auto-Installation CLI
2621
+ šŸ¤– HumanBehavior SDK AI Auto-Installation
2475
2622
 
2476
2623
  Usage: npx humanbehavior-js ai-auto-install [api-key] [options]
2477
2624
 
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
2625
  Options:
2485
- -y, --yes Skip all prompts and use defaults
2486
- -d, --dry-run Show what would be changed without making changes
2487
- -p, --project <path> Project directory (default: current directory)
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
2626
+ -h, --help Show this help message
2627
+ -y, --yes Skip all prompts and use defaults
2628
+ --dry-run Show what would be changed without making changes
2493
2629
 
2494
- Installation Modes:
2495
- 1. Manual AI-Enhanced (default): Choose your framework and use AI for optimization
2496
- 2. Traditional: Standard framework detection and installation
2497
- 3. Browser: Browser-based AI detection and code generation
2630
+ -p, --project <path> Specify project directory
2631
+ -f, --framework <name> Specify framework manually
2498
2632
 
2499
2633
  Examples:
2500
- npx humanbehavior-js ai-auto-install your-api-key
2501
- npx humanbehavior-js ai-auto-install your-api-key --manual --framework react
2502
- npx humanbehavior-js ai-auto-install your-api-key --traditional
2503
- npx humanbehavior-js ai-auto-install your-api-key --browser
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
2634
+ npx humanbehavior-js ai-auto-install
2635
+ npx humanbehavior-js ai-auto-install hb_your_api_key_here
2636
+ npx humanbehavior-js ai-auto-install --project ./my-app --ai
2637
+ npx humanbehavior-js ai-auto-install --framework react --yes
2533
2638
  `);
2534
2639
  }
2535
2640
  // Main execution
2536
- const options$1 = parseArgs$1();
2537
- // Check if we have enough arguments (api-key is required)
2538
- if (process.argv.length < 3 || process.argv.includes('--help') || process.argv.includes('-h')) {
2539
- showHelp$1();
2540
- process.exit(0);
2641
+ 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]}`) {
2642
+ const options = parseArgs$1();
2643
+ const cli = new AIAutoInstallCLI(options);
2644
+ cli.run().catch((error) => {
2645
+ clack__namespace.cancel(`Unexpected error: ${error.message}`);
2646
+ process.exit(1);
2647
+ });
2541
2648
  }
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
2649
 
2548
2650
  /**
2549
2651
  * HumanBehavior SDK Auto-Installation CLI
@@ -2556,46 +2658,46 @@ cli$1.run().catch((error) => {
2556
2658
  class AutoInstallCLI {
2557
2659
  constructor(options) {
2558
2660
  this.options = options;
2559
- this.rl = readline__namespace.createInterface({
2560
- input: process.stdin,
2561
- output: process.stdout
2562
- });
2563
2661
  }
2564
2662
  run() {
2565
2663
  return __awaiter(this, void 0, void 0, function* () {
2566
- console.log('šŸš€ HumanBehavior SDK Auto-Installation');
2567
- console.log('=====================================\n');
2664
+ clack__namespace.intro('šŸš€ HumanBehavior SDK Auto-Installation');
2568
2665
  try {
2569
2666
  // Get API key
2570
2667
  const apiKey = yield this.getApiKey();
2571
2668
  if (!apiKey) {
2572
- console.error('āŒ API key is required');
2669
+ clack__namespace.cancel('API key is required');
2573
2670
  process.exit(1);
2574
2671
  }
2575
2672
  // Get project path
2576
2673
  const projectPath = this.options.projectPath || process.cwd();
2674
+ // Choose framework
2675
+ const framework = yield this.chooseFramework();
2676
+ if (!framework) {
2677
+ clack__namespace.cancel('Installation cancelled.');
2678
+ process.exit(0);
2679
+ }
2577
2680
  // Confirm installation
2578
2681
  if (!this.options.yes) {
2579
- const confirmed = yield this.confirmInstallation(projectPath);
2682
+ const confirmed = yield this.confirmInstallation(projectPath, framework);
2580
2683
  if (!confirmed) {
2581
- console.log('Installation cancelled.');
2684
+ clack__namespace.cancel('Installation cancelled.');
2582
2685
  process.exit(0);
2583
2686
  }
2584
2687
  }
2585
- // Run auto-installation
2586
- console.log('šŸ” Detecting your project setup...');
2587
- const wizard = new AutoInstallationWizard(apiKey, projectPath);
2688
+ // Run installation
2689
+ const spinner = clack__namespace.spinner();
2690
+ spinner.start('šŸ” Analyzing your project...');
2691
+ const wizard = new ManualFrameworkInstallationWizard(apiKey, projectPath, framework);
2588
2692
  const result = yield wizard.install();
2693
+ spinner.stop('Detection complete!');
2589
2694
  // Display results
2590
2695
  this.displayResults(result);
2591
2696
  }
2592
2697
  catch (error) {
2593
- console.error('āŒ Error:', error instanceof Error ? error.message : error);
2698
+ clack__namespace.cancel(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`);
2594
2699
  process.exit(1);
2595
2700
  }
2596
- finally {
2597
- this.rl.close();
2598
- }
2599
2701
  });
2600
2702
  }
2601
2703
  getApiKey() {
@@ -2603,139 +2705,131 @@ class AutoInstallCLI {
2603
2705
  if (this.options.apiKey) {
2604
2706
  return this.options.apiKey;
2605
2707
  }
2606
- return new Promise((resolve) => {
2607
- this.rl.question('Enter your HumanBehavior API key: ', (answer) => {
2608
- resolve(answer.trim());
2609
- });
2708
+ const apiKey = yield clack__namespace.text({
2709
+ message: 'Enter your HumanBehavior API key:',
2710
+ placeholder: 'hb_...',
2711
+ validate: (value) => {
2712
+ if (!value)
2713
+ return 'API key is required';
2714
+ if (!value.startsWith('hb_'))
2715
+ return 'API key should start with "hb_"';
2716
+ return undefined;
2717
+ }
2610
2718
  });
2719
+ return apiKey;
2611
2720
  });
2612
2721
  }
2613
- confirmInstallation(projectPath) {
2722
+ chooseFramework() {
2614
2723
  return __awaiter(this, void 0, void 0, function* () {
2615
- console.log(`šŸ“ Project path: ${projectPath}`);
2616
- console.log('āš ļø This will modify your codebase to integrate HumanBehavior SDK.');
2617
- console.log(' The following changes will be made:');
2618
- console.log(' - Install humanbehavior-js package');
2619
- console.log(' - Modify your main app file');
2620
- console.log(' - Create environment files');
2621
- console.log(' - Add SDK initialization code\n');
2622
- return new Promise((resolve) => {
2623
- this.rl.question('Continue with auto-installation? (y/n): ', (answer) => {
2624
- resolve(answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes');
2625
- });
2724
+ const framework = yield clack__namespace.select({
2725
+ message: 'Select your framework:',
2726
+ options: [
2727
+ { label: 'React', value: 'react' },
2728
+ { label: 'Next.js', value: 'nextjs' },
2729
+ { label: 'Vue', value: 'vue' },
2730
+ { label: 'Angular', value: 'angular' },
2731
+ { label: 'Svelte', value: 'svelte' },
2732
+ { label: 'Nuxt.js', value: 'nuxt' },
2733
+ { label: 'Remix', value: 'remix' },
2734
+ { label: 'Astro', value: 'astro' },
2735
+ { label: 'Gatsby', value: 'gatsby' },
2736
+ { label: 'Vanilla JS/TS', value: 'vanilla' }
2737
+ ]
2738
+ });
2739
+ return framework;
2740
+ });
2741
+ }
2742
+ confirmInstallation(projectPath, framework) {
2743
+ return __awaiter(this, void 0, void 0, function* () {
2744
+ const confirmed = yield clack__namespace.confirm({
2745
+ message: `Ready to install HumanBehavior SDK in ${projectPath} for ${framework}?`
2626
2746
  });
2747
+ return confirmed;
2627
2748
  });
2628
2749
  }
2629
2750
  displayResults(result) {
2630
2751
  if (result.success) {
2631
- console.log('\nāœ… Installation completed successfully!');
2632
- console.log(`šŸ“¦ Framework detected: ${result.framework.name}`);
2633
- if (result.framework.bundler) {
2634
- console.log(`šŸ”§ Bundler: ${result.framework.bundler}`);
2635
- }
2636
- if (result.framework.packageManager) {
2637
- console.log(`šŸ“‹ Package Manager: ${result.framework.packageManager}`);
2638
- }
2639
- console.log('\nšŸ“ Changes made:');
2640
- result.modifications.forEach((mod) => {
2641
- console.log(` ${mod.action === 'create' ? 'āž•' : 'āœļø'} ${mod.description}`);
2642
- console.log(` ${mod.filePath}`);
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');
2752
+ clack__namespace.outro('šŸŽ‰ Installation completed successfully!');
2753
+ // Display framework info
2754
+ clack__namespace.note(`Framework detected: ${result.framework.name} (${result.framework.type})`, 'Framework Info');
2755
+ // Display modifications
2756
+ if (result.modifications && result.modifications.length > 0) {
2757
+ const modifications = result.modifications.map((mod) => `${mod.action}: ${mod.filePath} - ${mod.description}`);
2758
+ clack__namespace.note(modifications.join('\n'), 'Files Modified');
2759
+ }
2760
+ // Display next steps
2761
+ if (result.nextSteps && result.nextSteps.length > 0) {
2762
+ clack__namespace.note(result.nextSteps.join('\n'), 'Next Steps');
2763
+ }
2650
2764
  }
2651
2765
  else {
2652
- console.log('\nāŒ Installation failed:');
2653
- result.errors.forEach((error) => {
2654
- console.log(` ${error}`);
2655
- });
2656
- console.log('\nšŸ’” Try running with --help for more options');
2766
+ clack__namespace.cancel('Installation failed');
2767
+ if (result.errors && result.errors.length > 0) {
2768
+ clack__namespace.note(result.errors.join('\n'), 'Errors');
2769
+ }
2657
2770
  }
2658
2771
  }
2659
2772
  }
2660
- // CLI argument parsing
2661
2773
  function parseArgs() {
2662
2774
  const args = process.argv.slice(2);
2663
2775
  const options = {};
2664
2776
  for (let i = 0; i < args.length; i++) {
2665
2777
  const arg = args[i];
2666
- if (arg === '--yes' || arg === '-y') {
2667
- options.yes = true;
2668
- }
2669
- else if (arg === '--dry-run' || arg === '-d') {
2670
- options.dryRun = true;
2671
- }
2672
- else if (arg === '--project' || arg === '-p') {
2673
- options.projectPath = args[i + 1];
2674
- i++;
2675
- }
2676
- else if (arg === '--help' || arg === '-h') {
2677
- showHelp();
2678
- process.exit(0);
2679
- }
2680
- else if (!options.apiKey) {
2681
- options.apiKey = arg;
2778
+ switch (arg) {
2779
+ case '--help':
2780
+ case '-h':
2781
+ showHelp();
2782
+ process.exit(0);
2783
+ break;
2784
+ case '--yes':
2785
+ case '-y':
2786
+ options.yes = true;
2787
+ break;
2788
+ case '--dry-run':
2789
+ options.dryRun = true;
2790
+ break;
2791
+ case '--project':
2792
+ case '-p':
2793
+ options.projectPath = args[++i];
2794
+ break;
2795
+ default:
2796
+ if (!options.apiKey && !arg.startsWith('-')) {
2797
+ options.apiKey = arg;
2798
+ }
2799
+ break;
2682
2800
  }
2683
2801
  }
2684
2802
  return options;
2685
2803
  }
2686
2804
  function showHelp() {
2687
2805
  console.log(`
2688
- HumanBehavior SDK Auto-Installation CLI
2689
-
2690
- Usage: npx humanbehavior-js [api-key] [options]
2806
+ šŸš€ HumanBehavior SDK Auto-Installation
2691
2807
 
2692
- This tool automatically detects your project's framework and modifies your codebase
2693
- to integrate the HumanBehavior SDK with minimal user intervention.
2808
+ Usage: npx humanbehavior-js auto-install [api-key] [options]
2694
2809
 
2695
- Arguments:
2696
- api-key Your HumanBehavior API key
2810
+ This tool automatically detects your framework and integrates the HumanBehavior SDK.
2697
2811
 
2698
2812
  Options:
2699
- -y, --yes Skip all prompts and use defaults
2700
- -d, --dry-run Show what would be changed without making changes
2701
- -p, --project <path> Project directory (default: current directory)
2702
- -h, --help Show this help message
2813
+ -h, --help Show this help message
2814
+ -y, --yes Skip all prompts and use defaults
2815
+ --dry-run Show what would be changed without making changes
2816
+ -p, --project <path> Specify project directory
2703
2817
 
2704
2818
  Examples:
2705
- npx humanbehavior-js your-api-key
2706
- npx humanbehavior-js your-api-key --yes
2707
- npx humanbehavior-js your-api-key -p /path/to/project
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
2819
+ npx humanbehavior-js auto-install
2820
+ npx humanbehavior-js auto-install hb_your_api_key_here
2821
+ npx humanbehavior-js auto-install --project ./my-app --yes
2725
2822
  `);
2726
2823
  }
2727
2824
  // Main execution
2728
- const options = parseArgs();
2729
- // Check if we have enough arguments (api-key is required)
2730
- if (process.argv.length < 3 || process.argv.includes('--help') || process.argv.includes('-h')) {
2731
- showHelp();
2732
- process.exit(0);
2825
+ 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]}`) {
2826
+ const options = parseArgs();
2827
+ const cli = new AutoInstallCLI(options);
2828
+ cli.run().catch((error) => {
2829
+ clack__namespace.cancel(`Unexpected error: ${error.message}`);
2830
+ process.exit(1);
2831
+ });
2733
2832
  }
2734
- const cli = new AutoInstallCLI(options);
2735
- cli.run().catch((error) => {
2736
- console.error('āŒ Fatal error:', error);
2737
- process.exit(1);
2738
- });
2739
2833
 
2740
2834
  /**
2741
2835
  * Centralized AI Service Implementation