Skip to content

Commit

Permalink
feat: support array for 'complete'
Browse files Browse the repository at this point in the history
  • Loading branch information
jednano committed Aug 14, 2019
1 parent 1bfe968 commit cf30238
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 22 deletions.
44 changes: 30 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ $ pollinate howardroark/webapp --name newproject --image alpine --description="A

###### `template.json` (optional)

```
```json
{
// Core schema
"name": "webapp",
Expand All @@ -72,25 +72,25 @@ $ pollinate howardroark/webapp --name newproject --image alpine --description="A
}
```

You can omit any or all of `discard`, `parse` and `move`.
You can omit any or all of `discard`, `parse` and `move`.

###### `PROJECT-README`

```
```md
# {{ name }}

{{ description }}
```

###### `Dockerfile`

```
```md
FROM {{ image }}
```

##### The project data

```
```json
{
"name": "newproject",
"image": "alpine",
Expand All @@ -100,7 +100,7 @@ FROM {{ image }}

##### The data after extending and parsing

```
```json
{
"name": "newproject",
"parse": [
Expand Down Expand Up @@ -182,33 +182,49 @@ $ pollinate howardroark/webapp data.json --name=alternate --image=ubuntu
```

You can specify a command to run on completion
```
```json
{
"complete": "git init {{ name }}"
}
```

Which can also be an array of commands
```json
{
"complete": [
"cd {{ name }}",
"git init",
"npm install",
"git add .",
"git commit -m 'initial commit'",
"git remote add origin https://github.com/{{ org }}/{{ name }}.git",
"git push -u origin master",
"code ."
]
}
```

You can supply user specific data each time with a `~/.pollen` defaults file

```
```json
{
"api_key":"secret"
}
```

You can preserve the commit history from the skeleton project with the `--keep-history` CLI option or:

```
```json
{
keepHistory: true
"keepHistory": true
}
```

## Filters

You can supply custom [Nunjucks `filter`](https://mozilla.github.io/nunjucks/templating.html#filters) functions (files must be included within template)

```
```json
{
"filters": {
"markdown": "filters/markdown.js"
Expand All @@ -218,7 +234,7 @@ You can supply custom [Nunjucks `filter`](https://mozilla.github.io/nunjucks/tem

##### `filters/markdown.js`

```
```js
var markdownParser = function() { ... }

module.exports = function(markdownText) {
Expand All @@ -231,12 +247,12 @@ module.exports = function(markdownText) {

All `parse` paths are first passed to [globby](https://github.com/sindresorhus/globby)

```
```json
{
"parse": ["*"]
}
```
```
```json
{
"parse": [
"*",
Expand Down
28 changes: 20 additions & 8 deletions lib/complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@ module.exports = function (state, callback) {
// Call the shell command specified as `complete`
function (next) {
if (complete !== undefined) {
exec(complete, function (err) {
if (err) {
next(err);
return;
}
next(null);
});
var commands = (typeof complete === 'string')
? [complete]
: complete;
async.series(commands.map(onCommand)).then(next, next);
} else {
next(null);
}
Expand All @@ -48,6 +45,21 @@ module.exports = function (state, callback) {
}
callback(null, state);
});

};

function onCommand(command) {
if (/^cd /.test(command)) {
process.chdir(command.substr(3));
return Promise.resolve(null);
}
return new Promise((resolve, reject) => {
exec(command, (err, data) => {
if (err) {
reject(err);
return;
}
data && console.log(data);
resolve(null);
});
});
}
21 changes: 21 additions & 0 deletions tests/mocks/data-complete-array.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "data-complete",
"image": "debian",
"discard": [
"README.md"
],
"parse": [
"Dockerfile",
"PROJECT-README"
],
"move": [
{ "PROJECT-README": "README.md" },
{ "project-name": "{{ name }}.txt" },
{ "project-name-dir": "{{ name }}" },
{ "project-name-nested": "{{ name }}/{{ name }}/{{ name }}.txt" }
],
"complete": [
"cd {{ name }}",
"pwd"
]
}
15 changes: 15 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,19 @@ describe('Test basic example', function () {
rimraf('data-complete', done);
});
});
it('Local path without template.json, json file with complete array', function (done) {
pollinate({
"inputs": [
"./tests/mocks/template-no-data/",
"tests/mocks/data-complete-array.json"
],
"options": {
//
}
}, function (err, result) {
assert.isNull(err);
assert.isObject(result);
rimraf('data-complete-array', done);
});
});
});

0 comments on commit cf30238

Please sign in to comment.