#!/usr/bin/env node import yargs, { Arguments } from 'yargs' import { hideBin } from 'yargs/helpers' import chalk from 'chalk' import { edit, unedit, log, getArgs, CVRT, isLegal as executing } from './modules/core' export interface ActionParams { isEdit: boolean isOverwrite: unknown file: string } const argv: Arguments = await yargs(hideBin(process.argv)) .scriptName(chalk.blue.bold('bl3-convert: by 0mjs')) .usage(chalk.blueBright('How to: $0 [options]')) .option('edit', { alias: 'e', type: 'boolean', description: 'Convert a PS4 save to a PC save', }) .option('unedit', { alias: 'u', type: 'boolean', description: 'Covert a PC save (back) to a PS4 save', }) .option('o', { alias: 'overwrite', type: 'boolean', description: 'Covert to PC/PS4 and *overwrite* current file', }) .example([ ['$0 -e 1 2.sav', 'Convert a PS4 save to a PC save'], ['$0 -u 2.sav 1', 'Convert a PC save to a PS4 save'], ['$0 -e -o 2.sav', 'Convert a PS4 save to a PC save (overwrite)'], ['$0 -u -o 8.sav', 'Covert a PC save to a PS4 save (overwrite)'], ]) .help(chalk.cyanBright.bold('h')) .alias('h', 'help') .argv const { firstArg, secondArg, outputFile, actionParams }: any = getArgs(argv) switch (executing) { case argv.edit: edit(firstArg, outputFile) console.log(log(actionParams(true))) break case argv.unedit: unedit(firstArg, outputFile) console.log(log(actionParams(false))) break default: console.error(chalk.redBright.bold('Invalid command')) process.exit(1) break }