UNPKG

spanwright

Version:

CLI tool to generate Cloud Spanner E2E testing framework projects with Go database tools and Playwright browser automation

109 lines 4.88 kB
#!/usr/bin/env node "use strict"; 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; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const path = __importStar(require("path")); const cli_1 = require("./cli"); const configuration_1 = require("./configuration"); const validation_1 = require("./validation"); const errors_1 = require("./errors"); const constants_1 = require("./constants"); const file_operations_1 = require("./file-operations"); async function createProject() { try { // Parse command line arguments const { projectName, flags } = (0, cli_1.parseCommandLineArgs)(); // Check for version and help flags first (0, cli_1.checkForHelpAndVersion)(flags); // Validate project name if (!projectName) { (0, cli_1.showUsageError)(); } (0, validation_1.validateProjectName)(projectName); // Check if directory already exists const projectPath = path.resolve(process.cwd(), projectName); const fs = await Promise.resolve().then(() => __importStar(require('fs'))); if (fs.existsSync(projectPath)) { console.error(constants_1.MESSAGES.ERRORS.DIRECTORY_EXISTS(projectName)); process.exit(1); } console.log(constants_1.MESSAGES.INFO.STARTING_SETUP); console.log(''); // Get configuration const isNonInteractive = (0, cli_1.isNonInteractiveMode)(flags); const config = await (0, configuration_1.getConfiguration)(isNonInteractive); console.log(''); console.log(constants_1.MESSAGES.INFO.CREATING_DIRECTORY); (0, file_operations_1.ensureDirectoryExists)(projectPath); // Copy template files console.log(constants_1.MESSAGES.INFO.COPYING_TEMPLATES); const templatePath = path.join(__dirname, '..', 'template'); (0, file_operations_1.copyDirectory)(templatePath, projectPath); // Process template files (0, file_operations_1.processTemplateFiles)(projectPath, projectName); // Replace PROJECT_NAME in Go files console.log(constants_1.MESSAGES.INFO.CONFIGURING_GO); (0, file_operations_1.replaceProjectNameInGoFiles)(projectPath, projectName); // Create environment configuration console.log(constants_1.MESSAGES.INFO.CREATING_ENV); const envContent = (0, configuration_1.generateEnvironmentContent)(config); const envPath = path.join(projectPath, constants_1.FILE_PATTERNS.ENV); (0, file_operations_1.writeFileContent)(envPath, envContent); // Remove unnecessary files for single DB configuration if (config.count === '1') { console.log(constants_1.MESSAGES.INFO.REMOVING_FILES); (0, file_operations_1.removeSecondaryDbFiles)(projectPath); } // Show completion message console.log(''); console.log(constants_1.MESSAGES.INFO.COMPLETED); console.log(''); console.log('📋 Next steps:'); console.log(` cd ${projectName}`); console.log(' make init # Initial setup'); console.log(' make run-all-examples # Run samples'); console.log(''); console.log('🔧 Create new test scenario:'); console.log(' make new-scenario SCENARIO=scenario-01-my-test'); console.log(''); console.log('📚 Detailed documentation: See README.md'); } catch (error) { (0, errors_1.handleError)(error); } } // Start the application createProject(); //# sourceMappingURL=index.js.map