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

pz

v1.1.1

Published

Dead simple templating.

Downloads

9

Readme

pz

Dead simple templating. Requires Node.js.

Install

npm install -g pz

Creating your first template

$ pz --create template
? Name: foo
? Template file extension: tmpl
? View engine: lodash
? Outputted file name: ./somewhere/<%= foo_name %>.js

Generating a file using your first template.

Your template is empty (we'll fix that later), but you can already use it to generate new files:

$ pz --create foo
? Name: bar
? Description: A pretty useless file, for now!

Customizing your template.

In the subdirectory /pz-templates/create/foo, you'll find two files: foo.tmpl and index.js. We can edit the prompts defined in index.js. Pz uses Inquirer to handle command prompting. We'll answer these prompts whenever we create a new foo file.

module.exports = {
    translate: {
        'foo.tmpl': './somewhere/<%= foo_name %>.js'
    },
    engine: 'lodash',
    beforePrompt: function(context, done) {
		//this is an optional function
        console.log('I\'mma bout to prompt you.');
        done(); 
    },
	beforeRender: function(context, done) {
		//this is an optional function
		//context.viewModel.anotherValue = 1;
		//console.log(context.viewModel);
		done();
	},
    prompts: [
        {
            'name': 'foo_name',
            'message': 'Name'
        },
        {
            'name': 'description',
            'message': 'Description'
        },
        {
            'name': 'message',
            'message': 'Message',
            'default': 'Aloha, World!'
        }
    ],
    after: function() {
		//this is an optional function
        //console.log('all done.');
    }
};

Let's edit the template file, foo.tmpl, to make use of our prompts:

'use strict';

/*
*	<%= foo_name %>
*	<%= description %>
*/

(function($) {
	$(function() {
		alert('<%= message %>');
	});
})(jQuery);

Time to generate a new foo file:

$ pz --create foo
I'mma bout to prompt you.
? Name: hello
? Description: Say hello using javascript.
? Message: Aloha, world!

Here's the generated somewhere/hello.js file:

'use strict';

/*
*	hello
*	Say hello using javascript.
*/

(function($) {
	$(function() {
		alert('Aloha, World!');
	});
})(jQuery);

Sharing templates and view models

Let's say our foo template lives in git/pz-templates. But we want to use foo in the directory git/chocolate. First, we'll need to create a pz config file in the chocolate folder:

$ cd chocolate
$ pz --create config

Then, open the generated config file, at documents/git/chocolate/pz-templates/config.json, and add the full git/pz-templates path to the paths array. We'll also add some context variables, just for kicks:

{
	"context": {
		"author": "Evan Nagle",
		"email": "[email protected]",
		"version": "1.0.0"
	},
	"paths": [
		"C:/.../pz-templates"
	]
}

We're good to go!

When working in the chocolate directory, our template files can make use of the context variables:

'use strict';

/*
*	<%= foo_name %>
*	<%= description %>
*
*	Author: <%= context.author %>
*	Email: <%= context.email %>
*	Version: <%= context.version %>	
*/

(function($) {
	$(function() {
		alert('<%= message %>');
	});
})(jQuery);