# erector-set

> A tool for creating project generators

Latest version **1.0.0-beta.3** (published 2017-07-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install erector-set
pnpm add erector-set
yarn add erector-set
bun add erector-set
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-beta.3 |
| Published | 2017-07-31 |
| First published | 2017-01-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Matt Fehskens |
| Maintainers | gonzofish |
| Keywords | generator |

## Links

- npm: https://www.npmjs.com/package/erector-set
- Repository: https://github.com/gonzofish/erector-set
- Homepage: https://github.com/gonzofish/erector-set#readme
- Issues: https://github.com/gonzofish/erector-set/issues
- npm.io page: https://npm.io/package/erector-set

## Recent versions

- 1.0.0-beta.3 (latest) — 2017-07-31
- 1.0.0-beta.2 — 2017-07-31
- 1.0.0-beta.1 — 2017-07-17
- 1.0.0-alpha.4 — 2017-06-28
- 1.0.0-alpha.3 — 2017-06-20
- 1.0.0-alpha.2 — 2017-02-28
- 1.0.0-alpha.1 — 2017-02-17
- 1.0.2-alpha — 2017-01-19
- 1.0.1-alpha — 2017-01-19
- 1.0.0-alpha — 2017-01-19
- 0.0.0-alpha — 2017-01-19

## README

[![Build Status](https://semaphoreci.com/api/v1/gonzofish/erector-set/branches/master/badge.svg)](https://semaphoreci.com/gonzofish/erector-set)

# erector-set
A tool for creating project generators

## <a name="usage"></a>Usage

Install this package

```shell
npm i -S erector-set
```

And use it in a file

```javascript
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:

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

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

```shell
|_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:

```shell
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](https://angular.io/ "Angular") or
[Vue](http://vuejs.org/ "Vue.js"), as shown in the following example:

```html
<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.

---
_Source: https://npm.io/package/erector-set · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
