Generate a new project directly from Git(Hub) using a simple schema.
It is a command that takes a templated tree of files and generates them for new
projects using data defined by a simple schema. The data can define an output
name
, files to discard
, files to parse
with the data, and files to move
or rename. The template can supply the default data, and that data can be
extended for each project. You can throw in any other data you'd like to be
passed to the template context as well.
All templates are parsed with Nunjucks aka Jinja and Twig.
When starting new projects the quickest way is often to just copy the last project and fiddle with it until it works. This can introduce many unwanted issues, like having one client's name appear in place of the other's. This project's goal is to offer an elegant and efficient way of working with a base set of files that can be understood by looking at a single example.
$ npm install -g pollinate
$ pollinate howardroark/webapp --name newproject --image alpine --description="A thing that does something."
.
├── PROJECT-README
├── README.md
├── Dockerfile
├── project-name
└── template.json
{
// Core schema
"name": "webapp",
"parse": [
"PROJECT-README",
"Dockerfile"
],
"discard": [
"README.md",
"template.json"
],
"move": [
{ "PROJECT-README": "README.md" },
{ "project-name": "{{ name }}.txt" }
],
// Custom defaults
"image": "debian",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
}
You can omit any or all of discard
, parse
and move
.
# {{ name }}
{{ description }}
FROM {{ image }}
{
"name": "newproject",
"image": "alpine",
"description": "A thing that does something."
}
{
"name": "newproject",
"parse": [
"Dockerfile",
"PROJECT-README"
],
"discard": [
"README.md",
"template.json"
],
"move": [
{ "PROJECT-README": "README.md" },
{ "project-name": "newproject.txt" }
],
"image": "alpine",
"description": "A thing that does something."
}
.
└── newproject
├── README.md
├── newproject.txt
└── Dockerfile
# newproject
A thing that does something.
FROM alpine
You can specify template files as a local directory (.git will be removed)
$ pollinate ./template --name newproject --image ubuntu
You can use any Git url (.git will be removed)
$ pollinate https://github.com/howardroark/webapp.git --name newproject --image ubuntu
You can pass project data as a file
$ pollinate howardroark/webapp data.json
You can pass project data as a JSON string
$ pollinate howardroark/webapp '{"name":"newproject","image":"alpine","description":"A thing that does a thing."}'
You can pass project data as a JSON endpoint
$ pollinate howardroark/webapp https://example.com/json/data
You can generate from the default data in the template
$ pollinate howardroark/webapp
You can override data as CLI options
$ pollinate howardroark/webapp data.json --name=alternate --image=ubuntu
You can specify a command to run on completion
{
"complete": "git init {{ name }}"
}
You can supply user specific data each time with a ~/.pollen
defaults file
{
"api_key":"secret"
}
You can preserve the commit history from the skeleton project with the --keep-history
CLI option or:
{
keepHistory: true
}
You can supply custom Nunjucks filter
functions (files must be included within template)
{
"filters": {
"markdown": "filters/markdown.js"
}
}
var markdownParser = function() { ... }
module.exports = function(markdownText) {
var html = markdownParser(markdownText)
return '<div class="markdown">'+html+'</div>'
}
All parse
paths are first passed to globby
{
"parse": ["*"]
}
{
"parse": [
"*",
"!templates"
]
}
You can specify .json
files to merge
{
"name": "@howardroark/webapp",
"version": "1.0.0",
"description": "project for testing pollinate with merge",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/howardroark/webapp.git"
},
"author": "Andy Edwards",
"license": "ISC",
"bugs": {
"url": "https://github.com/howardroark/webapp/issues"
},
"homepage": "https://github.com/howardroark/webapp#readme",
"dependencies": {
"lodash": "^4.17.4"
}
}
{
"name": "@{{ organization }}/{{ name }}",
"version": "1.0.0",
"description": "{{ description }}",
"repository": {
"type": "git",
"url": "git+https://github.com/{{ organization }}/{{ name }}.git"
},
"author": "{{ author }}",
"bugs": {
"url": "https://github.com/{{ organization }}/{{ name }}/issues"
},
"homepage": "https://github.com/{{ organization }}/{{ name }}#readme",
}
{
"name": "webapp",
"description": "project for testing pollinate with merge",
"organization": "howardroark",
"author": "Andy Edwards",
"parse": [
"PROJECT-package.json"
],
"merge": [
["package.json", "PROJECT-package.json"]
],
"discard": [
"PROJECT-package.json"
]
}
pollinate howardroark/webapp#merge-test --name myapp --description 'my new app' --organization myorg --author Me
This will overwrite package.json
with the contents of package.json
and PROJECT-package.json
merged with
lodash.merge
. This is useful when you want to keep template variables out of package.json
, since they would cause
certain npm
commands to fail.
{
"name": "@myorg/myapp",
"version": "1.0.0",
"description": "my new app",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/myorg/myapp.git"
},
"author": "Me",
"license": "ISC",
"bugs": {
"url": "https://github.com/myorg/myapp/issues"
},
"homepage": "https://github.com/myorg/myapp#readme",
"dependencies": {
"lodash": "^4.17.4"
}
}
- @binhood for the fantastic work on the logo!
- @jedwards1211 for the handy object
merge
option :) - @ben657 for refactoring a bunch of stuff :o