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

@njmyers/boil

v0.0.3

Published

Generate boilerplate for file and folder structures

Downloads

4

Readme

Boil CLI

Cook up your team's favorite recipes! This time don't wait for the pot to boil. That means not spending anymore time writing boilerplate! Boil CLI is an easy to use code generator that let's you write your own templates.

Motivation

I have had great success when using domain concepts to group related code files in folders. When using this approach it is easy to make changes as all related code is co-located. However there are a few issues with that. Given the following structure...

src/
  components/
    Cart/
      action.js
      reducer.js
      index.js
      __test__/
        action.test.js
        reducer.test.js
    Checkout/
      action.js
      reducer.js
      index.js
      __test__/
        action.test.js
        reducer.test.js

You can see already the problem. All of the files have the same name. If every file is named reducer.js then it will be impossible to search for files. Eventually I started using/naming files like follows.

src/
  components/
    Cart/
      cart-action.js
      cart-reducer.js
      index.js
      __test__/
        cart-action.test.js
        cart-reducer.test.js
    Checkout/
      checkout-action.js
      checkout-reducer.js
      index.js
      __test__/
        checkout-action.test.js
        checkout-reducer.test.js

I really liked this approach. The filenames/paths were verbose and easy to search for while the files inside of the domain folders were easy to identify. However there was a boilerplate problem and my wrists got tired. Different languages like css or classes had different naming conventions so it wasn't always easy to use text editor search/replace with differently cased names. Enter the boil cli...

Installation

npm install -g @njmyers/boil

Usage

Boil up your favorite recipes. Simply enter the command boil [template] kebab-case-name. Template is simply the name of the template you wish to use. Boil cli comes with 4 ready-made templates but the point is to create your own! kebab-case-name is whatever the domain concept of the folder and files. In traditional unix style you can pass as many kebab-case-names as you wish to create multiple files/folders.

Templates

By default, Boil CLI will look for a folder called templates in your project root. If it does not find this folder it will fallback to the included templates. The template folder path is configurable please see the config section.

One of the main ideas behind the templates was to make them look like code. That way when you are creating templates and editing them you can use all of your favorite tools to format your templates. Using template strings or a template syntax makes it difficult to read templates and spot errors. Although these systems give you more functionality I decided to use a limited set of syntax tokens that will hopefully make the template process something you can complete quickly. It also makes it so the code you write in your template looks like the code that will wind up in your src folder. These are the available tokens.

  • camelCase
  • PascalCase
  • snake_case
  • SNAKE_CASE
  • kebab-case
  • KEBAB-CASE

When you write a template file just use these exact strings and they will be replaced. If you pass a cli argument big-button the above tokens would turn into these strings.

  • bigButton
  • BigButton
  • big_button
  • BIG_BUTTON
  • big-button
  • BIG-BUTTON

In terms of a folder structure, you simply name your folders or files using these same tokens and they will also be replaced. Here is an example of what your template folder structure could look like. For examples sake we will use .js files but you could use whatever files you want.

templates/
  function/ // this folder name will become the template type on your cli args
    index.js
    camelCase.js
    camelCase.test.js

and then inside these files

// camelCase.js
/**
 * Write some documentation
 */
function camelCase() {
  return null;
}

export default camelCase;

// camelCase.test.js
import camelCase from './camelCase';

describe('camelCase', () => {
  test('it works', () => {
    expect(typeof camelCase).toBe('function');
  });
});

// index.js
export { default } from './camelCase';

No more writing index files or test boilerplate! This encourages good practices especially on teams. If you already have test files or markdown files created then your team members will be more likely to fill them in with things that should be there. This is called the default effect.

Configuration

Even boil gets it's own rcfile! Put your own .boilrc file in the repo root or use cli flags. Here are the json options for .boilrc

{
  // The relative or absolute directory where your templates are kept.
  // Defaults to "./templates"
  "templateDirectory": "String",
  // The relative or absolute directory of you project root.
  // Defaults to the nearest package.json.
  "projectRoot": "String",
  // The path where the code should be written.
  // For example "./src" if you use the cli from project root.
  // Defaults to process.cwd().
  "codePath": "String",
  // Override the template file extension.
  // No default.
  "extension": "Boolean",
  // A string to match against template files that should be included.
  // No default.
  "include": "String",
  // A string to match against template files that should be excluded.
  // No default.
  "exclude": "String",
  // Print your current configuration.
  // Defaults to false.
  "debug": "Boolean",
  // Print code and codePath to the console but don't write anything.
  // Defaults to false.
  "dryRun": "Boolean"
}

The command boil -h will give you a list of accepted flags. In general they follow the --kebab-case format of the camelCase json options listed above.

Zero Config

Create most of a frontend react project with this command.

boil component -p src button link header footer layout cart checkout

Now the easy part writing the code :)