Skip to content

Commit

Permalink
Integrate eslint, auto-changelog, prettier and jest as commands
Browse files Browse the repository at this point in the history
  • Loading branch information
eaviles committed Oct 4, 2021
1 parent 803736c commit 330939c
Show file tree
Hide file tree
Showing 15 changed files with 5,158 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./shared/eslint.json",
"rules": {
"global-require": "off"
}
}
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"./shared/prettier.json"
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2021 Lifion/ADP

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# core-commons

Lifion's development setup in one command for our public Node.js projects.
34 changes: 34 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env node

'use strict';

const chalk = require('chalk');
const path = require('path');
const yargs = require('yargs');

async function start() {
const argv = process.argv.slice(2);
const header = 'Development framework by and for the Core Team.';
const learnMore = 'Read the manual at https://core.lifion.oneadp.com/libs/core-commons';
const { npm_lifecycle_event: lifecycleEvent } = process.env;

if (lifecycleEvent) {
argv.push(lifecycleEvent);
}

yargs(argv)
.usage(`${header}\n\n${chalk.bold('USAGE')}\n $0 <command> [options]`)
.epilogue(`${chalk.bold('LEARN MORE')}\n ${learnMore}`)
.commandDir(path.resolve(__dirname, '../lib/commands'))
.demandCommand()
.recommendCommands()
.strict()
.help()
.updateStrings({
'Commands:': chalk.bold('COMMANDS'),
'Options:': chalk.bold('OPTIONS')
})
.parse();
}

start();
16 changes: 16 additions & 0 deletions lib/commands/eslint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

const path = require('path');

async function handler() {
process.argv.push(
...[['.'], ['--ext', '.js,.json,.md'], ['--ignore-pattern', '!.*.*']].flatMap((i) => i)
);
require('eslint/bin/eslint');
}

module.exports = {
command: path.parse(__filename).name,
describe: 'Check the codebase with ESLint.',
handler
};
15 changes: 15 additions & 0 deletions lib/commands/prettier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

const path = require('path');

async function handler() {
const exts = ['hbs', 'js', 'json', 'md', 'ts'];
process.argv.push('--write', `**/*.{${exts.join(',')}}`, '.*rc', '!reports/*');
require('prettier/bin-prettier');
}

module.exports = {
command: path.parse(__filename).name,
describe: 'Format the codebase with Prettier.',
handler
};
30 changes: 30 additions & 0 deletions lib/commands/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

const path = require('path');

async function handler() {
const cfg = {
collectCoverage: true,
collectCoverageFrom: ['**/*.js'],
coverageDirectory: path.resolve(process.cwd(), 'coverage'),
coverageReporters: ['clover', 'lcov', 'text'],
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100
}
},
rootDir: path.resolve(process.cwd(), 'lib'),
testEnvironment: 'node'
};
process.argv.push('--config', JSON.stringify(cfg));
require('jest/bin/jest');
}

module.exports = {
command: path.parse(__filename).name,
describe: 'Run tests with Jest.',
handler
};
20 changes: 20 additions & 0 deletions lib/commands/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

const path = require('path');

async function handler() {
process.argv.push(
...[
['--package'],
['--commit-limit', 'false'],
['--template', path.resolve(__dirname, '../../shared/CHANGELOG.hbs')]
].flatMap((i) => i)
);
require('auto-changelog');
}

module.exports = {
command: path.parse(__filename).name,
describe: 'Generate the changelog.',
handler
};

0 comments on commit 330939c

Please sign in to comment.