Skip to content

Commit

Permalink
feat(requirements): support optional requirements (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
chimurai committed Oct 5, 2019
1 parent 99fc74b commit 2f21db3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -23,7 +23,10 @@ module.exports = {
software: {
node: '*',
yarn: '~1.17.3',
nginx: '>= 1.16.x',
nginx: {
semver: '>= 1.16.x',
optional: true // optional (won't fail)
},
httpd: {
semver: '^1.x',
flag: '-v' // custom version flag
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "requirements",
"version": "1.1.0",
"version": "1.2.0",
"license": "MIT",
"author": "chimurai",
"homepage": "https://github.com/chimurai/requirements",
Expand Down
5 changes: 4 additions & 1 deletion src/bin.ts
Expand Up @@ -14,7 +14,10 @@ export async function exec() {

const config = getConfiguration(argv);
let rawResults = await checkSoftware(config.software);
const ALL_OK = rawResults.every(result => result.satisfies === true);

const ALL_OK = rawResults
.filter(result => !result.optional)
.every(result => result.satisfies === true);

if (argv.debug) {
console.debug('馃憖 RAW data:\n', rawResults);
Expand Down
14 changes: 9 additions & 5 deletions src/reporter.ts
Expand Up @@ -5,15 +5,19 @@ import { RawResult } from './types';

export function renderTable(rawResults: RawResult[] = []) {
let results = rawResults.map(item => {
const { bin, semver, installed, version, satisfies } = item;
const { bin, semver, installed, version, satisfies, optional } = item;

const pass = satisfies
? `${logSymbols.success} ${chalk.dim('OK')}`
: optional
? `${logSymbols.warning} ${chalk.dim('NOK (optional)')}`
: `${logSymbols.error} ${chalk.dim('NOK')}`;

return {
bin,
bin: optional ? chalk.dim(`${bin}`) : bin,
semver: chalk.dim(semver),
version: installed ? chalk.dim(version) : chalk.dim('not installed'),
pass: satisfies
? `${logSymbols.success} ${chalk.dim('OK')}`
: `${logSymbols.error} ${chalk.dim('NOK')}`
pass
};
});

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Expand Up @@ -23,4 +23,5 @@ export interface RawResult {
installed: boolean;
version?: string;
satisfies?: boolean;
optional?: boolean;
}
8 changes: 6 additions & 2 deletions tests/requirements.config.js
@@ -1,11 +1,15 @@
module.exports = {
software: {
// java: '>= 1.8.x',
git: '~1.9.4 || 2.0.0 - 2.10.0',
node: '8 || 10 || 12',
npm: '>= 6.x',
yarn: '>= 1.6.x',
yarn: '>= 1.19.x',
mvn: '^3.x',
nginx: '^6.x',
nginx: {
semver: '^6.x',
optional: true
},
httpd: {
semver: '^2.x',
flag: '-v'
Expand Down

0 comments on commit 2f21db3

Please sign in to comment.