mhulse / node-boilerplate-cli

A simple boilerplate starting point for Node.js command line projects.
Apache License 2.0
18 stars 8 forks source link

Make options a const #14

Closed mhulse closed 6 years ago

mhulse commented 7 years ago
const OPTIONS = {};

Complete example:

function getOptions() {

    let argv = yargs
        .version(pkg.version)
        .usage('Usage: example-command <message string or text file> [message string] ...')
        .command('example-command', 'Create xxxxxx from a text file or command line arguments.')
        .example('example-command ~/dropbox/fooo/bazzz.txt', 'Load texts from text file; each text should be on a new line.')
        .example('example-command foo "bar\nbaz" bing', 'Use provided texts to create image files.')
        .alias('h', 'help')
        .help('h', 'Show help.')
        .argv;

    OPTIONS.dirBase = '/Users/xxxxx/yyyyy/fooo';
    OPTIONS.dirFiles = '/files';
    OPTIONS.dirFonts = '/fonts';
    OPTIONS.fontResolution = 300;
    OPTIONS.imageHeight = 5400;
    OPTIONS.imageResolution = 300;
    OPTIONS.imageWidth = 4500;
    OPTIONS.repeat = 10;
    OPTIONS.textKerning = {start: -200, end: 0};
    OPTIONS.textLeading = {start: -2000, end: -500};
    OPTIONS.textOffset = {start: 100, end: 500};
    OPTIONS.textPadding = {start: 1000, end: 3000};
    OPTIONS.textPlacement = 'north';
    OPTIONS.textRotation = {start: -2, end: 2};
    OPTIONS.texts = argv._; // Returns an array.

    if (utilities.fileExists(OPTIONS.texts[0])) {

        OPTIONS.texts = fs.readFileSync(OPTIONS.texts[0]).toString().trim().replace(/\n{2,}/g, '\n').split('\n');

    }

    startApp();

}

getOptions();
mhulse commented 6 years ago

Fixed via ae9df4bdd3d5e3da733b28c25c342d73432c52f3