|
@@ -5,6 +5,8 @@ import get from 'lodash/get';
|
|
|
// @ts-ignore
|
|
// @ts-ignore
|
|
|
import flatten from 'lodash/flatten';
|
|
import flatten from 'lodash/flatten';
|
|
|
import execa = require('execa');
|
|
import execa = require('execa');
|
|
|
|
|
+import { nodeVersionCheckerTask, nodeVersionFiles } from './nodeVersionChecker';
|
|
|
|
|
+import { execTask } from '../utils/execTask';
|
|
|
const simpleGit = require('simple-git/promise')(process.cwd());
|
|
const simpleGit = require('simple-git/promise')(process.cwd());
|
|
|
|
|
|
|
|
interface PrecommitOptions {}
|
|
interface PrecommitOptions {}
|
|
@@ -27,27 +29,37 @@ const tasks = {
|
|
|
},
|
|
},
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+interface GitStatus {
|
|
|
|
|
+ files: GitFile[];
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+interface GitFile {
|
|
|
|
|
+ path: string;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
const precommitRunner: TaskRunner<PrecommitOptions> = async () => {
|
|
const precommitRunner: TaskRunner<PrecommitOptions> = async () => {
|
|
|
- const status = await simpleGit.status();
|
|
|
|
|
|
|
+ const status: GitStatus = await simpleGit.status();
|
|
|
const sassFiles = status.files.filter(
|
|
const sassFiles = status.files.filter(
|
|
|
- (file: any) =>
|
|
|
|
|
- (file.path as string).match(/^[a-zA-Z0-9\_\-\/]+(\.scss)$/g) || file.path.indexOf('.sass-lint.yml') > -1
|
|
|
|
|
|
|
+ file => file.path.match(/^[a-zA-Z0-9\_\-\/]+(\.scss)$/g) || file.path.indexOf('.sass-lint.yml') > -1
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- const tsFiles = status.files.filter((file: any) => (file.path as string).match(/^[a-zA-Z0-9\_\-\/]+(\.(ts|tsx))$/g));
|
|
|
|
|
- const testFiles = status.files.filter((file: any) =>
|
|
|
|
|
- (file.path as string).match(/^[a-zA-Z0-9\_\-\/]+(\.test.(ts|tsx))$/g)
|
|
|
|
|
- );
|
|
|
|
|
- const goTestFiles = status.files.filter((file: any) =>
|
|
|
|
|
- (file.path as string).match(/^[a-zA-Z0-9\_\-\/]+(\_test.go)$/g)
|
|
|
|
|
- );
|
|
|
|
|
- const grafanaUiFiles = tsFiles.filter((file: any) => (file.path as string).indexOf('grafana-ui') > -1);
|
|
|
|
|
|
|
+ const tsFiles = status.files.filter(file => file.path.match(/^[a-zA-Z0-9\_\-\/]+(\.(ts|tsx))$/g));
|
|
|
|
|
+ const testFiles = status.files.filter(file => file.path.match(/^[a-zA-Z0-9\_\-\/]+(\.test.(ts|tsx))$/g));
|
|
|
|
|
+ const goTestFiles = status.files.filter(file => file.path.match(/^[a-zA-Z0-9\_\-\/]+(\_test.go)$/g));
|
|
|
|
|
+ const grafanaUiFiles = tsFiles.filter(file => file.path.indexOf('grafana-ui') > -1);
|
|
|
|
|
+ const affectedNodeVersionFiles = status.files
|
|
|
|
|
+ .filter(file => nodeVersionFiles.indexOf(file.path) !== -1)
|
|
|
|
|
+ .map(f => f.path);
|
|
|
|
|
|
|
|
const grafanaUIFilesChangedOnly = tsFiles.length > 0 && tsFiles.length - grafanaUiFiles.length === 0;
|
|
const grafanaUIFilesChangedOnly = tsFiles.length > 0 && tsFiles.length - grafanaUiFiles.length === 0;
|
|
|
const coreFilesChangedOnly = tsFiles.length > 0 && grafanaUiFiles.length === 0;
|
|
const coreFilesChangedOnly = tsFiles.length > 0 && grafanaUiFiles.length === 0;
|
|
|
|
|
|
|
|
const taskPaths = [];
|
|
const taskPaths = [];
|
|
|
|
|
|
|
|
|
|
+ if (affectedNodeVersionFiles.length > 0) {
|
|
|
|
|
+ await execTask(nodeVersionCheckerTask)({});
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (sassFiles.length > 0) {
|
|
if (sassFiles.length > 0) {
|
|
|
taskPaths.push('lint.sass');
|
|
taskPaths.push('lint.sass');
|
|
|
}
|
|
}
|