Skip to content
This repository was archived by the owner on Feb 8, 2019. It is now read-only.

Commit 130a884

Browse files
authored
Merge pull request #132 from cellsjs/feature/dynamic_type_inquirer
Feature/dynamic type inquirer
2 parents e044393 + 4c81b1a commit 130a884

File tree

3 files changed

+99
-64
lines changed

3 files changed

+99
-64
lines changed

README.md

+57-55
Original file line numberDiff line numberDiff line change
@@ -34,93 +34,89 @@ So, you can use all your favorites tools keeping it under control and versioned.
3434
* [Complete documentation](doc/README.md) - Complete documentation, howtos, api, examples...
3535
* [Spanish documentation](doc/spanish/README.md) - Spanish documentation for piscosour.
3636

37-
# Installing piscosour
3837

39-
Install piscosour globally
38+
# Index: 'piscosour'
4039

41-
npm install -g piscosour
40+
- [ Commands Availables](#commands-availables)
41+
- [Plugins](#plugins)
42+
- [Contexts](#recipes)
43+
- [Recipes](#recipes)
4244

4345

44-
# Recipes
4546

47+
# Commands Availables
4648

47-
|Name|Version|Description|
48-
|---|---|---|
49-
|pisco-user|-|User Piscosour Recipe|
50-
|piscosour|0.6.5|Get all your devops tools wrapped-up!|
5149

50+
## Index:
5251

5352

54-
# Commands
53+
- from **piscosour v.0.6.8**
54+
- straws
55+
- [node-module:convert (Convert any module into a piscosour recipe)](#node-moduleconvert-convert-any-module-into-a-piscosour-recipe)
56+
- [recipe:add-shot (Add a shot to a piscosour recipe)](#recipeadd-shot-add-a-shot-to-a-piscosour-recipe)
57+
- [recipe:add-straw (Add a straw to a piscosour recipe)](#recipeadd-straw-add-a-straw-to-a-piscosour-recipe)
58+
- [recipe:configure (Manage a piscosour recipe)](#recipeconfigure-manage-a-piscosour-recipe)
59+
- [recipe:create (Starting a repository from scratch)](#recipecreate-starting-a-repository-from-scratch)
60+
- [recipe:docs (Append documentation from info.md to readme.md of the recipe)](#recipedocs-append-documentation-from-info.md-to-readme.md-of-the-recipe)
61+
- shots
62+
- [all::npm (Checking all npm commands needed)](#allnpm-checking-all-npm-commands-needed)
63+
- [node-module::convert (Convert any nodejs module into a piscosour recipe)](#node-moduleconvert-convert-any-nodejs-module-into-a-piscosour-recipe)
64+
- [recipe::add-shots (Create new pisco shot inside this module)](#recipeadd-shots-create-new-pisco-shot-inside-this-module)
65+
- [recipe::add-straws (Adding shot to a straw)](#recipeadd-straws-adding-shot-to-a-straw)
66+
- [recipe::configure (Configure piscosour.json)](#recipeconfigure-configure-piscosour.json)
67+
- [recipe::generate-docs (Generate one file per straw inside a directory)](#recipegenerate-docs-generate-one-file-per-straw-inside-a-directory)
68+
- [recipe::scaffolding (Create a piscosour recipe from a scaffold template)](#recipescaffolding-create-a-piscosour-recipe-from-a-scaffold-template)
69+
- [recipe::update (Update tool)](#recipeupdate-update-tool)
5570

5671

5772

58-
**from piscosour v.0.6.5:**
73+
## node-module:convert (Convert any module into a piscosour recipe)
5974

60-
- **pisco node-module::convert** ( Convert any nodejs module into a piscosour recipe )
61-
- **pisco recipe::generate-docs** ( Generate one file per straw inside a directory )
62-
- **pisco all::npm** ( Checking all npm commands needed )
63-
- **pisco recipe::piscosour** ( Configure piscosour.json )
64-
- **pisco recipe::scaffolding** ( Create a piscosour recipe from a scaffold template )
65-
- **pisco recipe::shots** ( Create new pisco shot inside this module )
66-
- **pisco recipe::straws** ( Adding shot to a straw )
67-
- **pisco recipe::updateversion** ( Update tool )
68-
- **pisco recipe:add-shot** ( Add a shot to a piscosour recipe )
69-
- **pisco recipe:add-straw** ( Add a straw to a piscosour recipe )
70-
- **pisco recipe:config** ( Manage a piscosour recipe )
71-
- **pisco node-module:convert** ( Convert any module into a piscosour recipe )
72-
- **pisco recipe:create** ( Starting a repository from scratch )
73-
- **pisco recipe:docs** ( Append documentation from info.md to readme.md of the recipe )
75+
convert straw
7476

77+
### 1. convert: 'Convert any nodejs module into a piscosour recipe'
78+
```
79+
Repository types: node-module
80+
Recipes: piscosour (0.6.8)
81+
```
82+
shot convert
7583

84+
## recipe:add-shot (Add a shot to a piscosour recipe)
7685

77-
## add-shot: 'Add a shot'
78-
Add a shot to a piscosour recipe
7986

8087

81-
### 1. shots: 'Create new pisco shot inside this module'
88+
### 1. add-shots: 'Create new pisco shot inside this module'
8289
```
8390
Repository types: recipe
84-
Recipes: piscosour (0.6.5)
91+
Recipes: piscosour (0.6.8)
8592
```
8693
shot shots
8794

88-
## add-straw: 'Add straw'
89-
Add a straw to a piscosour recipe
95+
## recipe:add-straw (Add a straw to a piscosour recipe)
96+
9097

9198

92-
### 1. straws: 'Adding shot to a straw'
99+
### 1. add-straws: 'Adding shot to a straw'
93100
```
94101
Repository types: recipe
95-
Recipes: piscosour (0.6.5)
102+
Recipes: piscosour (0.6.8)
96103
```
97104
shot straws
98105

99-
## config: 'Configure piscosour'
100-
Manage a piscosour recipe
106+
## recipe:configure (Manage a piscosour recipe)
107+
101108

102109

103-
### 1. piscosour: 'Configure piscosour.json'
110+
### 1. configure: 'Configure piscosour.json'
104111
```
105112
Repository types: recipe
106-
Recipes: piscosour (0.6.5)
113+
Recipes: piscosour (0.6.8)
107114
```
108115
shot piscosour
109116

110-
## convert: 'Module to recipe'
111-
Convert any module into a piscosour recipe
117+
## recipe:create (Starting a repository from scratch)
112118

113119

114-
### 1. convert: 'Convert any nodejs module into a piscosour recipe'
115-
```
116-
Repository types: node-module
117-
Recipes: piscosour (0.6.5)
118-
```
119-
shot convert
120-
121-
## create: 'Create from scratch'
122-
Starting a repository from scratch
123-
124120
- Pisco te preguntará por el nombre de la receta que quieres crear. Este será el nombre de tu paquete npm que usarás para compartir la funcionalidad y las herramientas que envuelvas. Introduce el nombre que más te guste.
125121
- Deberás introducir el comando que quieres usar para hacer correr los "straws" (flujos) que vas a introducir en este módulo.
126122
- También deberás introducir una breve descripción para tu módulo.
@@ -138,12 +134,12 @@ Listo! ya tienes tu primer ejecutable de pisco creado! pruebalo
138134
### 1. scaffolding: 'Create a piscosour recipe from a scaffold template'
139135
```
140136
Repository types: recipe
141-
Recipes: piscosour (0.6.5)
137+
Recipes: piscosour (0.6.8)
142138
```
143139
shot scaffolding
144140

145-
## docs: 'Generate Documentation'
146-
Append documentation from info.md to readme.md of the recipe
141+
## recipe:docs (Append documentation from info.md to readme.md of the recipe)
142+
147143
Command: **node bin/pisco.js recipe:docs**
148144

149145
Generate documentation for your recipe.
@@ -157,7 +153,7 @@ Info.md is a regular md file, so you can use all the markdown specification. The
157153
### 1. generate-docs: 'Generate one file per straw inside a directory'
158154
```
159155
Repository types: recipe
160-
Recipes: piscosour (0.6.5)
156+
Recipes: piscosour (0.6.8)
161157
```
162158
shot generate-docs
163159

@@ -499,7 +495,6 @@ By default this is the versions defined inside core:
499495
```
500496
"versions": {
501497
"npm" : {
502-
"disableCheck": true,
503498
"list": "npm list -g --depth 0",
504499
"regexp": "\\@(.*?)\\s"
505500
},
@@ -520,7 +515,6 @@ By default this is the versions defined inside core:
520515
- **key** (for example 'java'): is the command that you need inside your shot.
521516
- **option**: (optional, default is '-v') if version is set the way to check this version.
522517
- **regexp**: (optional) if version is on a string the way to extract only the version. Overwrite version defined on piscosour.json
523-
- **disableCheck:** (optional) used by tools as npm that asume are allways installed.
524518
- **list:** (optional) command used to get a stdout to use the regexp function in orther to get the version of the item you want to check.
525519

526520
##### List tip
@@ -654,4 +648,12 @@ this is the file resulting of the execution: the mix of all system requirements
654648
```
655649
## test
656650

657-
Testing plugin. NO FUNCTIONALITY.
651+
Testing plugin. NO FUNCTIONALITY.
652+
# Recipes
653+
654+
655+
|Name|Version|Description|
656+
|---|---|---|
657+
|piscosour|0.6.8|Get all your devops tools wrapped-up!|
658+
659+

plugins/inquirer/info.md

+24
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@
22

33
This plugin use inquirer library [Inquirer documentation](https://www.npmjs.com/package/inquirer)
44

5+
set type
6+
7+
params.json
8+
```
9+
"prompts": [
10+
{
11+
"type": "#setType()",
12+
"name": "doDefault",
13+
"required": true,
14+
"message": "Do you want to set default repository type?"
15+
}
16+
],
17+
```
18+
19+
- '#' indicate that is necesary to use a function in the shot in order to resolve the type value.
20+
- '()' set that pisco needs to execute this function on order to get the value.
21+
22+
shot.js
23+
```
24+
setType: function() {
25+
return 'confirm';
26+
},
27+
```
28+
529
#### this.inquire
630

731
| Param | Description |

plugins/inquirer/plugin.js

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
var inquirer = require('inquirer');
3+
const inquirer = require('inquirer');
44

55
module.exports = {
66
description: 'Plugin inquirer',
@@ -14,35 +14,44 @@ module.exports = {
1414
addons: {
1515

1616
inquire: function(name) {
17-
var prompts = this.params[name];
17+
const prompts = this.params[name];
1818

19-
var getValidate = function(prompt) {
19+
const getValidate = function(prompt) {
2020
return function(userInput) {
2121
return userInput ? true : '"' + prompt.name + '" is required. ' + prompt.message;
2222
};
2323
};
2424

25-
var shotResolution = function(prompt, attr) {
26-
if (prompt[attr] !== undefined && Object.prototype.toString.call(prompt[attr]) !== '[object Function]' && typeof prompt[attr] !== 'boolean' && prompt[attr].indexOf('#') === 0) {
27-
var functionName = prompt[attr].replace('#', '');
28-
var func = this.runner[functionName];
25+
const shotResolution = function(prompt, attr) {
26+
if (prompt[attr] !== undefined
27+
&& Object.prototype.toString.call(prompt[attr]) !== '[object Function]'
28+
&& typeof prompt[attr] !== 'boolean'
29+
&& prompt[attr].indexOf('#') === 0) {
30+
let functionName = prompt[attr].replace('#', '');
31+
let exec = false;
32+
if (functionName.indexOf('(') !== 0) {
33+
functionName = functionName.replace('()', '');
34+
exec = true;
35+
}
36+
const func = this.runner[functionName];
2937
if (func) {
30-
prompt[attr] = func;
38+
prompt[attr] = exec ? func() : func;
3139
} else {
3240
prompt[attr] = undefined;
3341
this.logger.info('#yellow', 'WARNING', 'value', functionName, 'doesn\'t exists!! in this shot');
3442
}
3543
}
3644
}.bind(this);
3745

38-
var reqs = [];
46+
const reqs = [];
3947

4048
if (prompts) {
4149
prompts.forEach((prompt) => {
4250

4351
shotResolution(prompt, 'when');
4452
shotResolution(prompt, 'validate');
4553
shotResolution(prompt, 'choices');
54+
shotResolution(prompt, 'type');
4655
shotResolution(prompt, 'default');
4756

4857
if (prompt.required && !prompt.validate) {

0 commit comments

Comments
 (0)