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();
|
|
|
|
const { take } = require('lodash');
|
2018-05-04 15:38:42 +02:00
|
|
|
|
|
|
|
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';
|
2018-05-04 18:02:35 +02:00
|
|
|
const helperCmd =
|
|
|
|
'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 lib/src';
|
2018-05-04 15:38:42 +02:00
|
|
|
const backCmd =
|
2018-05-04 17:02:27 +02:00
|
|
|
'node ../../node_modules/strapi-lint/node_modules/.bin/eslint --ignore-path .gitignore --ignore-pattern \'/admin\' --config ../../node_modules/strapi-lint/lib/internals/eslint/back/.eslintrc.json 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-05-04 18:02:35 +02:00
|
|
|
const cmd = pckgName === 'strapi-helper-plugin' ? helperCmd : `${frontCmd} && ${backCmd}`;
|
|
|
|
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(
|
|
|
|
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)
|
2018-05-04 17:02:27 +02:00
|
|
|
.forEach(package => {
|
|
|
|
watcher(`Testing ${package}`, package);
|
|
|
|
});
|