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

@epdoc/cmdutil

v2.6.0

Published

Commander utility classes and general CLI helpers.

Downloads

29

Readme

epdoc-fs

Commander command line utilities for limited distribution.

Build

npm install
npm run build

Examples

import { CmdProps } from '@epdoc/cmdutil';
import pkg from '../package.json';
import { MainCmd, RosGenCmd, RosReadCmd } from './commands';

// import { FileRenameAll } from './commands/rename-all';
// import { FileRenameCamelcase } from './commands/rename-camelcase';
// import { FileRenameDate } from './commands/rename-date';

const mainCmd = new MainCmd(pkg as CmdProps);

mainCmd.addSubCommand(new RosGenCmd());
mainCmd.addSubCommand(new RosReadCmd());

mainCmd.parseArgs();

main-cmd.ts

import { BaseMainCmd } from '@epdoc/cmdutil';

export class MainCmd extends BaseMainCmd {
  private _isMain = true;

  static isInstance(val: any): val is MainCmd {
    return val && val._isMain === true;
  }
}

ros-gen-cmd.ts

import { CmdProps, FileBaseCmd, log } from '@epdoc/cmdutil';
import { FSItem, FolderPath } from '@epdoc/fsutil';
import { isNonEmptyArray } from '@epdoc/typeutil';
import { Argument, Option } from 'commander';
import { EnvType, isEnvType, skip } from '../lib';
import { FileOperation } from '../file-operation';

export class RosGenCmd extends FileBaseCmd {
  private _isGenRunner = true;

  static isInstance(val: any): val is RosGenCmd {
    return val && val._isGenRunner === true;
  }

  constructor() {
    super({ name: 'generate', description: 'Generate RSC files from JSON configuration' });
  }

  getProps(): CmdProps {
    return {
      aliases: ['gen'],
      options: [
        new Option('-j --json', 'Also output as JSON'),
        new Option('-t --time', 'Include time in filename of output file'),
        new Option('--env <env>', 'Set env').default(skip.env),
        new Option('--comment <text>', 'Comment to put in header of RSC file'),
        new Option('-o --output <path>', 'Output filename. Defaults to same folder as input file')
      ],
      arguments: [new Argument('<files...>', 'List of configuration files')]
    };
  }

  public async run(): Promise<void> {
    return Promise.resolve()
      .then((resp) => {
        if (this.opts.env) {
          if (isEnvType(this.opts.env)) {
            skip.setEnv(this.opts.env);
          } else {
            let envs: string[] = Object.keys(EnvType).map((key) => EnvType[key]);
            throw new Error(`Invalid env value '${this.opts.env}', must be one of ${envs.join(',')}`);
          }
        }
        return this.getFilesFromArgs(this.parent.opts.pwd as FolderPath, {
          levels: 1,
          files: true,
          folders: false
        });
      })
      .then(async (resp) => {
        if (isNonEmptyArray(resp)) {
          log.h2(`Generating output from ${resp.length} config files`).trace();
          let deviceOpts = {
            cwd: this.parent.opts.cwd,
            pwd: this.parent.opts.pwd,
            json: this.opts.json,
            time: this.opts.time,
            output: this.opts.output,
            comment: this.opts.comment
          };
          for (let fdx = 0; fdx < resp.length; ++fdx) {
            const fs: FSItem = resp[fdx];
            log.h2('Generate RSC file for device').path(fs.basename).trace();
            const device = new FileOperation(deviceOpts);
            await device
              .read(fs)
              .then((resp) => {
                device.initOutput();
                return device.generate();
              })
              .then((resp) => {
                return device.write();
              })
              .then((resp) => {
                return Promise.resolve();
              });
          }
        } else {
          log.h2('No config files specified').info();
        }
      });
  }
}