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

churnjs

v0.1.5

Published

Create files from templates

Downloads

6

Readme

Churn

Generate files and folders from a template. Let it do the boring stuff for you.

!! WARNING !!

This is barely a pre-alpha. It's literally something that I threw together in half an hour. Do feel free to contribute!

Currently unimplemented features:

  • Tests
  • Parallel file/folder processing (currently everything is synchronous)
  • Symlink handling
  • Many other things

Why

Because I'm tired of having to copypaste trivial code

How

First, create a file named churnfile.js (or you can name it something different and pass it with the --config option) like this:

const path = require('path')

module.exports = {
	variables: {
		TEST_VARIABLE: 'hello',
		CREATION_DATE: () => new Date(),
		NAME_VARIATION: name => `${name}-san`
	},
	templates: [path.join(__dirname, 'templates')],
	output: path.join(__dirname, 'out')
}

You can specify your variables and you must specify at least one template path within the templates array. The output option allows you to specify where you want the output to be saved, but you can also set it when calling churn by using the --output option.

The complete command call is this:

./src/cli.js --config <config_name> --template <template_name> --output <wherever> lowercase-name-of-the-thing

A simple example that uses the default churnfile.js is the following

./src/cli.js --template component progress-bar

You can omit the --template option. In that case, churn will look for a template with the same name of what you are trying to create. This is not recommended.

You can add it to you project by running npm install churnjs ( churn was already taken :( ), adding a churnfile and some templates and then alias some npm scripts in your package.json:

{
	//...
	scripts: {
		"make:component": "churnjs --template component --output src/components"
	},
	//...
}

You can then call npm run make:component MyComponent and be happy!

Templates

Templates are directories with files in them. They can also have other directories with other files, as deep as your heart desires. The content of a file will be replicated, with variables replaced. Variables can also be used in a file or a directory's name, check out the example templates within the example_templates directory.

Variables are enclosed between % symbols, and these are defined by default:

NAME: toLower(name),									// hellofriend
UPPER_NAME: toUpper(name),								// HELLOFRIEND
NAME_PLURAL: toLower(pluralize.plural(name)),			// hellofriends
UPPER_NAME_PLURAL: toUpper(pluralize.plural(name)),		// HELLOFRIENDS
CAMEL_NAME: camel(name),								// HelloFriend
CAMEL_NAME_PLURAL: camel(pluralize.plural(name))		// HelloFriends

where name is the one you pass from the command line. All the above variables can be overridden within the churnfile, and new ones can be defined within its variables key. You can use either immediate values or functions to define them, with the function variant always receiving the name as its first and only argument.

The .tpl extension is optional, it will be stripped away if present. Use it if your editor screams at you for using %VARIABLES%, knowing that you'll probably lose syntax highlighting.

Contribute

Yes, please!

Acknowledgements

React Native Create Library has a way of handling the command definition that I liked, so I used that. Thank you @frostney!

License

MIT