mirror of
https://github.com/strapi/strapi.git
synced 2025-08-08 08:46:42 +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 shell = require('shelljs');
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
const eslintErrorsFormatter = require('./eslintErrorsFormatter');
|
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 =
|
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';
|
'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') => {
|
const watcher = (label, pckgName, type = 'front') => {
|
||||||
shell.echo(label);
|
shell.echo(label);
|
||||||
shell.cd(`packages/${pckgName}`);
|
shell.cd(pckgName);
|
||||||
const cmd = pckgName === 'strapi-helper-plugin' ? helperCmd : `${frontCmd} && ${backCmd}`;
|
const cmd = pckgName === 'strapi-helper-plugin' ? helperCmd : `${frontCmd} && ${backCmd}`;
|
||||||
const data = shell.exec(cmd, { silent: true });
|
const data = shell.exec(cmd, { silent: true });
|
||||||
shell.echo(chalk(eslintErrorsFormatter(data.stdout)));
|
shell.echo(chalk(eslintErrorsFormatter(data.stdout)));
|
||||||
@ -25,9 +30,27 @@ const watcher = (label, pckgName, type = 'front') => {
|
|||||||
shell.echo('');
|
shell.echo('');
|
||||||
};
|
};
|
||||||
|
|
||||||
const packagesPath = path.resolve(process.env.PWD, 'packages');
|
const files = glob
|
||||||
shell.ls('* -d', packagesPath)
|
.sync('**/*.js', { ignore: '**/node_modules/**' })
|
||||||
.filter(package => package !== 'README.md' && package !== 'strapi-middleware-views' && package !== 'strapi-lint' && package !== 'strapi-plugin-settings-manager')
|
.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 => {
|
.forEach(package => {
|
||||||
watcher(`Testing ${package}`, package);
|
watcher(`Testing ${package}`, package);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user