@eyeglass/cli 0.1.1 → 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.
Files changed (2) hide show
  1. package/dist/index.js +31 -56
  2. package/package.json +1 -1
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
- const isTs = configFile.endsWith('.ts');
203
- const pluginFile = path.join(cwd, isTs ? 'eyeglass.plugin.ts' : 'eyeglass.plugin.js');
204
- // Create plugin file
205
- if (!fileExists(pluginFile)) {
206
- if (dryRun) {
207
- log(`Would create ${path.basename(pluginFile)}`);
208
- }
209
- else {
210
- writeFile(pluginFile, VITE_PLUGIN);
211
- log(`Created ${path.basename(pluginFile)}`, 'success');
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
- // Modify vite.config
215
- const config = readFile(configFile);
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 modify ${path.basename(configFile)} to add eyeglassPlugin()`);
221
+ log(`Would add inspector import to ${path.relative(cwd, entryFile)}`);
247
222
  }
248
223
  else {
249
- writeFile(configFile, newConfig);
250
- log(`Updated ${path.basename(configFile)} with eyeglass plugin`, 'success');
224
+ writeFile(entryFile, newContent);
225
+ log(`Added inspector import to ${path.relative(cwd, entryFile)}`, 'success');
251
226
  }
252
227
  return true;
253
228
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eyeglass/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Visual debugging for AI coding agents - CLI",
5
5
  "type": "module",
6
6
  "bin": {