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

erector-set

v1.0.0-beta.3

Published

A tool for creating project generators

Downloads

42

Readme

Build Status

erector-set

A tool for creating project generators

Usage

Install this package

npm i -S erector-set

And use it in a file

const erectorSet = require('erector-set');

const questions = [
    { name: 'animal', question: 'Enter an animal:' },
    { name: 'unused', question: 'What\'s your age?' },
    { name: 'animalId', transform: convertSpaces, useAnswer: 'animal' }
];
const templates = [
    { destination: './animal-story.txt', template: 'My favorite animal is a(n) {{ animal }} (id: {{ animalId }})' },
    { destination: './sub/{{ animalId }}-file' }
];

const convertSpaces = value => {
    return value.replace(/\s/g, '_');
};

erectorSet.build(questions, templates);

When run, this will prompt the user similar to the following:

Enter an animal: Tiger Shark
What's your age? 24

Given the above answers, it would produce the following file structure:

|_sub/
| |_TigerShark-file
|_animal-story.txt

The file in sub/TigerShark-file would be empty since there was no template provided while the contents of animal-story.txt would be:

My favorite animal is a(n) Tiger Shark (id: TigerShark)

Methods

  • build(questions, templates): asks the provided questions, performs string replacements on templates based on those answers, then outputs those files; returns a Promise
  • construct(answers, templates): function to perform string replacement on template templates based on the answers
  • inquire(questions): tool used by build to ask questions; returns a Promise

Data Structures

Questions

The questions to ask a user should be provided as an Array of Objects with the following structure:

  • allowBlank: if truthy, will allow blank answers
  • defaultAnswer: provide a default value to use; if provided, allowBlank is true
  • name (required): an ID, unique to the set of questions
  • question: the String prompt to show the user
  • transform: a Function to transform the user's input; method signature is transformMethod(value, allAnswers) where allAnswers is the Array of answers up until that point.
  • useAnswer: if a question is not provided, this attribute can be provided to use another question's answer. Make sure these questions are at the end of the list of questions!

Templates

The templates should be provided as an Array of Objects with the following structure:

  • check: a function to see if the file should be created; if omitted or not a Function, it defaults to true.
  • destination (required): the file path to create. Note that destination values are run through the same template variable-replacement as the template values. This means your can output variable file names.
  • template: the string to do replacements on; if this is omitted, a blank file will be created. This can also be a file path to a template; if it is, the file will be read and used for replacements.

Template Format

The template.template value is a String which can either point to a file location or be the template itself. The format of templates uses a variable scheme similar to Angular or Vue, as shown in the following example:

<html>
    <body>
        <h1>{{ myHeader }}</h1>
    </body>
</html>

In this template, the question named myHeader would be replaced with the answer to that question. It is important to remember any {{ }}-wrapped strings that DO NOT have a matching answer will not be replaced. This was done purposefully to allow accurate generation of libraries which use such a syntax.