Skip to content

Commit

Permalink
ci: add sync-docs to sync nextui docs (#66)
Browse files Browse the repository at this point in the history
* feat: all up to data do not show select

* feat: init cache

* feat: add fetch version log

* feat: add cache use in getLatestVersion

* feat: add cache script

* fix: issues

* fix: ci

* feat: optimize exec speed and exec loading state

* fix: add main pkg when upgrade (#62)

* feat: add sort disabled pkg when select compoents (#63)

* feat: add sort disabled pkg when select compoents

* feat: optimize display

* feat(doctor): add peerDependencies check and less color (#64)

* feat: optimize log and less color

* feat(doctor): add peerDependencies check

* docs: update README (#65)

* feat: optimize log and less color

* feat(doctor): add peerDependencies check

* docs: update README

* docs: update README.md

* ci: sync docs

* docs: test

* ci: test

* ci: update

* ci: update

* ci: update

* ci: update

* ci: update

* ci: update

* ci: update

* ci: update

* ci: update

* feat: add api-references update

* ci: init sync

* docs: update

* ci: update repo name

* ci: test

* ci: test

* ci: update

* fix: issues

* fix: init cache error
  • Loading branch information
winchesHe committed Jun 14, 2024
1 parent 93e5cdc commit 0dadabe
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 7 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: sync docs

on:
push:
branches:
- main
paths:
- README.md

jobs:
sync-docs:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- uses: actions/setup-node@v3
with:
check-latest: true
node-version-file: '.nvmrc'

- name: Setup pnpm
uses: pnpm/action-setup@v2

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Set up Git
run: |
git config --global user.name 'GitHub Action'
git config --global user.email 'action@github.com'
- name: Clone nextui repository
run: |
git clone https://github.com/nextui-org/nextui nextui --depth 1
- name: Run docs sync script
run: |
pnpm sync:docs
- name: Get version from package.json
id: get_version
run: |
VERSION=$(jq -r '.version' package.json)
echo "::set-output name=version::$VERSION"
- name: Commit changes to nextui repository
run: |
cd nextui
git add .
git commit -m "docs: sync api from nextui-cli v${{ steps.get_version.outputs.version }}"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.PAT }}
path: nextui
branch: sync-docs-${{ steps.get_version.outputs.version }}
title: "docs: sync api from nextui-cli v${{ steps.get_version.outputs.version }}"
body: Sync api from nextui-cli.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ NextUI CLI v0.2.1
◇ Template created successfully!
◇ Next steps ───────────────────
cd next-app-template
│ npm install
├────────────────────────────────
◇ Next steps ───────╮
│ │
cd my-nextui-app
│ npm install │
│ │
├────────────────────╯
└ 🚀 Get started with npm run dev
```
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"link:remove": "pnpm uninstall --global nextui-cli",
"build": "tsup",
"update:components": "tsx src/scripts/update/update-components.ts",
"sync:docs": "tsx src/scripts/sync/sync.ts",
"clean:cache": "tsx src/scripts/cache/clean.ts",
"lint": "eslint . --max-warnings=0",
"lint:fix": "eslint . -max-warnings=0 --fix",
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/cache/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface CacheData {
};
}

export function initCache(_noCache?: boolean) {
export function initCache(_noCache = noCache) {
noCache = !!_noCache;

const isExistCache = existsSync(CACHE_DIR);
Expand Down
36 changes: 36 additions & 0 deletions src/scripts/sync/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {readFileSync, writeFileSync} from 'node:fs';

import {resolver} from 'src/constants/path';

export function syncDocs() {
const docs = readFileSync(resolver('README.md'), 'utf-8');
const matchDocs = docs.match(/(?<=Usage: nextui \[command]\n\n)[\W\w]+(?=## Documentation)/)?.[0];

const targetPath = resolver('nextui/apps/docs/content/docs/api-references/cli-api.mdx');
const targetDocs = readFileSync(targetPath, 'utf-8');
const replaceTargetDocs = targetDocs.replace(/(?<=Usage: nextui \[command])[\W\w]+/, '');
let writeDocs = `${replaceTargetDocs}\n\n${matchDocs?.replace(/\n$/, '')}`;

writeDocs = writeDocs.replaceAll(/```bash/g, '```codeBlock bash');

writeFileSync(targetPath, writeDocs, 'utf-8');

syncApiRoutes();
}

function syncApiRoutes() {
const targetPath = resolver('nextui/apps/docs/config/routes.json');
const targetDocs = JSON.parse(readFileSync(targetPath, 'utf-8'));

targetDocs.routes.forEach((route) => {
if (route.key === 'api-references') {
route.routes.forEach((apiRoute) => {
if (apiRoute.key === 'cli-api') {
apiRoute.updated = true;
}
});
}
});

writeFileSync(targetPath, JSON.stringify(targetDocs, null, 2), 'utf-8');
}
3 changes: 3 additions & 0 deletions src/scripts/sync/sync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {syncDocs} from '.';

syncDocs();

0 comments on commit 0dadabe

Please sign in to comment.