|
| 1 | +#!/usr/bin/env node |
| 2 | +/* |
| 3 | +* Copyright © 2021 Dominik Szczepaniak, MIT License. |
| 4 | +*/ |
| 5 | + |
| 6 | +import chalk from 'chalk'; |
| 7 | +import yargs from 'yargs'; |
| 8 | + |
| 9 | +import MFR from '../Engine'; |
| 10 | + |
| 11 | +interface IOptions extends Record<string, unknown> { |
| 12 | + mode: string; |
| 13 | + source: string; |
| 14 | + destination: string; |
| 15 | + formats?: string[]; |
| 16 | + pattern?: string; |
| 17 | + appendix?: 'prefix' | 'postfix' | 'all' | 'none'; |
| 18 | + prefix?: string; |
| 19 | + postfix?: string; |
| 20 | +} |
| 21 | + |
| 22 | +// @ts-ignore - issue with typings |
| 23 | +const options: IOptions = yargs |
| 24 | + .usage( 'Usage: -m <mode> -s <source> -d <destination>' ) |
| 25 | + .option( 'm', { alias: 'mode', describe: 'Application mode', type: 'string', demandOption: true } ) |
| 26 | + .option( 's', { alias: 'source', describe: 'Source path', type: 'string', demandOption: true } ) |
| 27 | + .option( 'd', { alias: 'destination', describe: 'Destiatnion path', type: 'string', demandOption: true } ) |
| 28 | + .option( 'f', { alias: 'formats', describe: 'Handled formats', type: 'array' } ) |
| 29 | + .option( 'p', { alias: 'pattern', describe: 'Pattern', type: 'string' } ) |
| 30 | + .option( 'a', { alias: 'appendix', describe: 'Appendix', type: 'string' } ) |
| 31 | + .option( 'pre', { alias: 'prefix', describe: 'Prefix pattern', type: 'string' } ) |
| 32 | + .option( 'pos', { alias: 'postfix', describe: 'Prefix patern', type: 'string' } ) |
| 33 | + .argv; |
| 34 | + |
| 35 | +( async function() { |
| 36 | + try { |
| 37 | + const mfr: MFR = new MFR(); |
| 38 | + |
| 39 | + const { mode, source, destination, formats, pattern, appendix, prefix, postfix } = options; |
| 40 | + |
| 41 | + await mfr.run( { |
| 42 | + mode, |
| 43 | + sourcePath: source, |
| 44 | + destinationPath: destination, |
| 45 | + formats, |
| 46 | + pattern, |
| 47 | + appendix, |
| 48 | + prefixPattern: prefix, |
| 49 | + postfixPattern: postfix |
| 50 | + } ); |
| 51 | + |
| 52 | + chalk.green.bold( 'Done!' ); |
| 53 | + } catch ( error ) { |
| 54 | + chalk.red.bold( 'Rename operation failed. An unexpected error occurred!', error ); |
| 55 | + } |
| 56 | +}() ); |
0 commit comments