UNPKG

@dkoul/auto-testid-cli

Version:

Command-line interface for React and Vue.js custom attribute generation

93 lines • 3.86 kB
"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; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.initCommand = initCommand; const chalk_1 = __importDefault(require("chalk")); const fs = __importStar(require("fs/promises")); const path = __importStar(require("path")); async function initCommand(options) { const format = options.format || 'json'; const filename = format === 'json' ? '.autotestidrc.json' : 'autotestid.config.js'; const defaultConfig = { frameworks: ['react'], namingStrategy: { type: 'kebab-case' }, prefix: 'test', exclude: [ '**/node_modules/**', '**/dist/**', '**/build/**', '**/*.test.*', '**/*.spec.*' ], includeElementTypes: ['button', 'input', 'select', 'textarea', 'form', 'a', 'div'], maxIdLength: 50, preserveExisting: true }; try { const configPath = path.join(process.cwd(), filename); // Check if config already exists try { await fs.access(configPath); console.log(chalk_1.default.yellow(`āš ļø Configuration file already exists: ${filename}`)); console.log(chalk_1.default.gray('Use --force to overwrite (not implemented yet)')); return; } catch { // File doesn't exist, continue } let configContent; if (format === 'json') { configContent = JSON.stringify(defaultConfig, null, 2); } else { configContent = `module.exports = ${JSON.stringify(defaultConfig, null, 2)};`; } await fs.writeFile(configPath, configContent, 'utf-8'); console.log(chalk_1.default.green(`āœ… Created configuration file: ${filename}`)); console.log(chalk_1.default.blue('\nšŸ“ Default configuration:')); console.log(chalk_1.default.gray(JSON.stringify(defaultConfig, null, 2))); console.log(chalk_1.default.cyan('\nšŸ’” Next steps:')); console.log(' • Edit the configuration file to match your project needs'); console.log(' • Run "auto-testid generate ./src" to start generating test IDs'); } catch (error) { console.error(chalk_1.default.red(`āŒ Failed to create configuration: ${error.message}`)); process.exit(1); } } //# sourceMappingURL=init.js.map