Skip to content

Commit 1e9a685

Browse files
Merge pull request #21 from CodeshiftCommunity/generate-docs
📚 Auto generate explore tab on website
2 parents b31318c + f9a204b commit 1e9a685

File tree

10 files changed

+1127
-2360
lines changed

10 files changed

+1127
-2360
lines changed

.github/workflows/documentation.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ jobs:
1515
- uses: actions/setup-node@v1
1616
with:
1717
node-version: '14.x'
18+
- name: Generate docs
19+
run: |
20+
yarn install --frozen-lockfile
21+
yarn predocs:start
1822
- name: Test Build
1923
run: |
2024
cd website
@@ -31,6 +35,10 @@ jobs:
3135
- uses: webfactory/ssh-agent@v0.5.0
3236
with:
3337
ssh-private-key: ${{ secrets.GH_PAGES_DEPLOY }}
38+
- name: Generate docs
39+
run: |
40+
yarn install --frozen-lockfile
41+
yarn predocs:start
3442
- name: Release to GitHub Pages
3543
env:
3644
USE_SSH: true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Repo
22
.tmp/
33
plugin_packages/
4+
website/docs/explore/*
45

56
# Logs
67
logs

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
14.16.0

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"license": "MIT",
88
"private": true,
99
"scripts": {
10+
"predocs:start": "ts-node scripts/docs",
1011
"docs:start": "cd website && yarn start",
1112
"postinstall": "preconstruct dev && yarn monorepo:check",
1213
"build": "yarn clean && preconstruct build",

scripts/docs.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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();

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
"@codeshift/*": ["../packages/*/src"]
2525
}
2626
},
27-
"include": ["packages/**/*", "community/**/*", ".tmp/**/*"],
27+
"include": ["packages/**/*", "community/**/*", ".tmp/**/*", "scripts"],
2828
"exclude": ["node_modules", "dist", "__tests__", "**/*.test*", "**/*.spec*"]
2929
}

website/docusaurus.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ module.exports = {
2929
label: 'API',
3030
position: 'left',
3131
},
32+
{
33+
type: 'doc',
34+
docId: 'explore/atlaskit__avatar',
35+
label: 'Explore',
36+
position: 'left',
37+
},
3238
{
3339
href: 'https://github.com/CodeshiftCommunity/CodeshiftCommunity',
3440
label: 'GitHub',

website/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"write-heading-ids": "docusaurus write-heading-ids"
1515
},
1616
"dependencies": {
17-
"@docusaurus/core": "2.0.0-alpha.72",
18-
"@docusaurus/preset-classic": "2.0.0-alpha.72",
17+
"@docusaurus/core": "2.0.0-beta.0",
18+
"@docusaurus/preset-classic": "2.0.0-beta.0",
1919
"@mdx-js/react": "^1.6.21",
2020
"clsx": "^1.1.1",
2121
"react": "^17.0.1",
@@ -33,4 +33,4 @@
3333
"last 1 safari version"
3434
]
3535
}
36-
}
36+
}

website/sidebars.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,10 @@ module.exports = {
4444
items: ['api/cli', 'api/utils', 'api/test-utils'],
4545
},
4646
],
47+
explore: [
48+
{
49+
dirName: 'explore',
50+
type: 'autogenerated',
51+
},
52+
],
4753
};

0 commit comments

Comments
 (0)