UNPKG

nmdk

Version:

CLI tool for downloading and setting up Minecraft mod development kits (MDK) for Forge, Fabric, and NeoForge

155 lines (139 loc) 4.89 kB
const inquirer = require('inquirer'); const chalk = require('chalk'); const stripAnsi = require('strip-ansi'); async function collectModConfigurationData(modName) { console.log(chalk.blue.bold('\n' + '='.repeat(75))); console.log(chalk.blue('Mod Configuration')); console.log(chalk.blue.bold('='.repeat(75))); const questions = [ { type: 'input', name: 'groupId', message: 'Group ID (e.g., com.yourname):', default: 'com.example', validate: (input) => { if (!input || !input.includes('.')) { return 'Group ID must contain at least one dot (e.g., com.example)'; } return true; } }, { type: 'input', name: 'modId', message: 'Mod ID (lowercase, no spaces):', default: modName.toLowerCase().replace(/[^a-z0-9]/g, ''), validate: (input) => { if (!input || !/^[a-z0-9]+$/.test(input)) { return 'Mod ID must contain only lowercase letters and numbers'; } return true; } }, { type: 'input', name: 'modName', message: 'Mod Name (display name):', default: modName, validate: (input) => { if (!input || input.trim().length === 0) { return 'Mod name cannot be empty'; } return true; } }, { type: 'input', name: 'author', message: 'Author name:', default: 'Unknown', validate: (input) => { if (!input || input.trim().length === 0) { return 'Author name cannot be empty'; } return true; } }, { type: 'input', name: 'description', message: 'Mod description:', default: 'A Minecraft mod', validate: (input) => { if (!input || input.trim().length === 0) { return 'Description cannot be empty'; } return true; } }, { type: 'input', name: 'version', message: 'Mod version:', default: '1.0.0', validate: (input) => { if (!input || !/^\d+\.\d+\.\d+$/.test(input)) { return 'Version must be in format X.Y.Z (e.g., 1.0.0)'; } return true; } } ]; const answers = await inquirer.prompt(questions); answers.packageName = answers.groupId + '.' + answers.modId; return answers; } async function requestProjectCreationConfirmation(config) { const lines = [ ` Mod Name: ${config.modName}`, ` Mod ID: ${config.modId}`, ` Group ID: ${config.groupId}`, ` Package: ${config.packageName}`, ` Author: ${config.author}`, ` Version: ${config.version}`, ` Description: ${config.description}`, ` The following project will be created:` ]; const maxLineLength = Math.max(...lines.map(line => line.length), 'The following project will be created'.length + 4); const minWidth = 50; const width = Math.max(minWidth, maxLineLength + 4); const innerWidth = width - 2; const topBorder = chalk.green('╔' + '═'.repeat(innerWidth) + '╗'); const titleText = ' The following project will be created'; const title = chalk.green('║') + chalk.bold(titleText) + ' '.repeat(innerWidth - titleText.length) + chalk.green('║'); const separator = chalk.green('╠' + '═'.repeat(innerWidth) + '╣'); const midLine = chalk.green('║') + chalk.gray('─'.repeat(innerWidth)) + chalk.green('║'); const bottomBorder = chalk.green('╚' + '═'.repeat(innerWidth) + '╝'); const makeLine = (text) => { const visualLength = stripAnsi(text).length; const padding = ' '.repeat(Math.max(0, innerWidth - visualLength)); return chalk.green('║') + text + padding + chalk.green('║'); }; console.clear(); console.log('\n' + topBorder); console.log(title); console.log(separator); console.log(midLine); console.log(makeLine(' Mod Name: ' + chalk.cyan(config.modName))); console.log(makeLine(' Mod ID: ' + chalk.cyan(config.modId))); console.log(makeLine(' Group ID: ' + chalk.cyan(config.groupId))); console.log(makeLine(' Package: ' + chalk.cyan(config.packageName))); console.log(makeLine(' Author: ' + chalk.cyan(config.author))); console.log(makeLine(' Version: ' + chalk.yellow(config.version))); console.log(makeLine(' Description: ' + chalk.gray(config.description))); console.log(midLine); console.log(bottomBorder); const { confirm } = await inquirer.prompt([ { type: 'confirm', name: 'confirm', message: 'Do you want to create this project?', default: true } ]); return confirm; } module.exports = { collectModConfigurationData, requestProjectCreationConfirmation };