@ray-js/ray 1.3.1-beta.4 → 1.3.1-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -7
- package/plugins/i18n-plugin/index.js +15 -10
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ray-js/ray",
|
3
|
-
"version": "1.3.1-beta.
|
3
|
+
"version": "1.3.1-beta.5",
|
4
4
|
"description": "ray",
|
5
5
|
"keywords": [
|
6
6
|
"ray"
|
@@ -24,11 +24,11 @@
|
|
24
24
|
},
|
25
25
|
"dependencies": {
|
26
26
|
"@ray-core/html2mini-plugin": "0.0.6",
|
27
|
-
"@ray-core/macro": "^0.3.0-beta.
|
28
|
-
"@ray-js/api": "^1.3.1-beta.
|
29
|
-
"@ray-js/capability": "^1.3.1-beta.
|
30
|
-
"@ray-js/components": "^1.3.1-beta.
|
31
|
-
"@ray-js/framework": "^1.3.1-beta.
|
27
|
+
"@ray-core/macro": "^0.3.0-beta.5",
|
28
|
+
"@ray-js/api": "^1.3.1-beta.5",
|
29
|
+
"@ray-js/capability": "^1.3.1-beta.5",
|
30
|
+
"@ray-js/components": "^1.3.1-beta.5",
|
31
|
+
"@ray-js/framework": "^1.3.1-beta.5"
|
32
32
|
},
|
33
33
|
"maintainers": [
|
34
34
|
{
|
@@ -36,6 +36,6 @@
|
|
36
36
|
"ezmail": "tuyafe@tuya.com"
|
37
37
|
}
|
38
38
|
],
|
39
|
-
"gitHead": "
|
39
|
+
"gitHead": "a92b86f3b329e95087bee33c396019c1467ce414",
|
40
40
|
"repository": {}
|
41
41
|
}
|
@@ -1,8 +1,8 @@
|
|
1
1
|
/**
|
2
2
|
* i18n plugin
|
3
3
|
*
|
4
|
-
* 用于将语言包从项目 src/i18n 目录 或 node_modules/@ray-js/i18n 目录
|
5
|
-
* 且该目录下的以 strings.{js|json|ts} 结尾的文件转换为 strings.json
|
4
|
+
* 用于将语言包从项目 src/i18n 或 src/locales 目录 或 node_modules/@ray-js/i18n 目录
|
5
|
+
* 且该目录下的以 {strings|index}.{js|json|ts} 结尾的文件转换为 strings.json
|
6
6
|
* 并 strings.json 提取到构建目录的 i18n 目录中
|
7
7
|
*
|
8
8
|
*/
|
@@ -13,7 +13,7 @@ const fs = require('fs-extra')
|
|
13
13
|
const { requireJSFile } = require('@ray-js/shared')
|
14
14
|
|
15
15
|
const exts = ['json', 'js', 'ts']
|
16
|
-
const names = exts.map((ext) => `strings.${ext}`)
|
16
|
+
const names = exts.map((ext) => `strings.${ext}`).concat(exts.map((ext) => `index.${ext}`))
|
17
17
|
|
18
18
|
const throttle = function (fn, timeout) {
|
19
19
|
let id
|
@@ -79,14 +79,14 @@ const i18nPkgBuilderCreator = function (root, outputFile) {
|
|
79
79
|
return handle
|
80
80
|
}
|
81
81
|
|
82
|
-
const i18nHandleCreator = (root, outputFile) => {
|
82
|
+
const i18nHandleCreator = (root, langDirName, outputFile) => {
|
83
83
|
let i18nDirWatcher
|
84
|
-
const i18nDirName = path.join(root,
|
84
|
+
const i18nDirName = path.join(root, langDirName)
|
85
85
|
const i18nPkgBuilder = i18nPkgBuilderCreator(i18nDirName, outputFile)
|
86
86
|
const throttledI18nPkgBuilder = throttle(i18nPkgBuilder, 50)
|
87
87
|
|
88
88
|
const i18nDirHandle = (name) => {
|
89
|
-
if (!i18nDirWatcher && name !==
|
89
|
+
if (!i18nDirWatcher && name !== langDirName) {
|
90
90
|
return
|
91
91
|
}
|
92
92
|
|
@@ -112,7 +112,9 @@ const i18nHandleCreator = (root, outputFile) => {
|
|
112
112
|
// 初始化时判断是否存在 i18n 目录,若存在则监听之
|
113
113
|
const exist = fs.existsSync(i18nDirName)
|
114
114
|
if (exist) {
|
115
|
-
i18nDirWatcher = fs.watch(i18nDirName, (_, name) =>
|
115
|
+
i18nDirWatcher = fs.watch(i18nDirName, { recursive: true }, (_, name) =>
|
116
|
+
throttledI18nPkgBuilder(name)
|
117
|
+
)
|
116
118
|
}
|
117
119
|
// 监听 root(即src目录),用于动态判断 i18n 目录是否存在,若存在则监听之
|
118
120
|
fs.watch(root, (_, name) => throttledI18nDirHandle(name))
|
@@ -126,14 +128,17 @@ module.exports = (ctx) => {
|
|
126
128
|
const { cwd, source, output, watch } = options
|
127
129
|
const i18nDistPath = path.join(output, 'i18n', 'strings.json')
|
128
130
|
const srcDir = path.join(cwd, source)
|
129
|
-
const
|
131
|
+
const i18n = i18nHandleCreator(srcDir, 'i18n', i18nDistPath)
|
132
|
+
const locales = i18nHandleCreator(srcDir, 'locales', i18nDistPath)
|
130
133
|
|
131
134
|
return {
|
132
135
|
name: pluginName,
|
133
136
|
setup() {
|
134
|
-
i18nPkgBuilder()
|
137
|
+
i18n.i18nPkgBuilder()
|
138
|
+
locales.i18nPkgBuilder()
|
135
139
|
if (watch) {
|
136
|
-
i18nWatcherHandle()
|
140
|
+
i18n.i18nWatcherHandle()
|
141
|
+
locales.i18nWatcherHandle()
|
137
142
|
}
|
138
143
|
},
|
139
144
|
}
|