knifecycle
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -10,4 +10,5 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /* eslint max-len: ["warn", { "ignoreComments": true }] */ | ||
var _yerror = require('yerror'); | ||
@@ -245,5 +246,71 @@ | ||
/** | ||
* Outputs a Mermaid compatible dependency graph of the declared services. | ||
* See [Mermaid docs](https://github.com/knsv/mermaid) | ||
* @param {Object} options Options for generating the graph (destructured) | ||
* @param {Array<Object>} options.shapes Various shapes to apply | ||
* @param {Array<Object>} options.styles Various styles to apply | ||
* @param {Object} options.classes A hash of various classes contents | ||
* @return {String} Returns a string containing the Mermaid dependency graph | ||
* @example | ||
* | ||
* import Knifecycle from 'knifecycle' | ||
* | ||
* const $ = new Knifecycle(); | ||
* | ||
* $.constant('ENV', process.env); | ||
* $.constant('OS', require('os')); | ||
* $.service('app', $.depends(['ENV', 'OS'], () => Promise.resolve())); | ||
* $.toMermaidGraph(); | ||
* | ||
* // returns | ||
* graph TD | ||
* app-->ENV | ||
* app-->OS | ||
*/ | ||
}, { | ||
key: 'toMermaidGraph', | ||
value: function toMermaidGraph() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
_ref$shapes = _ref.shapes, | ||
shapes = _ref$shapes === undefined ? [] : _ref$shapes, | ||
_ref$styles = _ref.styles, | ||
styles = _ref$styles === undefined ? [] : _ref$styles, | ||
_ref$classes = _ref.classes, | ||
classes = _ref$classes === undefined ? {} : _ref$classes; | ||
var servicesProviders = this._servicesProviders; | ||
var links = Array.from(servicesProviders.keys()).reduce(function (links, serviceName) { | ||
var serviceProvider = servicesProviders.get(serviceName); | ||
if (!serviceProvider[DEPENDENCIES].length) { | ||
return links; | ||
} | ||
return links.concat(serviceProvider[DEPENDENCIES].map(function (dependencyDeclaration) { | ||
var dependedServiceName = _pickServiceNameFromDeclaration(dependencyDeclaration); | ||
return { serviceName: serviceName, dependedServiceName: dependedServiceName }; | ||
})); | ||
}, []); | ||
var classesApplications = _applyClasses(classes, styles, links); | ||
if (!links.length) { | ||
return ''; | ||
} | ||
return ['graph TD'].concat(links.map(function (_ref2) { | ||
var serviceName = _ref2.serviceName, | ||
dependedServiceName = _ref2.dependedServiceName; | ||
return ' ' + (_applyShapes(shapes, serviceName) || serviceName) + '-->' + (_applyShapes(shapes, dependedServiceName) || dependedServiceName); | ||
})).concat(Object.keys(classes).map(function (className) { | ||
return ' classDef ' + className + ' ' + classes[className]; | ||
})).concat(Object.keys(classesApplications).map(function (serviceName) { | ||
return ' class ' + serviceName + ' ' + classesApplications[serviceName] + ';'; | ||
})).join('\n'); | ||
} | ||
/** | ||
* Creates a new execution silo | ||
* @param {String[]} dependenciesDeclarations Service name. | ||
* @return {Promise} Service descriptor promise Returns the decorator function | ||
* @return {Promise} Service descriptor promise | ||
* @example | ||
@@ -486,2 +553,46 @@ * | ||
return mappedName || serviceName; | ||
} | ||
function _applyShapes(shapes, serviceName) { | ||
return shapes.reduce(function (shapedService, shape) { | ||
var matches = void 0; | ||
if (shapedService) { | ||
return shapedService; | ||
} | ||
matches = shape.pattern.exec(serviceName); | ||
if (!matches) { | ||
return shapedService; | ||
} | ||
return shape.template.replace(/\$([0-9])+/g, function ($, $1) { | ||
return matches[parseInt($1, 10)]; | ||
}); | ||
}, ''); | ||
} | ||
function _applyClasses(classes, styles, links) { | ||
return links.reduce(function (classesApplications, link) { | ||
return Object.assign(classesApplications, _applyStyles(classes, styles, link)); | ||
}, {}); | ||
} | ||
function _applyStyles(classes, styles, _ref3) { | ||
var serviceName = _ref3.serviceName, | ||
dependedServiceName = _ref3.dependedServiceName; | ||
return styles.reduce(function (classesApplications, style) { | ||
if (style.pattern.test(serviceName) && !classesApplications[serviceName]) { | ||
if (!classes[style.className]) { | ||
throw new _yerror2.default('E_BAD_CLASS', style.className, serviceName); | ||
} | ||
classesApplications[serviceName] = style.className; | ||
} | ||
if (style.pattern.test(dependedServiceName) && !classesApplications[dependedServiceName]) { | ||
if (!classes[style.className]) { | ||
throw new _yerror2.default('E_BAD_CLASS', style.className, dependedServiceName); | ||
} | ||
classesApplications[dependedServiceName] = style.className; | ||
} | ||
return classesApplications; | ||
}, {}); | ||
} |
@@ -525,2 +525,79 @@ 'use strict'; | ||
}); | ||
describe('toMermaidGraph', function () { | ||
it('should print nothing when no dependency', function () { | ||
$.constant('ENV', ENV); | ||
$.constant('time', time); | ||
_assert2.default.equal($.toMermaidGraph(), ''); | ||
}); | ||
it('should print a dependency graph', function () { | ||
$.constant('ENV', ENV); | ||
$.constant('time', time); | ||
$.provider('hash', $.depends(['ENV'], hashProvider)); | ||
$.provider('hash1', $.depends(['hash'], hashProvider)); | ||
$.provider('hash2', $.depends(['hash1'], hashProvider)); | ||
$.provider('hash3', $.depends(['hash2'], hashProvider)); | ||
$.provider('hash4', $.depends(['hash3'], hashProvider)); | ||
$.provider('hash5', $.depends(['hash4'], hashProvider)); | ||
_assert2.default.equal($.toMermaidGraph(), 'graph TD\n' + ' hash-->ENV\n' + ' hash1-->hash\n' + ' hash2-->hash1\n' + ' hash3-->hash2\n' + ' hash4-->hash3\n' + ' hash5-->hash4'); | ||
}); | ||
it('should allow custom shapes', function () { | ||
$.constant('ENV', ENV); | ||
$.constant('time', time); | ||
$.provider('hash', $.depends(['ENV'], hashProvider)); | ||
$.provider('hash1', $.depends(['hash'], hashProvider)); | ||
$.provider('hash2', $.depends(['hash1'], hashProvider)); | ||
$.provider('hash3', $.depends(['hash2'], hashProvider)); | ||
$.provider('hash4', $.depends(['hash3'], hashProvider)); | ||
$.provider('hash5', $.depends(['hash4'], hashProvider)); | ||
_assert2.default.equal($.toMermaidGraph({ | ||
shapes: [{ | ||
pattern: /^hash([0-9]+)$/, | ||
template: '$0(($1))' | ||
}, { | ||
pattern: /^[A-Z_]+$/, | ||
template: '$0{$0}' | ||
}, { | ||
pattern: /^.+$/, | ||
template: '$0[$0]' | ||
}] | ||
}), 'graph TD\n' + ' hash[hash]-->ENV{ENV}\n' + ' hash1((1))-->hash[hash]\n' + ' hash2((2))-->hash1((1))\n' + ' hash3((3))-->hash2((2))\n' + ' hash4((4))-->hash3((3))\n' + ' hash5((5))-->hash4((4))'); | ||
}); | ||
it('should allow custom styles', function () { | ||
$.constant('ENV', ENV); | ||
$.constant('time', time); | ||
$.provider('hash', $.depends(['ENV'], hashProvider)); | ||
$.provider('hash1', $.depends(['hash'], hashProvider)); | ||
$.provider('hash2', $.depends(['hash1'], hashProvider)); | ||
$.provider('hash3', $.depends(['hash2'], hashProvider)); | ||
$.provider('hash4', $.depends(['hash3'], hashProvider)); | ||
$.provider('hash5', $.depends(['hash4'], hashProvider)); | ||
_assert2.default.equal($.toMermaidGraph({ | ||
classes: { | ||
exotic: 'fill:#f9f,stroke:#333,stroke-width:4px;' | ||
}, | ||
styles: [{ | ||
pattern: /^hash([0-9]+)$/, | ||
className: 'exotic' | ||
}, { | ||
pattern: /^hash([0-9]+)$/, | ||
className: 'notapplied' | ||
}], | ||
shapes: [{ | ||
pattern: /^hash([0-9]+)$/, | ||
template: '$0(($1))' | ||
}, { | ||
pattern: /^[A-Z_]+$/, | ||
template: '$0{$0}' | ||
}, { | ||
pattern: /^.+$/, | ||
template: '$0[$0]' | ||
}] | ||
}), 'graph TD\n' + ' hash[hash]-->ENV{ENV}\n' + ' hash1((1))-->hash[hash]\n' + ' hash2((2))-->hash1((1))\n' + ' hash3((3))-->hash2((2))\n' + ' hash4((4))-->hash3((3))\n' + ' hash5((5))-->hash4((4))\n' + ' classDef exotic fill:#f9f,stroke:#333,stroke-width:4px;\n' + ' class hash1 exotic;\n' + ' class hash2 exotic;\n' + ' class hash3 exotic;\n' + ' class hash4 exotic;\n' + ' class hash5 exotic;'); | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "knifecycle", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Manage your NodeJS processes's lifecycle.", | ||
"main": "dist/index.js", | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=6.9.5" | ||
}, | ||
"metapak": { | ||
"data": { | ||
"files": "src/*.js", | ||
"testsFiles": "src/*.mocha.js" | ||
}, | ||
"configs": [ | ||
"babel", | ||
"jsdocs", | ||
"readme" | ||
] | ||
}, | ||
"files": [ | ||
@@ -14,11 +25,16 @@ "dist", | ||
"scripts": { | ||
"cli": "env NPM_RUN_CLI=1", | ||
"test": "mocha --compilers js:babel-register src/*.mocha.js", | ||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", | ||
"cli": "env NODE_ENV=${NODE_ENV:-cli}", | ||
"compile": "babel src --out-dir=dist", | ||
"cover": "istanbul cover _mocha --report html -- --compilers js:babel-register src/*.mocha.js -R spec -t 5000", | ||
"coveralls": "istanbul cover _mocha --report lcovonly -- --compilers js:babel-register src/*.mocha.js -R spec -t 5000 && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage", | ||
"cz": "env NODE_ENV=${NODE_ENV:-cli} git cz", | ||
"doc": "mkdir -p .readme; echo \"# API\" > .readme/API.md; jsdoc2md src/*.js >> .readme/API.md", | ||
"lint": "eslint src/*.js", | ||
"metapak": "metapak || echo 'Please `npm install --save-dev metapak`' && exit 0", | ||
"postinstall": "npm run metapak; npm run metapak --silent", | ||
"prepublish": "npm run compile", | ||
"preversion": "npm t && npm run lint && npm run compile", | ||
"prepublish": "npm run compile", | ||
"coveralls": "istanbul cover _mocha --report lcovonly -- --compilers js:babel-register src/*.mocha.js src/**/*.mocha.js -R spec -t 5000 && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage", | ||
"cover": "istanbul cover _mocha --report html -- --compilers js:babel-register src/*.mocha.js src/**/*.mocha.js -R spec -t 5000", | ||
"lint": "eslint src/*.js", | ||
"doc": "cat src/*.js | jsdoc2md > API.md" | ||
"test": "mocha --compilers js:babel-register src/*.mocha.js", | ||
"version": "npm run changelog && git add CHANGELOG.md" | ||
}, | ||
@@ -31,3 +47,3 @@ "keywords": [ | ||
], | ||
"author": "Nicolas Froidure (7Digital)", | ||
"author": "Nicolas Froidure", | ||
"license": "MIT", | ||
@@ -43,15 +59,40 @@ "devDependencies": { | ||
"babel-register": "^6.9.0", | ||
"coveralls": "^2.11.12", | ||
"eslint": "^3.4.0", | ||
"eslint-config-simplifield": "^4.1.1", | ||
"commitizen": "^2.9.6", | ||
"conventional-changelog-cli": "^1.2.0", | ||
"coveralls": "2.11.15", | ||
"cz-conventional-changelog": "^2.0.0", | ||
"eslint": "3.16.0", | ||
"eslint-config-simplifield": "4.1.1", | ||
"istanbul": "^1.0.0-alpha.2", | ||
"jsdoc-to-markdown": "^2.0.1", | ||
"mocha": "^3.0.2", | ||
"mocha-lcov-reporter": "^1.2.0", | ||
"jsdoc-to-markdown": "^3.0.0", | ||
"metapak": "0.0.18", | ||
"metapak-nfroidure": "0.4.1", | ||
"mocha": "3.2.0", | ||
"mocha-lcov-reporter": "1.3.0", | ||
"sinon": "^1.16.1" | ||
}, | ||
"dependencies": { | ||
"debug": "^2.2.0", | ||
"yerror": "^1.0.2" | ||
"debug": "2.6.1", | ||
"yerror": "^2.0.0" | ||
}, | ||
"greenkeeper": { | ||
"ignore": [ | ||
"debug", | ||
"eslint", | ||
"eslint-config-simplifield", | ||
"mocha", | ||
"mocha-lcov-reporter", | ||
"commitizen", | ||
"cz-conventional-changelog", | ||
"coveralls", | ||
"istanbul", | ||
"conventional-changelog-cli", | ||
"jsdoc-to-markdown" | ||
] | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
} | ||
} |
@@ -0,12 +1,18 @@ | ||
<!-- | ||
# This file is automatically generated by a `metapak` | ||
# module. Do not change it elsewhere, changes would | ||
# be overriden. | ||
--> | ||
# knifecycle | ||
> Manage your NodeJS processes's lifecycle. | ||
[![NPM version](https://img.shields.io/npm/v/knifecycle.svg)](https://www.npmjs.com/package/knifecycle) | ||
[![Build Status](https://travis-ci.org/nfroidure/knifecycle.svg?branch=master)](https://travis-ci.org/nfroidure/knifecycle) | ||
[![NPM version](https://badge.fury.io/js/knifecycle.svg)](https://npmjs.org/package/knifecycle) | ||
[![Build status](https://secure.travis-ci.org/nfroidure/knifecycle.svg)](https://travis-ci.org/nfroidure/knifecycle) | ||
[![Dependency Status](https://david-dm.org/nfroidure/knifecycle.svg)](https://david-dm.org/nfroidure/knifecycle) | ||
[![devDependency Status](https://david-dm.org/nfroidure/knifecycle/dev-status.svg)](https://david-dm.org/nfroidure/knifecycle#info=devDependencies) | ||
[![Coverage Status](https://coveralls.io/repos/nfroidure/knifecycle/badge.svg?branch=master)](https://coveralls.io/r/nfroidure/knifecycle?branch=master) | ||
[![Code Climate](https://codeclimate.com/github/nfroidure/knifecycle/badges/gpa.svg)](https://codeclimate.com/github/nfroidure/knifecycle) | ||
[![Code Climate](https://codeclimate.com/github/nfroidure/knifecycle.svg)](https://codeclimate.com/github/nfroidure/knifecycle) | ||
[![Dependency Status](https://dependencyci.com/github/nfroidure/knifecycle/badge)](https://dependencyci.com/github/nfroidure/knifecycle) | ||
Most (maybe all) applications rely on two kinds of dependencies. | ||
@@ -143,3 +149,3 @@ | ||
depends('app', 'now', 'logger', | ||
function timeRoutesProvider() { | ||
function timeRoutesProvider({ app, now, logger }) { | ||
return Promise.resolve() | ||
@@ -253,3 +259,4 @@ .then(() => { | ||
## API | ||
# API | ||
## Functions | ||
@@ -269,6 +276,6 @@ <dl> | ||
</dd> | ||
<dt><a href="#depends">depends(dependenciesNames, serviceProvider)</a> ⇒ <code>function</code></dt> | ||
<dt><a href="#depends">depends(dependenciesDeclarations, serviceProvider)</a> ⇒ <code>function</code></dt> | ||
<dd><p>Decorator to claim that a service depends on others ones.</p> | ||
</dd> | ||
<dt><a href="#run">run(dependenciesNames)</a> ⇒ <code>Promise</code></dt> | ||
<dt><a href="#run">run(dependenciesDeclarations)</a> ⇒ <code>Promise</code></dt> | ||
<dd><p>Creates a new execution silo</p> | ||
@@ -282,3 +289,3 @@ </dd> | ||
</dd> | ||
<dt><a href="#_initializeDependencies">_initializeDependencies(siloContext, serviceName, servicesNames, injectOnly)</a> ⇒ <code>Promise</code></dt> | ||
<dt><a href="#_initializeDependencies">_initializeDependencies(siloContext, serviceName, servicesDeclarations, injectOnly)</a> ⇒ <code>Promise</code></dt> | ||
<dd><p>Initialize a service dependencies</p> | ||
@@ -404,3 +411,3 @@ </dd> | ||
## depends(dependenciesNames, serviceProvider) ⇒ <code>function</code> | ||
## depends(dependenciesDeclarations, serviceProvider) ⇒ <code>function</code> | ||
Decorator to claim that a service depends on others ones. | ||
@@ -413,3 +420,3 @@ | ||
| --- | --- | --- | | ||
| dependenciesNames | <code>Array.<String></code> | Dependencies the decorated service provider depends on. | | ||
| dependenciesDeclarations | <code>Array.<String></code> | Dependencies the decorated service provider depends on. | | ||
| serviceProvider | <code>function</code> | Service provider or a service provider promise | | ||
@@ -445,3 +452,3 @@ | ||
## run(dependenciesNames) ⇒ <code>Promise</code> | ||
## run(dependenciesDeclarations) ⇒ <code>Promise</code> | ||
Creates a new execution silo | ||
@@ -454,3 +461,3 @@ | ||
| --- | --- | --- | | ||
| dependenciesNames | <code>Array.<String></code> | Service name. | | ||
| dependenciesDeclarations | <code>Array.<String></code> | Service name. | | ||
@@ -500,3 +507,3 @@ **Example** | ||
## _initializeDependencies(siloContext, serviceName, servicesNames, injectOnly) ⇒ <code>Promise</code> | ||
## _initializeDependencies(siloContext, serviceName, servicesDeclarations, injectOnly) ⇒ <code>Promise</code> | ||
Initialize a service dependencies | ||
@@ -511,3 +518,7 @@ | ||
| serviceName | <code>String</code> | | Service name. | | ||
| servicesNames | <code>String</code> | | Dependencies names. | | ||
| servicesDeclarations | <code>String</code> | | Dependencies names. | | ||
| injectOnly | <code>Boolean</code> | <code>false</code> | Flag indicating if existing services only should be used | | ||
# License | ||
[MIT](https://github.com/nfroidure/knifecycle/blob/master/LICENSE) |
120
src/index.js
@@ -0,1 +1,2 @@ | ||
/* eslint max-len: ["warn", { "ignoreComments": true }] */ | ||
import YError from 'yerror'; | ||
@@ -219,5 +220,72 @@ import initDebug from 'debug'; | ||
/** | ||
* Outputs a Mermaid compatible dependency graph of the declared services. | ||
* See [Mermaid docs](https://github.com/knsv/mermaid) | ||
* @param {Object} options Options for generating the graph (destructured) | ||
* @param {Array<Object>} options.shapes Various shapes to apply | ||
* @param {Array<Object>} options.styles Various styles to apply | ||
* @param {Object} options.classes A hash of various classes contents | ||
* @return {String} Returns a string containing the Mermaid dependency graph | ||
* @example | ||
* | ||
* import Knifecycle from 'knifecycle' | ||
* | ||
* const $ = new Knifecycle(); | ||
* | ||
* $.constant('ENV', process.env); | ||
* $.constant('OS', require('os')); | ||
* $.service('app', $.depends(['ENV', 'OS'], () => Promise.resolve())); | ||
* $.toMermaidGraph(); | ||
* | ||
* // returns | ||
* graph TD | ||
* app-->ENV | ||
* app-->OS | ||
*/ | ||
toMermaidGraph({ shapes = [], styles = [], classes = {} } = {}) { | ||
const servicesProviders = this._servicesProviders; | ||
const links = Array.from(servicesProviders.keys()) | ||
.reduce((links, serviceName) => { | ||
const serviceProvider = servicesProviders.get(serviceName); | ||
if(!serviceProvider[DEPENDENCIES].length) { | ||
return links; | ||
} | ||
return links.concat(serviceProvider[DEPENDENCIES] | ||
.map((dependencyDeclaration) => { | ||
const dependedServiceName = _pickServiceNameFromDeclaration( | ||
dependencyDeclaration | ||
); | ||
return { serviceName, dependedServiceName }; | ||
})); | ||
}, []); | ||
const classesApplications = _applyClasses(classes, styles, links); | ||
if(!links.length) { | ||
return ''; | ||
} | ||
return ['graph TD'].concat( | ||
links.map( | ||
({ serviceName, dependedServiceName }) => | ||
' ' + (_applyShapes(shapes, serviceName) || serviceName) + '-->' + | ||
(_applyShapes(shapes, dependedServiceName) || dependedServiceName) | ||
) | ||
) | ||
.concat(Object.keys(classes).map( | ||
className => ' classDef ' + className + ' ' + classes[className] | ||
)) | ||
.concat( | ||
Object.keys(classesApplications).map( | ||
serviceName => | ||
' class ' + serviceName + ' ' + classesApplications[serviceName] + ';' | ||
) | ||
) | ||
.join('\n'); | ||
} | ||
/** | ||
* Creates a new execution silo | ||
* @param {String[]} dependenciesDeclarations Service name. | ||
* @return {Promise} Service descriptor promise Returns the decorator function | ||
* @return {Promise} Service descriptor promise | ||
* @example | ||
@@ -445,1 +513,51 @@ * | ||
} | ||
function _applyShapes(shapes, serviceName) { | ||
return shapes.reduce((shapedService, shape) => { | ||
let matches; | ||
if(shapedService) { | ||
return shapedService; | ||
} | ||
matches = shape.pattern.exec(serviceName); | ||
if(!matches) { | ||
return shapedService; | ||
} | ||
return shape.template.replace( | ||
/\$([0-9])+/g, | ||
($, $1) => matches[parseInt($1, 10)] | ||
); | ||
}, ''); | ||
} | ||
function _applyClasses(classes, styles, links) { | ||
return links.reduce( | ||
(classesApplications, link) => | ||
Object.assign(classesApplications, _applyStyles(classes, styles, link)), | ||
{} | ||
); | ||
} | ||
function _applyStyles(classes, styles, { serviceName, dependedServiceName }) { | ||
return styles.reduce((classesApplications, style) => { | ||
if( | ||
style.pattern.test(serviceName) && | ||
!classesApplications[serviceName] | ||
) { | ||
if(!classes[style.className]) { | ||
throw new YError('E_BAD_CLASS', style.className, serviceName); | ||
} | ||
classesApplications[serviceName] = style.className; | ||
} | ||
if( | ||
style.pattern.test(dependedServiceName) && | ||
!classesApplications[dependedServiceName] | ||
) { | ||
if(!classes[style.className]) { | ||
throw new YError('E_BAD_CLASS', style.className, dependedServiceName); | ||
} | ||
classesApplications[dependedServiceName] = style.className; | ||
} | ||
return classesApplications; | ||
}, {}); | ||
} |
@@ -581,2 +581,110 @@ import assert from 'assert'; | ||
describe('toMermaidGraph', () => { | ||
it('should print nothing when no dependency', () => { | ||
$.constant('ENV', ENV); | ||
$.constant('time', time); | ||
assert.equal($.toMermaidGraph(), ''); | ||
}); | ||
it('should print a dependency graph', () => { | ||
$.constant('ENV', ENV); | ||
$.constant('time', time); | ||
$.provider('hash', $.depends(['ENV'], hashProvider)); | ||
$.provider('hash1', $.depends(['hash'], hashProvider)); | ||
$.provider('hash2', $.depends(['hash1'], hashProvider)); | ||
$.provider('hash3', $.depends(['hash2'], hashProvider)); | ||
$.provider('hash4', $.depends(['hash3'], hashProvider)); | ||
$.provider('hash5', $.depends(['hash4'], hashProvider)); | ||
assert.equal($.toMermaidGraph(), | ||
'graph TD\n' + | ||
' hash-->ENV\n' + | ||
' hash1-->hash\n' + | ||
' hash2-->hash1\n' + | ||
' hash3-->hash2\n' + | ||
' hash4-->hash3\n' + | ||
' hash5-->hash4' | ||
); | ||
}); | ||
it('should allow custom shapes', () => { | ||
$.constant('ENV', ENV); | ||
$.constant('time', time); | ||
$.provider('hash', $.depends(['ENV'], hashProvider)); | ||
$.provider('hash1', $.depends(['hash'], hashProvider)); | ||
$.provider('hash2', $.depends(['hash1'], hashProvider)); | ||
$.provider('hash3', $.depends(['hash2'], hashProvider)); | ||
$.provider('hash4', $.depends(['hash3'], hashProvider)); | ||
$.provider('hash5', $.depends(['hash4'], hashProvider)); | ||
assert.equal($.toMermaidGraph({ | ||
shapes: [{ | ||
pattern: /^hash([0-9]+)$/, | ||
template: '$0(($1))', | ||
}, { | ||
pattern: /^[A-Z_]+$/, | ||
template: '$0{$0}', | ||
}, { | ||
pattern: /^.+$/, | ||
template: '$0[$0]', | ||
}], | ||
}), | ||
'graph TD\n' + | ||
' hash[hash]-->ENV{ENV}\n' + | ||
' hash1((1))-->hash[hash]\n' + | ||
' hash2((2))-->hash1((1))\n' + | ||
' hash3((3))-->hash2((2))\n' + | ||
' hash4((4))-->hash3((3))\n' + | ||
' hash5((5))-->hash4((4))' | ||
); | ||
}); | ||
it('should allow custom styles', () => { | ||
$.constant('ENV', ENV); | ||
$.constant('time', time); | ||
$.provider('hash', $.depends(['ENV'], hashProvider)); | ||
$.provider('hash1', $.depends(['hash'], hashProvider)); | ||
$.provider('hash2', $.depends(['hash1'], hashProvider)); | ||
$.provider('hash3', $.depends(['hash2'], hashProvider)); | ||
$.provider('hash4', $.depends(['hash3'], hashProvider)); | ||
$.provider('hash5', $.depends(['hash4'], hashProvider)); | ||
assert.equal($.toMermaidGraph({ | ||
classes: { | ||
exotic: 'fill:#f9f,stroke:#333,stroke-width:4px;', | ||
}, | ||
styles: [{ | ||
pattern: /^hash([0-9]+)$/, | ||
className: 'exotic', | ||
}, { | ||
pattern: /^hash([0-9]+)$/, | ||
className: 'notapplied', | ||
}], | ||
shapes: [{ | ||
pattern: /^hash([0-9]+)$/, | ||
template: '$0(($1))', | ||
}, { | ||
pattern: /^[A-Z_]+$/, | ||
template: '$0{$0}', | ||
}, { | ||
pattern: /^.+$/, | ||
template: '$0[$0]', | ||
}], | ||
}), | ||
'graph TD\n' + | ||
' hash[hash]-->ENV{ENV}\n' + | ||
' hash1((1))-->hash[hash]\n' + | ||
' hash2((2))-->hash1((1))\n' + | ||
' hash3((3))-->hash2((2))\n' + | ||
' hash4((4))-->hash3((3))\n' + | ||
' hash5((5))-->hash4((4))\n' + | ||
' classDef exotic fill:#f9f,stroke:#333,stroke-width:4px;\n' + | ||
' class hash1 exotic;\n' + | ||
' class hash2 exotic;\n' + | ||
' class hash3 exotic;\n' + | ||
' class hash4 exotic;\n' + | ||
' class hash5 exotic;' | ||
); | ||
}); | ||
}); | ||
}); |
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
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
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
112750
12
2169
515
21
1
+ Addeddebug@2.6.1(transitive)
+ Addedms@0.7.2(transitive)
+ Addedyerror@2.1.3(transitive)
- Removeddebug@2.6.9(transitive)
- Removedms@2.0.0(transitive)
- Removedyerror@1.0.2(transitive)
Updateddebug@2.6.1
Updatedyerror@^2.0.0