diff --git a/.dumi/theme/builtins/SourceGenerate.less b/.dumi/theme/builtins/SourceGenerate.less new file mode 100644 index 0000000..d913e93 --- /dev/null +++ b/.dumi/theme/builtins/SourceGenerate.less @@ -0,0 +1,15 @@ +@import (reference) '../style/variables.less'; + +.@{prefix}-source-generate { + text-align: center; + margin: 16px 0; + + &-tool { + display: flex; + margin-bottom: 8px; + + &-query { + margin-right: 6px; + } + } +} diff --git a/.dumi/theme/builtins/SourceGenerate.tsx b/.dumi/theme/builtins/SourceGenerate.tsx new file mode 100644 index 0000000..2216d8d --- /dev/null +++ b/.dumi/theme/builtins/SourceGenerate.tsx @@ -0,0 +1,203 @@ +import React, { useState } from 'react'; +import { Select, Tooltip } from 'antd'; +import { QuestionCircleOutlined } from '@ant-design/icons'; +// @ts-ignore +import SourceCode from 'dumi-theme-default/src/builtins/SourceCode'; + +import './SourceGenerate.less'; +import { Mirror, mirrorData, Platform } from '../constants'; + +const Option = Select.Option; + +const mirrorConfig = [ + { + key: Mirror.USTC, + value: '中科大', + }, + { + key: Mirror.Tsinghua, + value: '清华', + }, + { + key: Mirror.BFSU, + value: '北京外国语', + }, + { + key: Mirror.Tencent, + value: '腾讯', + }, +]; + +const platformList = [ + { + key: Platform.MacOS, + value: 'macOS', + }, + { + key: Platform.Windows, + value: 'Windows', + }, + { + key: Platform.Linux, + value: 'Linux', + }, +]; + +const SourceGenerate = ({ first }) => { + const [mirror, setMirror] = useState(Mirror.USTC); + const [platform, setPlatform] = useState(Platform.MacOS); + const [terminalType, setTerminalType] = useState('zsh'); + + function generateMirror() { + const matchMirror = mirrorData[`${mirror}Mirror`] || {}; + + const shellArray = ['# 脚本']; + + shellArray.push( + `git -C "$(brew --repo)" remote set-url origin ${matchMirror.brew}`, + ); + + if (platform === Platform.Linux && matchMirror.linuxCore) { + shellArray.push( + `git -C "$(brew --repo homebrew/core)" remote set-url origin ${matchMirror.linuxCore}`, + ); + } else { + shellArray.push( + `git -C "$(brew --repo homebrew/core)" remote set-url origin ${matchMirror.core}`, + ); + } + + shellArray.push( + `git -C "$(brew --repo homebrew/cask)" remote set-url origin ${matchMirror.cask}`, + ); + + shellArray.push('brew update'); + + shellArray.push(''); + + const file = terminalType === 'zsh' ? '.zprofile' : '.bash_profile'; + + if (platform === Platform.Linux && matchMirror.linuxBottles) { + shellArray.push( + `echo 'export HOMEBREW_BOTTLE_DOMAIN=${matchMirror.linuxBottles}' >> ~/${file}`, + ); + } else { + shellArray.push( + `echo 'export HOMEBREW_BOTTLE_DOMAIN=${matchMirror.bottles}' >> ~/${file}`, + ); + } + + shellArray.push(`source ~/${file}`); + + return shellArray.join('\n'); + } + + function generateFirstMirrorSet() { + const matchMirror = mirrorData[`${mirror}Mirror`] || {}; + + const shellArray = ['# 1.执行安装脚本']; + + shellArray.push(`export HOMEBREW_BREW_GIT_REMOTE="${matchMirror.brew}"`); + + if (platform === Platform.Linux && matchMirror.linuxCore) { + shellArray.push( + `export HOMEBREW_CORE_GIT_REMOTE="${matchMirror.linuxCore}"`, + ); + } else { + shellArray.push(`export HOMEBREW_CORE_GIT_REMOTE="${matchMirror.core}"`); + } + + shellArray.push( + '/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"', + ); + + shellArray.push(''); + shellArray.push('# 2.安装完成后设置'); + + const file = terminalType === 'zsh' ? '.zprofile' : '.bash_profile'; + + if (platform === Platform.Linux && matchMirror.linuxBottles) { + shellArray.push( + `echo 'export HOMEBREW_BOTTLE_DOMAIN=${matchMirror.linuxBottles}' >> ~/${file}`, + ); + } else { + shellArray.push( + `echo 'export HOMEBREW_BOTTLE_DOMAIN=${matchMirror.bottles}' >> ~/${file}`, + ); + } + + shellArray.push(`source ~/${file}`); + + return shellArray.join('\n'); + } + + return ( +
+
+
+ + +
+
+ + +
+
+ + + +

macOS Catalina(10.15.x)以及更高版本默认是zsh

+

+ 执行命令echo $SHELL +
+ 显示/bin/bash则是bash,显示/bin/zsh则是zsh +

+
+ } + > + + +
+
+ + + ); +}; + +export default SourceGenerate; diff --git a/.dumi/theme/constants/index.ts b/.dumi/theme/constants/index.ts new file mode 100644 index 0000000..7e91204 --- /dev/null +++ b/.dumi/theme/constants/index.ts @@ -0,0 +1,56 @@ +export const tencentMirror = { + brew: 'https://mirrors.cloud.tencent.com/homebrew/brew.git', + core: 'https://mirrors.cloud.tencent.com/homebrew/homebrew-core.git', + linuxCore: 'https://mirrors.cloud.tencent.com/homebrew/linuxbrew-core.git', + cask: 'https://mirrors.cloud.tencent.com/homebrew/homebrew-cask.git', + bottles: 'https://mirrors.cloud.tencent.com/homebrew-bottles/bottles', + linuxBottles: '', +}; + +export const tsinghuaMirror = { + brew: 'https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git', + core: 'https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git', + linuxCore: + 'https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/linuxbrew-core.git', + cask: 'https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git', + bottles: 'https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles', + linuxBottles: 'https://mirrors.tuna.tsinghua.edu.cn/linuxbrew-bottles', +}; + +export const ustcMirror = { + brew: 'https://mirrors.ustc.edu.cn/brew.git', + core: 'https://mirrors.ustc.edu.cn/homebrew-core.git', + linuxCore: 'https://mirrors.ustc.edu.cn/linuxbrew-core.git', + cask: 'https://mirrors.ustc.edu.cn/homebrew-cask.git', + bottles: 'https://mirrors.ustc.edu.cn/homebrew-bottles', + linuxBottles: 'https://mirrors.ustc.edu.cn/linuxbrew-bottles', +}; + +export const bfsuMirror = { + brew: 'https://mirrors.bfsu.edu.cn/git/homebrew/brew.git', + core: 'https://mirrors.bfsu.edu.cn/git/homebrew/homebrew-core.git', + linuxCore: 'https://mirrors.bfsu.edu.cn/git/homebrew/linuxbrew-core.git', + cask: 'https://mirrors.bfsu.edu.cn/git/homebrew/homebrew-cask.git', + bottles: 'https://mirrors.bfsu.edu.cn/homebrew-bottles', + linuxBottles: 'https://mirrors.bfsu.edu.cn/linuxbrew-bottles', +}; + +export const mirrorData: { [key: string]: any } = { + bfsuMirror, + ustcMirror, + tencentMirror, + tsinghuaMirror, +}; + +export enum Mirror { + BFSU = 'bfsu', + Tsinghua = 'tsinghua', + Tencent = 'tencent', + USTC = 'ustc', +} + +export enum Platform { + MacOS, + Linux, + Windows, +} diff --git a/.umirc.ts b/.umirc.ts index 315d22e..80b6c20 100644 --- a/.umirc.ts +++ b/.umirc.ts @@ -49,7 +49,11 @@ export default defineConfig({ children: ['/guide/index', '/guide/how-it-works', '/guide/start'], }, { - title: 'M1芯片 ', + title: '工 具', + children: ['/guide/change-source'], + }, + { + title: 'M1芯片', path: '/guide/m1/', }, { @@ -58,6 +62,16 @@ export default defineConfig({ }, ], }, + extraBabelPlugins: [ + [ + 'import', + { + libraryName: 'antd', + libraryDirectory: 'es', + style: 'css', + }, + ], + ], analytics: { ga: 'UA-39288503-8', baidu: 'be934bce3f81621badc0bb5b581ab622', diff --git a/docs/guide/change-source.md b/docs/guide/change-source.md new file mode 100644 index 0000000..1d14077 --- /dev/null +++ b/docs/guide/change-source.md @@ -0,0 +1,13 @@ +# 镜像助手 + +## 如果你是初次安装,并且需要换其他源 + +脚本默认内置中科大镜像,如果需要换源,请使用小助手获取安装脚本: + + + +## 如果你已经安装过,需要换源 + +选择"镜像"、"平台"、"终端类型"后,会自动生成对应的设置镜像脚本。 + + diff --git a/docs/guide/start.md b/docs/guide/start.md index b975975..bac4e1a 100644 --- a/docs/guide/start.md +++ b/docs/guide/start.md @@ -12,6 +12,8 @@ order: 3 /bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)" ``` +> 默认使用中科大源,如果需要换源参考 [换源](/guide/change-source/)。 + 如果命令执行中卡在下面信息: ```shell @@ -47,6 +49,8 @@ brew update

设置镜像

+> 更新:强烈建议使用[镜像助手](/guide/change-source/),你可以自助获取镜像脚本,目前支持中科大、清华、腾讯、北京外国语镜像源。 + ### 中科大源 ```shell @@ -98,16 +102,6 @@ source ~/.bash_profile > 注意:上述区别仅仅是`.zprofile`和`.bash_profile`不同,上下文如有再次提及编辑`.zprofile`,均按此方法判断具体操作的文件。 -如果想使用清华源: - -```shell -把 -https://mirrors.ustc.edu.cn/homebrew-bottles - -替换为 -https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles -``` - 至此,安装和设置操作都完成了。 ### 恢复默认源 diff --git a/docs/index.md b/docs/index.md index e6a90b6..488ff32 100644 --- a/docs/index.md +++ b/docs/index.md @@ -5,7 +5,7 @@ hero: image: /images/homebrew-256x256.png actions: - text: 快速开始 - link: /guide/ + link: /guide/start/ footer: Open-source MIT Licensed | Copyright © 2021
Powered by [Neo](https://github.com/ineo6) --- @@ -17,7 +17,8 @@ footer: Open-source MIT Licensed | Copyright © 2021
Powered by [Neo](https /bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)" ``` -
将以上命令粘贴至终端。
-
脚本内置中科大镜像,所以让Homebrew安装速度飞快。
+
将以上命令粘贴至终端。脚本内置中科大镜像,所以能让Homebrew安装速度飞快。
-
如果对安装有疑问,请通过 快速开始 安装。
+
如果想使用其他源安装,或者已安装但是想换源,请使用镜像助手获取脚本。
+ +
更详细的安装说明,请点击 快速开始 开始安装。
diff --git a/package.json b/package.json index 49b46df..335cb24 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ }, "homepage": "https://github.com/ineo6/homebrew-install#readme", "devDependencies": { + "babel-plugin-import": "^1.13.3", "chalk": "^4.1.0", "download-git-repo": "^3.0.2", "dumi": "^1.0.12", @@ -42,5 +43,9 @@ "prettier": "^1.19.1", "sitemap": "^6.3.5", "yorkie": "^2.0.0" + }, + "dependencies": { + "@ant-design/icons": "^4.5.0", + "antd": "^4.13.1" } }