https://github.com/mglagola/easy-generator
A simple template generator that utilizes handlebars
https://github.com/mglagola/easy-generator
generator javascript nodejs
Last synced: 7 months ago
JSON representation
A simple template generator that utilizes handlebars
- Host: GitHub
- URL: https://github.com/mglagola/easy-generator
- Owner: mglagola
- Created: 2017-03-19T18:09:04.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-13T14:36:25.000Z (over 7 years ago)
- Last Synced: 2025-03-20T07:42:58.289Z (7 months ago)
- Topics: generator, javascript, nodejs
- Language: JavaScript
- Homepage:
- Size: 43 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Easy Generator
A simple template generator that combs through a template directory (`templateDir`) and will compile all files via `handlebars`. The files are then written to the provided output directory (`outputDir`).
## Install
```bash
npm install --save easy-generator
```## Examples
### Production Example
* [hapi-site-gen](https://github.com/mglagola/hapi-site-generator)
### Simple Example
```js
const gen = require('easy-generator');const outputDir = '/Users/SOME_USER/Desktop/temp';
const templateDir = './TEMPLATE_DIR';// `data` is passed to every file in the templateDir for handlebars compilation
const data = {
name: 'Mark',
nodeVersion: '7.7',
};gen({ outputDir, templateDir, data })
.then(() => {
console.log('✅ Generated ✅');
process.exit(0);
})
.catch(error => {
console.error(error);
console.error(`❌ FAILED to generate ❌`);
process.exit(1);
});```
### Longer Example
```js
#! /usr/bin/env node'use strict';
const Promise = require('bluebird');
global.Promise = Promise;const Inquirer = require('inquirer');
const Path = require('path');
const program = require('commander');
const gen = require('easy-generator');const Questions = [{
type: 'input',
name: 'name',
message: 'What is the name of your site?',
}, {
type: 'input',
name: 'description',
message: 'Site\'s description?',
}, {
type: 'input',
name: 'version',
message: 'Site\'s version?',
}, {
type: 'input',
name: 'author',
message: 'Site author?',
}, {
type: 'input',
name: 'nodeVersion',
message: 'What node version are you using?',
default: '7.7',
}];const outputDir = Path.join(process.cwd(), name);
const templateDir = '/SOME/PATH/TO/TEMPLATE/DIR';Inquirer.prompt(questions(name))
.then(answers => {
const data = answers;
return gen({ templateDir, outputDir, data });
})
.then(() => {
console.log('✅ Generated ✅');
process.exit(0);
})
.catch(error => {
console.error(error);
console.error(`❌ FAILED to generate ❌`);
process.exit(1);
});```