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

component-crafter

v2.0.5

Published

Component Crafter is a tool that allows you to create custom commands to generate templates for files and folders in your project. With Component Crafter, you can streamline your workflow by automating the creation of common structures and boilerplate cod

Downloads

11

Readme

Component Crafter

Component Crafter is a tool that allows you to create custom commands to generate templates for files and folders in your project. With Component Crafter, you can streamline your workflow by automating the creation of common structures and boilerplate code, saving you time and effort.

Installation

Downloading the Package

You can install Component Crafter via npm:

npm install component-crafter --save-dev

or you can install Component Crafter via yarn:

yarn add -D component-crafter

IMPORTANT: THIS PACKAGE DON'T WORK WHEN IS GLOBALLY INSTALLED

Inizializing the Component Crafter

After you have installed your package in your project, you should run the command yarn crafter init to create the template configuration file.

You can inizialize Component Crafter via npm:

npm run crafter init

or you can inizialize Component Crafter via yarn:

yarn crafter init

Once this is done, it will create a file which should be in the root of the project named '.component-crafter-config.json'. This file is important and should not be deleted.

Usage

Creating new command for a template

First of all, all configurations are done within the file named '.component-crafter-config.json' that we created earlier. The structure of the file should be as follows:

{
    "commands": [
        ...
    ]
}

To create a new command, we must create an object within the array of 'commands' that has the following properties:

{
    "name": "your custom command name",
    "description": "your custom command description",
    "startingPath": [],
    "scaffold": []
}

| Property Name | Description | Example | |---------------|-------------|---------| | "name" | The custom command name. | "component" | | "description" | The custom command description. | "A command for make a react component." | | "startingPath" | Where the command will start creating files and folders. This path starts from the root of the project. | [ "src", "components"] (This indicates that it will start from the root, then proceed to the 'src' folder, and within that folder, it will continue to 'components' where it will create the scaffold.) | | "scaffold" | The files and folders it will create. | [ ]|

Customizing the Scaffold

Once we have created the command, we need to define the scaffold, which is the tree structure of folders and files that we want to create each time we execute that command.

We will start with the following example:

{
    "commands": [
        {
            "name": "web",
            "description": "this command will create an html file inside a folder.",
            "startingPath": [],
            "scaffold": []
        }
    ]
}

To begin, before creating a file or a folder, we need the following three properties:

{
    "name": "folder/file name",
    "type": "file" for files / "folder" for folder ,
    "content": "" for files / [] for folder,
}

| Property Name | Description | Example | |---------------|-------------|---------| | "name" | The name for the file or folder. | "coolFolder" Remember if you want to make a file you need to put the extennsion like .html and if you want to pass the name via command you need to put |SPECIAL|.| | "type" | The type of element you are creating (file or folder). | "folder" for folders and "file" for files. | | "content" | The content of the file or folder. | "Im a file content :)" this is for files and you need to put the string of the content. this content accepts too the |SPECIAL|. [ ] this is an array of objects that can be other folders or files. |

Now we will create an empty folder within the html command, for make that we need to make the next object inside the scaffold:

{
    "name": "|SPECIAL|",
    "type": "folder",
    "content": [],
}

This folder has the name that you will pass on your command, later this will we explained on the Execute a new custom command.

This folder need to be inside the scaffold:

{
    "commands": [
        {
            "name": "web",
            "description": "this command will create an html file inside a folder.",
            "startingPath": [],
            "scaffold": [
                {
                    "name": "|SPECIAL|",
                    "type": "folder",
                    "content": [],
                }
            ]
        }
    ]
}

For finally the example we gonna add the file inside the content of the folder:

{
    "commands": [
        {
            "name": "web",
            "description": "this command will create an html file inside a folder.",
            "startingPath": [],
            "scaffold": [
                {
                    "name": "|SPECIAL|",
                    "type": "folder",
                    "content": [
                        {
                            "name": "|SPECIAL|.html",
                            "type": "file",
                            "content": "<html><head><title>|SPECIAL|</title></head><body></body</html>"
                        }
                    ],
                }
            ]
        }
    ]
}

Execute a new custom command

Once we have our commands set up and we want to execute them, we should do the following:

On yarn:

yarn crafter customCommandName specialParameter

On npm:

npm run crafter customCommandName specialParameter

You will need to replace the customCommandName with the name of your command and if you are using the "|SPECIAL|" you need to replace the specialParameter with the name example:

yarn crafter web Cool

Following the example of Customizing the Scaffold this will create a folder with name 'Cool' and inside the folder will be a file named 'Cool.html'

    Cool
     |____Cool.html