@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.
- package/dist/index.js +31 -56
- 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
|
-
|
|
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
|
}
|