0.3.2 • Published 5 years ago

a-cli-utils v0.3.2

Weekly downloads
14
License
MIT
Repository
github
Last release
5 years ago

a-cli-utils

A JavaScript utility library for a-cli project.

Installation

npm install a-cli-utils

Usage

all utils

util namedescriptiondocument
batchRegCommandBatch registered command for package commanderbatchRegCommand, commander(github)
fsExtrafs extra functionfsExtra
parseArgsParse process argv to objectparseArgs
pathExtrapath extra functionpathExtra

batchRegCommand

Batch registered command by command config list:

const { Command } = require('commander');
const { batchRegCommand } = require('a-cli-utils');

const commands = [
  {
    command: 'init',
    description: 'initial project',
    action: function () {},
  },
  {
    command: 'run [script]',
    // single option
    option: ['-d, --debug', 'run customize command  with [debug] mode'],
    description: 'run customize command',
    action: function () {},
  },
  {
    command: 'dev',
    // multiple options
	options: [
	  ['-d, --debug', 'dev command with [debug] mode'],
	  ['-t, --test', 'dev command with [test] mode'],
	],
	description: 'develop project',
	action: function () {},
    // other attribute you can add if program had
  },
];

const program = new Command();

program
  .version('1.0.0')
  .description('some description');

batchRegCommand(program, commands);

program.parse(process.argv);

fsExtra

fsExtra.ensureDir

ensure the directory exists, it will create directory if isn't exist

ensureDir('xxx/yyy/zzz');

parseArgs

Parse process argv to object:

const { parseArgs } = require('a-cli-utils');

const args = parseArgs(['debug', 'text=string', 'num=123', 'visible=true', 'disabled=false', 'val=null', 'id=undefined']);

console.log(args);
/*
{
  debug: true,
  test: 'string',
  num: '123',
  visible: true,
  disabled: false,
  val: null,
  id: undefiend,
}
*/

pathExtra

fsExtra.removeExtname

remove the path extname if it had

removeExtname('index.js');
// return index

removeExtname('xxx/yyy/index.js');
// return xxx/yyy/index
0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago