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

@merry-solutions/cli

v1.3.0

Published

Generate application components based on templates using command line.

Downloads

9

Readme

Cast

Well, what is it?

@merry-solutions/cli is a cli-tool designed to do the heavylifting when developing components requiring alot of boilerplate. It is originally intended for use with React, but can also be used for generating basically any set of files based on moustache templates.

Use existing presets or create your own with moustache templates.

How to use it

Install as dev dependency

npm i -D @merry-solutions/cli

Add to scripts in the package.json.

"cast": "cast"

Or simply run from command line without installation:

npx @merry-solutions/cli {some arguments here}

i.e.

npx @merry-solutions/cli cool-stuff/CoolHook --itemType=hook

Generate an item using one of the preset templates, currently component and hook creating is supported.

Example to generate a hook:

npm run cast -- shared/hooks/MyAwesomeHook --itemType=hook

Would generate a hook in src/shared/hooks/MyAwesomeHook based on the preset template.

Example to generate a component:

npm run cast -- components/MyAwesomeComponent --itemType=component

Would generate a component in src/components/MyAwesomeComponent based on the preset template.

Full list of params

itemType = required, should correspond to the name of a subfolder in the provided templatesRoot directory.

templatesRoot = optional, relative path to your custom folder with tempaltes, see below how to create your own templates.

nameCase = optional, name case for the entity name inside the template file, can be either set to camelCase or PascalCase. Defaults to PascalCase, is used to convert file name to entity name if the file name contains dashes or underscores.

folderPrefix = optional, prepend item folder with a string, i.e. --folderPrefix=use- for a hook.

Also can add any additional amount of --key=value pairs for replacements. I.e. if your template looks like:

// ./templates/random/random.txt.mustache
Hello, {{ name }}! I am {{ reaction }} to {{ verb }} you!

You can generate a file from it using the following command (yes, it is included in the default templates folder for demo purposes):

npx @merry-solutions/cli --itemType=random  some-random-stuff/happy-to-see-bob-file --name=Bob --reaction=happy --verb=see

Creating your own templates

Is pretty easy. You need a folder for templates, which would hold a collection of subfolders, each named same as the eitity you are attempting to create, i.e. the default templates folder has 2 subfolders: component and hook, so you can only create these two if you're using defaults.

Let's assume you want to create your own template for component, you would have to create a directory with a subfolder named after the type of the item you plan to create, i.e. my-templates/component.

project
└───src
│
└───my-templates
│   └───component
│       │   component.model.ts.mustache
│       │   component.tsx.mustache
│       │   ...

Place some moustache templates inside, note that if file name contains the subdirectory name in it, it will be swapped for the item name during file generation, i.e. component.tsx.mustache => SomeComponent.tsx.

The variable used in templates should hold same name as the subfolder, i.e. for the component we'd have:

// component.tsx.mustache
import { FC } from "react";

import { {{ component }}Props } from "./{{ component }}.model";
import style from "./{{ component }}.module.scss";

export const {{ component }}: FC<{{ component }}Props> = ({}: {{ component }}Props) => {
    return <div className={style.{{ component }}}>{{ component }} works!</div>;
};

Now simply invoke cast to create new files based on the provided templates by passing the template root as the templatesRoot param, i.e.:

npm run cast -- shared/components/MyComponent --itemType=component --templatesRoot=./templates/

See sample templates in the templates folder of this repo or check the demo react repo for templates folder and commands for generating files in package.json.

"Buy Me A Coffee"