Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 增加搭建 HK 本地开发环境,以及还原 CN 本地开发环境的脚本 #1166

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions .ci/build-hk.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
#!/bin/sh

set -e
source .ci/consts.sh

# 移除 TDS 文档
rm -rf docs i18n versioned_docs versioned_sidebars versions.json
rm -rf ${DIFF_FILES}

# 移动 TDS HK 文档
mv tds_hk/docs .
mv tds_hk/i18n .

# 替换配置文件
mv tds_hk/conf/env.ts src/constants/env.ts
mv tds_hk/conf/docusaurus.config.js docusaurus.config.js
mv tds_hk/conf/sidebars.js sidebars.js
mv tds_hk/* .

# 构建
yarn build --out-dir build-hk
Expand Down
3 changes: 3 additions & 0 deletions .ci/consts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

DIFF_FILES="docs i18n src versioned_docs versioned_sidebars versions.json docusaurus.config.js sidebars.js"
10 changes: 10 additions & 0 deletions .ci/restore-cn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

source .ci/consts.sh

# 移动 TDS HK 文档
mv ${DIFF_FILES} tds_hk/

# 还原 CN 文档
mv cn_bak/* .
rm -rf cn_bak
15 changes: 0 additions & 15 deletions .ci/restore_cn_dev.sh

This file was deleted.

11 changes: 11 additions & 0 deletions .ci/setup-hk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

source .ci/consts.sh

# 备份 CN 文档
mkdir -p cn_bak
rm -rf cn_bak/*
mv ${DIFF_FILES} cn_bak

# 移动 TDS HK 文档
mv tds_hk/* .
23 changes: 0 additions & 23 deletions .ci/setup_hk_dev.sh

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ yarn start --locale zh-hans

### 切换 HK 本地开发环境

执行 .ci/setup-hk.sh 脚本,会把本地变成 HK 文档开发环境,在 docs 目录下修改内容,可以直接在本地预览。
执行`yarn setup-hk`,会把本地变成 HK 文档开发环境,在 docs 目录下修改内容,可以直接在本地预览。

### 还原 CN 本地开发环境

HK 文档修改完毕后,执行 .ci/restore_cn_dev.sh 脚本,会把修改移动到 tds_hk 目录,然后把本地还原成 CN 文档开发环境。
HK 文档修改完毕后,提交前,执行`yarn restore-cn`,会把修改移动到 tds_hk 目录,然后把本地还原成 CN 文档开发环境。

## 贡献

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"write-translations": "docusaurus write-translations",
"write-heading-ids": "docusaurus write-heading-ids",
"typecheck": "tsc",
"optimg": "find img -name \"*.jpg\" -exec jpegoptim --max=90 {} \\; && find img -name \"*.jpeg\" -exec jpegoptim --max=90 {} \\; && find img -name \"*.png\" -exec optipng {} \\;"
"optimg": "find img -name \"*.jpg\" -exec jpegoptim --max=90 {} \\; && find img -name \"*.jpeg\" -exec jpegoptim --max=90 {} \\; && find img -name \"*.png\" -exec optipng {} \\;",
"setup-hk": ".ci/setup-hk.sh",
"restore-cn": ".ci/restore-cn.sh"
},
"dependencies": {
"@docusaurus/core": "2.1.0",
Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions tds_hk/src/@types/common.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare module '*.scss';
declare module '*.sass';

// alias
declare type MayUndefined<T> = T | undefined;
declare type Nullable<T> = T | null | undefined;
declare type Timestamp = number;
declare type ISODateString = string;

// utils
declare type PromisePayload<T> = T extends Promise<infer F> ? F : never;
File renamed without changes.
95 changes: 95 additions & 0 deletions tds_hk/src/docComponents/ExchangeTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import React, {useEffect, useState} from 'react';
import Translate from '@docusaurus/Translate';
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";

export const ExchangeTable = ({}) => {
const delay = 60 * 60 * 1000;

const exchangeData = {
"zh-Hans": {
"common": {
"CNY": "人民币",
"HKD": "港币",
"TWD": "新台币元",
"EUR": "欧元",
"USD": "美元",
"GBP": "英镑",
"AUD": "澳大利亚元",
"KRW": "韩元",
"JPY": "日元",
"VND": "越南盾",
"THB": "泰铢",
"SGD": "新加坡元",
"IDR": "印度尼西亚盾/卢比"
},
},
"en-US": {
"common": {
"CNY": "RMB",
"HKD": "Hongkong dollar",
"TWD": "New Taiwanese Dollar",
"EUR": "Euro",
"USD": "Dollar",
"GBP": "Pound",
"AUD": "Australian dollar",
"KRW": "Korean Won",
"JPY": "Yen",
"VND": "Vietnamese dong",
"THB": "Thai Baht",
"SGD": "Singapore dollar",
"IDR": "Indonesian rupiah/Rupee"
},
},
};
const { i18n: { currentLocale } } = useDocusaurusContext();
const currentExchangeData = exchangeData[currentLocale] || exchangeData['zh-Hans'];
const commonCurrencyList = Object.keys(currentExchangeData.common);
let [exchangeMap, setExchangeMap] = useState({});

const getExchangeRates = () => {
fetch(`//www.tapdb.com/api/v1/ga-exchange/exchange-rates`, {mode: 'cors'})
.then(res => res.json())
.then(
(result) => {
const rawData = result.data;
const nameIndex = rawData.index.indexOf('exchangeTo');
const rateIndex = rawData.index.indexOf('currentExchangeRate');
if (nameIndex !== -1 && rateIndex !== -1) {
const newExchangeMap = {}
rawData.data.forEach((item) => {
newExchangeMap[item[nameIndex]] = item[rateIndex];
});
setExchangeMap(newExchangeMap);
}
},
(error) => {}
)
}

useEffect(()=>{
getExchangeRates();
},[]);

useEffect(()=>{
const id = setInterval(getExchangeRates, delay);
return () => clearInterval(id);
},[]);

return (
<table>
<thead>
<tr>
<th><Translate id="exchange.currency">币种</Translate></th>
<th><Translate id="exchange.currencyType">货币类型(currency_type)</Translate></th>
<th><Translate id="exchange.currentRate">实时汇率(本位币:美元 USD)</Translate></th>
</tr>
</thead>
<tbody>
<tr>
<td colSpan={3}><Translate id="exchange.commonCurrent">常用货币</Translate></td>
</tr>
{ commonCurrencyList.map(currency => <tr key={currency}><td>{currentExchangeData.common[currency]}</td><td>{currency}</td><td>{exchangeMap[currency] || '-'}</td></tr>) }
</tbody>
</table>
)
};
11 changes: 11 additions & 0 deletions tds_hk/src/docComponents/Mermaid/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React, { useEffect } from "react";
import mermaid from "mermaid";

mermaid.initialize({startOnLoad: true});

const Mermaid = ({ diagram }) => {
useEffect(() => {mermaid.contentLoaded();}, []);
return <div className="mermaid">{diagram}</div>;
};

export default Mermaid;
54 changes: 54 additions & 0 deletions tds_hk/src/docComponents/MultiLang/engine.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react'
import Tabs from '@theme/Tabs'

const runtimes = [
{label: 'Web App', value: 'webapp'},
{label: 'Node.js', value: 'nodejs'},
{label: 'Python', value: 'python'},
{label: 'PHP', value: 'php'},
{label: 'Java', value: 'java'},
{label: '.NET (C#)', value: 'dotnet'},
{label: 'Go', value: 'go'}
]

interface EngineRuntimesProps {
group?: string
only?: string
children: React.ReactElement[] | React.ReactElement
}

export default function EngineRuntimes({only, group, children}: EngineRuntimesProps): JSX.Element | null {
const values: typeof runtimes = []
const tabItems: JSX.Element[] = []

if (only) {
if (children instanceof Array) {
return children.find( child => child.props.value === only) || null
} else {
return children.props.value === only ? children : null
}
}

for (const runtime of runtimes) {
if (children instanceof Array) {
const matchedChild = children.find( child => child.props.value === runtime.value)

if (matchedChild) {
values.push(runtime)
tabItems.push(matchedChild)
}
} else {
if (children.props.value === runtime.value ? children : undefined) {
values.push(runtime)
tabItems.push(children)
}
}
}

return <Tabs
groupId={group ?? 'engine-runtimes'}
defaultValue={values[0].value}
values={values}>
{tabItems}
</Tabs>
}
Loading
Loading