UNPKG

817 BJavaScriptView Raw
1#!/usr/bin/env node
2
3const program = require('commander'),
4 sh = require('shelljs'),
5 rules = require('./lib/audit/rules'),
6 version = require('./package.json').version;
7
8program.version(version);
9
10const checkPath = ({ find, directory, message }) => {
11 const dirGlob = `{marketplace_builder,modules/**}/${directory}`;
12
13 const matches = sh
14 .grep('-l', find, dirGlob)
15 .stdout.split('\n') // convert stdout to array of paths
16 .filter(path => path) // filter out empty elements
17 .map(path => path.replace('/./', '/')); // shorten path a little bit
18
19 if (matches.length === 0) {
20 return;
21 }
22 message(matches);
23 console.log('\n');
24};
25
26const Audit = {
27 run: () => rules.map(checkPath),
28 runSingle: filePath => rules.map(options => checkPath({ ...options, directory: filePath }))
29};
30
31Audit.run();