mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Backports the following commits to 7.x: - [ts] add script to verify that all ts is in a project (#32727)
This commit is contained in:
parent
5a89f2106b
commit
5098c3331c
7 changed files with 136 additions and 5 deletions
21
scripts/check_ts_projects.js
Normal file
21
scripts/check_ts_projects.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
require('../src/setup_node_env');
|
||||
require('../src/dev/typescript/run_check_ts_projects_cli').runCheckTsProjectsCli();
|
|
@ -21,6 +21,8 @@ import { relative } from 'path';
|
|||
|
||||
import getopts from 'getopts';
|
||||
|
||||
import { Options } from './run';
|
||||
|
||||
export interface Flags {
|
||||
verbose: boolean;
|
||||
quiet: boolean;
|
||||
|
@ -57,11 +59,11 @@ export function getFlags(argv: string[]): Flags {
|
|||
};
|
||||
}
|
||||
|
||||
export function getHelp() {
|
||||
export function getHelp(options: Options) {
|
||||
return `
|
||||
node ${relative(process.cwd(), process.argv[1])}
|
||||
|
||||
Runs a dev task
|
||||
${options.helpDescription || 'Runs a dev task'}
|
||||
|
||||
Options:
|
||||
--verbose, -v Log verbosely
|
||||
|
|
|
@ -21,11 +21,17 @@ import { pickLevelFromFlags, ToolingLog } from '@kbn/dev-utils';
|
|||
import { isFailError } from './fail';
|
||||
import { Flags, getFlags, getHelp } from './flags';
|
||||
|
||||
export async function run(body: (args: { log: ToolingLog; flags: Flags }) => Promise<void> | void) {
|
||||
type RunFn = (args: { log: ToolingLog; flags: Flags }) => Promise<void> | void;
|
||||
|
||||
export interface Options {
|
||||
helpDescription?: string;
|
||||
}
|
||||
|
||||
export async function run(fn: RunFn, options: Options = {}) {
|
||||
const flags = getFlags(process.argv.slice(2));
|
||||
|
||||
if (flags.help) {
|
||||
process.stderr.write(getHelp());
|
||||
process.stderr.write(getHelp(options));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
@ -35,7 +41,7 @@ export async function run(body: (args: { log: ToolingLog; flags: Flags }) => Pro
|
|||
});
|
||||
|
||||
try {
|
||||
await body({ log, flags });
|
||||
await fn({ log, flags });
|
||||
} catch (error) {
|
||||
if (isFailError(error)) {
|
||||
log.error(error.message);
|
||||
|
|
91
src/dev/typescript/run_check_ts_projects_cli.ts
Normal file
91
src/dev/typescript/run_check_ts_projects_cli.ts
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { resolve } from 'path';
|
||||
|
||||
import execa from 'execa';
|
||||
|
||||
import { run } from '../run';
|
||||
|
||||
const REPO_ROOT = resolve(__dirname, '../../../');
|
||||
import { File } from '../file';
|
||||
import { PROJECTS } from './projects';
|
||||
|
||||
export async function runCheckTsProjectsCli() {
|
||||
run(
|
||||
async ({ log }) => {
|
||||
const files = await execa.stdout('git', ['ls-tree', '--name-only', '-r', 'HEAD'], {
|
||||
cwd: REPO_ROOT,
|
||||
});
|
||||
|
||||
const isNotInTsProject: File[] = [];
|
||||
const isInMultipleTsProjects: File[] = [];
|
||||
|
||||
for (const lineRaw of files.split('\n')) {
|
||||
const line = lineRaw.trim();
|
||||
|
||||
if (!line) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const file = new File(resolve(REPO_ROOT, line));
|
||||
if (!file.isTypescript() || file.isFixture()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
log.verbose('Checking %s', file.getAbsolutePath());
|
||||
|
||||
const projects = PROJECTS.filter(p => p.isAbsolutePathSelected(file.getAbsolutePath()));
|
||||
if (projects.length === 0) {
|
||||
isNotInTsProject.push(file);
|
||||
}
|
||||
if (projects.length > 1) {
|
||||
isInMultipleTsProjects.push(file);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isNotInTsProject.length && !isInMultipleTsProjects.length) {
|
||||
log.success('All ts files belong to a single ts project');
|
||||
return;
|
||||
}
|
||||
|
||||
if (isNotInTsProject.length) {
|
||||
log.error(
|
||||
`The following files do not belong to a tsconfig.json file, or that tsconfig.json file is not listed in src/dev/typescript/projects.ts\n${isNotInTsProject
|
||||
.map(file => ` - ${file.getRelativePath()}`)
|
||||
.join('\n')}`
|
||||
);
|
||||
}
|
||||
|
||||
if (isInMultipleTsProjects.length) {
|
||||
log.error(
|
||||
`The following files belong to multiple tsconfig.json files listed in src/dev/typescript/projects.ts\n${isInMultipleTsProjects
|
||||
.map(file => ` - ${file.getRelativePath()}`)
|
||||
.join('\n')}`
|
||||
);
|
||||
}
|
||||
|
||||
process.exit(1);
|
||||
},
|
||||
{
|
||||
helpDescription:
|
||||
'Check that all .ts and .tsx files in the repository are assigned to a tsconfig.json file',
|
||||
}
|
||||
);
|
||||
}
|
|
@ -109,6 +109,15 @@ module.exports = function (grunt) {
|
|||
]
|
||||
},
|
||||
|
||||
// used by the test and jenkins:unit tasks
|
||||
// ensures that all typescript files belong to a typescript project
|
||||
checkTsProjects: {
|
||||
cmd: process.execPath,
|
||||
args: [
|
||||
require.resolve('../../scripts/check_ts_projects')
|
||||
]
|
||||
},
|
||||
|
||||
// used by the test and jenkins:unit tasks
|
||||
// runs the i18n_check script to check i18n engine usage
|
||||
i18nCheck: {
|
||||
|
|
|
@ -26,6 +26,7 @@ module.exports = function (grunt) {
|
|||
'run:eslint',
|
||||
'run:tslint',
|
||||
'run:sasslint',
|
||||
'run:checkTsProjects',
|
||||
'run:typeCheck',
|
||||
'run:i18nCheck',
|
||||
'run:checkFileCasing',
|
||||
|
|
|
@ -72,6 +72,7 @@ module.exports = function (grunt) {
|
|||
!grunt.option('quick') && 'run:eslint',
|
||||
!grunt.option('quick') && 'run:tslint',
|
||||
!grunt.option('quick') && 'run:sasslint',
|
||||
!grunt.option('quick') && 'run:checkTsProjects',
|
||||
!grunt.option('quick') && 'run:typeCheck',
|
||||
!grunt.option('quick') && 'run:i18nCheck',
|
||||
'run:checkFileCasing',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue