|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2026 Google LLC |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +import {execSync} from 'node:child_process'; |
| 8 | +import fs from 'node:fs'; |
| 9 | +import path from 'node:path'; |
| 10 | + |
| 11 | +const ROOT_DIR = process.cwd(); |
| 12 | +const LIGHTHOUSE_DIR = path.resolve(ROOT_DIR, '../lighthouse'); |
| 13 | +const DEST_PATH = path.join( |
| 14 | + ROOT_DIR, |
| 15 | + 'src/third_party/lighthouse-devtools-mcp-bundle.js', |
| 16 | +); |
| 17 | + |
| 18 | +function main() { |
| 19 | + if (!fs.existsSync(LIGHTHOUSE_DIR)) { |
| 20 | + console.error(`Lighthouse directory not found at ${LIGHTHOUSE_DIR}`); |
| 21 | + process.exit(1); |
| 22 | + } |
| 23 | + |
| 24 | + console.log('Running yarn in lighthouse directory...'); |
| 25 | + execSync('yarn', {cwd: LIGHTHOUSE_DIR, stdio: 'inherit'}); |
| 26 | + |
| 27 | + console.log('Building lighthouse-devtools-mcp bundle...'); |
| 28 | + execSync('yarn build-devtools-mcp', {cwd: LIGHTHOUSE_DIR, stdio: 'inherit'}); |
| 29 | + |
| 30 | + // Look for the bundle in dist/ or root |
| 31 | + const potentialPaths = [ |
| 32 | + path.join(LIGHTHOUSE_DIR, 'dist', 'lighthouse-devtools-mcp-bundle.js'), |
| 33 | + path.join(LIGHTHOUSE_DIR, 'lighthouse-devtools-mcp-bundle.js'), |
| 34 | + ]; |
| 35 | + |
| 36 | + let bundlePath = ''; |
| 37 | + for (const p of potentialPaths) { |
| 38 | + if (fs.existsSync(p)) { |
| 39 | + bundlePath = p; |
| 40 | + break; |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + if (!bundlePath) { |
| 45 | + console.error( |
| 46 | + `Could not find built bundle. Checked:\n${potentialPaths.join('\n')}`, |
| 47 | + ); |
| 48 | + process.exit(1); |
| 49 | + } |
| 50 | + |
| 51 | + console.log(`Copying bundle from ${bundlePath} to ${DEST_PATH}...`); |
| 52 | + fs.copyFileSync(bundlePath, DEST_PATH); |
| 53 | + |
| 54 | + console.log('Done.'); |
| 55 | +} |
| 56 | + |
| 57 | +main(); |
0 commit comments