rollup-umd-scripts
Version:
CLI for rollup-umd projects
40 lines (36 loc) • 1.18 kB
JavaScript
;
/* eslint-disable no-undef, no-param-reassign, global-require, no-unused-vars, no-console, no-underscore-dangle */
var async = require('async');
var path = require('path');
var fs = require('fs');
exports.command = 'variable <variable> [variables..]';
exports.desc = 'Replace variable(s) in README.md (eg: SOMETHING=value)';
exports.builder = function (yargs) {
return yargs.option('path', {
alias: 'p',
describe: 'path',
default: process.cwd()
});
};
exports.handler = function (argv) {
switch (argv.path[0]) {
case '/':
break;
default:
argv.path = argv.path[1] === '/' ? path.join(process.cwd(), argv.path.slice(2)) : path.join(process.cwd(), argv.path);
break;
}
var d = path.join(argv.path, 'README.md');
async.map([].concat(argv.variable).concat(argv.variables), function (variable, cb) {
var split = variable.split('=');
var before = split[0];
before = before[0] === '$' ? before : '$' + before;
var after = split[1];
sedReplace(d, before, after, d, cb);
}, function (err, results) {
if (err) {
console.error('[ERROR] ' + err.message);
process.exit(1);
}
});
};