UNPKG

@interaktiv/dia-scripts

Version:

CLI toolbox with common scripts for most sort of projects at DIA

50 lines (39 loc) 1.52 kB
"use strict"; const path = require('path'); const exit = require('exit'); const spawn = require('cross-spawn'); const yargsParser = require('yargs-parser'); const { fromRoot, isJsFile, parseEnv, resolveBin, removeValueFromArray } = require('../../utils'); const SRC_DIR = fromRoot('force-app/main/default/aura'); let rawArgv = process.argv.slice(2); const argv = yargsParser(rawArgv); const preCommit = parseEnv('SCRIPTS_PRE-COMMIT', false); if (preCommit) lintAuraOnPreCommit();else lintAuraFiles(); function lintAuraOnPreCommit() { const files = argv._.filter(a => /force-app\/main\/default\/aura/.test(a) && isJsFile(a)); if (files.length > 0) { rawArgv = rawArgv.filter(a => files.includes(a) === false); rawArgv = rawArgv.filter(a => argv._.includes(a) === false); lintAuraFiles(files.map(f => path.basename(f))); } else exit(0); } function lintAuraFiles(files = []) { const ignore = rawArgv.includes('--ignore') ? [] : ['--ignore', ['**/__tests__/**', '**/fixtures/**', '**/__snapshots__/**', '**/__mocks__/**'].join(',')]; let exitArg = ['--exit']; if (rawArgv.includes('--no-exit')) { rawArgv = removeValueFromArray(rawArgv, '--no-exit'); exitArg = []; } const filesGiven = files.length > 0; const filesToApply = filesGiven ? ['--files', files.join(',')] : []; const result = spawn.sync(resolveBin('sfdx'), ['force:lightning:lint', ...exitArg, ...ignore, ...rawArgv, ...[SRC_DIR], ...filesToApply], { stdio: 'inherit' }); exit(result.status); }