Comparing version 0.1.1 to 0.1.2
@@ -0,5 +1,6 @@ | ||
export * from './IActionHandlerMetadata'; | ||
export * from './IContext'; | ||
export * from './IFlow'; | ||
export * from './IIteration'; | ||
export * from './IPlugin'; | ||
export * from './IContext'; | ||
export * from './IActionHandlerMetadata'; | ||
export * from './IReporter'; |
@@ -9,2 +9,4 @@ "use strict"; | ||
const TryCatchFinallyFlowHandler_1 = require("./TryCatchFinallyFlowHandler"); | ||
const ForEachFlowHandler_1 = require("./ForEachFlowHandler"); | ||
const TemplateFlowHandler_1 = require("./TemplateFlowHandler"); | ||
const version = require('../../../../package.json').version; | ||
@@ -19,2 +21,3 @@ module.exports = { | ||
new AttachedFlowHandler_1.AttachedFlowHandler(), | ||
new ForEachFlowHandler_1.ForEachFlowHandler(), | ||
new ParallelFlowHandler_1.ParallelFlowHandler(), | ||
@@ -24,2 +27,3 @@ new SequenceFlowHandler_1.SequenceFlowHandler(), | ||
new RepeatFlowHandler_1.RepeatFlowHandler(), | ||
new TemplateFlowHandler_1.TemplateFlowHandler(), | ||
new TryCatchFinallyFlowHandler_1.TryCatchFinallyFlowHandler() | ||
@@ -26,0 +30,0 @@ ] |
@@ -28,5 +28,6 @@ "use strict"; | ||
const promises = options.map((action, index) => __awaiter(this, void 0, void 0, function* () { | ||
const keys = Object.keys(action); | ||
const idOrAlias = keys[0]; | ||
snapshots[index] = yield flowService.executeAction(snapshot.wd, idOrAlias, action[idOrAlias], context, index); | ||
const idOrAlias = services_1.FBLService.extractIdOrAlias(action); | ||
snapshots[index] = yield flowService.executeAction(snapshot.wd, idOrAlias, action[idOrAlias], context, { | ||
index | ||
}); | ||
})); | ||
@@ -33,0 +34,0 @@ yield Promise.all(promises); |
@@ -28,12 +28,14 @@ "use strict"; | ||
const snapshots = []; | ||
const keys = Object.keys(options.action); | ||
const idOrAlias = keys[0]; | ||
const idOrAlias = services_1.FBLService.extractIdOrAlias(options.action); | ||
for (let i = 0; i < options.times; i++) { | ||
const iteration = { | ||
index: i | ||
}; | ||
if (options.async) { | ||
promises.push(((index) => __awaiter(this, void 0, void 0, function* () { | ||
snapshots[index] = yield flowService.executeAction(snapshot.wd, idOrAlias, options.action[idOrAlias], context, index); | ||
}))(i)); | ||
promises.push(((iter) => __awaiter(this, void 0, void 0, function* () { | ||
snapshots[iter.index] = yield flowService.executeAction(snapshot.wd, idOrAlias, options.action[idOrAlias], context, iter); | ||
}))(iteration)); | ||
} | ||
else { | ||
snapshots[i] = yield flowService.executeAction(snapshot.wd, idOrAlias, options.action[idOrAlias], context, i); | ||
snapshots[i] = yield flowService.executeAction(snapshot.wd, idOrAlias, options.action[idOrAlias], context, iteration); | ||
} | ||
@@ -40,0 +42,0 @@ } |
@@ -28,5 +28,6 @@ "use strict"; | ||
for (const action of options) { | ||
const keys = Object.keys(action); | ||
const idOrAlias = keys[0]; | ||
const childSnapshot = yield flowService.executeAction(snapshot.wd, idOrAlias, action[idOrAlias], context, index); | ||
const idOrAlias = services_1.FBLService.extractIdOrAlias(action); | ||
const childSnapshot = yield flowService.executeAction(snapshot.wd, idOrAlias, action[idOrAlias], context, { | ||
index | ||
}); | ||
snapshot.registerChildActionSnapshot(childSnapshot); | ||
@@ -33,0 +34,0 @@ index++; |
@@ -43,4 +43,3 @@ "use strict"; | ||
if (action) { | ||
const keys = Object.keys(action); | ||
const idOrAlias = keys[0]; | ||
const idOrAlias = services_1.FBLService.extractIdOrAlias(action); | ||
snapshot.log(`Based on value: ${options.value} invoking handler: ${idOrAlias}`); | ||
@@ -47,0 +46,0 @@ const childSnapshot = yield flowService.executeAction(snapshot.wd, idOrAlias, action[idOrAlias], context); |
@@ -37,2 +37,3 @@ "use strict"; | ||
__dirname + '/../plugins/context', | ||
__dirname + '/../plugins/exec', | ||
__dirname + '/../plugins/flow', | ||
@@ -39,0 +40,0 @@ __dirname + '/../plugins/fs', |
@@ -14,2 +14,8 @@ import { IContext, IFlow, IPlugin, IReporter } from '../interfaces'; | ||
/** | ||
* Extract idOrAlias from step object | ||
* @param {object} step | ||
* @return {string} | ||
*/ | ||
static extractIdOrAlias(step: object): string; | ||
/** | ||
* Get reporter by name | ||
@@ -16,0 +22,0 @@ * @param {string} name |
@@ -33,2 +33,11 @@ "use strict"; | ||
/** | ||
* Extract idOrAlias from step object | ||
* @param {object} step | ||
* @return {string} | ||
*/ | ||
static extractIdOrAlias(step) { | ||
const keys = Object.keys(step); | ||
return keys[0]; | ||
} | ||
/** | ||
* Get reporter by name | ||
@@ -114,4 +123,3 @@ * @param {string} name | ||
} | ||
const keys = Object.keys(flow.pipeline); | ||
const idOrAlias = keys[0]; | ||
const idOrAlias = FBLService_1.extractIdOrAlias(flow.pipeline); | ||
const options = flow.pipeline[idOrAlias]; | ||
@@ -118,0 +126,0 @@ return yield this.flowService.executeAction(wd, idOrAlias, options, context); |
import { ActionHandlersRegistry } from './ActionHandlersRegistry'; | ||
import { IContext, IFlow } from '../interfaces'; | ||
import { IContext, IFlow, IIteration } from '../interfaces'; | ||
import { ActionHandler, ActionSnapshot } from '../models'; | ||
@@ -25,6 +25,6 @@ import 'reflect-metadata'; | ||
* @param {IContext} context | ||
* @param {number} [index] - child execution order index | ||
* @param {IIteration} [iteration] - child execution iteration | ||
* @returns {Promise<void>} | ||
*/ | ||
executeAction(wd: string, idOrAlias: string, options: any, context: IContext, index?: number): Promise<ActionSnapshot>; | ||
executeAction(wd: string, idOrAlias: string, options: any, context: IContext, iteration?: IIteration): Promise<ActionSnapshot>; | ||
/** | ||
@@ -41,6 +41,6 @@ * Read flow from file | ||
* @param {boolean} [maskSecrets] if true - all secrets will be masked | ||
* @param {number} [index] execution order index | ||
* @param {IIteration} [iteration] execution iteration | ||
* @return {any} | ||
*/ | ||
resolveOptionsWithNoHandlerCheck(options: any, context: IContext, maskSecrets: boolean, index?: number): any; | ||
resolveOptionsWithNoHandlerCheck(options: any, context: IContext, maskSecrets: boolean, iteration?: IIteration): any; | ||
/** | ||
@@ -52,6 +52,6 @@ * Resolve options for handler | ||
* @param {boolean} [maskSecrets] if true - all secrets will be masked | ||
* @param {number} [index] execution order index | ||
* @param {IIteration} [iteration] execution iteration | ||
* @returns {Promise<any>} | ||
*/ | ||
resolveOptions(handler: ActionHandler, options: any, context: IContext, maskSecrets: boolean, index?: number): any; | ||
resolveOptions(handler: ActionHandler, options: any, context: IContext, maskSecrets: boolean, iteration?: IIteration): any; | ||
} |
@@ -28,2 +28,3 @@ "use strict"; | ||
const FSUtil_1 = require("../utils/FSUtil"); | ||
const EJSTemplateUtils_1 = require("../utils/EJSTemplateUtils"); | ||
const ejsLint = require('ejs-lint'); | ||
@@ -62,6 +63,6 @@ let FlowService = FlowService_1 = class FlowService { | ||
* @param {IContext} context | ||
* @param {number} [index] - child execution order index | ||
* @param {IIteration} [iteration] - child execution iteration | ||
* @returns {Promise<void>} | ||
*/ | ||
executeAction(wd, idOrAlias, options, context, index) { | ||
executeAction(wd, idOrAlias, options, context, iteration) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -78,3 +79,3 @@ const idx = ++this.index; | ||
// register options twice to see what's actually has been changed | ||
snapshot.setOptions(this.resolveOptions(handler, options, context, true, index)); | ||
snapshot.setOptions(this.resolveOptions(handler, options, context, true, iteration)); | ||
} | ||
@@ -85,3 +86,3 @@ else { | ||
// resolve without masking | ||
options = this.resolveOptions(handler, options, context, false, index); | ||
options = this.resolveOptions(handler, options, context, false, iteration); | ||
yield handler.validate(options, context, snapshot); | ||
@@ -128,6 +129,6 @@ snapshot.validated(); | ||
* @param {boolean} [maskSecrets] if true - all secrets will be masked | ||
* @param {number} [index] execution order index | ||
* @param {IIteration} [iteration] execution iteration | ||
* @return {any} | ||
*/ | ||
resolveOptionsWithNoHandlerCheck(options, context, maskSecrets, index) { | ||
resolveOptionsWithNoHandlerCheck(options, context, maskSecrets, iteration) { | ||
if (maskSecrets && context.secrets && Object.keys(context.secrets).length) { | ||
@@ -160,5 +161,11 @@ // make a copy of the context object first | ||
ejsLint(tpl); | ||
const data = {}; | ||
const data = { | ||
$: EJSTemplateUtils_1.EJSTemplateUtils | ||
}; | ||
Object.assign(data, context); | ||
Object.assign(data, { index }); | ||
if (iteration) { | ||
Object.assign(data, { | ||
iteration | ||
}); | ||
} | ||
const yaml = ejs_1.render(lines.join('\n'), data); | ||
@@ -175,10 +182,10 @@ options = js_yaml_1.safeLoad(yaml); | ||
* @param {boolean} [maskSecrets] if true - all secrets will be masked | ||
* @param {number} [index] execution order index | ||
* @param {IIteration} [iteration] execution iteration | ||
* @returns {Promise<any>} | ||
*/ | ||
resolveOptions(handler, options, context, maskSecrets, index) { | ||
resolveOptions(handler, options, context, maskSecrets, iteration) { | ||
if (handler.getMetadata().skipTemplateProcessing) { | ||
return options; | ||
} | ||
return this.resolveOptionsWithNoHandlerCheck(options, context, maskSecrets, index); | ||
return this.resolveOptionsWithNoHandlerCheck(options, context, maskSecrets, iteration); | ||
} | ||
@@ -185,0 +192,0 @@ }; |
@@ -165,3 +165,3 @@ "use strict"; | ||
{ [DummyActionHandler.ID + '.0']: 0 }, | ||
{ [DummyActionHandler.ID + '.1']: '<%- index %>' }, | ||
{ [DummyActionHandler.ID + '.1']: '<%- iteration.index %>' }, | ||
] | ||
@@ -168,0 +168,0 @@ }, |
@@ -114,3 +114,3 @@ "use strict"; | ||
[DummyActionHandler.ID]: { | ||
index: '<%- index %>' | ||
index: '<%- iteration.index %>' | ||
} | ||
@@ -146,3 +146,3 @@ } | ||
[DummyActionHandler.ID]: { | ||
index: '<%- index %>' | ||
index: '<%- iteration.index %>' | ||
} | ||
@@ -149,0 +149,0 @@ }, |
@@ -156,3 +156,3 @@ "use strict"; | ||
}, | ||
{ [DummyActionHandler.ID + '.2']: '<%- index %>' }, | ||
{ [DummyActionHandler.ID + '.2']: '<%- iteration.index %>' }, | ||
]; | ||
@@ -159,0 +159,0 @@ const context = services_1.FlowService.generateEmptyContext(); |
@@ -11,2 +11,5 @@ # Flow control plugin | ||
- try-catch-finally | ||
- repeat (async and sync) | ||
- foreach (async and sync) | ||
- based on template | ||
@@ -110,3 +113,3 @@ ## Action Handler: Sequential steps execution | ||
# run flow_0.yml and flow_1.yml flows | ||
@: flow_<%- index %>.yml | ||
@: flow_<%- iteration.index %>.yml | ||
``` | ||
@@ -167,2 +170,82 @@ | ||
@: cleanup.yml | ||
``` | ||
## Action Handler: For Each | ||
Allows to execute action for every item in the array or key of an object. | ||
ID: com.fireblink.fbl.flow.foreach | ||
Aliases: | ||
- fbl.flow.foreach | ||
- flow.foreach | ||
- foreach | ||
- each | ||
**Example:** | ||
```yaml | ||
each: | ||
of: [1, 2, 3] | ||
action: | ||
ctx: | ||
test_<%- iteration.index %>: | ||
inline: <%- iteration.value %> | ||
``` | ||
## Action Handler: Template | ||
Run action based on dynamically constructed template. This is handy as you generally can not dynamically construct YAML with EJS template inside most of the actions. | ||
E.g: following is invalid: | ||
```yaml | ||
ctx: | ||
something: | ||
<% [1, 2, 3].forEach(item => { %> | ||
- <%- item %> | ||
<% }) %> | ||
``` | ||
It will fail as upon processing everything that goes after something will be treated as string, causing to produce following action: | ||
```yaml | ||
ctx: | ||
something: '-1\n -2\n -3' | ||
``` | ||
But there is a template handler that can help you with that. | ||
ID: com.fireblink.fbl.flow.template | ||
Aliases: | ||
- fbl.flow.template | ||
- flow.template | ||
- template | ||
- tpl | ||
**Example:** | ||
```yaml | ||
tpl: |- | ||
ctx: | ||
something: | ||
<% [1, 2, 3].forEach(item => { %> | ||
- <%- item %> | ||
<% }) %> | ||
``` | ||
or the same with helper function that converts anything to JSON string (JSON is a valid YAML): | ||
```yaml | ||
tpl: |- | ||
ctx: | ||
something: <%- $.toJSON([1, 2, 3]) %> | ||
``` | ||
that will generally produce: | ||
```yaml | ||
ctx: | ||
something: [1, 2, 3] | ||
``` |
{ | ||
"name": "fbl", | ||
"version": "0.1.1", | ||
"description": "", | ||
"version": "0.1.2", | ||
"description": "Command Line tool to automate any kind of work. Originally designed to help with deployments.", | ||
"keywords": ["fireblink", "fbl", "automation", "cli", "flows"], | ||
"main": "dist/cli.js", | ||
@@ -36,3 +37,2 @@ "scripts": { | ||
"semver": "5.5.0", | ||
"shelljs": "0.8.2", | ||
"tmp-promise": "1.0.5", | ||
@@ -46,3 +46,3 @@ "typedi": "0.8.0" | ||
"@types/js-yaml": "3.11.2", | ||
"@types/node": "10.9.2", | ||
"@types/node": "10.9.4", | ||
"@types/semver": "5.5.0", | ||
@@ -58,2 +58,3 @@ "@types/shelljs": "0.8.0", | ||
"rimraf": "2.6.2", | ||
"shelljs": "0.8.2", | ||
"source-map-support": "0.5.6", | ||
@@ -60,0 +61,0 @@ "tslint": "5.11.0", |
@@ -50,4 +50,5 @@ # FBL or FireBlink Logistics | ||
- [Context](docs/plugins/context.md) | ||
- [Exec](docs/plugins/exec.md) | ||
- [Flow Control](docs/plugins/flow.md) | ||
- [File System](docs/plugins/flow.md) | ||
- [File System](docs/plugins/fs.md) | ||
- [Execution Reporters](docs/plugins/reporters.md) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
705329
15
255
8049
54
20
18
2
- Removedshelljs@0.8.2
- Removedinterpret@1.4.0(transitive)
- Removedrechoir@0.6.2(transitive)
- Removedshelljs@0.8.2(transitive)