Comparing version 0.4.6 to 0.4.7
@@ -365,3 +365,3 @@ "use strict"; | ||
this.fbl.registerPlugins(plugins); | ||
this.fbl.validatePlugins(); | ||
this.fbl.validatePlugins(process.cwd()); | ||
} | ||
@@ -368,0 +368,0 @@ /** |
@@ -57,2 +57,15 @@ import { IContext, IFlow, IPlugin, IReporter } from '../interfaces'; | ||
/** | ||
* Try to require plugin, just return null if not found. Doesn't throw exceptions | ||
* @param {string} pluginName | ||
* @return {IPlugin | null} | ||
*/ | ||
static requirePluginSafe(pluginName: string): IPlugin | null; | ||
/** | ||
* Require plugin | ||
* @param {string} pluginName | ||
* @param {string} wd | ||
* @return {IPlugin | null} | ||
*/ | ||
static requirePlugin(pluginName: string, wd: string): IPlugin; | ||
/** | ||
* Validate plugin to be registered and try to auto load if not | ||
@@ -62,20 +75,24 @@ * @param {string} pluginName | ||
* @param {string[]} errors | ||
* @param {string} wd working directory | ||
* @param {boolean} dryRun if true plugin just be verified, not actually registered | ||
*/ | ||
validateRequiredPlugin(pluginName: string, pluginExpectedVersion: string, errors: string[], dryRun: boolean): void; | ||
validateRequiredPlugin(pluginName: string, pluginExpectedVersion: string, errors: string[], wd: string, dryRun: boolean): void; | ||
/** | ||
* Validate plugin | ||
* @param {IPlugin} plugin | ||
* @param {string} wd | ||
*/ | ||
validatePlugin(plugin: IPlugin): void; | ||
validatePlugin(plugin: IPlugin, wd: string): void; | ||
/** | ||
* Validate plugins to be compatible | ||
* @param {string} wd | ||
*/ | ||
validatePlugins(): void; | ||
validatePlugins(wd: string): void; | ||
/** | ||
* Validate flow requirements | ||
* @param {IFlow} flow | ||
* @param {string} wd | ||
* @return {Promise<void>} | ||
*/ | ||
validateFlowRequirements(flow: IFlow): Promise<void>; | ||
validateFlowRequirements(flow: IFlow, wd: string): Promise<void>; | ||
/** | ||
@@ -82,0 +99,0 @@ * Execute flow |
@@ -28,2 +28,3 @@ "use strict"; | ||
const shelljs_1 = require("shelljs"); | ||
const path_1 = require("path"); | ||
const requireg = require('requireg'); | ||
@@ -144,2 +145,44 @@ const fblVersion = require('../../../package.json').version; | ||
/** | ||
* Try to require plugin, just return null if not found. Doesn't throw exceptions | ||
* @param {string} pluginName | ||
* @return {IPlugin | null} | ||
*/ | ||
static requirePluginSafe(pluginName) { | ||
let plugin = null; | ||
try { | ||
plugin = requireg(pluginName); | ||
} | ||
catch (e) { | ||
// ignore this | ||
} | ||
return plugin; | ||
} | ||
/** | ||
* Require plugin | ||
* @param {string} pluginName | ||
* @param {string} wd | ||
* @return {IPlugin | null} | ||
*/ | ||
static requirePlugin(pluginName, wd) { | ||
let plugin = FBLService_1.requirePluginSafe(pluginName); | ||
let childDir = null; | ||
if (!plugin) { | ||
while (!plugin && (!childDir || childDir !== wd)) { | ||
// search in node_modules dir | ||
plugin = FBLService_1.requirePluginSafe(path_1.join(wd, 'node_modules', pluginName)); | ||
/* istanbul ignore else */ | ||
if (!plugin) { | ||
// search in directory with plugin name (useful when referencing sources) | ||
plugin = FBLService_1.requirePluginSafe(path_1.join(wd, pluginName)); | ||
} | ||
childDir = wd; | ||
wd = path_1.join(wd, '..'); | ||
} | ||
} | ||
if (!plugin) { | ||
throw new Error(`Unable to locate plugin ${pluginName}`); | ||
} | ||
return plugin; | ||
} | ||
/** | ||
* Validate plugin to be registered and try to auto load if not | ||
@@ -149,10 +192,11 @@ * @param {string} pluginName | ||
* @param {string[]} errors | ||
* @param {string} wd working directory | ||
* @param {boolean} dryRun if true plugin just be verified, not actually registered | ||
*/ | ||
validateRequiredPlugin(pluginName, pluginExpectedVersion, errors, dryRun) { | ||
validateRequiredPlugin(pluginName, pluginExpectedVersion, errors, wd, dryRun) { | ||
let plugin = this.plugins[pluginName]; | ||
if (!plugin) { | ||
try { | ||
plugin = requireg(pluginName); | ||
this.validatePlugin(plugin); | ||
plugin = FBLService_1.requirePlugin(pluginName, wd); | ||
this.validatePlugin(plugin, wd); | ||
/* istanbul ignore else */ | ||
@@ -174,4 +218,5 @@ if (!dryRun) { | ||
* @param {IPlugin} plugin | ||
* @param {string} wd | ||
*/ | ||
validatePlugin(plugin) { | ||
validatePlugin(plugin, wd) { | ||
const errors = []; | ||
@@ -185,3 +230,3 @@ if (!semver.satisfies(fblVersion, plugin.requires.fbl)) { | ||
const dependencyPluginRequiredVersion = plugin.requires.plugins[dependencyPluginName]; | ||
this.validateRequiredPlugin(dependencyPluginName, dependencyPluginRequiredVersion, errors, dryRun); | ||
this.validateRequiredPlugin(dependencyPluginName, dependencyPluginRequiredVersion, errors, wd, dryRun); | ||
} | ||
@@ -208,6 +253,7 @@ } | ||
* Validate plugins to be compatible | ||
* @param {string} wd | ||
*/ | ||
validatePlugins() { | ||
validatePlugins(wd) { | ||
for (const name of Object.keys(this.plugins)) { | ||
this.validatePlugin(this.plugins[name]); | ||
this.validatePlugin(this.plugins[name], wd); | ||
} | ||
@@ -218,5 +264,6 @@ } | ||
* @param {IFlow} flow | ||
* @param {string} wd | ||
* @return {Promise<void>} | ||
*/ | ||
validateFlowRequirements(flow) { | ||
validateFlowRequirements(flow, wd) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -234,3 +281,3 @@ const errors = []; | ||
const pluginExpectedVersion = flow.requires.plugins[pluginName]; | ||
this.validateRequiredPlugin(pluginName, pluginExpectedVersion, errors, dryRun); | ||
this.validateRequiredPlugin(pluginName, pluginExpectedVersion, errors, wd, dryRun); | ||
} | ||
@@ -269,3 +316,3 @@ } | ||
} | ||
yield this.validateFlowRequirements(flow); | ||
yield this.validateFlowRequirements(flow, wd); | ||
const idOrAlias = FBLService_1.extractIdOrAlias(flow.pipeline); | ||
@@ -282,4 +329,3 @@ let metadata = FBLService_1.extractMetadata(flow.pipeline); | ||
version: Joi.string() | ||
.regex(/\d+\.\d+\.\d+/i) | ||
.required(), | ||
.regex(/\d+(\.\d+)*/i), | ||
requires: Joi.object({ | ||
@@ -286,0 +332,0 @@ fbl: Joi.string().min(1), |
@@ -545,3 +545,3 @@ "use strict"; | ||
assert.strictEqual(result.code, 1); | ||
assert.strictEqual(result.stderr, 'Required plugin test is not registered. Error: Could not require module \'test\''); | ||
assert.strictEqual(result.stderr, 'Required plugin test is not registered. Error: Unable to locate plugin test'); | ||
result = yield CliTestSuite_1.exec('node', [ | ||
@@ -556,3 +556,3 @@ 'dist/src/cli.js', | ||
} | ||
assert.strictEqual(result.stderr.split('\n')[0], 'Required plugin test is not registered. Error: Could not require module \'test\''); | ||
assert.strictEqual(result.stderr.split('\n')[0], 'Required plugin test is not registered. Error: Unable to locate plugin test'); | ||
}); | ||
@@ -700,3 +700,3 @@ } | ||
assert.strictEqual(result.code, 1); | ||
assert.strictEqual(result.stderr, 'Required plugin %some.unkown.plugin% is not registered. Error: Could not require module \'%some.unkown.plugin%\''); | ||
assert.strictEqual(result.stderr, 'Required plugin %some.unkown.plugin% is not registered. Error: Unable to locate plugin %some.unkown.plugin%'); | ||
result = yield CliTestSuite_1.exec('node', [ | ||
@@ -712,3 +712,3 @@ 'dist/src/cli.js', | ||
} | ||
assert.strictEqual(result.stderr.split('\n')[0], 'Required plugin %some.unkown.plugin% is not registered. Error: Could not require module \'%some.unkown.plugin%\''); | ||
assert.strictEqual(result.stderr.split('\n')[0], 'Required plugin %some.unkown.plugin% is not registered. Error: Unable to locate plugin %some.unkown.plugin%'); | ||
}); | ||
@@ -715,0 +715,0 @@ } |
export declare class FBLServiceTestSuite { | ||
after(): void; | ||
pluginAutoInclude(): Promise<void>; | ||
pluginAutoIncludeWithWD(): Promise<void>; | ||
extractIdOrAliasMissingKey(): Promise<void>; | ||
@@ -5,0 +6,0 @@ pipeline(): Promise<void>; |
@@ -101,3 +101,3 @@ "use strict"; | ||
} | ||
}); | ||
}, '.'); | ||
const plugin = fbl.getPlugin('flb.core.context'); | ||
@@ -107,2 +107,20 @@ assert(plugin); | ||
} | ||
pluginAutoIncludeWithWD() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const fbl = typedi_1.Container.get(services_1.FBLService); | ||
yield fbl.validateFlowRequirements({ | ||
version: '1.0.0', | ||
pipeline: { | ||
[DummyActionHandler.ID]: 'tst' | ||
}, | ||
requires: { | ||
plugins: { | ||
['context']: version | ||
} | ||
} | ||
}, path_1.join(__dirname, '../../../src/plugins')); | ||
const plugin = fbl.getPlugin('flb.core.context'); | ||
assert(plugin); | ||
}); | ||
} | ||
extractIdOrAliasMissingKey() { | ||
@@ -287,3 +305,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
}); | ||
}, '.'); | ||
}).to.throw('Application missing_app_1234 required by plugin test not found, make sure it is installed and its location presents in the PATH environment variable'); | ||
@@ -304,2 +322,8 @@ }); | ||
__metadata("design:returntype", Promise) | ||
], FBLServiceTestSuite.prototype, "pluginAutoIncludeWithWD", null); | ||
__decorate([ | ||
mocha_typescript_1.test(), | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", []), | ||
__metadata("design:returntype", Promise) | ||
], FBLServiceTestSuite.prototype, "extractIdOrAliasMissingKey", null); | ||
@@ -306,0 +330,0 @@ __decorate([ |
{ | ||
"name": "fbl", | ||
"version": "0.4.6", | ||
"version": "0.4.7", | ||
"description": "Command Line tool to automate any kind of work. Originally designed to help with deployments.", | ||
@@ -35,8 +35,8 @@ "keywords": [ | ||
"glob-promise": "3.4.0", | ||
"got": "9.2.2", | ||
"got": "9.3.0", | ||
"humanize-duration": "3.15.3", | ||
"joi": "14.0.1", | ||
"joi": "14.0.2", | ||
"js-yaml": "3.12.0", | ||
"jsonschema": "1.2.4", | ||
"prompts": "1.1.1", | ||
"prompts": "1.2.0", | ||
"reflect-metadata": "0.1.12", | ||
@@ -58,3 +58,3 @@ "requireg": "0.2.1", | ||
"@types/js-yaml": "3.11.2", | ||
"@types/node": "10.12.0", | ||
"@types/node": "10.12.1", | ||
"@types/semver": "5.5.0", | ||
@@ -61,0 +61,0 @@ "@types/shelljs": "0.8.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
1189228
14170
+ Added@sindresorhus/is@0.12.0(transitive)
+ Addedgot@9.3.0(transitive)
+ Addedjoi@14.0.2(transitive)
+ Addedp-cancelable@1.1.0(transitive)
+ Addedprompts@1.2.0(transitive)
- Removed@sindresorhus/is@0.11.0(transitive)
- Removedgot@9.2.2(transitive)
- Removedjoi@14.0.1(transitive)
- Removedp-cancelable@0.5.1(transitive)
- Removedprompts@1.1.1(transitive)
Updatedgot@9.3.0
Updatedjoi@14.0.2
Updatedprompts@1.2.0