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

chore: update docs sync source #2058

Merged
merged 5 commits into from
Mar 27, 2024
Merged
Changes from 1 commit
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
39 changes: 25 additions & 14 deletions scripts/sync-from-umi.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ const RM_FM_ACTION = {
type: 'replace',
value: [/^---[^]+?---\n/, ''],
};

const JSDELIVR_PREFIX = 'https://cdn.jsdelivr.net/gh/umijs/umi@4/';
const GITHUB_RAW_PREFIX = 'https://raw.githubusercontent.com/umijs/umi/master/';

const FILE_LIST = [
// config docs
{
localname: 'config.md',
upstream:
'https://cdn.jsdelivr.net/gh/umijs/umi@4/docs/docs/docs/api/config.md',
repoPath: 'docs/docs/docs/api/config.md',
actions: [
RM_FM_ACTION,
// remove head content
Expand Down Expand Up @@ -152,8 +155,7 @@ const FILE_LIST = [
},
{
localname: 'api.md',
upstream:
'https://cdn.jsdelivr.net/gh/umijs/umi@4/docs/docs/docs/api/api.md',
repoPath: 'docs/docs/docs/api/api.md',
actions: [
RM_FM_ACTION,
// remove head content
Expand All @@ -177,8 +179,7 @@ const FILE_LIST = [
},
{
localname: 'plugin.md',
upstream:
'https://cdn.jsdelivr.net/gh/umijs/umi@4/docs/docs/docs/guides/plugins.md',
repoPath: 'docs/docs/docs/api/plugin.md',
actions: [
RM_FM_ACTION,
// remove head content
Expand All @@ -203,8 +204,7 @@ const FILE_LIST = [
},
{
localname: 'plugin-api.md',
upstream:
'https://cdn.jsdelivr.net/gh/umijs/umi@4/docs/docs/docs/api/plugin-api.md',
repoPath: 'docs/docs/docs/api/plugin-api.md',
actions: [
RM_FM_ACTION,
// remove head content
Expand Down Expand Up @@ -243,8 +243,7 @@ const FILE_LIST = [
},
{
localname: 'runtime-config.md',
upstream:
'https://cdn.jsdelivr.net/gh/umijs/umi@4/docs/docs/docs/api/runtime-config.md',
repoPath: 'docs/docs/docs/api/runtime-config.md',
actions: [
RM_FM_ACTION,
// replace jsx to jsx | pure
Expand Down Expand Up @@ -281,13 +280,15 @@ const FILE_LIST = [
{ type: 'replace', value: [/(#+\s\w+)\([^)]+\)/g, '$1'] },
// remove HashAnchorCompat
// ref: https://github.com/umijs/umi/blob/8bfd4c761b3cc6209b9203c705842568c3ccbe62/docs/docs/docs/api/runtime-config.md#L183
{ type: 'replace', value: [/<HashAnchorCompat.+?<\/HashAnchorCompat>\n/g, ''] },
{
type: 'replace',
value: [/<HashAnchorCompat.+?<\/HashAnchorCompat>\n/g, ''],
},
],
},
{
localname: 'env-config.md',
upstream:
'https://cdn.jsdelivr.net/gh/umijs/umi@4/docs/docs/docs/guides/env-variables.md',
repoPath: 'docs/docs/docs/guides/env-variables.md',
actions: [
RM_FM_ACTION,
// remove head content
Expand All @@ -307,7 +308,17 @@ const FILE_LIST = [
{ type: 'replace', value: [/config\./g, '.dumirc.'] },
],
},
];
].map((file) => ({
...file,

upstream: [
// 可以完全自定义(也许是一个本地启动的服务)
Wxh16144 marked this conversation as resolved.
Show resolved Hide resolved
process.env.SYNC_CUSTOM_UPSTREAM,
// 同步遇到 443 失败时, 可以尝试 `SYNC_USE_GITHUB=1 npm run docs:sync` 使用 GitHub 作为源
process.env.SYNC_USE_GITHUB && GITHUB_RAW_PREFIX,
JSDELIVR_PREFIX,
].find(Boolean),
}));

if (!fs.existsSync(UMI_DOC_DIR)) {
fs.mkdirSync(UMI_DOC_DIR);
Expand Down
Loading