const helpers = require('./helpers'); const ora = require('ora'); const argv = require('yargs').argv; const colors = require('colors/safe'); const fs = require('fs'); const config = require('./config'); const path = require('path'); (async function() { const spinner = ora('Fetching mod info...').start() if ( argv.info ) { const mod = await helpers.fetch_mod(argv.info) spinner.stop() mod.print_info() } else if ( argv.list ) { if ( !argv.minecraft ) { spinner.stop() helpers.error_out('Please specify a target version using the --minecraft argument.') } const mod = await helpers.fetch_mod(argv.list) spinner.stop() let print = mod.version_info(argv.minecraft).sort((a, b) => a.id - b.id).reverse() if ( argv.type ) print = print.filter(x => x.type === argv.type) let truncated = false if ( !print ) helpers.error_out(`No supported versions found for Minecraft ${argv.minecraft}.`) if ( !argv.all && print.length > 15 ) { print = print.slice(0, 15) truncated = true } mod.print_header() console.log(` ${colors.green('Mod versions for Minecraft '+argv.minecraft+':')}`) for ( const item of print ) { console.log(` ${colors.cyan(item.id)} ${colors.blue('('+item.type+')')}\t${colors.yellow(new Date(item.uploaded_at).toLocaleString())}\t\t${item.name}`) } } else if ( argv.install ) { if ( !argv.minecraft && !argv.mod_version ) { spinner.stop() helpers.error_out('Please specify a Minecraft version target OR mod version id using the --minecraft and --mod_version arguments.') } const installs = argv.install.split(',').map(x => x.trim()) for ( const install of installs ) { await helpers.install_mod({ install, argv, spinner }) } } else if ( argv.archive ) { spinner.text = 'Archiving mod repository...'; (new Promise((res, rej) => { require('child_process').exec(`cd ${config.repo} && cd .. && zip -r archive.zip ./${path.basename(config.repo)}`, (err, stout, sterr) => { if ( err ) rej(err) else res() }) })).then(() => { spinner.stop() console.log(`Repository archived: ${path.dirname(config.repo)}/archive.zip`) }).catch(e => { spinner.stop() helpers.error_out('An error occurred while archiving the repository: '+e) }) } else if ( argv.show ) { const printVersions = (name, filenames) => { console.log(` ${colors.green(name)}`) filenames.map(x => x.replace('.zip', '').replace(`${name}-`, '')).forEach(x => { console.log(` ${colors.blue(x)}`) }) } spinner.stop() if ( argv.show === true ) { const mods = helpers.list_installed_mods() for ( const mod of mods ) { printVersions(mod, helpers.list_mod_versions(mod)) } } else if ( argv.show ) { const versions = helpers.list_mod_versions(argv.show) printVersions(argv.show, versions) } } else { spinner.stop() console.log(colors.blue(`MCM-CLI is an ad-hoc helper script for programmatically maintaining TechnicSolder repos.`)) console.log(`USAGE: node index.js [...OPTIONS]`) console.log('') console.log(` --info [mod]`) console.log(` Display information about a mod by CLI name.\n`) console.log(` --list [mod] --minecraft [version]`) console.log(` List mod versions for the specified Minecraft version target.\n`) console.log(` --install [mod] (--minecraft [version] | --mod_version [version id]`) console.log(` Download an install the specified mod at either the latest version for the specified`) console.log(` Minecraft target, or at the specified version ID.\n`) console.log(` --archive`) console.log(` Create a ZIP archive of the mod repository.\n`) console.log(`\nMake sure to update the "repo" and "download_staging" paths in config.js before use!`) } })()