Comparing version 0.0.3 to 0.0.4
@@ -5,2 +5,3 @@ import { ActionHandler, ActionSnapshot, IHandlerMetadata } from '../../models'; | ||
export declare class ContextValuesAssignment extends ActionHandler { | ||
private static ROOT_KEY; | ||
private static metadata; | ||
@@ -7,0 +8,0 @@ private static validationSchema; |
@@ -27,4 +27,5 @@ "use strict"; | ||
const promises = names.map((name) => __awaiter(this, void 0, void 0, function* () { | ||
let value = undefined; | ||
if (options[name].inline) { | ||
context.ctx[name] = options[name].inline; | ||
value = options[name].inline; | ||
} | ||
@@ -34,4 +35,10 @@ if (options[name].file) { | ||
snapshot.log(`Reading from file: ${file} into "ctx.${name}"`); | ||
context.ctx[name] = yield flowService.readYamlFromFile(file); | ||
value = yield flowService.readYamlFromFile(file); | ||
} | ||
if (name === ContextValuesAssignment.ROOT_KEY) { | ||
Object.assign(context.ctx, value); | ||
} | ||
else { | ||
context.ctx[name] = value; | ||
} | ||
})); | ||
@@ -43,6 +50,7 @@ snapshot.setContext(context); | ||
} | ||
ContextValuesAssignment.ROOT_KEY = '.'; | ||
ContextValuesAssignment.metadata = { | ||
id: 'com.fireblink.fbl.context.assignValues.inline', | ||
version: '1.0.0', | ||
description: 'Context values assignment. Either inline or from file for each key individually. Only top level keys are supported.', | ||
description: 'Context values assignment. Either inline or from file for each key individually. Only top level keys are supported. Assignment directly to context is possible when "." key is provided.', | ||
aliases: [ | ||
@@ -49,0 +57,0 @@ 'fbl.context.assign.inline', |
@@ -29,2 +29,3 @@ "use strict"; | ||
const path_1 = require("path"); | ||
const ejsLint = require('ejs-lint'); | ||
let FlowService = class FlowService { | ||
@@ -127,4 +128,22 @@ constructor() { | ||
if (options) { | ||
const tpl = js_yaml_1.dump(options); | ||
const yaml = ejs_1.render(tpl, context); | ||
let tpl = js_yaml_1.dump(options); | ||
// fix template after dump | ||
// while in yaml following string is fully valid '<%- ctx[''name''] %>' | ||
// for EJS it is broken due to quotes escape | ||
const lines = []; | ||
const ejsTemplateRegEx = /<%([^%>]*)%>/g; | ||
const doubleQuotesRegEx = /''/g; | ||
tpl.split('\n').forEach(line => { | ||
if (line.indexOf('\'\'') !== -1) { | ||
// we only want to replace '' to ' inside the EJS template | ||
line = line.replace(ejsTemplateRegEx, function (match, g1) { | ||
return `<%${g1.replace(doubleQuotesRegEx, '\'')}%>`; | ||
}); | ||
} | ||
lines.push(line); | ||
}); | ||
tpl = lines.join('\n'); | ||
// validate template | ||
ejsLint(tpl); | ||
const yaml = ejs_1.render(lines.join('\n'), context); | ||
options = js_yaml_1.safeLoad(yaml); | ||
@@ -131,0 +150,0 @@ } |
@@ -6,2 +6,4 @@ export declare class FblTestSuite { | ||
failedExecution(): Promise<void>; | ||
ejsTemplateValidation(): Promise<void>; | ||
templateProcessingStringEscape(): Promise<void>; | ||
} |
@@ -29,2 +29,3 @@ "use strict"; | ||
chai.use(chaiAsPromised); | ||
const jsyaml = require('js-yaml'); | ||
class DummyActionHandler extends models_1.ActionHandler { | ||
@@ -129,2 +130,51 @@ constructor(fn, skipExecution) { | ||
} | ||
ejsTemplateValidation() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const fbl = typedi_1.Container.get(fbl_1.FireBlinkLogistics); | ||
fbl.flowService.debug = true; | ||
let result = null; | ||
fbl.flowService.actionHandlersRegistry.register(new DummyActionHandler((opt) => __awaiter(this, void 0, void 0, function* () { | ||
result = opt; | ||
}), false)); | ||
const snapshot = yield fbl.execute('.', { | ||
version: '1.0.0', | ||
pipeline: { | ||
[DummyActionHandler.ID]: `<%- ctx.t1` | ||
} | ||
}, { | ||
ctx: { | ||
t1: 'tst' | ||
} | ||
}); | ||
assert.strictEqual(snapshot.successful, false); | ||
assert.strictEqual(snapshot.getSteps().find(s => s.type === 'failure').payload, 'Error: Could not find matching close tag for "<%-".'); | ||
assert.strictEqual(result, null); | ||
}); | ||
} | ||
templateProcessingStringEscape() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const fbl = typedi_1.Container.get(fbl_1.FireBlinkLogistics); | ||
fbl.flowService.debug = true; | ||
let result = null; | ||
fbl.flowService.actionHandlersRegistry.register(new DummyActionHandler((opt) => __awaiter(this, void 0, void 0, function* () { | ||
result = opt; | ||
}), false)); | ||
const snapshot = yield fbl.execute('.', { | ||
version: '1.0.0', | ||
pipeline: { | ||
[DummyActionHandler.ID]: `<%- ctx['t1']["t2"].value %>` | ||
} | ||
}, { | ||
ctx: { | ||
t1: { | ||
t2: { | ||
value: 'tst' | ||
} | ||
} | ||
} | ||
}); | ||
assert.strictEqual(snapshot.successful, true); | ||
assert.strictEqual(result, 'tst'); | ||
}); | ||
} | ||
}; | ||
@@ -149,2 +199,14 @@ __decorate([ | ||
], FblTestSuite.prototype, "failedExecution", null); | ||
__decorate([ | ||
mocha_typescript_1.test(), | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", []), | ||
__metadata("design:returntype", Promise) | ||
], FblTestSuite.prototype, "ejsTemplateValidation", null); | ||
__decorate([ | ||
mocha_typescript_1.test(), | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", []), | ||
__metadata("design:returntype", Promise) | ||
], FblTestSuite.prototype, "templateProcessingStringEscape", null); | ||
FblTestSuite = __decorate([ | ||
@@ -151,0 +213,0 @@ mocha_typescript_1.suite() |
@@ -5,2 +5,3 @@ export declare class ContextValuesAssignmentTestSuite { | ||
assignValues(): Promise<void>; | ||
assignRootValues(): Promise<void>; | ||
} |
@@ -129,2 +129,50 @@ "use strict"; | ||
} | ||
assignRootValues() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const actionHandler = new ContextValuesAssignment_1.ContextValuesAssignment(); | ||
const context = { | ||
ctx: { | ||
existing: { | ||
value: 'value' | ||
} | ||
} | ||
}; | ||
const fileContent = { | ||
file_content: 'ftpo' | ||
}; | ||
const tmpFile = yield tmp.file(); | ||
// write to temp file | ||
yield util_1.promisify(fs_1.writeFile)(tmpFile.path, js_yaml_1.dump(fileContent), 'utf8'); | ||
const options = { | ||
test: { | ||
inline: 123 | ||
}, | ||
'.': { | ||
inline: { | ||
other: 'other' | ||
} | ||
}, | ||
fromFile: { | ||
file: tmpFile.path | ||
} | ||
}; | ||
const snapshot = new models_1.ActionSnapshot('.', '', 0); | ||
yield actionHandler.validate(options, context, snapshot); | ||
yield actionHandler.execute(options, context, snapshot); | ||
assert.strictEqual(context.ctx.test, 123); | ||
assert.strictEqual(context.ctx.existing.value, 'value'); | ||
assert.strictEqual(context.ctx.other, 'other'); | ||
assert.strictEqual(context.ctx.fromFile.file_content, fileContent.file_content); | ||
console.log('->', tmpFile.path); | ||
// do the same with relative path | ||
options.fromFile.file = path_1.basename(tmpFile.path); | ||
snapshot.wd = path_1.dirname(tmpFile.path); | ||
yield actionHandler.validate(options, context, snapshot); | ||
yield actionHandler.execute(options, context, snapshot); | ||
assert.strictEqual(context.ctx.test, 123); | ||
assert.strictEqual(context.ctx.existing.value, 'value'); | ||
assert.strictEqual(context.ctx.other, 'other'); | ||
assert.strictEqual(context.ctx.fromFile.file_content, fileContent.file_content); | ||
}); | ||
} | ||
}; | ||
@@ -149,2 +197,8 @@ __decorate([ | ||
], ContextValuesAssignmentTestSuite.prototype, "assignValues", null); | ||
__decorate([ | ||
mocha_typescript_1.test(), | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", []), | ||
__metadata("design:returntype", Promise) | ||
], ContextValuesAssignmentTestSuite.prototype, "assignRootValues", null); | ||
ContextValuesAssignmentTestSuite = __decorate([ | ||
@@ -151,0 +205,0 @@ mocha_typescript_1.suite() |
{ | ||
"name": "fbl", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "", | ||
@@ -15,3 +15,3 @@ "main": "dist/cli.js", | ||
"lint": "tslint -c tslint.json 'src/**/*.ts' 'test/**/*.ts'", | ||
"prepublish": "npm run build && npm run lint", | ||
"prepublishOnly": "npm run build && npm run lint", | ||
"precommit": "npm run lint" | ||
@@ -26,5 +26,6 @@ }, | ||
"chai-as-promised": "7.1.1", | ||
"colors": "1.3.0", | ||
"colors": "1.3.1", | ||
"commander": "2.16.0", | ||
"ejs": "2.6.1", | ||
"ejs-lint": "0.3.0", | ||
"humanize-duration": "3.15.1", | ||
@@ -31,0 +32,0 @@ "joi": "13.4.0", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
325502
2969
0
11
+ Addedejs-lint@0.3.0
+ Addedacorn@7.4.1(transitive)
+ Addedacorn-node@1.8.2(transitive)
+ Addedacorn-walk@7.2.0(transitive)
+ Addedansi-regex@2.1.1(transitive)
+ Addedarray-union@1.0.2(transitive)
+ Addedarray-uniq@1.0.3(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addedcamelcase@3.0.0(transitive)
+ Addedcliui@3.2.0(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addedcolors@1.3.1(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddefine-properties@1.2.1(transitive)
+ Addedejs@2.5.6(transitive)
+ Addedejs-include-regex@1.0.0(transitive)
+ Addedejs-lint@0.3.0(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedfind-up@1.1.2(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-caller-file@1.0.3(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedglobby@6.1.0(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhosted-git-info@2.8.9(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedinvert-kv@1.0.0(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedis-fullwidth-code-point@1.0.0(transitive)
+ Addedis-utf8@0.2.1(transitive)
+ Addedlcid@1.0.0(transitive)
+ Addedload-json-file@1.1.0(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addednormalize-package-data@2.5.0(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedobject.assign@4.1.5(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedos-locale@1.4.0(transitive)
+ Addedparse-json@2.2.0(transitive)
+ Addedpath-exists@2.1.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-type@1.1.0(transitive)
+ Addedpify@2.3.0(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedread-input@0.3.1(transitive)
+ Addedread-pkg@1.1.0(transitive)
+ Addedread-pkg-up@1.0.1(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedrequire-main-filename@1.0.1(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedrewire@2.5.2(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedspdx-correct@3.2.0(transitive)
+ Addedspdx-exceptions@2.5.0(transitive)
+ Addedspdx-expression-parse@3.0.1(transitive)
+ Addedspdx-license-ids@3.0.20(transitive)
+ Addedstring-width@1.0.2(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedstrip-bom@2.0.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedsyntax-error@1.4.0(transitive)
+ Addedvalidate-npm-package-license@3.0.4(transitive)
+ Addedwhich-module@1.0.0(transitive)
+ Addedwrap-ansi@2.1.0(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedxtend@4.0.2(transitive)
+ Addedy18n@3.2.2(transitive)
+ Addedyargs@7.1.2(transitive)
+ Addedyargs-parser@5.0.1(transitive)
- Removedcolors@1.3.0(transitive)
Updatedcolors@1.3.1