Skip to content

Commit

Permalink
refactor: 文档网站改造
Browse files Browse the repository at this point in the history
  • Loading branch information
mmdapl committed Jul 22, 2024
1 parent e01466b commit d8c1652
Show file tree
Hide file tree
Showing 21 changed files with 133 additions and 77 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# 构建 VitePress 站点并将其部署到 GitHub Pages 的示例工作流程
#
name: Deploy VitePress Site To Pages

on:
push:
branches: [ next ]

# 允许你从 Actions 选项卡手动运行此工作流程
workflow_dispatch:

# 设置 GITHUB_TOKEN 的权限,以允许部署到 GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# 只允许同时进行一次部署,跳过正在运行和最新队列之间的运行队列
# 但是,不要取消正在进行的运行,因为我们希望允许这些生产部署完成
concurrency:
group: pages
cancel-in-progress: false

jobs:
# 构建工作
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # 如果未启用 lastUpdated,则不需要
- uses: pnpm/action-setup@v3

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20.12.2
cache: pnpm
- name: Setup Pages
uses: actions/configure-pages@v4

- name: Install dependencies
run: pnpm i

- name: Build with VitePress
run: pnpm build:docs

# 将README.md同步,利于github pages分支展示
- name: Add Readme.md To Dist
run: |
cp -f README.md docs/.vuepress/dist
- name: Check GitHub Pages status
uses: crazy-max/ghaction-github-status@v3
with:
pages_threshold: major_outage

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/.vitepress/dist

# 部署工作
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
needs: build
runs-on: ubuntu-latest
name: Deploy
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ dist/
**/.turbo/
**/.output/
**/node_modules
**/.vitepress/cache
**/.vite

32 changes: 18 additions & 14 deletions docs/.vitepress/config.ts → .vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { i18n } from '@142vip/vitepress'
import { defineConfig } from 'vitepress'
import { navbar } from './config/navbar'
import { sidebar } from './config/sidebar'
import { footer } from './config/footer'
import {defineConfig} from 'vitepress'
import {navbar} from './config/navbar'
import {sidebar} from './config/sidebar'
import {footer} from './config/footer'
import {name} from '../package.json'

// https://vitepress.dev/reference/site-config

Expand All @@ -11,7 +11,7 @@ export default defineConfig({
title: '@142vip/core-x',
titleTemplate: ':title - @142vip/core-x',
description: 'x代表一切都有可能',
srcDir: 'manuscripts',
srcDir: './',
// 排除部分
srcExclude: ['tutorial/**/description.md'],
// 编译输出目录
Expand All @@ -21,23 +21,22 @@ export default defineConfig({
assetsDir: 'static',
metaChunk: true,
head: [
['meta', { name: 'theme-color', content: '#3c8772' }],
['meta', { property: 'og:url', content: 'https://github.com/142vip/core-x' }],
['meta', { property: 'og:type', content: 'website' }],
['meta', { property: 'og:title', content: '@142vip/core-x' }],
['meta', {name: 'theme-color', content: '#3c8772'}],
['meta', {property: 'og:url', content: 'https://github.com/142vip/core-x'}],
['meta', {property: 'og:type', content: 'website'}],
['meta', {property: 'og:title', content: '@142vip/core-x'}],
[
'meta',
{
property: 'og:description',
content: '@142vip/core-x - 系列封装',
content: `${name} - 系列封装`,
},
],
],
themeConfig: {
// 导航栏
nav: navbar,
sidebar,
i18n,
footer,
lastUpdated: {
text: '最近更新',
Expand All @@ -48,12 +47,17 @@ export default defineConfig({
},
// 一些链接
socialLinks: [
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' },
{ icon: 'npm', link: 'https://github.com/vuejs/vitepress' },
{icon: 'github', link: 'https://github.com/vuejs/vitepress'},
{icon: 'npm', link: 'https://github.com/vuejs/vitepress'},
],
search: {
provider: 'local',
},
externalLinkIcon: true,
},
// 路径重写
rewrites: {
':packages/:pkg/README.md': ':packages/:pkg/index.md',
':packages/:pkg/CHANGELOG.md': ':packages/:pkg/changelog.md',
}
})
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { version } from '../../../package.json'
import { version } from '../../package.json'

/**
* 导航栏
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions docs/.vitepress/theme/index.ts → .vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// https://vitepress.dev/guide/custom-theme
import {h} from 'vue'
import type {Theme} from 'vitepress'
import { h } from 'vue'
import type { Theme } from 'vitepress'
import DefaultTheme from 'vitepress/theme'
import './style.css'

Expand Down
File renamed without changes.
15 changes: 0 additions & 15 deletions docs/package.json

This file was deleted.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@
},
"scripts": {
"preinstall": "npx only-allow pnpm && chmod +x ./scripts/* && pnpm build",
"dev": "npx fairy-cli turbo --build",
"dev": "vitepress dev --port 8080 --host",
"build": "npx fairy-cli turbo --build",
"build:docs": "vitepress build",
"clean": "npx fairy-cli clean --ignore-tips --all",
"lint": "npx eslint . --fix",
"publish": "npx lerna publish --canary from-git"
"publish": "npx lerna publish --canary from-git",
"preview": "vitepress preview"
},
"dependencies": {
},
"devDependencies": {
"@142vip/changelog": "workspace:*",
"@142vip/vitepress": "workspace:*",
"@antfu/eslint-config": "^2.20.0",
"@lerna-lite/cli": "^3.5.1",
"@lerna-lite/list": "^3.5.1",
Expand Down
1 change: 0 additions & 1 deletion packages/fairy-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@

- [rimraf](https://www.npmjs.com/package/rimraf)
- [del](https://www.npmjs.com/package/del)

2 changes: 1 addition & 1 deletion packages/fairy-cli/src/core/lint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {execCommand} from '../utils'
import { execCommand } from '../utils'

export interface LintOptions {
markdown: boolean
Expand Down
8 changes: 2 additions & 6 deletions packages/fairy-cli/src/core/login.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {execShell} from "@142vip/common";
import { execShell } from '@142vip/common'

export enum LoginPlatformEnum {
DOCKER = 'docker',
Expand Down Expand Up @@ -27,18 +27,15 @@ export interface NpmOptions extends Omit<LoginOptions, 'userName' | 'password'>
}

export async function execLogin(platform: LoginPlatformEnum, args: LoginOptions) {

if (LoginPlatformEnum.DOCKER === platform) {
await loginDocker(args)
}

if (LoginPlatformEnum.NPM === platform) {
await loginNpm(args)
}

}


// docker 登录
async function loginDocker(args: DockerOptions) {
let registryUrl = RegistryURLEnum.DOCKER as string
Expand All @@ -51,7 +48,7 @@ async function loginDocker(args: DockerOptions) {
}

// docker login --username=142vip --password="$password" registry.cn-hangzhou.aliyuncs.com
const command = `docker login ${args.userName != null ? `--username=${args.userName}` : ""} ${args.password != null ? `--password=${args.password}` : ""} ${registryUrl}`
const command = `docker login ${args.userName != null ? `--username=${args.userName}` : ''} ${args.password != null ? `--password=${args.password}` : ''} ${registryUrl}`
// npm login --registry https://registry.npmjs.org
await execShell(command)
}
Expand All @@ -70,4 +67,3 @@ async function loginNpm(args: NpmOptions) {
// npm login --registry https://registry.npmjs.org
await execShell(`npx npm login --registry ${registryUrl}`)
}

6 changes: 2 additions & 4 deletions packages/fairy-cli/src/core/turbopack.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import {execShell} from "@142vip/common";
import fsSync from 'node:fs'
import * as process from "process";
import * as process from 'node:process'
import { execShell } from '@142vip/common'

export interface TurboPackOptions {
dev?: boolean
build?: boolean
}

export async function execTurboPack(repoNames: string[], args: TurboPackOptions) {

// 判断当前目录下是否有turbo.json配置文件
if (!fsSync.existsSync('turbo.json')) {
console.log('项目根目录下缺少turbo.json配置文件,查看Turborepo官网:<https://turbo.build/repo/docs>')
Expand All @@ -26,7 +25,6 @@ export async function execTurboPack(repoNames: string[], args: TurboPackOptions)
}
}


/**
* 获取需要执行命令的repo
* - 支持多个--filter
Expand Down
32 changes: 16 additions & 16 deletions packages/fairy-cli/src/fairy-cli.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import * as process from 'node:process'
import {Command} from 'commander'
import {version, name} from '../package.json'
import type {LoginOptions} from './core/login'
import type {ReleaseOptions} from './core/release'
import type {ChangelogOptions} from './core/changelog'
import type {DeployOptions} from './core/deploy'
import {execDeploy} from './core/deploy'
import type {LintOptions} from './core/lint'
import {execLink} from './core/lint'
import type {CleanUpOptions} from './core/clean'
import {execCleanUp} from './core/clean'
import {execTurboPack, TurboPackOptions} from "./core/turbopack";
import {execLogin, LoginPlatformEnum} from "./core/login";
import { Command } from 'commander'
import { name, version } from '../package.json'
import type { LoginOptions } from './core/login'
import type { ReleaseOptions } from './core/release'
import type { ChangelogOptions } from './core/changelog'
import type { DeployOptions } from './core/deploy'
import { execDeploy } from './core/deploy'
import type { LintOptions } from './core/lint'
import { execLink } from './core/lint'
import type { CleanUpOptions } from './core/clean'
import { execCleanUp } from './core/clean'
import type { TurboPackOptions } from './core/turbopack'
import { execTurboPack } from './core/turbopack'
import { LoginPlatformEnum, execLogin } from './core/login'

enum CliCommandEnum {
LOGIN = 'login',
Expand All @@ -21,15 +22,14 @@ enum CliCommandEnum {
CLEAN = 'clean',
LINT = 'lint',
DEPLOY = 'deploy',
TURBO = 'turbo'
TURBO = 'turbo',
}

const program = new Command(name)

// 查看版本
program.version(version, '-v --version')


// fairy-cli create 创建
program
.command('create <projectName>')
Expand Down Expand Up @@ -153,7 +153,7 @@ program
program
.command(CliCommandEnum.TURBO)
.description('exec turbo pack command')
.argument('[repoName...]', '需要使用Turbo管理的项目名,支持多个',)
.argument('[repoName...]', '需要使用Turbo管理的项目名,支持多个')
.option('--dev', '执行dev命令', false)
.option('--build', '执行build命令', false)
.action(async (repoNames: string[], args: TurboPackOptions) => {
Expand Down
13 changes: 7 additions & 6 deletions packages/fairy-cli/src/utils/exec-command.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as childProcess from 'node:child_process'
import {Buffer} from 'node:buffer'
import { Buffer } from 'node:buffer'
import * as process from 'node:process'

type Command = string | string[]
Expand Down Expand Up @@ -31,7 +31,7 @@ export async function execCommand(
cwd: process.cwd(),
}

const {platform} = process
const { platform } = process

try {
const cmd = platform === 'win32' ? 'cmd' : 'sh'
Expand Down Expand Up @@ -61,13 +61,14 @@ export async function execCommand(
const getDefaultResult = () => {
const stderr = stderrList.join('\n')
const stdout = stdoutList.join('\n')
return {stdout, stderr, cmd: executable}
return { stdout, stderr, cmd: executable }
}

child.on('error', error => resolve({...getDefaultResult(), error}))
child.on('close', code => resolve({...getDefaultResult(), code}))
child.on('error', error => resolve({ ...getDefaultResult(), error }))
child.on('close', code => resolve({ ...getDefaultResult(), code }))
})
} catch (error) {
}
catch (error) {
return Promise.reject(error)
}
}
4 changes: 2 additions & 2 deletions packages/vitepress/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export const defaultThemeConfig = {
},
// 一些链接
socialLinks: [
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' },
{ icon: 'npm', link: 'https://github.com/vuejs/vitepress' },
{ icon: 'github', link: 'https://github.com/142vip/core-x' },
{ icon: 'npm', link: 'https://www.npmjs.com/search?q=%40142vip' },
],
search: {
provider: 'local',
Expand Down
Loading

0 comments on commit d8c1652

Please sign in to comment.