2018-05-04 15:38:42 +02:00
|
|
|
const path = require('path');
|
|
|
|
const shell = require('shelljs');
|
|
|
|
const chalk = require('chalk');
|
|
|
|
const eslintErrorsFormatter = require('./eslintErrorsFormatter');
|
2018-06-19 11:33:25 +02:00
|
|
|
const listChangedFiles = require('../packages/strapi-lint/lib/internals/shared/listChangedFiles.js');
|
|
|
|
const changedFiles = listChangedFiles();
|
2018-09-12 17:54:42 -05:00
|
|
|
const { take, template } = require('lodash');
|
2018-05-04 15:38:42 +02:00
|
|
|
|
2018-09-12 16:28:52 -05:00
|
|
|
const cmdEslint = template(
|
2018-09-12 17:54:42 -05:00
|
|
|
'node ../../node_modules/strapi-lint/node_modules/.bin/eslint --ignore-path .gitignore --ignore-pattern "${ignore}"'
|
2018-09-12 16:28:52 -05:00
|
|
|
+ ' --config ../../node_modules/strapi-lint/lib/internals/eslint/${conf}/.eslintrc.json ${params}'
|
|
|
|
);
|
2018-05-04 17:02:27 +02:00
|
|
|
|
2018-09-12 16:28:52 -05:00
|
|
|
const cmdFront = cmdEslint({ ignore: '/admin/build/', conf: 'front', params: 'admin' });
|
|
|
|
const cmdHelper = cmdEslint({ ignore: '/admin/build/', conf: 'front', params: 'lib/src' });
|
|
|
|
const cmdBack = cmdEslint({ ignore: '/admin', conf: 'back', params: 'controllers config services bin lib' });
|
2018-05-04 15:38:42 +02:00
|
|
|
|
2018-09-12 17:54:42 -05:00
|
|
|
const watcher = (label, pckgName) => {
|
2018-05-04 15:38:42 +02:00
|
|
|
shell.echo(label);
|
2018-06-19 11:33:25 +02:00
|
|
|
shell.cd(pckgName);
|
2018-09-12 17:54:42 -05:00
|
|
|
const cmd = pckgName.includes('strapi-helper-plugin') ? cmdHelper : `${cmdFront} && ${cmdBack}`;
|
2018-07-03 17:10:00 +02:00
|
|
|
|
2018-05-04 18:02:35 +02:00
|
|
|
const data = shell.exec(cmd, { silent: true });
|
2018-05-04 15:38:42 +02:00
|
|
|
shell.echo(chalk(eslintErrorsFormatter(data.stdout)));
|
|
|
|
shell.cd('../..');
|
|
|
|
|
|
|
|
if (data.code !== 0) {
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2018-05-04 18:27:39 +02:00
|
|
|
shell.echo('');
|
2018-05-04 15:38:42 +02:00
|
|
|
};
|
|
|
|
|
2018-09-12 17:54:42 -05:00
|
|
|
const except = [
|
|
|
|
'jest.config.js',
|
|
|
|
'scripts',
|
|
|
|
'strapi-lint',
|
|
|
|
'strapi-middleware-views',
|
|
|
|
'strapi-plugin-settings-manager',
|
|
|
|
'test',
|
|
|
|
];
|
|
|
|
|
|
|
|
const changedDirs = [...changedFiles]
|
|
|
|
.filter(file => path.extname(file) === '.js' && !except.some(path => file.includes(path)))
|
2018-06-19 11:33:25 +02:00
|
|
|
.map(file => {
|
|
|
|
const directoryArray = file.split('/');
|
|
|
|
const toTake = directoryArray.length === 2 ? 1 : 2;
|
|
|
|
|
|
|
|
return take(directoryArray, toTake).join('/');
|
|
|
|
});
|
|
|
|
|
2018-09-12 17:54:42 -05:00
|
|
|
[...new Set(changedDirs)]
|
|
|
|
.forEach(directory => {
|
|
|
|
watcher(`Testing ${directory}`, directory);
|
2018-09-12 16:28:52 -05:00
|
|
|
});
|