npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bitsun/mce

v1.1.6

Published

Make command executable easily

Downloads

4

Readme

MCE

FOSSA Status

Build StatusDependency StatusPRs Welcome

Code Climate Test Coverage Issue Count

semantic-releaseCommitizen friendlyTypeScript

Installation

npm i -g node-mce

Usage

    mce new <application> [options]
      Creates a new MCE project.
        -f, --force          Overrides target directory                            
        -n, --npm            Install npm dependencies                              
        -s, --style <style>  Define the style of command you will use. If you need
                              more than one command use git.
                              Values: git | *single

This will create project that is ready to work with mce. The project scaffolding look like this:

Project Structure

project_name::
  |--.vscode
  |  |--launch.json
  |  |--settings.json
  |  |--task.json
  |
  |--src
  |  |--index.ts       [single-style]
  |  |--cli.ts
  |  |--commands       [git-style]
  |    |--removeme.ts
  |
  |--.gitignore
  |--package.json
  |--tsconfig.json
  |--project_name

Configuring command

  • Single-Style only uses a index.ts in the src folder.
  • Git-Style uses [command].ts files inside the commands folder.

In any of both cases a command is defined in the same way.

import { numeric, floating, range, text, list, collect, bool, verbose, enumeration, Parsed} from '@bitsun/mce';
import { ok, error, warn, info, ask, input } from '@bitsun/mce/console';
import { created, updated, makeDir, cp, printRelativePath, targetPath, cliPath } from '@bitsun/mce/utils';
import { spin } from '@bitsun/mce/spinner';
enum Styles { 
    git = 'git',
    single = 'single' 
}
export let description = 'A description for your command';
export let args = '<arg1> [varidac...]';
export let options = {
    enumeration: enumeration('-e <enum>', 'Define the style of command you will use', Styles,Styles.single),
    number: numeric('-n <n>', 'A number'),
    floating: floating('-f <n>', 'A float number'),
    range: range('-r <a>..<b>', 'A Range of two numbers'),
    text: text('-t <n>', 'A string value'),
    list: list('-l <n>', 'comma separed values'),
    collect: collect('-c <n>', 'A repetable value'),
    bool: bool('-b', 'A boolean value'),
    verbose: verbose('Increase system verbosity'),
};
export async function action(arg1:string, varidac:string[], opt:Parsed<typeof options>) {
    // Your Code
}

Option Parsing

You must export a options variable with the options that you want to use. As you can see you can defined a lot of types for your options most of the options cant take a '' as first parameter and mce will generate the tags for you.

The name in the you use to define the property is used as main tag, if you pass '' as the first argument it will fill with a automatic tag_desc and no sort tag will be generated. On the other hand if you pass a string like -e --env <env> mce will use those values as the short tag, tag and tag value.

option|short|tag|tag_desc|desc -|-|-|-|- enumeration:enumeration('', 'description', ['a','b'])| | --enumeration|<e>|description Values a | b enumeration:enumeration('-l', 'description', ['a','b'])|-l|--enumeration|<e>|description Values a | b enumeration:enumeration('-l --list', 'description', ['a','b'])|-l|--list|<e>|description Values a | b enumeration:enumeration('-l --list <l>', 'description', ['a','b'])|-l|--list|<l>|description Values a | b

No mather the case the actual property that is created in the opt is always enumeration for this case.

Coercion

As you can see mce come with some handy functios to coerce and validate the user input.

import { numeric, floating, range, text, list, collect, bool, verbose, enumeration } from '@bitsun/mce';

Validation

If you need to validate the information of any of your arguments you can pass a RegExp as the third arguments of the option_functions

import { text } from '@bitsun/mce';

export let options = {
 size: text('-s --size <size>', 'Pizza size', /^(large|medium|small)$/);
}

Defaults

The last argument you pass will always be the default value.

import { text } from '@bitsun/mce';

export let options = {
 size: text('-s --size <size>', 'Pizza size', /^(large|medium|small)$/, 'medium');
}

Version option

By default mce will trace the --version tag and will respond with the version in your package.json.

Verbose option

By default mce will trace the -v --verbose tag and will respond wwith the version in your package.json.

Only if you define a verbose obtion you will be passed with the actual verbose value but in most of the cases is no needed.

Arguments

You need to export a args:string property with you arguments definition

Required args

<arg> is the convention to make your arg required is no arg detected mce will throw and error.

Required args

[arg] is the convention to make your arg optional.

Varidac args

[arg ...] is the convention to make the rest of the args be presented as varidad string[]

Coecion

Argument can be coerced by default they are treated as string but if you use:

  • <arg:number> will be coerce to number.
  • <arg:boolean> will be coerce to boolean.

Help Generation

By default mce will trace the -h --help options and will automatically render help

Final Notes

The executable file that is generated only call your ./cli file.

When in git-style cli.ts will look like:

import { MCE } from "@bitsun/mce";

MCE(__dirname).subcommand(process.argv);

And in single-style:

import { MCE } from "@bitsun/mce";

MCE(__dirname).command(process.argv);

During local development I use ts-node to call direct the .ts files