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.
- package/dist/cjs/install-wizard.cjs +231 -4
- package/dist/cjs/install-wizard.cjs.map +1 -1
- package/dist/cjs/wizard/index.cjs +468 -374
- package/dist/cjs/wizard/index.cjs.map +1 -1
- package/dist/cli/ai-auto-install.cjs +57161 -0
- package/dist/cli/ai-auto-install.cjs.map +1 -0
- package/dist/cli/ai-auto-install.js +355 -554
- package/dist/cli/ai-auto-install.js.map +1 -1
- package/dist/cli/auto-install.cjs +56352 -0
- package/dist/cli/auto-install.cjs.map +1 -0
- package/dist/cli/auto-install.js +760 -119
- package/dist/cli/auto-install.js.map +1 -1
- package/dist/esm/install-wizard.js +231 -4
- package/dist/esm/install-wizard.js.map +1 -1
- package/dist/esm/wizard/index.js +466 -373
- package/dist/esm/wizard/index.js.map +1 -1
- package/dist/types/install-wizard.d.ts +15 -1
- package/dist/types/wizard/index.d.ts +18 -10
- package/package.json +3 -1
- package/rollup.config.js +5 -1
- package/src/types/clack.d.ts +31 -0
- package/src/wizard/ai/ai-install-wizard.ts +4 -1
- package/src/wizard/ai/manual-framework-wizard.ts +2 -0
- package/src/wizard/cli/ai-auto-install.ts +122 -248
- package/src/wizard/cli/auto-install.ts +116 -117
- package/src/wizard/core/install-wizard.ts +272 -14
- package/src/wizard/services/centralized-ai-service.ts +1 -1
- package/src/wizard/services/remote-ai-service.ts +8 -2
- package/tsconfig.json +1 -1
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { AutoInstallationWizard } from '../core/install-wizard';
|
|
13
|
-
import
|
|
13
|
+
import { ManualFrameworkInstallationWizard } from '../ai/manual-framework-wizard';
|
|
14
|
+
import * as clack from '@clack/prompts';
|
|
14
15
|
import * as fs from 'fs';
|
|
15
16
|
import * as path from 'path';
|
|
16
17
|
|
|
@@ -22,54 +23,57 @@ interface CLIOptions {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
class AutoInstallCLI {
|
|
25
|
-
private rl: readline.Interface;
|
|
26
26
|
private options: CLIOptions;
|
|
27
27
|
|
|
28
28
|
constructor(options: CLIOptions) {
|
|
29
29
|
this.options = options;
|
|
30
|
-
this.rl = readline.createInterface({
|
|
31
|
-
input: process.stdin,
|
|
32
|
-
output: process.stdout
|
|
33
|
-
});
|
|
34
30
|
}
|
|
35
31
|
|
|
36
32
|
async run() {
|
|
37
|
-
|
|
38
|
-
console.log('=====================================\n');
|
|
33
|
+
clack.intro('š HumanBehavior SDK Auto-Installation');
|
|
39
34
|
|
|
40
35
|
try {
|
|
41
36
|
// Get API key
|
|
42
37
|
const apiKey = await this.getApiKey();
|
|
43
38
|
if (!apiKey) {
|
|
44
|
-
|
|
39
|
+
clack.cancel('API key is required');
|
|
45
40
|
process.exit(1);
|
|
46
41
|
}
|
|
47
42
|
|
|
48
43
|
// Get project path
|
|
49
44
|
const projectPath = this.options.projectPath || process.cwd();
|
|
50
45
|
|
|
46
|
+
// Choose framework
|
|
47
|
+
const framework = await this.chooseFramework();
|
|
48
|
+
if (!framework) {
|
|
49
|
+
clack.cancel('Installation cancelled.');
|
|
50
|
+
process.exit(0);
|
|
51
|
+
}
|
|
52
|
+
|
|
51
53
|
// Confirm installation
|
|
52
54
|
if (!this.options.yes) {
|
|
53
|
-
const confirmed = await this.confirmInstallation(projectPath);
|
|
55
|
+
const confirmed = await this.confirmInstallation(projectPath, framework);
|
|
54
56
|
if (!confirmed) {
|
|
55
|
-
|
|
57
|
+
clack.cancel('Installation cancelled.');
|
|
56
58
|
process.exit(0);
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
// Run
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
// Run installation
|
|
63
|
+
const spinner = clack.spinner();
|
|
64
|
+
spinner.start('š Analyzing your project...');
|
|
65
|
+
|
|
66
|
+
const wizard = new ManualFrameworkInstallationWizard(apiKey, projectPath, framework);
|
|
63
67
|
const result = await wizard.install();
|
|
64
68
|
|
|
69
|
+
spinner.stop('Detection complete!');
|
|
70
|
+
|
|
65
71
|
// Display results
|
|
66
72
|
this.displayResults(result);
|
|
67
73
|
|
|
68
74
|
} catch (error) {
|
|
69
|
-
|
|
75
|
+
clack.cancel(`Error: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
70
76
|
process.exit(1);
|
|
71
|
-
} finally {
|
|
72
|
-
this.rl.close();
|
|
73
77
|
}
|
|
74
78
|
}
|
|
75
79
|
|
|
@@ -78,68 +82,79 @@ class AutoInstallCLI {
|
|
|
78
82
|
return this.options.apiKey;
|
|
79
83
|
}
|
|
80
84
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
const apiKey = await clack.text({
|
|
86
|
+
message: 'Enter your HumanBehavior API key:',
|
|
87
|
+
placeholder: 'hb_...',
|
|
88
|
+
validate: (value) => {
|
|
89
|
+
if (!value) return 'API key is required';
|
|
90
|
+
if (!value.startsWith('hb_')) return 'API key should start with "hb_"';
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
return apiKey;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
private async chooseFramework(): Promise<string> {
|
|
101
|
+
const framework = await clack.select({
|
|
102
|
+
message: 'Select your framework:',
|
|
103
|
+
options: [
|
|
104
|
+
{ label: 'React', value: 'react' },
|
|
105
|
+
{ label: 'Next.js', value: 'nextjs' },
|
|
106
|
+
{ label: 'Vue', value: 'vue' },
|
|
107
|
+
{ label: 'Angular', value: 'angular' },
|
|
108
|
+
{ label: 'Svelte', value: 'svelte' },
|
|
109
|
+
{ label: 'Nuxt.js', value: 'nuxt' },
|
|
110
|
+
{ label: 'Remix', value: 'remix' },
|
|
111
|
+
{ label: 'Astro', value: 'astro' },
|
|
112
|
+
{ label: 'Gatsby', value: 'gatsby' },
|
|
113
|
+
{ label: 'Vanilla JS/TS', value: 'vanilla' }
|
|
114
|
+
]
|
|
85
115
|
});
|
|
116
|
+
|
|
117
|
+
return framework;
|
|
86
118
|
}
|
|
87
119
|
|
|
88
|
-
private async confirmInstallation(projectPath: string): Promise<boolean> {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
console.log(' The following changes will be made:');
|
|
92
|
-
console.log(' - Install humanbehavior-js package');
|
|
93
|
-
console.log(' - Modify your main app file');
|
|
94
|
-
console.log(' - Create environment files');
|
|
95
|
-
console.log(' - Add SDK initialization code\n');
|
|
96
|
-
|
|
97
|
-
return new Promise((resolve) => {
|
|
98
|
-
this.rl.question('Continue with auto-installation? (y/n): ', (answer) => {
|
|
99
|
-
resolve(answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes');
|
|
100
|
-
});
|
|
120
|
+
private async confirmInstallation(projectPath: string, framework: string): Promise<boolean> {
|
|
121
|
+
const confirmed = await clack.confirm({
|
|
122
|
+
message: `Ready to install HumanBehavior SDK in ${projectPath} for ${framework}?`
|
|
101
123
|
});
|
|
124
|
+
|
|
125
|
+
return confirmed;
|
|
102
126
|
}
|
|
103
127
|
|
|
104
128
|
private displayResults(result: any) {
|
|
105
129
|
if (result.success) {
|
|
106
|
-
|
|
107
|
-
console.log(`š¦ Framework detected: ${result.framework.name}`);
|
|
108
|
-
|
|
109
|
-
if (result.framework.bundler) {
|
|
110
|
-
console.log(`š§ Bundler: ${result.framework.bundler}`);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (result.framework.packageManager) {
|
|
114
|
-
console.log(`š Package Manager: ${result.framework.packageManager}`);
|
|
115
|
-
}
|
|
130
|
+
clack.outro('š Installation completed successfully!');
|
|
116
131
|
|
|
117
|
-
|
|
118
|
-
result.
|
|
119
|
-
console.log(` ${mod.action === 'create' ? 'ā' : 'āļø'} ${mod.description}`);
|
|
120
|
-
console.log(` ${mod.filePath}`);
|
|
121
|
-
});
|
|
132
|
+
// Display framework info
|
|
133
|
+
clack.note(`Framework detected: ${result.framework.name} (${result.framework.type})`, 'Framework Info');
|
|
122
134
|
|
|
123
|
-
|
|
124
|
-
result.
|
|
125
|
-
|
|
126
|
-
|
|
135
|
+
// Display modifications
|
|
136
|
+
if (result.modifications && result.modifications.length > 0) {
|
|
137
|
+
const modifications = result.modifications.map((mod: any) =>
|
|
138
|
+
`${mod.action}: ${mod.filePath} - ${mod.description}`
|
|
139
|
+
);
|
|
140
|
+
clack.note(modifications.join('\n'), 'Files Modified');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Display next steps
|
|
144
|
+
if (result.nextSteps && result.nextSteps.length > 0) {
|
|
145
|
+
clack.note(result.nextSteps.join('\n'), 'Next Steps');
|
|
146
|
+
}
|
|
127
147
|
|
|
128
|
-
console.log('\nš Your app is now ready to track user behavior!');
|
|
129
|
-
console.log('š View sessions in your HumanBehavior dashboard');
|
|
130
|
-
|
|
131
148
|
} else {
|
|
132
|
-
|
|
133
|
-
result.errors.forEach((error: string) => {
|
|
134
|
-
console.log(` ${error}`);
|
|
135
|
-
});
|
|
149
|
+
clack.cancel('Installation failed');
|
|
136
150
|
|
|
137
|
-
|
|
151
|
+
if (result.errors && result.errors.length > 0) {
|
|
152
|
+
clack.note(result.errors.join('\n'), 'Errors');
|
|
153
|
+
}
|
|
138
154
|
}
|
|
139
155
|
}
|
|
140
156
|
}
|
|
141
157
|
|
|
142
|
-
// CLI argument parsing
|
|
143
158
|
function parseArgs(): CLIOptions {
|
|
144
159
|
const args = process.argv.slice(2);
|
|
145
160
|
const options: CLIOptions = {};
|
|
@@ -147,18 +162,28 @@ function parseArgs(): CLIOptions {
|
|
|
147
162
|
for (let i = 0; i < args.length; i++) {
|
|
148
163
|
const arg = args[i];
|
|
149
164
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
165
|
+
switch (arg) {
|
|
166
|
+
case '--help':
|
|
167
|
+
case '-h':
|
|
168
|
+
showHelp();
|
|
169
|
+
process.exit(0);
|
|
170
|
+
break;
|
|
171
|
+
case '--yes':
|
|
172
|
+
case '-y':
|
|
173
|
+
options.yes = true;
|
|
174
|
+
break;
|
|
175
|
+
case '--dry-run':
|
|
176
|
+
options.dryRun = true;
|
|
177
|
+
break;
|
|
178
|
+
case '--project':
|
|
179
|
+
case '-p':
|
|
180
|
+
options.projectPath = args[++i];
|
|
181
|
+
break;
|
|
182
|
+
default:
|
|
183
|
+
if (!options.apiKey && !arg.startsWith('-')) {
|
|
184
|
+
options.apiKey = arg;
|
|
185
|
+
}
|
|
186
|
+
break;
|
|
162
187
|
}
|
|
163
188
|
}
|
|
164
189
|
|
|
@@ -167,59 +192,33 @@ function parseArgs(): CLIOptions {
|
|
|
167
192
|
|
|
168
193
|
function showHelp() {
|
|
169
194
|
console.log(`
|
|
170
|
-
HumanBehavior SDK Auto-Installation
|
|
195
|
+
š HumanBehavior SDK Auto-Installation
|
|
171
196
|
|
|
172
|
-
Usage: npx humanbehavior-js [api-key] [options]
|
|
197
|
+
Usage: npx humanbehavior-js auto-install [api-key] [options]
|
|
173
198
|
|
|
174
|
-
This tool automatically detects your
|
|
175
|
-
to integrate the HumanBehavior SDK with minimal user intervention.
|
|
176
|
-
|
|
177
|
-
Arguments:
|
|
178
|
-
api-key Your HumanBehavior API key
|
|
199
|
+
This tool automatically detects your framework and integrates the HumanBehavior SDK.
|
|
179
200
|
|
|
180
201
|
Options:
|
|
181
|
-
-
|
|
182
|
-
-
|
|
183
|
-
-
|
|
184
|
-
-
|
|
202
|
+
-h, --help Show this help message
|
|
203
|
+
-y, --yes Skip all prompts and use defaults
|
|
204
|
+
--dry-run Show what would be changed without making changes
|
|
205
|
+
-p, --project <path> Specify project directory
|
|
185
206
|
|
|
186
207
|
Examples:
|
|
187
|
-
npx humanbehavior-js
|
|
188
|
-
npx humanbehavior-js
|
|
189
|
-
npx humanbehavior-js
|
|
190
|
-
|
|
191
|
-
Supported Frameworks:
|
|
192
|
-
ā
React (CRA, Vite, Webpack)
|
|
193
|
-
ā
Next.js (App Router, Pages Router)
|
|
194
|
-
ā
Vue (Vue CLI, Vite)
|
|
195
|
-
ā
Angular
|
|
196
|
-
ā
Svelte (SvelteKit, Vite)
|
|
197
|
-
ā
Remix
|
|
198
|
-
ā
Vanilla JS/TS
|
|
199
|
-
ā
Node.js (CommonJS & ESM)
|
|
200
|
-
|
|
201
|
-
The tool will:
|
|
202
|
-
1. š Auto-detect your project's framework and setup
|
|
203
|
-
2. š¦ Install the humanbehavior-js package
|
|
204
|
-
3. āļø Modify your codebase to integrate the SDK
|
|
205
|
-
4. š§ Create environment files with your API key
|
|
206
|
-
5. š Make your app ready to track user behavior
|
|
208
|
+
npx humanbehavior-js auto-install
|
|
209
|
+
npx humanbehavior-js auto-install hb_your_api_key_here
|
|
210
|
+
npx humanbehavior-js auto-install --project ./my-app --yes
|
|
207
211
|
`);
|
|
208
212
|
}
|
|
209
213
|
|
|
210
214
|
// Main execution
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
215
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
216
|
+
const options = parseArgs();
|
|
217
|
+
const cli = new AutoInstallCLI(options);
|
|
218
|
+
cli.run().catch((error) => {
|
|
219
|
+
clack.cancel(`Unexpected error: ${error.message}`);
|
|
220
|
+
process.exit(1);
|
|
221
|
+
});
|
|
217
222
|
}
|
|
218
223
|
|
|
219
|
-
const cli = new AutoInstallCLI(options);
|
|
220
|
-
cli.run().catch((error) => {
|
|
221
|
-
console.error('ā Fatal error:', error);
|
|
222
|
-
process.exit(1);
|
|
223
|
-
});
|
|
224
|
-
|
|
225
224
|
export { AutoInstallCLI };
|