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

hia

v0.0.5

Published

Easy and customizable generator system for creating template.

Downloads

9

Readme

hia

Easy and customizable generator system for creating template.

It provides the following features:

  • Create command and provide cli for your generating template.
  • Setting by yaml or json.
  • Execute script for setting binding template value.

installation

Global

npm install -g hia

Local

npm install -D hia

Getting start

1. Create hia.yaml or hia.json on your project root.

Example:

---

command: hia
subcommands:
  component:
    description: generate view template.
    input: true
    templates:
      - name: component/[input]Component.jsx
        src: templates/component.ejs
    output:
      dir: src
    args:
      text:
        aliase: t
        description: text on your component.
        required: true

2. Create template.

Template is resolved as ejs.

  • templates/component.ejs
import React from 'react';

export default <%= input %> extends React.Component {
  render() {
    return (
      <div>
        <h1><%= input %> Component!</h1>
        <span><%= text %></span>
      </div>
    );
  }
}

3. Execute command

$ hia component Test -t 'Test Text!'

Then, created src/component/TestComponent.jsx on your project root.

src/component/TestComponent.jsx

import React from 'react';

export default Test extends React.Component {
  render() {
    return (
      <div>
        <h1>Test Component!</h1>
        <span>Test Text!</span>
      </div>
    );
  }
}

Configration

Example:

---
basedir: ./test
command: hia
subcommands:
  test:view:
    description: generate view template.
    input: true
    templates:
      src: fixtures/component.ejs
    script:
      fixtures/scripts/test.js
    output:
      dir: test/dist
      filename: '[name].jsx'
    args:
      feature_name:
        aliase: f
        description: Feature name. It is used as second directory name.(If you specify calendar, create 'test/dist/calendar/[name].jsx')
      require_args:
        aliase: r
        description: require args.
        required: true
      question_args:
        aliase: q
        description: This is Question Section.
        before: fixtures/scripts/before.js
        question: true
      default_args:
        aliase: d
        description: set default value.
        default: 'default value'

basedir

  • basedir: string

The base directory for resolving filepaths.

Default: process.cwd()

command

  • command: string

Your generator system's command name.

subcommands

  • Array
    • Subcommand: { [subcommandName: string]: Options }

Define your generator system's subcommands.
subcommandName become subcommand for cli.

Example:

command: hia
subcommands:
  view:
    description: generate view template.
    input: true
    ...

Usage

$ hia view hogeView

Options

description
  • description: string

Description of your subcommand. It is used for help message on cli.

input
  • input: boolean

Set whether or not require value of input.

Default: false

templates
  • templates: Array<{ src: string, name: string }>

src: template src of ejs. name(optional): output src file path based on setting of basedir. [input] or other arg name are replaced by the name of the chunk.

script
  • script: string

Specify filepath of Node.js script. It runs before rendering and writing templates.

Script Example:

module.exports = function script(params) {
  params.subcommand.output.dir += '/exchanged';
  params.cliParams.input += 'Exchanged';
  return params;
};

It needs runnable on Node.js and must be exported as default.
You can receive bellow parameter and can change included value freely.
Returned value is applied for template rendering and writing.

  • { subcommand: Object, cliParams: Object }
    • subcommand's value is one of the subcommands section on hia.yaml.Executed subcommand is selected.
    • cliParams is include below params.
      • subcommand: string
        • executed subcommand name
      • input: string
        • input by cli
      • args: { [argName: string]: string }
        • Options by cli

Example:

$ hia test:view Test --feature_name bar
{
  subcommand: {
    description: 'generate view template.',
    input: true,
    templates: { src: 'fixtures/component.ejs' },
    script: 'fixtures/scripts/test.js',
    output: { dir: 'test/dist', filename: '[name].jsx' },
    args: { feature_name: [Object] }
  },
  cliParams: {
    subcommand: 'test:view',
    input: 'Test',
    args: { feature_name: 'bar' }
  }
}
output
  • output(option): { dir(option): string, filename(option): string }

dir: Output directory. Default is basedir.

filename: output file. [name] is replaced by the name of the chunk.

args
  • args: { [argName: string]: Options }
    • argName is used as flag by cli.
    • Options:
      • aliase(option): string
        • aliase name.
      • description(option): string
        • description.
      • default(option): string
        • default value.
      • required(option): boolean
        • Set whether or not require value of input.Default is false.
      • question(options): boolean
        • Set whether or not to be questioned when execute script.Default is false.
        • It uses prompt.So you can specify prompto's parameters.But if you want to use before parameter, you have to set script path instead of function object.

Example:

---
subcommands:
  test:view:
    ...
    args:
      feature_name:
        aliase: f
        description: Feature name. It is used as second directory name.(If you specify calendar, create 'test/dist/calendar/[name].jsx')
      require_args:
        aliase: r
        description: require args.
        required: true
      question_args:
        aliase: q
        description: This is Question Section.
        before: fixtures/scripts/before.js
        question: true
      default_args:
        aliase: d
        description: set default value.
        default: 'default value'
    ...

CLI

hia has default options.

  • -h, --help: show help for your generate cli.
  • -c, --config: specify configuration path.
$ hia-flux -h

  Easy and customizable generator system for creating template by cli.

  Usage:
    hia-flux <SUBCOMMAND> <INPUT>
      -h, --help                  Show list available subcommands and some concept guides.

for node

You can require hia as function.

Example

import 'babel-core/register';
import 'babel-polyfill';
import hia from 'hia';
hia({ basedir: __dirname + '/..', configPath: `${__dirname}/../hia.yml` });

Now you need require 'babel-core/register' and 'babel-polifill' to use it.

hia can be received below option.

  • { basedir(option): string, configPath(option): string }
    • basedir: Your project's root. Default is process.cwd().
    • configPath: Configuration of hia's filepath.Defaul is hia.yaml(json) on your project root.

License

MIT © joe-re