Skip to content

Commit

Permalink
add a script to find ready to migrate to ts project refs plugins (#82305
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mshustov authored Nov 3, 2020
1 parent e94db63 commit 1de0296
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
21 changes: 21 additions & 0 deletions scripts/find_plugins_ready_to_migrate_to_ts_refs.js
Original file line number Diff line number Diff line change
@@ -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/run_find_plugins_ready_migrate_to_ts_refs');
89 changes: 89 additions & 0 deletions src/dev/run_find_plugins_ready_migrate_to_ts_refs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* 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 Path from 'path';
import Fs from 'fs';
import { get } from 'lodash';
import { run, KibanaPlatformPlugin } from '@kbn/dev-utils';
import { getPluginDeps, findPlugins } from './plugin_discovery';

interface AllOptions {
id?: string;
examples?: boolean;
extraPluginScanDirs?: string[];
}

run(
async ({ flags, log }) => {
const { examples = false, extraPluginScanDirs = [] } = flags as AllOptions;

const pluginMap = findPlugins({
oss: false,
examples,
extraPluginScanDirs,
});

const readyToMigrate = new Set<KibanaPlatformPlugin>();
for (const pluginId of pluginMap.keys()) {
const { deps, errors } = getPluginDeps({
pluginMap,
id: pluginId,
});

if (deps.size === 0 && errors.size === 0) {
readyToMigrate.add(pluginMap.get(pluginId)!);
}
}

const notMigratedPlugins = [...readyToMigrate].filter(
(plugin) => !isMigratedToTsProjectRefs(plugin.directory)
);
if (notMigratedPlugins.length > 0) {
log.info(
`Dependencies ready to migrate to TS project refs:\n${notMigratedPlugins
.map((p) => p.manifest.id)
.join('\n')}`
);
}
},
{
flags: {
boolean: ['examples'],
string: ['id'],
default: {
examples: false,
},
allowUnexpected: false,
help: `
--examples Include examples folder
--extraPluginScanDirs Include extra scan folder
`,
},
}
);

function isMigratedToTsProjectRefs(dir: string): boolean {
try {
const path = Path.join(dir, 'tsconfig.json');
const content = Fs.readFileSync(path, { encoding: 'utf8' });
return get(JSON.parse(content), 'compilerOptions.composite', false);
} catch (e) {
return false;
}
}

0 comments on commit 1de0296

Please sign in to comment.