1
0
Fork 0

feat: recursively load rules (fixes #135)

This commit is contained in:
ssube 2019-11-09 22:40:30 -06:00
parent c746f621af
commit 6f4b324cc8
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
4 changed files with 35 additions and 4 deletions

View File

@ -15,6 +15,9 @@
"isString",
"kebabCase"
],
"node_modules/minimatch/minimatch.js": [
"Minimatch"
],
"node_modules/noicejs/out/main-bundle.js": [
"BaseError",
"ConsoleLogger",

View File

@ -18,7 +18,7 @@
"yaml-lint",
"yaml-validation"
],
"main": "out/main.js",
"main": "out/index.js",
"bin": {
"salty-dog": "out/index.js"
},
@ -42,7 +42,9 @@
"@types/deep-diff": "1.0.0",
"@types/js-yaml": "3.12.1",
"@types/lodash": "4.14.146",
"@types/minimatch": "^3.0.3",
"@types/mocha": "5.2.7",
"@types/recursive-readdir": "^2.2.0",
"@types/sinon": "7.5.0",
"@types/sinon-chai": "3.2.3",
"@types/source-map-support": "0.5.0",
@ -65,9 +67,11 @@
"js-yaml": "3.13.1",
"jsonpath-plus": "1.1.0",
"lodash": "4.17.15",
"minimatch": "^3.0.4",
"mocha": "6.2.2",
"noicejs": "2.5.2",
"nyc": "14.1.1",
"recursive-readdir": "^2.2.2",
"rollup": "1.26.4",
"rollup-plugin-commonjs": "10.1.0",
"rollup-plugin-eslint": "7.0.0",

View File

@ -1,11 +1,13 @@
import { ValidateFunction } from 'ajv';
import { applyDiff, diff } from 'deep-diff';
import { cloneDeep, Dictionary, intersection, isNil } from 'lodash';
import { Minimatch } from 'minimatch';
import { LogLevel } from 'noicejs';
import { join } from 'path';
import recursive from 'recursive-readdir';
import { YamlParser } from '../parser/YamlParser';
import { readDir, readFile } from '../source';
import { readFile } from '../source';
import { ensureArray, hasItems } from '../utils';
import { VisitorResult } from '../visitor';
import { VisitorContext } from '../visitor/VisitorContext';
@ -119,13 +121,16 @@ export async function loadRuleFiles(paths: Array<string>, ctx: VisitorContext):
}
export async function loadRulePaths(paths: Array<string>, ctx: VisitorContext): Promise<Array<Rule>> {
const match = new Minimatch('*.+(json|yaml|yml)');
const rules = [];
for (const path of paths) {
const allFiles = await readDir(path);
const allFiles = await recursive(path);
ctx.logger.debug({ files: allFiles }, 'path matched files');
// skip files that start with `.`, limit to json and yaml/yml
const files = allFiles
.filter((name) => name.toLowerCase().match(/^[^\.].*\.(json|ya?ml)/))
.filter((name) => name[0] !== '.')
.filter((name) => match.match(name.toLowerCase()))
.map((name) => join(path, name));
const pathRules = await loadRuleFiles(files, ctx);

View File

@ -240,6 +240,11 @@
resolved "https://artifacts.apextoaster.com/repository/group-npm/@types/lodash/-/lodash-4.14.146.tgz#de0d2c8610012f12a6a796455054cbc654f8fecf"
integrity sha512-JzJcmQ/ikHSv7pbvrVNKJU5j9jL9VLf3/gqs048CEnBVVVEv4kve3vLxoPHGvclutS+Il4SBIuQQ087m1eHffw==
"@types/minimatch@^3.0.3":
version "3.0.3"
resolved "https://artifacts.apextoaster.com/repository/group-npm/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==
"@types/mocha@5.2.7":
version "5.2.7"
resolved "https://artifacts.apextoaster.com/repository/group-npm/@types/mocha/-/mocha-5.2.7.tgz#315d570ccb56c53452ff8638738df60726d5b6ea"
@ -255,6 +260,13 @@
resolved "https://artifacts.apextoaster.com/repository/group-npm/@types/node/-/node-8.10.54.tgz#1c88eb253ac1210f1a5876953fb70f7cc4928402"
integrity sha512-kaYyLYf6ICn6/isAyD4K1MyWWd5Q3JgH6bnMN089LUx88+s4W8GvK9Q6JMBVu5vsFFp7pMdSxdKmlBXwH/VFRg==
"@types/recursive-readdir@^2.2.0":
version "2.2.0"
resolved "https://artifacts.apextoaster.com/repository/group-npm/@types/recursive-readdir/-/recursive-readdir-2.2.0.tgz#b39cd5474fd58ea727fe434d5c68b7a20ba9121c"
integrity sha512-HGk753KRu2N4mWduovY4BLjYq4jTOL29gV2OfGdGxHcPSWGFkC5RRIdk+VTs5XmYd7MVAD+JwKrcb5+5Y7FOCg==
dependencies:
"@types/node" "*"
"@types/resolve@0.0.8":
version "0.0.8"
resolved "https://artifacts.apextoaster.com/repository/group-npm/@types/resolve/-/resolve-0.0.8.tgz#f26074d238e02659e323ce1a13d041eee280e194"
@ -2839,6 +2851,13 @@ readable-stream@~2.3.6:
string_decoder "~1.1.1"
util-deprecate "~1.0.1"
recursive-readdir@^2.2.2:
version "2.2.2"
resolved "https://artifacts.apextoaster.com/repository/group-npm/recursive-readdir/-/recursive-readdir-2.2.2.tgz#9946fb3274e1628de6e36b2f6714953b4845094f"
integrity sha512-nRCcW9Sj7NuZwa2XvH9co8NPeXUBhZP7CRKJtU+cS6PW9FpCIFoI5ib0NT1ZrbNuPoRy0ylyCaUL8Gih4LSyFg==
dependencies:
minimatch "3.0.4"
redent@^1.0.0:
version "1.0.0"
resolved "https://artifacts.apextoaster.com/repository/group-npm/redent/-/redent-1.0.0.tgz#cf916ab1fd5f1f16dfb20822dd6ec7f730c2afde"