UNPKG

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