Skip to content

Commit

Permalink
WIP feat: add command line utility
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Oct 16, 2024
1 parent 9b3be0b commit dd630a5
Show file tree
Hide file tree
Showing 5 changed files with 720 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
dist
55 changes: 55 additions & 0 deletions bin/linting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env node

const fs = require('fs');

Check failure on line 3 in bin/linting.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

'require' is not defined

Check failure on line 3 in bin/linting.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

'require' is not defined

const {
green,
red
} = require('ansi-colors');

Check failure on line 8 in bin/linting.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

'require' is not defined

Check failure on line 8 in bin/linting.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

'require' is not defined

const { Linter } = require('../dist/Linter.js');

Check failure on line 10 in bin/linting.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

'require' is not defined

Check failure on line 10 in bin/linting.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

'require' is not defined

const linter = new Linter();

const files = process.argv.filter(arg => arg.endsWith('.bpmn'));

Check failure on line 14 in bin/linting.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

'process' is not defined

Check failure on line 14 in bin/linting.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

'process' is not defined

if (files.length === 0) {
console.error('No files found matching the pattern:', pattern);

Check failure on line 17 in bin/linting.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

'pattern' is not defined

Check failure on line 17 in bin/linting.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

'pattern' is not defined

process.exit(1);

Check failure on line 19 in bin/linting.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

'process' is not defined

Check failure on line 19 in bin/linting.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

'process' is not defined
}

console.log(`Linting ${files.length} file(s)`);

let errors = 0;

files.forEach((file) => {
try {
const content = fs.readFileSync(file, 'utf8');

linter.lint(content).then((results) => {
if (!results.length) {
console.log(green(file));

return;
}

errors += results.length;

console.log(red(file));

results.forEach((result) => {
console.log(red(`\t[${result.id}] ${result.message}`));
});
});

} catch (err) {
console.error(`Error reading ${file}:`, err);
}
});

process.on('exit', () => {

Check failure on line 51 in bin/linting.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

'process' is not defined

Check failure on line 51 in bin/linting.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

'process' is not defined
if (errors) {
process.exit(1);

Check failure on line 53 in bin/linting.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

'process' is not defined

Check failure on line 53 in bin/linting.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, 20)

'process' is not defined
}
});
Loading

0 comments on commit dd630a5

Please sign in to comment.