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

folder-template-generator

v1.0.0

Published

A CLI to generate folder structure described in a yaml document.

Downloads

1

Readme

folder-template-generator

This is a CLI that generate folder structure described in a yaml document.

Getting started

Run npm install -g folder-template-generator to install the CLI globally. Then run npm gfs <template-name> --name=module-name to generate module-name folder structure like described in template-name. View example of the template below for configuration.

Adding the template configuration file

  • Create a folder called gfs-config at the root of the project
  • Create a file name template.yaml inside folder gfs-config which contains the folder structure template
  • Example of folder structure template (inside template.yaml)
---
module:
  rootFolder: src
  folderName: ${name}
  defaultFileExt: js
  actions:
    files:
      -
        name: ${name}-action.types
        extension: ts
        template: template/template-action.types.txt
      - 
        name: ${name}-actions
        extension: ts
        template: path-to-template
  screens: 
    components:
  services:
    files:
      -
        name: ${name}-services
        extension: ts
        template: empty
  store:
    files:
      -
        name: ${name}-reducer
        extension: ts
        template: empty
...

Template configuration file explanation

  • module is the name of the template and will be used when generating the folder structure with command gfs module (You can have multiple template, view the last section of this document for example).
  • rootFolder is the root folder where the folder will be generated. If not provided, it will fallback to src
  • folderName is the name of the folder that will be generated. If not provided, it will fallback to the --name option value.
  • defaultFileExt is required and will be the default file extension used for files.
  • All other node represents folder (actions, screens, components, services, store...)
  • To add file inside a folder, create the child node files inside the target folder:
    • name will be the name of the file
    • extension will be the extension of the file, if not provided will fallback to defaultFileExt
    • template is the path of the file (.txt) which content will be added to the file, specifying its value to empty or omitting it will generate an empty file

Generating the folder structure

With this example of configuration above, when you run gfs module user, the CLI will generate the following folder inside src folder:

- src
  - user
    - actions 
      - user-actions.types.ts
      - user-actions.ts
    - screens
      - components
    - services
      - user-services.ts
    - store
      - user-reducer.ts 

Example of a file template

As stated above, if you specify a path to a file on the key template, the content of this file will be added to the newly created file. For example, this is the content of the template/template-action.types.txt file that will be added inside user-actions.types.ts file.

export enum ${name}ActionTypes {}

--name interpolation

All placeholder $ufl{name} will be replaced by the value of the option --name when executing the CLI. If you want to upper the first letter of the --name option, please use $ufl{name} instead of ${name}.

Adding multiple folder template

To add multiple folder template inside template.yaml, just define another yaml document like below:

---
module:
  rootFolder: src
  folderName: ${name}
  defaultFileExt: ts
  actions:
    files:
      -
        name: ${name}-action.types
        extension: ts
        template: template/template-action.types.txt
      - 
        name: ${name}-actions
        template: path-to-template
  screens: 
    components:
  services:
    files:
      -
        name: ${name}-services
        extension: ts
        template: empty
  store:
    files:
      -
        name: ${name}-reducer
        extension: ts
        template: empty
...
---
test:
  rootFolder: src
  folderName: ${name}
  defaultFileExt: js
  testFolder:
    files:
      -
       name: test
       template: empty
...

Running gfs test test will generate the following folder structure:

- src
  - test
    - testFolder
      - test.js