@holdyapp/install 0.1.0

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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +72 -0
  3. package/dist/cli.js +566 -0
  4. package/package.json +42 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Holdy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # @holdyapp/install
2
+
3
+ CLI de instalação do Holdy SDK. Detecta seu framework e wira o SDK em 1 passo.
4
+
5
+ ## Uso
6
+
7
+ ```bash
8
+ npx @holdyapp/install <SUA_API_KEY>
9
+ ```
10
+
11
+ Sem argumentos? Roda em modo interativo:
12
+
13
+ ```bash
14
+ npx @holdyapp/install
15
+ ```
16
+
17
+ ## Opções
18
+
19
+ ```
20
+ npx @holdyapp/install <apiKey> [opções]
21
+
22
+ --account <id> Account ID padrão pro Holdy.init
23
+ --no-auto-capture Desabilita captura automática de page views
24
+ --version, -v Mostra versão
25
+ --help, -h Mostra ajuda
26
+
27
+ # Alternativa via env var:
28
+ HOLDY_API_KEY=hol_live_… npx @holdyapp/install
29
+ ```
30
+
31
+ ## Frameworks suportados
32
+
33
+ - **Next.js** App Router (cria `app/holdy-script.tsx` client component + patcha `app/layout.tsx`)
34
+ - **Next.js** Pages Router (patcha `pages/_app.tsx`)
35
+ - **Vite** React / Vue / Svelte (prepend no entry)
36
+ - **Nuxt** (cria `plugins/holdy.client.ts`)
37
+ - **Remix** (patcha `app/root.tsx`)
38
+ - **Astro** (patcha layout `.astro`)
39
+ - **Create React App** (script tag em `public/index.html`)
40
+ - **Angular** (prepend em `src/main.ts`)
41
+ - **Vanilla HTML** (script tag em `index.html`)
42
+
43
+ ## Idempotência
44
+
45
+ Re-rodar o CLI no mesmo projeto = no-op. Os patches detectam o marker `holdy-installed-by-cli` ou imports prévios de `@holdyapp/sdk`.
46
+
47
+ ## Como funciona
48
+
49
+ 1. Lê seu `package.json` pra identificar o framework
50
+ 2. Pra frameworks com bundler (Next/Vite/Nuxt etc): adiciona `import { Holdy } from '@holdyapp/sdk'` no entry e mostra `npm install @holdyapp/sdk` no fim
51
+ 3. Pra HTML puro (vanilla/CRA/Astro): injeta `<script src=".../holdy.iife.js">` no `<head>` direto — sem npm install
52
+ 4. Em todos os casos: chama `Holdy.init({ apiKey, accountId?, autoCapture: true })` com seus valores
53
+
54
+ ## Saída esperada
55
+
56
+ ```
57
+ Holdy · behavioral operating layer
58
+
59
+ [1] Detectando seu projeto…
60
+ framework: next-app → app/layout.tsx
61
+ [2] Aplicando snippet no(s) arquivo(s)…
62
+ ✓ Patched app/layout.tsx + criado app/holdy-script.tsx
63
+ [3] Falta instalar o pacote npm:
64
+
65
+ npm install @holdyapp/sdk
66
+
67
+ [4] Pronto! Inicie o app e abra o widget de status em app.holdy.com.br
68
+ ```
69
+
70
+ ## Licença
71
+
72
+ MIT
package/dist/cli.js ADDED
@@ -0,0 +1,566 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ // src/cli.ts
5
+ var import_node_fs3 = require("node:fs");
6
+ var import_node_readline = require("node:readline");
7
+ var import_node_path3 = require("node:path");
8
+
9
+ // src/detect.ts
10
+ var import_node_fs = require("node:fs");
11
+ var import_node_path = require("node:path");
12
+ function detectFramework(cwd) {
13
+ const pkgPath = (0, import_node_path.join)(cwd, "package.json");
14
+ if (!(0, import_node_fs.existsSync)(pkgPath)) {
15
+ return detectVanilla(cwd);
16
+ }
17
+ let pkg;
18
+ try {
19
+ pkg = JSON.parse((0, import_node_fs.readFileSync)(pkgPath, "utf8"));
20
+ } catch {
21
+ return { framework: "unknown", targetFile: null, usePackage: false };
22
+ }
23
+ const deps = { ...pkg.dependencies ?? {}, ...pkg.devDependencies ?? {} };
24
+ if (deps["next"]) {
25
+ const appLayoutTs = pick(cwd, ["app/layout.tsx", "app/layout.jsx", "src/app/layout.tsx", "src/app/layout.jsx"]);
26
+ if (appLayoutTs) return { framework: "next-app", targetFile: appLayoutTs, usePackage: true };
27
+ const pagesApp = pick(cwd, ["pages/_app.tsx", "pages/_app.jsx", "pages/_app.ts", "pages/_app.js", "src/pages/_app.tsx"]);
28
+ if (pagesApp) return { framework: "next-pages", targetFile: pagesApp, usePackage: true };
29
+ return { framework: "next-app", targetFile: (0, import_node_path.join)(cwd, "app/layout.tsx"), usePackage: true };
30
+ }
31
+ if (deps["nuxt"] || deps["nuxt3"]) {
32
+ return { framework: "nuxt", targetFile: (0, import_node_path.join)(cwd, "plugins/holdy.client.ts"), usePackage: true };
33
+ }
34
+ if (deps["@remix-run/react"] || deps["@remix-run/node"]) {
35
+ const root = pick(cwd, ["app/root.tsx", "app/root.jsx"]);
36
+ return { framework: "remix", targetFile: root ?? (0, import_node_path.join)(cwd, "app/root.tsx"), usePackage: true };
37
+ }
38
+ if (deps["astro"]) {
39
+ const layout = pick(cwd, ["src/layouts/Layout.astro", "src/layouts/BaseLayout.astro"]);
40
+ return { framework: "astro", targetFile: layout, usePackage: false };
41
+ }
42
+ if (deps["vite"]) {
43
+ if (deps["vue"]) {
44
+ const main3 = pick(cwd, ["src/main.ts", "src/main.js"]);
45
+ return { framework: "vite-vue", targetFile: main3, usePackage: true };
46
+ }
47
+ if (deps["svelte"]) {
48
+ const main3 = pick(cwd, ["src/main.ts", "src/main.js"]);
49
+ return { framework: "vite-svelte", targetFile: main3, usePackage: true };
50
+ }
51
+ const main2 = pick(cwd, ["src/main.tsx", "src/main.jsx", "src/main.ts", "src/main.js"]);
52
+ return { framework: "vite-react", targetFile: main2, usePackage: true };
53
+ }
54
+ if (deps["react-scripts"]) {
55
+ const indexHtml = pick(cwd, ["public/index.html"]);
56
+ return { framework: "react-cra", targetFile: indexHtml, usePackage: false };
57
+ }
58
+ if (deps["@angular/core"]) {
59
+ const main2 = pick(cwd, ["src/main.ts", "src/main.js"]);
60
+ return { framework: "angular", targetFile: main2, usePackage: true };
61
+ }
62
+ if (deps["vue"]) {
63
+ const main2 = pick(cwd, ["src/main.js", "src/main.ts"]);
64
+ return { framework: "vite-vue", targetFile: main2, usePackage: true };
65
+ }
66
+ return detectVanilla(cwd);
67
+ }
68
+ function detectVanilla(cwd) {
69
+ const html = pick(cwd, ["index.html", "public/index.html", "src/index.html"]);
70
+ if (html) return { framework: "vanilla", targetFile: html, usePackage: false };
71
+ return { framework: "unknown", targetFile: null, usePackage: false };
72
+ }
73
+ function pick(cwd, candidates) {
74
+ for (const c of candidates) {
75
+ const abs = (0, import_node_path.join)(cwd, c);
76
+ if ((0, import_node_fs.existsSync)(abs)) return abs;
77
+ }
78
+ return null;
79
+ }
80
+
81
+ // src/inject.ts
82
+ var import_node_fs2 = require("node:fs");
83
+ var import_node_path2 = require("node:path");
84
+ var HOLDY_MARKER = "holdy-installed-by-cli";
85
+ var CDN_URL = "https://app.holdy.com.br/sdk/v0/holdy.iife.js";
86
+ function inject(detection, opts) {
87
+ switch (detection.framework) {
88
+ case "next-app":
89
+ return injectNextApp(detection.targetFile, opts);
90
+ case "next-pages":
91
+ return injectNextPages(detection.targetFile, opts);
92
+ case "vite-react":
93
+ return injectViteReact(detection.targetFile, opts);
94
+ case "vite-vue":
95
+ return injectViteVue(detection.targetFile, opts);
96
+ case "vite-svelte":
97
+ return injectViteReact(detection.targetFile, opts);
98
+ case "nuxt":
99
+ return injectNuxt(detection.targetFile, opts);
100
+ case "remix":
101
+ return injectRemix(detection.targetFile, opts);
102
+ case "astro":
103
+ return injectHtmlOrAstro(detection.targetFile, opts);
104
+ case "react-cra":
105
+ return injectHtml(detection.targetFile, opts);
106
+ case "angular":
107
+ return injectAngular(detection.targetFile, opts);
108
+ case "vanilla":
109
+ return injectHtml(detection.targetFile, opts);
110
+ default:
111
+ return {
112
+ ok: false,
113
+ modified: false,
114
+ file: null,
115
+ message: "N\xE3o consegui detectar seu framework \xB7 cole o snippet manualmente:",
116
+ manualSnippet: buildScriptSnippet(opts)
117
+ };
118
+ }
119
+ }
120
+ function injectNextApp(file, opts) {
121
+ const dir = (0, import_node_path2.dirname)(file);
122
+ const scriptPath = `${dir}/holdy-script.tsx`;
123
+ const scriptRel = "./holdy-script";
124
+ if ((0, import_node_fs2.existsSync)(scriptPath)) {
125
+ return { ok: true, modified: false, file: scriptPath, message: "Holdy j\xE1 instalado (componente holdy-script.tsx existe)" };
126
+ }
127
+ ensureDir(scriptPath);
128
+ (0, import_node_fs2.writeFileSync)(scriptPath, buildHoldyScriptComponent(opts));
129
+ if (!(0, import_node_fs2.existsSync)(file)) {
130
+ ensureDir(file);
131
+ (0, import_node_fs2.writeFileSync)(file, buildMinimalLayout(scriptRel));
132
+ return {
133
+ ok: true,
134
+ modified: true,
135
+ file,
136
+ message: `Criado ${displayPath(file)} + ${displayPath(scriptPath)}`
137
+ };
138
+ }
139
+ const original = (0, import_node_fs2.readFileSync)(file, "utf8");
140
+ if (original.includes(HOLDY_MARKER) || original.includes("from './holdy-script'") || original.includes("HoldyScript")) {
141
+ return { ok: true, modified: false, file, message: "Holdy j\xE1 referenciado no layout \xB7 skip" };
142
+ }
143
+ let patched = original;
144
+ patched = addImport(patched, `import { HoldyScript } from '${scriptRel}' // ${HOLDY_MARKER}`);
145
+ const bodyMatch = patched.match(/<body[^>]*>/);
146
+ if (bodyMatch && bodyMatch.index !== void 0) {
147
+ const insertAt = bodyMatch.index + bodyMatch[0].length;
148
+ patched = patched.slice(0, insertAt) + "\n <HoldyScript />" + patched.slice(insertAt);
149
+ } else {
150
+ return {
151
+ ok: false,
152
+ modified: false,
153
+ file,
154
+ message: `N\xE3o achei <body> em ${displayPath(file)} pra injetar. Cole manualmente:`,
155
+ manualSnippet: `import { HoldyScript } from '${scriptRel}'
156
+ // dentro de <body>:
157
+ <HoldyScript />`
158
+ };
159
+ }
160
+ (0, import_node_fs2.writeFileSync)(file, patched);
161
+ return { ok: true, modified: true, file, message: `Patched ${displayPath(file)} + criado ${displayPath(scriptPath)}` };
162
+ }
163
+ function buildHoldyScriptComponent(opts) {
164
+ return `'use client'
165
+
166
+ /**
167
+ * Holdy SDK loader \xB7 gerado por @holdyapp/install ${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}.
168
+ * Edite livremente \xB7 o init pode crescer pra incluir identify() do user logado.
169
+ */
170
+
171
+ import { useEffect } from 'react'
172
+
173
+ declare global {
174
+ interface Window {
175
+ Holdy?: {
176
+ init: (opts: Record<string, unknown>) => void
177
+ identify: (opts: Record<string, unknown>) => void
178
+ track: (primitive: string, payload?: Record<string, unknown>) => void
179
+ }
180
+ }
181
+ }
182
+
183
+ export function HoldyScript() {
184
+ useEffect(() => {
185
+ if (typeof window === 'undefined' || window.Holdy) return
186
+ const s = document.createElement('script')
187
+ s.src = '${CDN_URL}'
188
+ s.async = true
189
+ s.onload = () => {
190
+ window.Holdy?.init({
191
+ apiKey: '${opts.apiKey}',
192
+ ${opts.accountId ? `accountId: '${opts.accountId}',
193
+ ` : ""}autoCapture: ${opts.autoCapture},
194
+ })
195
+ }
196
+ document.head.appendChild(s)
197
+ }, [])
198
+ return null
199
+ }
200
+ `;
201
+ }
202
+ function buildMinimalLayout(scriptRel) {
203
+ return `import { HoldyScript } from '${scriptRel}' // ${HOLDY_MARKER}
204
+
205
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
206
+ return (
207
+ <html lang="pt-BR">
208
+ <body>
209
+ <HoldyScript />
210
+ {children}
211
+ </body>
212
+ </html>
213
+ )
214
+ }
215
+ `;
216
+ }
217
+ function injectNextPages(file, opts) {
218
+ if (!(0, import_node_fs2.existsSync)(file)) {
219
+ return {
220
+ ok: false,
221
+ modified: false,
222
+ file,
223
+ message: `${displayPath(file)} n\xE3o encontrado \xB7 cole snippet manualmente:`,
224
+ manualSnippet: buildEsImportSnippet(opts)
225
+ };
226
+ }
227
+ const original = (0, import_node_fs2.readFileSync)(file, "utf8");
228
+ if (original.includes(HOLDY_MARKER) || original.includes("@holdyapp/sdk")) {
229
+ return { ok: true, modified: false, file, message: "Holdy j\xE1 presente no _app \xB7 skip" };
230
+ }
231
+ let patched = addImport(original, `import { Holdy } from '@holdyapp/sdk' // ${HOLDY_MARKER}`);
232
+ patched = patched.replace(
233
+ /export default function (\w+)\([^)]*\)\s*\{/,
234
+ (match) => `${match}
235
+ if (typeof window !== 'undefined' && !window.__holdyInit) { Holdy.init({ apiKey: '${opts.apiKey}', ${opts.accountId ? `accountId: '${opts.accountId}', ` : ""}autoCapture: ${opts.autoCapture} }); (window as unknown as { __holdyInit?: boolean }).__holdyInit = true }`
236
+ );
237
+ (0, import_node_fs2.writeFileSync)(file, patched);
238
+ return { ok: true, modified: true, file, message: `Patched ${displayPath(file)} \xB7 rode npm install @holdyapp/sdk` };
239
+ }
240
+ function injectViteReact(file, opts) {
241
+ if (!file || !(0, import_node_fs2.existsSync)(file)) {
242
+ return {
243
+ ok: false,
244
+ modified: false,
245
+ file,
246
+ message: "Entry file n\xE3o encontrado \xB7 cole snippet em src/main.tsx:",
247
+ manualSnippet: buildEsImportSnippet(opts)
248
+ };
249
+ }
250
+ const original = (0, import_node_fs2.readFileSync)(file, "utf8");
251
+ if (original.includes(HOLDY_MARKER) || original.includes("@holdyapp/sdk")) {
252
+ return { ok: true, modified: false, file, message: "Holdy j\xE1 presente no entry \xB7 skip" };
253
+ }
254
+ const patched = `import { Holdy } from '@holdyapp/sdk' // ${HOLDY_MARKER}
255
+ Holdy.init({ apiKey: '${opts.apiKey}', ${opts.accountId ? `accountId: '${opts.accountId}', ` : ""}autoCapture: ${opts.autoCapture} })
256
+
257
+ ${original}`;
258
+ (0, import_node_fs2.writeFileSync)(file, patched);
259
+ return { ok: true, modified: true, file, message: `Patched ${displayPath(file)} \xB7 rode npm install @holdyapp/sdk` };
260
+ }
261
+ function injectViteVue(file, opts) {
262
+ return injectViteReact(file, opts);
263
+ }
264
+ function injectNuxt(file, opts) {
265
+ if ((0, import_node_fs2.existsSync)(file)) {
266
+ return { ok: true, modified: false, file, message: `Plugin Holdy j\xE1 existe em ${displayPath(file)}` };
267
+ }
268
+ ensureDir(file);
269
+ const content = `// ${HOLDY_MARKER}
270
+ import { Holdy } from '@holdyapp/sdk'
271
+
272
+ export default defineNuxtPlugin(() => {
273
+ Holdy.init({
274
+ apiKey: '${opts.apiKey}',
275
+ ${opts.accountId ? `accountId: '${opts.accountId}',
276
+ ` : ""}autoCapture: ${opts.autoCapture},
277
+ })
278
+ })
279
+ `;
280
+ (0, import_node_fs2.writeFileSync)(file, content);
281
+ return { ok: true, modified: true, file, message: `Criado ${displayPath(file)} \xB7 rode npm install @holdyapp/sdk` };
282
+ }
283
+ function injectRemix(file, opts) {
284
+ if (!file || !(0, import_node_fs2.existsSync)(file)) {
285
+ return {
286
+ ok: false,
287
+ modified: false,
288
+ file,
289
+ message: "app/root.tsx n\xE3o encontrado \xB7 cole snippet manualmente:",
290
+ manualSnippet: buildEsImportSnippet(opts)
291
+ };
292
+ }
293
+ return injectViteReact(file, opts);
294
+ }
295
+ function injectAngular(file, opts) {
296
+ return injectViteReact(file, opts);
297
+ }
298
+ function injectHtml(file, opts) {
299
+ if (!file || !(0, import_node_fs2.existsSync)(file)) {
300
+ return {
301
+ ok: false,
302
+ modified: false,
303
+ file,
304
+ message: "index.html n\xE3o encontrado \xB7 cole no <head> do seu HTML:",
305
+ manualSnippet: buildScriptSnippet(opts)
306
+ };
307
+ }
308
+ const original = (0, import_node_fs2.readFileSync)(file, "utf8");
309
+ if (original.includes(HOLDY_MARKER) || original.includes(CDN_URL)) {
310
+ return { ok: true, modified: false, file, message: `${displayPath(file)} j\xE1 tem Holdy \xB7 skip` };
311
+ }
312
+ const snippet = `
313
+ <!-- ${HOLDY_MARKER} -->
314
+ ${buildScriptSnippet(opts).split("\n").join("\n ")}
315
+ `;
316
+ const headEnd = original.search(/<\/head>/i);
317
+ if (headEnd === -1) {
318
+ return {
319
+ ok: false,
320
+ modified: false,
321
+ file,
322
+ message: "N\xE3o achei </head> \xB7 cole manualmente antes:",
323
+ manualSnippet: buildScriptSnippet(opts)
324
+ };
325
+ }
326
+ const patched = original.slice(0, headEnd) + snippet + original.slice(headEnd);
327
+ (0, import_node_fs2.writeFileSync)(file, patched);
328
+ return { ok: true, modified: true, file, message: `Patched ${displayPath(file)}` };
329
+ }
330
+ function injectHtmlOrAstro(file, opts) {
331
+ if (!file) {
332
+ return {
333
+ ok: false,
334
+ modified: false,
335
+ file,
336
+ message: "N\xE3o achei layout Astro \xB7 cole no <head>:",
337
+ manualSnippet: buildScriptSnippet(opts)
338
+ };
339
+ }
340
+ return injectHtml(file, opts);
341
+ }
342
+ function buildScriptSnippet(opts) {
343
+ const accountLine = opts.accountId ? `
344
+ accountId: '${opts.accountId}',` : "";
345
+ return `<script src="${CDN_URL}"></script>
346
+ <script>
347
+ Holdy.init({
348
+ apiKey: '${opts.apiKey}',${accountLine}
349
+ autoCapture: ${opts.autoCapture},
350
+ })
351
+ </script>`;
352
+ }
353
+ function buildEsImportSnippet(opts) {
354
+ const accountLine = opts.accountId ? `
355
+ accountId: '${opts.accountId}',` : "";
356
+ return `import { Holdy } from '@holdyapp/sdk'
357
+
358
+ Holdy.init({
359
+ apiKey: '${opts.apiKey}',${accountLine}
360
+ autoCapture: ${opts.autoCapture},
361
+ })`;
362
+ }
363
+ function addImport(source, importLine) {
364
+ const importRegex = /^import .+$/gm;
365
+ let lastMatch = null;
366
+ let m;
367
+ while ((m = importRegex.exec(source)) !== null) {
368
+ lastMatch = m;
369
+ }
370
+ if (lastMatch) {
371
+ const insertAt = lastMatch.index + lastMatch[0].length;
372
+ return source.slice(0, insertAt) + "\n" + importLine + source.slice(insertAt);
373
+ }
374
+ return importLine + "\n" + source;
375
+ }
376
+ function ensureDir(filePath) {
377
+ const dir = (0, import_node_path2.dirname)(filePath);
378
+ if (!(0, import_node_fs2.existsSync)(dir)) (0, import_node_fs2.mkdirSync)(dir, { recursive: true });
379
+ }
380
+ function displayPath(p) {
381
+ return p.replace(process.cwd() + "/", "");
382
+ }
383
+
384
+ // src/cli.ts
385
+ var VERSION = "0.1.0";
386
+ async function main() {
387
+ const argv = process.argv.slice(2);
388
+ const cwd = process.cwd();
389
+ if (argv.includes("--help") || argv.includes("-h")) {
390
+ printHelp();
391
+ process.exit(0);
392
+ }
393
+ if (argv.includes("--version") || argv.includes("-v")) {
394
+ console.log(VERSION);
395
+ process.exit(0);
396
+ }
397
+ const args = parseArgs(argv);
398
+ log.banner();
399
+ log.step("1", "Detectando seu projeto\u2026");
400
+ const detection = detectFramework(cwd);
401
+ log.detection(detection);
402
+ if (detection.framework === "unknown") {
403
+ log.warn('N\xE3o consegui identificar o framework. Sigo no modo "vanilla" (script tag).');
404
+ }
405
+ let apiKey = args.apiKey;
406
+ if (!apiKey) {
407
+ apiKey = await promptApiKey();
408
+ }
409
+ if (!apiKey || !apiKey.startsWith("hol_")) {
410
+ log.error("API key inv\xE1lida. Use formato hol_live_\u2026 ou hol_test_\u2026 \xB7 gere em app.holdy.com.br/settings.");
411
+ process.exit(1);
412
+ }
413
+ log.step("2", "Aplicando snippet no(s) arquivo(s)\u2026");
414
+ const result = inject(detection, {
415
+ apiKey,
416
+ accountId: args.accountId,
417
+ autoCapture: args.autoCapture
418
+ });
419
+ if (result.ok) {
420
+ if (result.modified) {
421
+ log.success(result.message);
422
+ } else {
423
+ log.info(result.message);
424
+ }
425
+ } else {
426
+ log.error(result.message);
427
+ if (result.manualSnippet) {
428
+ console.log();
429
+ console.log(result.manualSnippet);
430
+ console.log();
431
+ }
432
+ process.exit(2);
433
+ }
434
+ if (detection.usePackage) {
435
+ log.step("3", "Falta instalar o pacote npm:");
436
+ console.log();
437
+ console.log(" npm install @holdyapp/sdk");
438
+ console.log();
439
+ } else {
440
+ log.step("3", "Sem npm install necess\xE1rio \xB7 script tag via CDN.");
441
+ }
442
+ log.step("4", 'Pronto! Inicie o app e abra o widget de status em app.holdy.com.br \xB7 voc\xEA deve ver "conectado" em segundos.');
443
+ process.exit(0);
444
+ }
445
+ function parseArgs(argv) {
446
+ const out = { apiKey: null, accountId: void 0, autoCapture: true };
447
+ for (let i = 0; i < argv.length; i++) {
448
+ const a = argv[i];
449
+ if (a === "--account" || a === "--account-id") {
450
+ out.accountId = argv[++i];
451
+ } else if (a === "--no-auto-capture") {
452
+ out.autoCapture = false;
453
+ } else if (a === "--auto-capture") {
454
+ out.autoCapture = true;
455
+ } else if (!a.startsWith("--") && !out.apiKey) {
456
+ out.apiKey = a;
457
+ }
458
+ }
459
+ if (!out.apiKey && process.env.HOLDY_API_KEY) {
460
+ out.apiKey = process.env.HOLDY_API_KEY;
461
+ }
462
+ return out;
463
+ }
464
+ function promptApiKey() {
465
+ return new Promise((resolve) => {
466
+ const rl = (0, import_node_readline.createInterface)({ input: process.stdin, output: process.stdout });
467
+ rl.question(`${dim("API key")} (hol_live_\u2026 ou hol_test_\u2026): `, (answer) => {
468
+ rl.close();
469
+ resolve(answer.trim());
470
+ });
471
+ });
472
+ }
473
+ function printHelp() {
474
+ const isLive = readPackageName();
475
+ console.log(`
476
+ ${bold("@holdyapp/install")} v${VERSION} \xB7 ${isLive ?? "Holdy SDK installer"}
477
+
478
+ ${bold("Uso:")}
479
+ npx @holdyapp/install <apiKey> [op\xE7\xF5es]
480
+ npx @holdyapp/install # modo interativo
481
+ HOLDY_API_KEY=hol_live_\u2026 npx @holdyapp/install # via env var
482
+
483
+ ${bold("Argumentos:")}
484
+ apiKey Token Holdy (hol_live_\u2026 ou hol_test_\u2026)
485
+
486
+ ${bold("Op\xE7\xF5es:")}
487
+ --account <id> Account ID padr\xE3o (vai pro Holdy.init)
488
+ --no-auto-capture Desabilita captura autom\xE1tica de page views
489
+ --version, -v Mostra vers\xE3o
490
+ --help, -h Mostra esta mensagem
491
+
492
+ ${bold("Frameworks suportados:")}
493
+ Next.js (App + Pages Router) \xB7 Vite (React/Vue/Svelte) \xB7 Nuxt \xB7 Remix
494
+ Astro \xB7 CRA \xB7 Angular \xB7 vanilla HTML
495
+
496
+ ${bold("Exemplos:")}
497
+ npx @holdyapp/install hol_live_abc123 --account acme-corp
498
+ npx @holdyapp/install hol_test_xyz789 --no-auto-capture
499
+ `);
500
+ }
501
+ function readPackageName() {
502
+ try {
503
+ const pkg = JSON.parse((0, import_node_fs3.readFileSync)((0, import_node_path3.join)(__dirname, "..", "package.json"), "utf8"));
504
+ return pkg.description ?? null;
505
+ } catch {
506
+ return null;
507
+ }
508
+ }
509
+ var COLORS = {
510
+ reset: "\x1B[0m",
511
+ bold: "\x1B[1m",
512
+ dim: "\x1B[2m",
513
+ cyan: "\x1B[36m",
514
+ green: "\x1B[32m",
515
+ red: "\x1B[31m",
516
+ yellow: "\x1B[33m"
517
+ };
518
+ function bold(s) {
519
+ return `${COLORS.bold}${s}${COLORS.reset}`;
520
+ }
521
+ function dim(s) {
522
+ return `${COLORS.dim}${s}${COLORS.reset}`;
523
+ }
524
+ function cyan(s) {
525
+ return `${COLORS.cyan}${s}${COLORS.reset}`;
526
+ }
527
+ function green(s) {
528
+ return `${COLORS.green}${s}${COLORS.reset}`;
529
+ }
530
+ function red(s) {
531
+ return `${COLORS.red}${s}${COLORS.reset}`;
532
+ }
533
+ function yellow(s) {
534
+ return `${COLORS.yellow}${s}${COLORS.reset}`;
535
+ }
536
+ var log = {
537
+ banner() {
538
+ console.log();
539
+ console.log(` ${bold("Holdy")} ${dim("\xB7 behavioral operating layer")}`);
540
+ console.log();
541
+ },
542
+ step(n, msg) {
543
+ console.log(` ${cyan(`[${n}]`)} ${msg}`);
544
+ },
545
+ detection(d) {
546
+ const label = d.framework === "unknown" ? "?" : d.framework;
547
+ const file = d.targetFile ? dim(` \u2192 ${d.targetFile.replace(process.cwd() + "/", "")}`) : "";
548
+ console.log(` ${dim("framework:")} ${bold(label)}${file}`);
549
+ },
550
+ success(msg) {
551
+ console.log(` ${green("\u2713")} ${msg}`);
552
+ },
553
+ info(msg) {
554
+ console.log(` ${dim("\xB7")} ${msg}`);
555
+ },
556
+ warn(msg) {
557
+ console.log(` ${yellow("!")} ${msg}`);
558
+ },
559
+ error(msg) {
560
+ console.log(` ${red("\u2717")} ${msg}`);
561
+ }
562
+ };
563
+ main().catch((err) => {
564
+ console.error(red("[holdy-install] erro inesperado:"), err instanceof Error ? err.message : err);
565
+ process.exit(1);
566
+ });
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@holdyapp/install",
3
+ "version": "0.1.0",
4
+ "description": "Holdy install CLI · detects your framework and wires the SDK in 1 step",
5
+ "license": "MIT",
6
+ "homepage": "https://app.holdy.com.br",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/augustoperolligaedke/holdymvp.git",
10
+ "directory": "packages/install-cli"
11
+ },
12
+ "bin": {
13
+ "holdy-install": "./dist/cli.js"
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "scripts": {
21
+ "build": "node build.mjs",
22
+ "type-check": "tsc --noEmit",
23
+ "prepublishOnly": "npm run build"
24
+ },
25
+ "engines": {
26
+ "node": ">=18"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^20.0.0",
30
+ "esbuild": "^0.25.0",
31
+ "typescript": "^5.9.0"
32
+ },
33
+ "keywords": [
34
+ "holdy",
35
+ "cli",
36
+ "install",
37
+ "onboarding"
38
+ ],
39
+ "publishConfig": {
40
+ "access": "public"
41
+ }
42
+ }