@eyeglass/cli 0.1.0 → 0.1.2
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 +41 -0
- package/dist/index.js +31 -56
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# @eyeglass/cli
|
|
2
|
+
|
|
3
|
+
CLI for initializing [Eyeglass](https://github.com/donutboyband/eyeglass) in your project.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx @eyeglass/cli init
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This single command will:
|
|
12
|
+
|
|
13
|
+
1. **Install** `@eyeglass/inspector` as a dev dependency
|
|
14
|
+
2. **Create** `.claude/settings.json` with MCP server configuration
|
|
15
|
+
3. **Configure** your bundler (Vite, Next.js, CRA, or Remix)
|
|
16
|
+
|
|
17
|
+
## Options
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx @eyeglass/cli init --dry-run # Preview changes without making them
|
|
21
|
+
npx @eyeglass/cli init --skip-install # Skip installing @eyeglass/inspector
|
|
22
|
+
npx @eyeglass/cli help # Show help
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Supported Frameworks
|
|
26
|
+
|
|
27
|
+
| Framework | Auto-Detection | Component Names | File Paths |
|
|
28
|
+
|-----------|:--------------:|:---------------:|:----------:|
|
|
29
|
+
| Vite | ✓ | ✓ | ✓ |
|
|
30
|
+
| Next.js | ✓ | ✓ | ✓ |
|
|
31
|
+
| CRA | ✓ | ✓ | ✓ |
|
|
32
|
+
| Remix | ✓ | ✓ | ✓ |
|
|
33
|
+
|
|
34
|
+
## After Setup
|
|
35
|
+
|
|
36
|
+
1. Start your dev server (`npm run dev`)
|
|
37
|
+
2. Run `claude` in your project directory
|
|
38
|
+
3. Tell Claude: `watch eyeglass` or `eg`
|
|
39
|
+
4. Select elements in your browser and submit requests!
|
|
40
|
+
|
|
41
|
+
See the [main repo](https://github.com/donutboyband/eyeglass) for full documentation.
|
package/dist/index.js
CHANGED
|
@@ -5,20 +5,6 @@ import { execFileSync } from 'child_process';
|
|
|
5
5
|
// ============================================================================
|
|
6
6
|
// Templates
|
|
7
7
|
// ============================================================================
|
|
8
|
-
const VITE_PLUGIN = `// Eyeglass Vite Plugin - Auto-generated by eyeglass init
|
|
9
|
-
export function eyeglassPlugin() {
|
|
10
|
-
return {
|
|
11
|
-
name: 'eyeglass',
|
|
12
|
-
transformIndexHtml(html) {
|
|
13
|
-
if (process.env.NODE_ENV === 'production') return html;
|
|
14
|
-
return html.replace(
|
|
15
|
-
'</body>',
|
|
16
|
-
'<script type="module">import "@eyeglass/inspector";</script></body>'
|
|
17
|
-
);
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
`;
|
|
22
8
|
const NEXT_CONFIG_ADDITION = `
|
|
23
9
|
// Eyeglass configuration - Auto-generated by eyeglass init
|
|
24
10
|
const withEyeglass = (nextConfig) => {
|
|
@@ -199,55 +185,44 @@ function setupClaudeConfig(dryRun) {
|
|
|
199
185
|
}
|
|
200
186
|
function setupVite(configFile, dryRun) {
|
|
201
187
|
const cwd = process.cwd();
|
|
202
|
-
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
188
|
+
// Find entry file (main.tsx, main.ts, main.jsx, main.js, src/main.*, etc.)
|
|
189
|
+
const entryFiles = [
|
|
190
|
+
'src/main.tsx',
|
|
191
|
+
'src/main.ts',
|
|
192
|
+
'src/main.jsx',
|
|
193
|
+
'src/main.js',
|
|
194
|
+
'main.tsx',
|
|
195
|
+
'main.ts',
|
|
196
|
+
'main.jsx',
|
|
197
|
+
'main.js',
|
|
198
|
+
];
|
|
199
|
+
let entryFile = null;
|
|
200
|
+
for (const entry of entryFiles) {
|
|
201
|
+
const fullPath = path.join(cwd, entry);
|
|
202
|
+
if (fileExists(fullPath)) {
|
|
203
|
+
entryFile = fullPath;
|
|
204
|
+
break;
|
|
212
205
|
}
|
|
213
206
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
// Check if already configured
|
|
217
|
-
if (config.includes('eyeglassPlugin')) {
|
|
218
|
-
log('Vite config already has eyeglass plugin', 'success');
|
|
219
|
-
return true;
|
|
220
|
-
}
|
|
221
|
-
// Add import
|
|
222
|
-
const importStatement = `import { eyeglassPlugin } from './eyeglass.plugin';\n`;
|
|
223
|
-
let newConfig = config;
|
|
224
|
-
// Find a good place to add the import (after other imports or at the top)
|
|
225
|
-
const lastImportMatch = config.match(/^import .+$/gm);
|
|
226
|
-
if (lastImportMatch) {
|
|
227
|
-
const lastImport = lastImportMatch[lastImportMatch.length - 1];
|
|
228
|
-
const lastImportIndex = config.lastIndexOf(lastImport) + lastImport.length;
|
|
229
|
-
newConfig = config.slice(0, lastImportIndex) + '\n' + importStatement + config.slice(lastImportIndex);
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
newConfig = importStatement + config;
|
|
233
|
-
}
|
|
234
|
-
// Add to plugins array
|
|
235
|
-
// This handles: plugins: [...] or plugins: [react(), ...]
|
|
236
|
-
const pluginsMatch = newConfig.match(/plugins\s*:\s*\[/);
|
|
237
|
-
if (pluginsMatch) {
|
|
238
|
-
const insertPos = newConfig.indexOf(pluginsMatch[0]) + pluginsMatch[0].length;
|
|
239
|
-
newConfig = newConfig.slice(0, insertPos) + 'eyeglassPlugin(), ' + newConfig.slice(insertPos);
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
log('Could not find plugins array in vite config - please add eyeglassPlugin() manually', 'warn');
|
|
207
|
+
if (!entryFile) {
|
|
208
|
+
log('Could not find entry file - please import @eyeglass/inspector manually in your main file', 'warn');
|
|
243
209
|
return false;
|
|
244
210
|
}
|
|
211
|
+
const content = readFile(entryFile);
|
|
212
|
+
// Check if already imported
|
|
213
|
+
if (content.includes('@eyeglass/inspector')) {
|
|
214
|
+
log('Inspector already imported', 'success');
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
// Add import at the top
|
|
218
|
+
const importStatement = `import '@eyeglass/inspector';\n`;
|
|
219
|
+
const newContent = importStatement + content;
|
|
245
220
|
if (dryRun) {
|
|
246
|
-
log(`Would
|
|
221
|
+
log(`Would add inspector import to ${path.relative(cwd, entryFile)}`);
|
|
247
222
|
}
|
|
248
223
|
else {
|
|
249
|
-
writeFile(
|
|
250
|
-
log(`
|
|
224
|
+
writeFile(entryFile, newContent);
|
|
225
|
+
log(`Added inspector import to ${path.relative(cwd, entryFile)}`, 'success');
|
|
251
226
|
}
|
|
252
227
|
return true;
|
|
253
228
|
}
|