strapi/scripts/lint.js

77 lines
1.9 KiB
JavaScript
Raw Normal View History

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
const cmdEslint = template(
2019-03-20 18:39:55 +01:00
'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
2019-04-23 15:18:57 +02: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);
2019-04-23 15:18:57 +02:00
const cmd = pckgName.includes('strapi-helper-plugin')
? cmdHelper
: `${cmdFront} && ${cmdBack}`;
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 = [
2019-04-23 15:18:57 +02:00
'babel.config.js',
2018-10-17 18:16:59 +02:00
'docs',
2018-09-12 17:54:42 -05:00
'jest.config.js',
2019-03-06 09:54:29 +01:00
'jest.config.front.js',
'fileTransformer.js',
2019-03-06 19:19:33 +01:00
'jest.config.e2e.js',
2018-09-12 17:54:42 -05:00
'scripts',
'strapi-lint',
'strapi-middleware-views',
'strapi-plugin-settings-manager',
'test',
'cypress',
2018-09-12 17:54:42 -05:00
];
const changedDirs = [...changedFiles]
2019-04-23 15:18:57 +02:00
.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('/');
});
2019-03-20 18:39:55 +01:00
[...new Set(changedDirs)].forEach(directory => {
watcher(`Testing ${directory}`, directory);
});