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

@jamen/new-common

v1.0.0

Published

Base functions for project generators.

Downloads

11

Readme

@jamen/new-common

Base functions for project generators.

Install

npm i @jamen/new-common

Usage

create(output, questions, templates)

Prompts for the questions then writes to the output using templates.

  • output is the directory where templates created.
  • questions is a function of questions(output) -> Promise<Array<question>> (see propmts)
  • templates is a function of templates(answers) -> Promise<Array<template>> (see Templates)
create(
    process.cwd(),
    questions,
    templates
)

preview(output, questions, templates)

Like create(), but doesn't create any files. Just runs the prompts and displays a file tree at the end. This is helpful, because answers can often affect the structure of the output.

Templates

Each template is:

templates : {
    input: String,
    create: Function<answers> -> Promise<Array<template>>
}

template : {
    from: String,
    to: String,
    use: Function<from, to, answers>
}

The function in use is called a "directive" or simply a "use", and its job is to copy or create the source (if there is one) to the destination, using prompt answers to add variance to the output.

Note that from can be absent, since the files wont always have static contents (i.e. empty contents, or completely dynamic contents).

Uses

The package has common uses for templating, merging, and creating files.

  • createTemplateNormal: Templates with lodash.template
  • createTemplateJson: Templates and then merges into destination (e.g. a package.json)
  • createTemplateUniq: Templates and enforces unique lines (e.g. a .gitignore)
  • createLicense: Creates a license file given a license type answer.
  • createFile: Creates any file.

An example of how two variations of these functions would look:

const templates = answers => [
    {
        from: 'package.json',
        to: 'package.json',
        use: createTemplateJson
    },
    {
        from: 'lib/project.js',
        to: `lib/${basename(answers.name)}.js`,
        use: createTemplateNormal
    },
    {
        to: 'license',
        use: createLicense
    },
]

Utils

The package has other utility functions for common tasks

  • exactTemplates(input, templates) is used for composing templates from a different generator.
  • installNpmPackages(dir, packages, dev) is to install dependencies (with yarn, pnpm, or npm).
  • templateFile(from, answers) is used for reading and templating a file without writing it yet.
  • message are functions to create any message logged by the core functions.
  • prompts is prompts.

Other utils are functions from Node core that have been promisified.