From cda54ebdb68f1169e1668efd7262bd27df0155a3 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sun, 5 Feb 2023 13:09:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E7=BF=BB=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 并优化了国内网络在请求在线声明时的网络体验 --- apps/cli/src/commands/declaration.ts | 8 ++++++-- apps/cli/src/commands/docker/init.ts | 8 +------- apps/cli/src/utils.ts | 7 +++++++ apps/cli/templates/client-plugin/{{id}}/src/index.tsx | 2 +- apps/cli/templates/client-plugin/{{id}}/src/translate.ts | 8 ++++++++ .../{{id}}/web/plugins/{{id}}/src/index.tsx | 2 +- .../{{id}}/web/plugins/{{id}}/src/translate.ts | 8 ++++++++ 7 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 apps/cli/templates/client-plugin/{{id}}/src/translate.ts create mode 100644 apps/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/src/translate.ts diff --git a/apps/cli/src/commands/declaration.ts b/apps/cli/src/commands/declaration.ts index 1482e245..38a705f9 100644 --- a/apps/cli/src/commands/declaration.ts +++ b/apps/cli/src/commands/declaration.ts @@ -4,6 +4,11 @@ import fs, { mkdirp } from 'fs-extra'; import path from 'path'; import ora from 'ora'; import got from 'got'; +import { withGhProxy } from '../utils'; + +const onlineDeclarationUrl = withGhProxy( + 'https://raw.githubusercontent.com/msgbyte/tailchat/master/client/web/tailchat.d.ts' +); export const declarationCommand: CommandModule = { command: 'declaration ', @@ -44,8 +49,7 @@ export const declarationCommand: CommandModule = { content = "declare module '@capital/common';\ndeclare module '@capital/component';\n"; } else if (source === 'github') { - const url = - 'https://raw.githubusercontent.com/msgbyte/tailchat/master/client/web/tailchat.d.ts'; + const url = onlineDeclarationUrl; const spinner = ora(`正在从 Github 下载插件类型声明: ${url}`).start(); diff --git a/apps/cli/src/commands/docker/init.ts b/apps/cli/src/commands/docker/init.ts index 2d36042b..7ca1498a 100644 --- a/apps/cli/src/commands/docker/init.ts +++ b/apps/cli/src/commands/docker/init.ts @@ -6,6 +6,7 @@ import path from 'path'; import chalk from 'chalk'; import inquirer from 'inquirer'; import randomString from 'crypto-random-string'; +import { withGhProxy } from '../../utils'; // https://docs.docker.com/engine/api/v1.41/ @@ -179,10 +180,3 @@ async function promptConfirm(message: string): Promise { return res; } - -/** - * 增加github资源代理以优化国内访问速度 - */ -function withGhProxy(url: string): string { - return `https://ghproxy.com/${url}`; -} diff --git a/apps/cli/src/utils.ts b/apps/cli/src/utils.ts index 8e653835..cfc5b9e4 100644 --- a/apps/cli/src/utils.ts +++ b/apps/cli/src/utils.ts @@ -4,3 +4,10 @@ export function isDev(): boolean { return process.env.NODE_ENV === 'development'; } + +/** + * 增加github资源代理以优化国内访问速度 + */ +export function withGhProxy(url: string): string { + return `https://ghproxy.com/${url}`; +} diff --git a/apps/cli/templates/client-plugin/{{id}}/src/index.tsx b/apps/cli/templates/client-plugin/{{id}}/src/index.tsx index 17eb3890..304a1da5 100644 --- a/apps/cli/templates/client-plugin/{{id}}/src/index.tsx +++ b/apps/cli/templates/client-plugin/{{id}}/src/index.tsx @@ -1,3 +1,3 @@ -const PLUGIN_NAME = '{{name}}'; +const PLUGIN_NAME = '{{id}}'; console.log(`Plugin ${PLUGIN_NAME} is loaded`); diff --git a/apps/cli/templates/client-plugin/{{id}}/src/translate.ts b/apps/cli/templates/client-plugin/{{id}}/src/translate.ts new file mode 100644 index 00000000..96b0360b --- /dev/null +++ b/apps/cli/templates/client-plugin/{{id}}/src/translate.ts @@ -0,0 +1,8 @@ +import { localTrans } from '@capital/common'; + +export const Translate = { + name: localTrans({ + 'zh-CN': '{{name}}', + 'en-US': '{{name}}', + }), +}; diff --git a/apps/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/src/index.tsx b/apps/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/src/index.tsx index 17eb3890..304a1da5 100644 --- a/apps/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/src/index.tsx +++ b/apps/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/src/index.tsx @@ -1,3 +1,3 @@ -const PLUGIN_NAME = '{{name}}'; +const PLUGIN_NAME = '{{id}}'; console.log(`Plugin ${PLUGIN_NAME} is loaded`); diff --git a/apps/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/src/translate.ts b/apps/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/src/translate.ts new file mode 100644 index 00000000..96b0360b --- /dev/null +++ b/apps/cli/templates/server-plugin-web/{{id}}/web/plugins/{{id}}/src/translate.ts @@ -0,0 +1,8 @@ +import { localTrans } from '@capital/common'; + +export const Translate = { + name: localTrans({ + 'zh-CN': '{{name}}', + 'en-US': '{{name}}', + }), +};