Skip to content

Commit

Permalink
feat(client): setup experimental i18n schema
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed May 14, 2023
1 parent 0a3c2db commit 7c5b2dd
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 14 deletions.
6 changes: 4 additions & 2 deletions crowdin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ pull_request_labels:
files:
- source: /**/locales/zh-CN.yml
translation: /**/locales/%locale%.yml
- source: /**/*.zh-CN.md
translation: /**/*.%locale%.md
- source: /**/*.zh-CN.yml
translation: /**/%original_file_name%.%locale%.yml
translation_replace:
.zh-CN.yml: ''
38 changes: 35 additions & 3 deletions packages/client/build/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { appendFile, copyFile } from 'fs/promises'
import { resolve } from 'path'
import * as vite from 'vite'
import vue from '@vitejs/plugin-vue'
import yaml from '@maikolib/vite-plugin-yaml'

function findModulePath(id: string) {
const path = require.resolve(id).replace(/\\/g, '/')
Expand All @@ -13,7 +14,7 @@ function findModulePath(id: string) {
const cwd = resolve(__dirname, '../../..')
const dist = cwd + '/plugins/console/dist'

export async function build(root: string, config: vite.UserConfig = {}) {
export async function build(root: string, config: vite.UserConfig = {}, isClient = false) {
const { rollupOptions = {} } = config.build || {}
return await vite.build({
root,
Expand All @@ -27,9 +28,11 @@ export async function build(root: string, config: vite.UserConfig = {}) {
makeAbsoluteExternalsRelative: true,
external: [
root + '/vue.js',
root + '/vue-i18n.js',
root + '/vue-router.js',
root + '/client.js',
root + '/vueuse.js',
root + '/intlify.js',
],
output: {
format: 'module',
Expand All @@ -40,13 +43,18 @@ export async function build(root: string, config: vite.UserConfig = {}) {
},
},
},
plugins: [vue()],
plugins: [
vue(),
yaml(),
],
resolve: {
alias: {
'vue': root + '/vue.js',
'vue-i18n': root + '/vue-i18n.js',
'vue-router': root + '/vue-router.js',
'@vueuse/core': root + '/vueuse.js',
'@koishijs/client': root + '/client.js',
'@intlify/core-base': root + '/intlify.js',
},
},
}) as RollupOutput
Expand All @@ -58,6 +66,30 @@ export default async function () {

await Promise.all([
copyFile(findModulePath('vue') + '/dist/vue.runtime.esm-browser.prod.js', dist + '/vue.js'),
build(findModulePath('@intlify/core-base') + '/dist', {
build: {
outDir: dist,
emptyOutDir: false,
rollupOptions: {
input: {
'intlify': findModulePath('@intlify/core-base') + '/dist/core-base.esm-browser.js',
},
preserveEntrySignatures: 'strict',
},
},
}),
build(findModulePath('vue-i18n') + '/dist', {
build: {
outDir: dist,
emptyOutDir: false,
rollupOptions: {
input: {
'vue-i18n': findModulePath('vue-i18n') + '/dist/vue-i18n.esm-browser.js',
},
preserveEntrySignatures: 'strict',
},
},
}),
build(findModulePath('vue-router') + '/dist', {
build: {
outDir: dist,
Expand Down Expand Up @@ -100,7 +132,7 @@ export default async function () {
preserveEntrySignatures: 'strict',
},
},
})
}, true)

for (const file of output) {
if (file.type === 'asset' && file.name === 'style.css') {
Expand Down
4 changes: 4 additions & 0 deletions packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ export async function buildExtension(root: string, config: UserConfig = {}) {
makeAbsoluteExternalsRelative: true,
external: [
root + '/vue.js',
root + '/vue-i18n.js',
root + '/vue-router.js',
root + '/vueuse.js',
root + '/client.js',
root + '/intlify.js',
],
output: {
format: 'iife',
Expand All @@ -49,9 +51,11 @@ export async function buildExtension(root: string, config: UserConfig = {}) {
resolve: {
alias: {
'vue': root + '/vue.js',
'vue-i18n': root + '/vue-i18n.js',
'vue-router': root + '/vue-router.js',
'@vueuse/core': root + '/vueuse.js',
'@koishijs/client': root + '/client.js',
'@intlify/core-base': root + '/intlify.js',
},
},
define: {
Expand Down
22 changes: 13 additions & 9 deletions plugins/console/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@ class NodeConsole extends Console {
alias: {
'../client.js': '@koishijs/client',
'../vue.js': 'vue',
'../vue-i18n.js': 'vue-i18n',
'../vue-router.js': 'vue-router',
'../vueuse.js': '@vueuse/core',
'../intlify.js': '@intlify/core-base',
},
},
optimizeDeps: {
Expand Down Expand Up @@ -208,17 +210,19 @@ namespace NodeConsole {
}

export const Config: Schema<Config> = Schema.object({
root: Schema.string().description('前端页面的根目录。').hidden(),
uiPath: Schema.string().description('前端页面呈现的路径。').default(''),
apiPath: Schema.string().description('后端 API 服务的路径。').default('/status'),
selfUrl: Schema.string().description('Koishi 服务暴露在公网的地址。').role('link').default(''),
open: Schema.boolean().description('在应用启动后自动在浏览器中打开控制台。'),
root: Schema.string().hidden(),
uiPath: Schema.string().default(''),
apiPath: Schema.string().default('/status'),
selfUrl: Schema.string().role('link').default(''),
open: Schema.boolean(),
heartbeat: Schema.object({
interval: Schema.number().description('心跳发送间隔 (单位毫秒)。').default(Time.second * 30),
timeout: Schema.number().description('心跳超时时间 (单位毫秒)。').default(Time.minute),
interval: Schema.number().default(Time.second * 30),
timeout: Schema.number().default(Time.minute),
}),
devMode: Schema.boolean().description('启用调试模式 (仅供开发者使用)。').default(process.env.NODE_ENV === 'development').hidden(),
cacheDir: Schema.string().description('调试服务器缓存目录。').default('.vite').hidden(),
devMode: Schema.boolean().default(process.env.NODE_ENV === 'development').hidden(),
cacheDir: Schema.string().default('.vite').hidden(),
}).i18n({
'zh-CN': require('./locales/zh-CN'),
})
}

Expand Down
10 changes: 10 additions & 0 deletions plugins/console/src/node/locales/zh-CN.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root: 前端页面的根目录。
uiPath: 前端页面呈现的路径。
apiPath: 后端 API 服务的路径。
selfUrl: Koishi 服务暴露在公网的地址。
open: 在应用启动后自动在浏览器中打开控制台。
heartbeat:
interval: 心跳发送间隔 (单位毫秒)。
timeout: 心跳超时时间 (单位毫秒)。
devMode: 启用调试模式 (仅供开发者使用)。
cacheDir: 调试服务器缓存目录。

0 comments on commit 7c5b2dd

Please sign in to comment.