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

hcp

v0.3.1

Published

Like cp, but with Handlebars template

Downloads

4

Readme

hcp Build Status

hcp - handlebars-copy

Like cp, but with Handlebars template

Install

npm install hcp

Usage

  $ hcp <files...> [options]

  Options:
    --help             Show this help output
    --version          Show package version
    --debug            Show extended debug output

  Examples:

    $ hcp package.json package.copy.json
    $ hcp index.html package.json app/ --name foobar
    $ hcp_name="foobar" hcp text/examples/* ~/dev/myapp/app

Description

hcp is a CLI tool similar to the cp command.

File copy is done using Streams, with lodash.template parsing files if they have template placeholders {{ ... }}.

Handlebars template are executed in the context of the following object:

Object.assign({}, env, opts)

// where `env` and `opts` have the following structure

{
  env: {
    PATH: '...',
    ...
  },

  opts: {
    debug: true,
    name: 'Foobar'
  }
}

The templates context is a merged version of various sources, with the following order of precedence:

  • opts - Command line flags as parsed by minimist
  • env - process.env variables begining with hcp_
  • prompts - Generated prompts, see below

Prompts

Handlebars templates can have any number of placeholders. Variables are either available in the context object, or automatically prompted for the user to enter a value.

Skipping a prompt is then available with --name Value.

To enable it, inquirer must be installed and available in node_modules.

npm i inquirer -D

If not installed, prompts are not generated.

JSON

JSON files are merged together with destination, if it already exists.

Tests / API

hcp

cli

Copy files

hcp test/examples/package.json test/output.json.

hcp('test/examples/package.json test/output.json')
  .expect(0)
  .end(() => {
    assert.deepEqual(require('./output.json'), {
      name: 'input',
      description: '',
      foo: 'bar'
    });
    done();
  });

Merges files with existing JSON destination

hcp test/examples/package.json test/existing.json.

hcp('test/examples/package.json test/existing.json')
  .expect(0, (err) => {
    if (err) return done(err);
    assert.deepEqual(require('./existing.json'), {
      name: 'output',
      description: '...',
      foo: 'bar',
      bar: true
    });
    fs.writeFile(path.join(__dirname, 'existing.json'), JSON.stringify({
      name: 'output',
      description: '...',
      bar: true
    }, null, 2), done);
  });

Transfrom Handlebars / Mustache like placeholders with lodash.template

hcp test/examples/* test/output/ --name blah --description desc --foo bar.

hcp('test/examples/* test/output/ --name blah --description desc --foo bar')
  .expect(0, (err) => {
    if (err) return done(err);
    assert.deepEqual(require('./output/package.json'), {
      name: 'input',
      description: '',
      foo: 'bar'
    });
    assert.deepEqual(require('./output/tpl.json'), {
      name: 'blah',
      description: 'desc',
      foo: 'bar'
    });
    done();
  });