Comparing version 6.5.0 to 7.0.0
#!/usr/bin/env node | ||
const meow = require('meow'); | ||
const mri = require('mri'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const colors = require('ansi-colors'); | ||
colors.enabled = require('color-support').hasBasic; | ||
const { | ||
@@ -11,3 +15,3 @@ red, | ||
magenta | ||
} = require('chalk'); | ||
} = colors; | ||
@@ -28,2 +32,23 @@ const { promisify } = require('util'); | ||
const CONFIG_NAME = '.bpmnlintrc'; | ||
const DEFAULT_CONFIG_CONTENTS = `{ | ||
"extends": "bpmnlint:recommended" | ||
}`; | ||
const HELP_STRING = ` | ||
Usage | ||
$ bpmnlint diagram.bpmn | ||
Options | ||
--config, -c Path to configuration file. It overrides .bpmnlintrc if present. | ||
--init Generate a .bpmnlintrc file in the current working directory | ||
Examples | ||
$ bpmnlint ./invoice.bpmn | ||
$ bpmnlint --init | ||
`; | ||
const moddle = new BpmnModdle(); | ||
@@ -41,3 +66,3 @@ | ||
return Promise.all( | ||
cli.input.map( | ||
files.map( | ||
file => tinyGlob(file, { dot: true }) | ||
@@ -50,22 +75,30 @@ ) | ||
* Reads XML form path and return moddle object | ||
* @param {*} sourcePath | ||
* | ||
* @param {string} diagramXML | ||
* | ||
* @return { { rootElement: any; warnings: Error[], error?: Error } } parseResult | ||
*/ | ||
function parseDiagram(diagramXML) { | ||
return new Promise((resolve, reject) => { | ||
moddle.fromXML(diagramXML, (error, moddleElement, context) => { | ||
async function parseDiagram(diagramXML) { | ||
if (error) { | ||
return resolve({ | ||
error | ||
}); | ||
} | ||
try { | ||
const { | ||
rootElement: moddleElement, | ||
warnings = [] | ||
} = await moddle.fromXML(diagramXML); | ||
const warnings = context.warnings || []; | ||
return { | ||
moddleElement, | ||
warnings | ||
}; | ||
} catch (error) { | ||
return resolve({ | ||
moddleElement, | ||
warnings | ||
}); | ||
}); | ||
}); | ||
const { | ||
warnings = [] | ||
} = error; | ||
return { | ||
error, | ||
warnings | ||
}; | ||
} | ||
} | ||
@@ -114,3 +147,14 @@ | ||
function errorAndExit(...args) { | ||
console.error(...args); | ||
process.exit(1); | ||
} | ||
function infoAndExit(...args) { | ||
console.log(...args); | ||
process.exit(0); | ||
} | ||
/** | ||
@@ -169,54 +213,2 @@ * Prints lint results to the console | ||
const cli = meow( | ||
` | ||
Usage | ||
$ bpmnlint diagram.bpmn | ||
Options | ||
--config, -c Path to configuration file. It overrides .bpmnlintrc if present. | ||
--init Generate a .bpmnlintrc file in the current working directory | ||
Examples | ||
$ bpmnlint ./invoice.bpmn | ||
$ bpmnlint --init | ||
`, | ||
{ | ||
flags: { | ||
init: { | ||
type: 'boolean' | ||
}, | ||
config: { | ||
type: 'string', | ||
alias: 'c' | ||
} | ||
} | ||
} | ||
); | ||
if (cli.flags.init) { | ||
if (fs.existsSync('.bpmnlintrc')) { | ||
console.warn('Not overriding existing .bpmnlintrc'); | ||
process.exit(1); | ||
} | ||
fs.writeFileSync('.bpmnlintrc', `{ | ||
"extends": "bpmnlint:recommended" | ||
}`, 'utf8'); | ||
console.error(`Created ${magenta('.bpmnlintrc')} file`); | ||
process.exit(0); | ||
} | ||
if (cli.input.length === 0) { | ||
console.log('Error: bpmn file path missing'); | ||
process.exit(1); | ||
} | ||
function logAndExit(...args) { | ||
console.error(...args); | ||
process.exit(1); | ||
} | ||
async function lintDiagram(diagramPath, config) { | ||
@@ -229,3 +221,3 @@ | ||
} catch (error) { | ||
return logAndExit(`Error: Failed to read ${diagramPath}\n\n%s`, error.message); | ||
return errorAndExit(`Error: Failed to read ${diagramPath}\n\n%s`, error.message); | ||
} | ||
@@ -284,7 +276,7 @@ | ||
} catch (e) { | ||
return logAndExit(e); | ||
return errorAndExit(e); | ||
} | ||
} | ||
async function lint(config) { | ||
async function lint(files, config) { | ||
@@ -296,4 +288,2 @@ let errorCount = 0; | ||
const files = await glob(cli.input); | ||
for (let i = 0; i < files.length; i++) { | ||
@@ -333,6 +323,34 @@ let results = await lintDiagram(files[i], config); | ||
const configOverridePath = cli.flags.config; | ||
const { | ||
help, | ||
init, | ||
config: configOverridePath, | ||
_: files | ||
} = mri(process.argv.slice(2), { | ||
string: [ 'config' ], | ||
alias: { | ||
c: 'config' | ||
} | ||
}); | ||
const configPath = configOverridePath || '.bpmnlintrc'; | ||
if (help) { | ||
return infoAndExit(HELP_STRING); | ||
} | ||
if (init) { | ||
if (fs.existsSync(CONFIG_NAME)) { | ||
return errorAndExit('Not overriding existing .bpmnlintrc'); | ||
} | ||
fs.writeFileSync(CONFIG_NAME, DEFAULT_CONFIG_CONTENTS, 'utf8'); | ||
return infoAndExit(`Created ${magenta(CONFIG_NAME)} file`); | ||
} | ||
if (files.length === 0) { | ||
return errorAndExit('Error: bpmn file path missing'); | ||
} | ||
const configPath = configOverridePath || CONFIG_NAME; | ||
let configString, config; | ||
@@ -346,4 +364,4 @@ | ||
configOverridePath | ||
? `Error: Could not read ${ configOverridePath }` | ||
: `Error: Could not locate local ${ magenta('.bpmnlintrc') } file. Create one via | ||
? `Error: Could not read ${ magenta(configOverridePath) }` | ||
: `Error: Could not locate local ${ magenta(CONFIG_NAME) } file. Create one via | ||
@@ -355,3 +373,3 @@ ${magenta('bpmnlint --init')} | ||
return logAndExit(message); | ||
return errorAndExit(message); | ||
} | ||
@@ -362,8 +380,10 @@ | ||
} catch (err) { | ||
return logAndExit('Error: Could not parse %s\n\n%s', configPath, err.message); | ||
return errorAndExit('Error: Could not parse %s\n\n%s', configPath, err.message); | ||
} | ||
return lint(config); | ||
const actualFiles = await glob(files); | ||
return lint(actualFiles, config); | ||
} | ||
run().catch(logAndExit); | ||
run().catch(errorAndExit); |
@@ -9,2 +9,8 @@ # Changelog | ||
## 7.0.0 | ||
* `CHORE`: update to `bpmn-moddle@7` | ||
* `CHORE`: reduce library footprint | ||
* `CHORE`: require `NodeJS>=10` | ||
## 6.5.0 | ||
@@ -11,0 +17,0 @@ |
@@ -51,2 +51,3 @@ const Module = require('module'); | ||
} catch (err) { | ||
/* ignore */ | ||
@@ -53,0 +54,0 @@ } |
@@ -13,18 +13,18 @@ const BpmnModdle = require('bpmn-moddle'); | ||
*/ | ||
function createModdle(xml, elementType = 'bpmn:Definitions') { | ||
async function createModdle(xml, elementType = 'bpmn:Definitions') { | ||
const moddle = new BpmnModdle(); | ||
return new Promise((resolve, reject) => { | ||
moddle.fromXML(xml, elementType, { lax: true }, function(err, root, context) { | ||
if (err) { | ||
return reject(err); | ||
} else { | ||
return resolve({ | ||
root, | ||
context, | ||
moddle | ||
}); | ||
} | ||
}); | ||
}); | ||
const { | ||
rootElement: root, | ||
warnings = [] | ||
} = await moddle.fromXML(xml, elementType, { lax: true }); | ||
return { | ||
root, | ||
moddle, | ||
context: { | ||
warnings | ||
}, | ||
warnings | ||
}; | ||
} | ||
@@ -31,0 +31,0 @@ |
{ | ||
"name": "bpmnlint", | ||
"description": "Validate your BPMN diagrams based on configurable lint rules", | ||
"version": "6.5.0", | ||
"version": "7.0.0", | ||
"main": "lib/index.js", | ||
@@ -26,3 +26,3 @@ "keywords": [ | ||
"engines": { | ||
"node": ">= 8" | ||
"node": ">= 10" | ||
}, | ||
@@ -41,7 +41,8 @@ "license": "MIT", | ||
"dependencies": { | ||
"bpmn-moddle": "^6.0.0", | ||
"bpmnlint-utils": "^1.0.1", | ||
"chalk": "^2.4.2", | ||
"ansi-colors": "^4.1.1", | ||
"bpmn-moddle": "^7.0.3", | ||
"bpmnlint-utils": "^1.0.2", | ||
"cli-table": "^0.3.1", | ||
"meow": "^5.0.0", | ||
"color-support": "^1.1.3", | ||
"mri": "^1.1.6", | ||
"pluralize": "^7.0.0", | ||
@@ -52,12 +53,12 @@ "tiny-glob": "^0.2.8" | ||
"chai": "^4.2.0", | ||
"eslint": "^5.16.0", | ||
"eslint-plugin-bpmn-io": "^0.8.2", | ||
"eslint": "^7.14.0", | ||
"eslint-plugin-bpmn-io": "^0.11.0", | ||
"esm": "^3.2.25", | ||
"execa": "^2.0.3", | ||
"install-local": "^1.0.0", | ||
"mocha": "^6.2.0", | ||
"mocha": "^8.2.1", | ||
"npm-run-all": "^4.1.5", | ||
"nyc": "^14.1.1", | ||
"nyc": "^15.1.0", | ||
"strip-indent": "^2.0.0" | ||
} | ||
} |
@@ -32,2 +32,3 @@ const { | ||
if (is(node, 'bpmn:SubProcess')) { | ||
// TODO(nikku): better ignore expanded sub-processes only | ||
@@ -34,0 +35,0 @@ return; |
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
47730
1408
8
+ Addedansi-colors@^4.1.1
+ Addedcolor-support@^1.1.3
+ Addedmri@^1.1.6
+ Addedansi-colors@4.1.3(transitive)
+ Addedbpmn-moddle@7.1.3(transitive)
+ Addedcolor-support@1.1.3(transitive)
+ Addedmoddle-xml@9.0.6(transitive)
+ Addedmri@1.2.0(transitive)
- Removedchalk@^2.4.2
- Removedmeow@^5.0.0
- Removedansi-styles@3.2.1(transitive)
- Removedarray-find-index@1.0.2(transitive)
- Removedarrify@1.0.1(transitive)
- Removedbpmn-moddle@6.0.7(transitive)
- Removedcamelcase@4.1.0(transitive)
- Removedcamelcase-keys@4.2.0(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedcurrently-unhandled@0.4.1(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removeddecamelize-keys@1.1.1(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedfind-up@2.1.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhosted-git-info@2.8.9(transitive)
- Removedindent-string@3.2.0(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-core-module@2.15.1(transitive)
- Removedis-plain-obj@1.1.0(transitive)
- Removedjson-parse-better-errors@1.0.2(transitive)
- Removedload-json-file@4.0.0(transitive)
- Removedlocate-path@2.0.0(transitive)
- Removedloud-rejection@1.6.0(transitive)
- Removedmap-obj@1.0.12.0.0(transitive)
- Removedmeow@5.0.0(transitive)
- Removedminimist-options@3.0.2(transitive)
- Removedmoddle-xml@8.0.8(transitive)
- Removednormalize-package-data@2.5.0(transitive)
- Removedp-limit@1.3.0(transitive)
- Removedp-locate@2.0.0(transitive)
- Removedp-try@1.0.0(transitive)
- Removedparse-json@4.0.0(transitive)
- Removedpath-exists@3.0.0(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpath-type@3.0.0(transitive)
- Removedpify@3.0.0(transitive)
- Removedquick-lru@1.1.0(transitive)
- Removedread-pkg@3.0.0(transitive)
- Removedread-pkg-up@3.0.0(transitive)
- Removedredent@2.0.0(transitive)
- Removedresolve@1.22.8(transitive)
- Removedsemver@5.7.2(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedspdx-correct@3.2.0(transitive)
- Removedspdx-exceptions@2.5.0(transitive)
- Removedspdx-expression-parse@3.0.1(transitive)
- Removedspdx-license-ids@3.0.20(transitive)
- Removedstrip-bom@3.0.0(transitive)
- Removedstrip-indent@2.0.0(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedtrim-newlines@2.0.0(transitive)
- Removedvalidate-npm-package-license@3.0.4(transitive)
- Removedyargs-parser@10.1.0(transitive)
Updatedbpmn-moddle@^7.0.3
Updatedbpmnlint-utils@^1.0.2