@jwiedeman/gtm-kit-cli 1.0.1

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/README.md ADDED
@@ -0,0 +1,263 @@
1
+ # @react-gtm-kit/cli
2
+
3
+ [![CI](https://github.com/jwiedeman/react-gtm-kit/actions/workflows/ci.yml/badge.svg)](https://github.com/jwiedeman/react-gtm-kit/actions/workflows/ci.yml)
4
+ [![Coverage](https://codecov.io/gh/jwiedeman/react-gtm-kit/graph/badge.svg?flag=cli)](https://codecov.io/gh/jwiedeman/react-gtm-kit)
5
+ [![npm version](https://img.shields.io/npm/v/@react-gtm-kit/cli.svg)](https://www.npmjs.com/package/@react-gtm-kit/cli)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
+ [![Node.js](https://img.shields.io/badge/Node.js-18+-339933.svg?logo=node.js)](https://nodejs.org/)
9
+
10
+ **Zero-config GTM Kit setup. Auto-detects your framework. Installs everything you need.**
11
+
12
+ The CLI tool for GTM Kit - get up and running in under 60 seconds.
13
+
14
+ ---
15
+
16
+ ## Quick Start
17
+
18
+ ```bash
19
+ npx @react-gtm-kit/cli init
20
+ ```
21
+
22
+ That's it. The CLI will:
23
+
24
+ 1. Detect your framework (React, Vue, Next.js, Nuxt, etc.)
25
+ 2. Detect your package manager (npm, yarn, pnpm, bun)
26
+ 3. Install the right packages
27
+ 4. Generate setup code for your project
28
+ 5. Optionally configure Consent Mode v2
29
+
30
+ ---
31
+
32
+ ## Commands
33
+
34
+ ### `init` - Interactive Setup
35
+
36
+ ```bash
37
+ npx @react-gtm-kit/cli init
38
+ ```
39
+
40
+ Walks you through the complete setup with prompts for:
41
+ - GTM container ID
42
+ - Consent Mode v2 configuration
43
+ - File locations
44
+
45
+ ### `init <GTM-ID>` - Quick Setup
46
+
47
+ ```bash
48
+ npx @react-gtm-kit/cli init GTM-XXXXXX
49
+ ```
50
+
51
+ Skip the prompts if you already know your GTM ID.
52
+
53
+ ### `detect` - Framework Detection
54
+
55
+ ```bash
56
+ npx @react-gtm-kit/cli detect
57
+ ```
58
+
59
+ Shows what framework and package manager the CLI detected.
60
+
61
+ ### `validate <GTM-ID>` - ID Validation
62
+
63
+ ```bash
64
+ npx @react-gtm-kit/cli validate GTM-XXXXXX
65
+ ```
66
+
67
+ Validates a GTM container ID format.
68
+
69
+ ### `generate <GTM-ID>` - Code Generation
70
+
71
+ ```bash
72
+ npx @react-gtm-kit/cli generate GTM-XXXXXX
73
+ ```
74
+
75
+ Generates setup code without installing packages.
76
+
77
+ ---
78
+
79
+ ## Supported Frameworks
80
+
81
+ | Framework | Detection | Priority |
82
+ |-----------|-----------|----------|
83
+ | Nuxt 3 | `nuxt.config.ts/js` | Highest |
84
+ | Next.js | `next.config.ts/js/mjs` | High |
85
+ | Vue 3 | `vue` in dependencies | Medium |
86
+ | React | `react` in dependencies | Low |
87
+ | Vanilla | Default fallback | Lowest |
88
+
89
+ The CLI uses priority order because some projects have multiple frameworks (e.g., Next.js includes React).
90
+
91
+ ---
92
+
93
+ ## Package Manager Detection
94
+
95
+ The CLI automatically detects your package manager:
96
+
97
+ | Package Manager | Detection |
98
+ |-----------------|-----------|
99
+ | pnpm | `pnpm-lock.yaml` |
100
+ | yarn | `yarn.lock` |
101
+ | bun | `bun.lockb` |
102
+ | npm | Default fallback |
103
+
104
+ ---
105
+
106
+ ## Generated Code Examples
107
+
108
+ ### React
109
+
110
+ ```tsx
111
+ // src/gtm.tsx (generated)
112
+ import { GtmProvider } from '@react-gtm-kit/react-modern';
113
+
114
+ export function GtmWrapper({ children }) {
115
+ return (
116
+ <GtmProvider config={{ containers: 'GTM-XXXXXX' }}>
117
+ {children}
118
+ </GtmProvider>
119
+ );
120
+ }
121
+ ```
122
+
123
+ ### Vue
124
+
125
+ ```ts
126
+ // src/plugins/gtm.ts (generated)
127
+ import { GtmPlugin } from '@react-gtm-kit/vue';
128
+
129
+ export function setupGtm(app) {
130
+ app.use(GtmPlugin, { containers: 'GTM-XXXXXX' });
131
+ }
132
+ ```
133
+
134
+ ### Next.js
135
+
136
+ ```tsx
137
+ // app/layout.tsx additions (generated)
138
+ import { GtmHeadScript, GtmNoScript } from '@react-gtm-kit/next';
139
+
140
+ // Add to <head>: <GtmHeadScript containers="GTM-XXXXXX" />
141
+ // Add to <body>: <GtmNoScript containers="GTM-XXXXXX" />
142
+ ```
143
+
144
+ ### Nuxt
145
+
146
+ ```ts
147
+ // plugins/gtm.client.ts (generated)
148
+ import { GtmPlugin } from '@react-gtm-kit/nuxt';
149
+
150
+ export default defineNuxtPlugin((nuxtApp) => {
151
+ nuxtApp.vueApp.use(GtmPlugin, { containers: 'GTM-XXXXXX' });
152
+ });
153
+ ```
154
+
155
+ ---
156
+
157
+ ## Options
158
+
159
+ ### `--dry-run`
160
+
161
+ Preview what would happen without making changes.
162
+
163
+ ```bash
164
+ npx @react-gtm-kit/cli init --dry-run
165
+ ```
166
+
167
+ ### `--typescript` / `--no-typescript`
168
+
169
+ Force TypeScript or JavaScript output.
170
+
171
+ ```bash
172
+ npx @react-gtm-kit/cli init --typescript
173
+ npx @react-gtm-kit/cli init --no-typescript
174
+ ```
175
+
176
+ ### `--consent`
177
+
178
+ Include Consent Mode v2 configuration.
179
+
180
+ ```bash
181
+ npx @react-gtm-kit/cli init --consent
182
+ ```
183
+
184
+ ---
185
+
186
+ ## Troubleshooting
187
+
188
+ ### "Framework not detected correctly"
189
+
190
+ The CLI checks for config files and dependencies. If detection is wrong:
191
+
192
+ ```bash
193
+ # Check what was detected
194
+ npx @react-gtm-kit/cli detect
195
+
196
+ # You can manually install the right packages
197
+ npm install @react-gtm-kit/core @react-gtm-kit/react-modern
198
+ ```
199
+
200
+ ### "Permission denied"
201
+
202
+ On Unix systems, you may need to use `npx` or install globally:
203
+
204
+ ```bash
205
+ # Use npx (recommended)
206
+ npx @react-gtm-kit/cli init
207
+
208
+ # Or install globally
209
+ npm install -g @react-gtm-kit/cli
210
+ gtm-kit init
211
+ ```
212
+
213
+ ### "Package installation failed"
214
+
215
+ If automatic installation fails:
216
+
217
+ 1. Check your internet connection
218
+ 2. Try installing manually:
219
+ ```bash
220
+ npm install @react-gtm-kit/core @react-gtm-kit/react-modern
221
+ ```
222
+ 3. Check for npm registry issues
223
+
224
+ ---
225
+
226
+ ## Programmatic Usage
227
+
228
+ ```ts
229
+ import { detectFramework, detectPackageManager, validateGtmId, generateCode } from '@react-gtm-kit/cli';
230
+
231
+ // Detect framework
232
+ const framework = await detectFramework('./my-project');
233
+ console.log(framework); // { name: 'react', confidence: 90 }
234
+
235
+ // Detect package manager
236
+ const pm = await detectPackageManager('./my-project');
237
+ console.log(pm); // 'pnpm'
238
+
239
+ // Validate GTM ID
240
+ const isValid = validateGtmId('GTM-XXXXXX');
241
+ console.log(isValid); // true
242
+
243
+ // Generate code
244
+ const code = generateCode({
245
+ framework: 'react',
246
+ gtmId: 'GTM-XXXXXX',
247
+ typescript: true,
248
+ consent: true
249
+ });
250
+ ```
251
+
252
+ ---
253
+
254
+ ## Requirements
255
+
256
+ - Node.js 18+
257
+ - npm, yarn, pnpm, or bun
258
+
259
+ ---
260
+
261
+ ## License
262
+
263
+ MIT