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 glob = require('glob');
|
|
|
|
const fs = require('fs');
|
|
|
|
const listChangedFiles = require('../packages/strapi-lint/lib/internals/shared/listChangedFiles.js');
|
|
|
|
const changedFiles = listChangedFiles();
|
2018-09-12 16:28:52 -05:00
|
|
|
const { includes, take, template } = require('lodash');
|
2018-05-04 15:38:42 +02:00
|
|
|
|
2018-09-12 16:28:52 -05:00
|
|
|
const cmdEslint = template(
|
|
|
|
"node ../../node_modules/strapi-lint/node_modules/.bin/eslint --ignore-path .gitignore --ignore-pattern '${ignore}'"
|
|
|
|
+ ' --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
|
|
|
|
|
|
|
const watcher = (label, pckgName, type = 'front') => {
|
|
|
|
shell.echo(label);
|
2018-06-19 11:33:25 +02:00
|
|
|
shell.cd(pckgName);
|
2018-09-12 16:28:52 -05:00
|
|
|
const cmd = includes(pckgName, '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-06-19 11:33:25 +02:00
|
|
|
const files = glob
|
|
|
|
.sync('**/*.js', { ignore: '**/node_modules/**' })
|
|
|
|
.filter(f => changedFiles.has(f))
|
|
|
|
.filter(
|
2018-06-29 15:40:55 +02:00
|
|
|
package =>
|
2018-06-19 11:33:25 +02:00
|
|
|
!package.includes('README.md') &&
|
|
|
|
!package.includes('strapi-middleware-views') &&
|
|
|
|
!package.includes('strapi-lint') &&
|
|
|
|
!package.includes('strapi-plugin-settings-manager') &&
|
|
|
|
!package.includes('scripts') &&
|
2018-06-29 15:40:55 +02:00
|
|
|
!package.includes('test') &&
|
|
|
|
!package.includes('jest.config.js')
|
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-06-21 15:28:49 +02:00
|
|
|
|
2018-06-19 11:33:25 +02:00
|
|
|
files
|
|
|
|
.filter((directory, index) => files.indexOf(directory) === index)
|
2018-05-04 17:02:27 +02:00
|
|
|
.forEach(package => {
|
|
|
|
watcher(`Testing ${package}`, package);
|
2018-09-12 16:28:52 -05:00
|
|
|
});
|