-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathlist.ts
55 lines (45 loc) · 1.49 KB
/
list.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import chalk from 'chalk';
import { PluginManager } from 'live-plugin-manager';
import { CodeshiftConfig } from '@codeshift/types';
export default async function list(packages: string[]) {
const packageManager = new PluginManager();
for (const packageName of packages) {
const pkgSplit = packageName.split('@').filter(str => !!str);
const name = pkgSplit[0].replace('/', '__');
const codemodName = `@codeshift/mod-${name}`;
try {
await packageManager.install(codemodName);
} catch {
console.warn(
chalk.red(
`Unable to find codeshift package: ${chalk.bold(packageName)}.`,
),
);
continue;
}
await packageManager.install(codemodName);
const pkg = packageManager.require(codemodName);
const config: CodeshiftConfig = pkg.default || pkg;
console.log(chalk.bold(packageName));
if (config.transforms) {
console.log(`├─ transforms`);
Object.keys(config.transforms).forEach((transform, index, array) => {
if (index + 1 === array.length) {
console.log(`| └─ ${transform}`);
return;
}
console.log(`| ├─ ${transform}`);
});
}
if (config.presets) {
console.log(`└─ presets`);
Object.keys(config.presets).forEach((transform, index, array) => {
if (index + 1 === array.length) {
console.log(` └─ ${transform}`);
return;
}
console.log(`| ├─ ${transform}`);
});
}
}
}