mirror of
https://github.com/strapi/strapi.git
synced 2025-08-08 00:37:38 +00:00
Merge pull request #1422 from strapi/improve-eslint
Run eslint only on modified files
This commit is contained in:
commit
a37e97bfef
@ -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);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user