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

node-templer

v0.0.4

Published

template engine for projects.

Downloads

3

Readme

Intention

As a developer, it is not uncommon to copy and paste skeleton boilerplate across projects. Some IDEs provide nice and handly skeleton (e.g.: xcode). However there seems no such thing in the world of javascript. Hence I decide to make a tiny tools for project based templating.

Install

npm install node-templer

Example

Let's say in a React project with the app structure like this:

src /
  components /
    MyButton /
      index.js
      test.js
      style.css
    MyCard /
      index.js
      test.js
      style.css
// ...

At project root, run:

bash $ node-templer init

or

bash $ npx node-templer init

This will create a .temp folder in the project root for storing templates.

After that, create a folder in .temp named with the type of template you want to create and add files with extension temp in it. For example:

.temp /
  components /
    index.js.temp
    style.css.temp
    test.js.temp

In those .temp files, edit your own skeleton:

index.js.temp

// .temp/components/index.js.temp

import React from 'react'
import './style.css'

export default class %%name%% extends React.Component {
  render() {
    return (
      <div className="%%classname%%">
        This is %%name%% component
      </div>
    )
  }
}

style.css.temp

// .temp/components/style.css.temp

.%%classname%% {
  // component style goes here
}

test.js.temp

// .temp/components/test/js/temp

import React from 'react'
import { shallow } from 'enzyme'
import %%name%% from './index'

describe('Component: %%name%%', () => {
  it('renders without crashes', () => {
    shallow(<%%name%% />)
  })
})

If we want to add a MyForm component, just run:

bash $ node-templer create components Form classname=custom_form

and it will generate files:

index.js

// src/components/MyForm/index.js

import React from 'react'
import './style.css'

export default class MyForm extends React.Component {
  render() {
    return (
      <div className="custom_form">
        This is MyForm component
      </div>
    )
  }
}

style.css

// src/components/MyForm/style.css

.custom_form {
  // component style goes here
}

test.js

// src/components/MyForm/test.js

import React from 'react'
import { shallow } from 'enzyme'
import MyForm from './index'

describe('Component: MyForm', () => {
  it('renders without crashes', () => {
    shallow(<MyForm />)
  })
})

Usage

node-templer <command>

Commands:
  node-templer init                         Initialize templer to the project.
  node-templer create <temp> <name>         Create templates defined in .temp
  [vars..]                                  folders.

Options:
  --version       Show version number                                  [boolean]
  -r, --root      Set base folder of templates to be created.   [default: "src"]
  -e, --encoding  Set file encoding.                           [default: "utf8"]
  --help          Show help                                            [boolean]

For the command node-templer create will create nested folder <temp>/<name> in the root folder (default: src). You can still define name=something in [vars], it will not affacting the name of the folder but the variable %%name%% in your template files. For example, in the above case, if we use command

node-templer create components MyForm classname=custom_form name=OtherName,

it will create files in path src/components/MyForm, while in the context of the files, %%name%% will be replaced by OtherName instead of MyForm.