From 4c97088e1e1a8e5ef21bd74d99bb2780eb7ca4ca Mon Sep 17 00:00:00 2001 From: soupette Date: Tue, 19 Jun 2018 11:33:25 +0200 Subject: [PATCH] Run eslint only on modified files --- scripts/lint.js | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/scripts/lint.js b/scripts/lint.js index f3a782a4f0..7170dac323 100644 --- a/scripts/lint.js +++ b/scripts/lint.js @@ -2,6 +2,11 @@ const path = require('path'); const shell = require('shelljs'); const chalk = require('chalk'); const eslintErrorsFormatter = require('./eslintErrorsFormatter'); +const glob = require('glob'); +const fs = require('fs'); +const listChangedFiles = require('../packages/strapi-lint/lib/internals/shared/listChangedFiles.js'); +const changedFiles = listChangedFiles(); +const { take } = require('lodash'); const frontCmd = 'node ../../node_modules/strapi-lint/node_modules/.bin/eslint --ignore-path .gitignore --ignore-pattern \'/admin/build/\' --config ../../node_modules/strapi-lint/lib/internals/eslint/front/.eslintrc.json admin'; @@ -13,7 +18,7 @@ const backCmd = const watcher = (label, pckgName, type = 'front') => { shell.echo(label); - shell.cd(`packages/${pckgName}`); + shell.cd(pckgName); const cmd = pckgName === 'strapi-helper-plugin' ? helperCmd : `${frontCmd} && ${backCmd}`; const data = shell.exec(cmd, { silent: true }); shell.echo(chalk(eslintErrorsFormatter(data.stdout))); @@ -25,9 +30,27 @@ const watcher = (label, pckgName, type = 'front') => { shell.echo(''); }; -const packagesPath = path.resolve(process.env.PWD, 'packages'); -shell.ls('* -d', packagesPath) - .filter(package => package !== 'README.md' && package !== 'strapi-middleware-views' && package !== 'strapi-lint' && package !== 'strapi-plugin-settings-manager') +const files = glob + .sync('**/*.js', { ignore: '**/node_modules/**' }) + .filter(f => changedFiles.has(f)) + .filter( + package => + !package.includes('README.md') && + !package.includes('strapi-middleware-views') && + !package.includes('strapi-lint') && + !package.includes('strapi-plugin-settings-manager') && + !package.includes('scripts') && + !package.includes('test') + ) + .map(file => { + const directoryArray = file.split('/'); + const toTake = directoryArray.length === 2 ? 1 : 2; + + return take(directoryArray, toTake).join('/'); + }); + +files + .filter((directory, index) => files.indexOf(directory) === index) .forEach(package => { watcher(`Testing ${package}`, package); });