claude-playwright
Version:
Seamless integration between Claude Code and Playwright MCP for efficient browser automation and testing
116 lines (113 loc) • 4.77 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateProjectConfig = generateProjectConfig;
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
const chalk_1 = __importDefault(require("chalk"));
const readline = __importStar(require("readline"));
/**
* Generate project configuration file with base URL
*/
async function generateProjectConfig(projectPath) {
// Ask user for base URL
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const baseURL = await new Promise((resolve) => {
const askForUrl = () => {
rl.question(chalk_1.default.blue('🌐 Enter your application base URL (default: http://localhost:3000): '), (url) => {
const inputUrl = url.trim() || 'http://localhost:3000';
// Validate URL format
if (!inputUrl.startsWith('http://') && !inputUrl.startsWith('https://')) {
console.log(chalk_1.default.red('❌ URL must start with http:// or https://'));
console.log(chalk_1.default.yellow(' Example: http://localhost:3000 or https://example.com'));
askForUrl(); // Ask again
return;
}
try {
// Try to parse URL to ensure it's valid
new URL(inputUrl);
rl.close();
resolve(inputUrl);
}
catch (error) {
console.log(chalk_1.default.red('❌ Invalid URL format'));
console.log(chalk_1.default.yellow(' Example: http://localhost:3000 or https://example.com'));
askForUrl(); // Ask again
}
});
};
askForUrl();
});
const configSource = path_1.default.join(__dirname, '../../templates/claude-playwright.config.js');
const configDest = path_1.default.join(projectPath, 'claude-playwright.config.js');
// Check if template exists
if (await fs_extra_1.default.pathExists(configSource)) {
// Read template config
let configContent = await fs_extra_1.default.readFile(configSource, 'utf8');
// Replace base URL
configContent = configContent.replace("baseURL: process.env.BASE_URL || 'http://localhost:3000'", `baseURL: process.env.BASE_URL || '${baseURL}'`);
await fs_extra_1.default.writeFile(configDest, configContent);
}
else {
// Generate minimal config if template doesn't exist
const minimalConfig = `/**
* Claude-Playwright Configuration
*/
module.exports = {
// Base URL for all browser operations
baseURL: process.env.BASE_URL || '${baseURL}',
// Session configuration
sessions: {
timeout: 8 * 60 * 60 * 1000,
autoExtend: true,
directory: './playwright-sessions'
},
// MCP Server configuration
mcp: {
enforceBaseURL: true,
redirectRelativeToBase: true
}
};`;
await fs_extra_1.default.writeFile(configDest, minimalConfig);
}
console.log(chalk_1.default.green(`✓ Project config created with base URL: ${baseURL}`));
}
//# sourceMappingURL=project-config.js.map
;