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

generator-bash

v2.0.0

Published

A generator to scaffold out a shell script, with arguments, options and flags handling

Downloads

39

Readme

generator-bash NPM version Dependency Status

A generator to scaffold out a shell script, with arguments, options and flags handling.

Table of Contents

Installation

First, install Yeoman and generator-bash using npm (node.js is assumed to be installed )

$ npm install -g yo
$ npm install -g generator-bash

Initialization

When starting a new generable-script project, you will want to: open up a terminal/command prompt, make a new folder, and navigate into it

$ mkdir my-generable-script-folder && cd $_

then, run the bash generator.

$ yo bash my-script.sh

Follow all the prompts and choose what suits you most for the script you would like to create. When you finish with all of the prompts, your generable-script will be created.

NOTE: You can also start with a basic blank project and add what you need later (see init)

Once finished, you will see a structure like below:

├── .my-script.sh       # The folder containing all the snippets used to compose
|   |                   # your script. The snippets are listed in the composing order
|   ├── .header
|   ├── .error
|   ├── .log
|   ├── .debug
|   ├── .usage
|   ├── .get_options
|   ├── .get_arguments
|   ├── .init
|   └── body            # The snippet where to put your own logic
|
├── .yo-rc.json         # The yeoman config file where you can change your script config 
|                       # faster than using the provided prompts
|
└── my-script.sh        # Your generated script ready to be run

Congratulations! You should now have successfully created a generable-script project.

To start adding your own logic you can modify the body snippet and use the provided subgenerators to handle ARGUMENTs, OPTIONs and FLAGs and also the VERSION of your script. Under the hood, what these subgenerators do, is modifying the .yo-rc.json configuration file and once understood the mechanisms you can also modify directly this file to speed up the workflow or when there's no way with subgenerators to achieve a task for example: renaming an OPTION long or short name previously created with the main generator or with the option subgenerator.

NOTE: You should not modify the dotfiles under your generable-script folder, if you want to preserve the automatic usage generation and the correct input arguments/options reading

Sub-Generators

Note: Generators need to be run from the root directory of your generable-script (Where the .yo-rc.json is located)

Argument

Allows to add an input argument inside your script

Example:

$ yo bash:argument my-script.sh

Following the prompts you will choose your argument's variable name and the optional description to show into the generated usage.

Option

Allows to add an input option inside your script

Example:

$ yo bash:option my-script.sh

Following the prompts you will choose your option's variable name, short/long name and the optional description to show into the generated usage.

Flag

Allows to add an input flag inside your script

Example:

$ yo bash:flag my-script.sh

Following the prompts you will choose your flag's variable name, short/long name and the optional description to show into the generated usage.

Version

Allows to handle the version of your script following semver specs

Example:

$ yo bash:version my-script.sh patch

This will bump the patch version of your script changing the output of:

$ ./my-script.sh --version

From

0.1.0

To

0.1.1

Other possible values are: minor and major :

  • minor) will bump the minor and reset the patch to 0 e.g. 0.1.1 -> 0.2.0
  • major) will bump the major and reset the minor and the patch to 0 e.g. 0.2.1 -> 1.0.0

that respectively also reset the patch to 0 and both the minor and the patch to 0

Init

Initializes a bare generable-script with no arguments, options nor flag. You can add them later by using the respective subgenerators or by properly modifying the .yo-rc.json

Example:

$ yo bash:init my-script.sh

The output will be

create my-script.sh

Write

Called internally by every above described generators, it's the piece of code that converts the data stored into the .yo-rc.json into the final generated script. You should use this generator only when the .yo-rc.json has been modified manually to reflect the changes into the script.

$ yo bash:write my-script.sh

The output will be

conflict my-script.sh
? Overwrite my-script.sh? (Ynaxdh)

with the Yeoman's conflicter asking you to override the old script. Pressing return, the default Y will be passed and your script will be updated.

NOTE: This will also run chmod +x my-script.sh

License

Apache-2.0 / © Claudio Stella