|
| 1 | +import fs from 'fs-extra'; |
| 2 | + |
| 3 | +const COMMUNITY_PATH = `${__dirname}/../community`; |
| 4 | +const DOCS_PATH = `${__dirname}/../website/docs/explore`; |
| 5 | + |
| 6 | +function cleanTargetDir(path: string) { |
| 7 | + if (fs.existsSync(path)) fs.emptyDirSync(path); |
| 8 | +} |
| 9 | + |
| 10 | +interface Config { |
| 11 | + maintainers: string[]; |
| 12 | + transforms: { |
| 13 | + [key: string]: any; |
| 14 | + }; |
| 15 | +} |
| 16 | + |
| 17 | +interface DocsData { |
| 18 | + name: string; |
| 19 | + config: Config; |
| 20 | +} |
| 21 | + |
| 22 | +function main() { |
| 23 | + const communityCodemods = fs.readdirSync(COMMUNITY_PATH); |
| 24 | + const data: DocsData[] = []; |
| 25 | + |
| 26 | + communityCodemods.forEach(dir => { |
| 27 | + // eslint-disable-next-line @typescript-eslint/no-var-requires |
| 28 | + const config = require(`${COMMUNITY_PATH}/${dir}/codeshift.config.js`) |
| 29 | + .default; |
| 30 | + |
| 31 | + data.push({ |
| 32 | + name: dir, |
| 33 | + config, |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + cleanTargetDir(DOCS_PATH); |
| 38 | + |
| 39 | + data.forEach(({ name, config }) => { |
| 40 | + const safeName = name.replace('@', ''); |
| 41 | + const rawName = name.replace('__', '/'); |
| 42 | + const urlSafeName = encodeURIComponent(name); |
| 43 | + const packageLink = `[${rawName}](https://www.npmjs.com/package/${rawName})`; |
| 44 | + |
| 45 | + fs.outputFileSync( |
| 46 | + `${DOCS_PATH}/${name}.mdx`, |
| 47 | + `--- |
| 48 | +id: ${safeName} |
| 49 | +title: ${safeName.replace('__', '/')} |
| 50 | +slug: /${safeName} |
| 51 | +--- |
| 52 | +
|
| 53 | +**Target package:** ${packageLink} |
| 54 | +
|
| 55 | +**Maintainers:** |
| 56 | +${config.maintainers.map( |
| 57 | + maintainer => `- [${maintainer}](https://github.com/${maintainer})`, |
| 58 | +)} |
| 59 | +
|
| 60 | +${Object.keys(config.transforms) |
| 61 | + .map( |
| 62 | + key => `## ${key} |
| 63 | +
|
| 64 | +[Source](https://github.com/CodeshiftCommunity/CodeshiftCommunity/tree/main/community/${urlSafeName}) | [Report an issue](https://github.com/CodeshiftCommunity/CodeshiftCommunity/issues/new?title=${safeName}@${key}) |
| 65 | +
|
| 66 | +Migrates ${packageLink} to version ${key}. |
| 67 | +
|
| 68 | +### Usage |
| 69 | +
|
| 70 | +
|
| 71 | +\`\`\` |
| 72 | +npx @codeshift/cli --packages ${name}@${key} path/to/source |
| 73 | +\`\`\` |
| 74 | +`, |
| 75 | + ) |
| 76 | + .join('')} |
| 77 | +`, |
| 78 | + ); |
| 79 | + }); |
| 80 | +} |
| 81 | + |
| 82 | +main(); |
0 commit comments