rollup-umd-scripts
Version:
CLI for rollup-umd projects
73 lines (67 loc) • 2.25 kB
JavaScript
;
/* eslint-disable no-undef, no-param-reassign, global-require, no-unused-vars, no-console, no-underscore-dangle, prefer-destructuring */
var path = require('path');
var fs = require('fs');
var p = path.join(__dirname, '../../../../internals/declination');
var cliPkgPath = path.join(__dirname, '../../../../package.json');
var cliPkg = require(cliPkgPath);
var files = fs.existsSync(p) ? fs.readdirSync(p) : [];
var declinationList = files.filter(function (f) {
return f !== 'create';
});
exports.command = 'list';
exports.desc = 'List available declinations.';
exports.builder = function (yargs) {
return yargs.option('path', {
alias: 'p',
describe: 'path',
default: process.cwd()
}).option('with-link', {
alias: 'l',
describe: 'Add declination link to documentation',
default: false
}).option('type', {
alias: 't',
describe: 'Choose a type',
default: 'numbered-markdown',
choices: ['numbered-markdown', 'numbered-dashed', 'array']
});
};
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;
}
function getLink(fileName, text) {
return '[' + text + '](https://dev-tools.yeutech.com/' + cliPkg.name + '/#' + fileName + ')';
}
var after = void 0;
switch (argv.type) {
case 'numbered-markdown':
after = declinationList.map(function (i) {
if (argv['with-link']) {
return i.split('-')[0] + '. ' + getLink(i, i.split('-').slice(1).join('-'));
}
return i.split('-')[0] + '. ' + i.split('-').slice(1).join('-');
});
break;
case 'numbered-dashed':
after = argv['with-link'] ? declinationList.map(function (i) {
return getLink(i, i);
}) : declinationList;
break;
case 'array':
after = argv['with-link'] ? declinationList.map(function (i) {
return '' + getLink(i, i.split('-').slice(1).join('-'));
}) : declinationList.map(function (i) {
return '' + i.split('-').slice(1).join('-');
});
break;
default:
break;
}
console.log(after.join('\n'));
};