@ray-js/ray 1.3.0-beta.3 → 1.3.0

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/index.d.ts CHANGED
@@ -5,3 +5,4 @@ export { router as nativeRouter } from '@ray-js/api'
5
5
  export { default as location } from '@ray-js/location'
6
6
  export { default as router } from '@ray-js/router'
7
7
  export { default as platform } from '@ray-js/env'
8
+ export * from '@ray-js/capability'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/ray",
3
- "version": "1.3.0-beta.3",
3
+ "version": "1.3.0",
4
4
  "description": "ray",
5
5
  "keywords": [
6
6
  "ray"
@@ -23,11 +23,12 @@
23
23
  "registry": "https://registry.npmjs.org"
24
24
  },
25
25
  "dependencies": {
26
- "@ray-core/html2mini-plugin": "0.0.6",
27
- "@ray-core/macro": "^0.3.0-beta.4",
28
- "@ray-js/api": "^1.3.0-beta.3",
29
- "@ray-js/components": "^1.3.0-beta.3",
30
- "@ray-js/framework": "^1.3.0-beta.3"
26
+ "@ray-core/html2mini-plugin": "0.0.7",
27
+ "@ray-core/macro": "^0.3.0",
28
+ "@ray-js/api": "^1.3.0",
29
+ "@ray-js/capability": "^1.3.0",
30
+ "@ray-js/components": "^1.3.0",
31
+ "@ray-js/framework": "^1.3.0"
31
32
  },
32
33
  "maintainers": [
33
34
  {
@@ -35,6 +36,6 @@
35
36
  "ezmail": "tuyafe@tuya.com"
36
37
  }
37
38
  ],
38
- "gitHead": "be72a5dad6214ebf9c6653df02956374c735c98e",
39
+ "gitHead": "f7f96c375a429a2fa94452b0a9af3f841572921a",
39
40
  "repository": {}
40
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,21 @@ 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
+
18
+ class I18nPlugin {
19
+ constructor({ i18n, locales }) {
20
+ this.i18n = i18n
21
+ this.locales = locales
22
+ }
23
+
24
+ apply(compiler) {
25
+ compiler.hooks.assetEmitted.tap(pluginName, () => {
26
+ this.i18n.i18nPkgBuilder()
27
+ this.locales.i18nPkgBuilder()
28
+ })
29
+ }
30
+ }
17
31
 
18
32
  const throttle = function (fn, timeout) {
19
33
  let id
@@ -79,14 +93,14 @@ const i18nPkgBuilderCreator = function (root, outputFile) {
79
93
  return handle
80
94
  }
81
95
 
82
- const i18nHandleCreator = (root, outputFile) => {
96
+ const i18nHandleCreator = (root, langDirName, outputFile) => {
83
97
  let i18nDirWatcher
84
- const i18nDirName = path.join(root, 'i18n')
98
+ const i18nDirName = path.join(root, langDirName)
85
99
  const i18nPkgBuilder = i18nPkgBuilderCreator(i18nDirName, outputFile)
86
100
  const throttledI18nPkgBuilder = throttle(i18nPkgBuilder, 50)
87
101
 
88
102
  const i18nDirHandle = (name) => {
89
- if (!i18nDirWatcher && name !== 'i18n') {
103
+ if (!i18nDirWatcher && name !== langDirName) {
90
104
  return
91
105
  }
92
106
 
@@ -112,7 +126,9 @@ const i18nHandleCreator = (root, outputFile) => {
112
126
  // 初始化时判断是否存在 i18n 目录,若存在则监听之
113
127
  const exist = fs.existsSync(i18nDirName)
114
128
  if (exist) {
115
- i18nDirWatcher = fs.watch(i18nDirName, (_, name) => throttledI18nPkgBuilder(name))
129
+ i18nDirWatcher = fs.watch(i18nDirName, { recursive: true }, (_, name) =>
130
+ throttledI18nPkgBuilder(name)
131
+ )
116
132
  }
117
133
  // 监听 root(即src目录),用于动态判断 i18n 目录是否存在,若存在则监听之
118
134
  fs.watch(root, (_, name) => throttledI18nDirHandle(name))
@@ -126,14 +142,22 @@ module.exports = (ctx) => {
126
142
  const { cwd, source, output, watch } = options
127
143
  const i18nDistPath = path.join(output, 'i18n', 'strings.json')
128
144
  const srcDir = path.join(cwd, source)
129
- const { i18nWatcherHandle, i18nPkgBuilder } = i18nHandleCreator(srcDir, i18nDistPath)
145
+ const i18n = i18nHandleCreator(srcDir, 'i18n', i18nDistPath)
146
+ const locales = i18nHandleCreator(srcDir, 'locales', i18nDistPath)
130
147
 
131
148
  return {
132
149
  name: pluginName,
133
150
  setup() {
134
- i18nPkgBuilder()
135
151
  if (watch) {
136
- i18nWatcherHandle()
152
+ i18n.i18nPkgBuilder()
153
+ locales.i18nPkgBuilder()
154
+ i18n.i18nWatcherHandle()
155
+ locales.i18nWatcherHandle()
156
+ }
157
+ },
158
+ configWebpack({ config }) {
159
+ if (!watch) {
160
+ config.plugin(pluginName).use(I18nPlugin, [{ i18n, locales }])
137
161
  }
138
162
  },
139
163
  }
package/unified.js CHANGED
@@ -17,3 +17,4 @@ export { router as nativeRouter } from '@ray-js/api'
17
17
  export { default as router } from '@ray-js/router'
18
18
  export { default as location } from '@ray-js/location'
19
19
  export { default as platform } from '@ray-js/env'
20
+ export * from '@ray-js/capability'
package/unified.mini.js CHANGED
@@ -5,3 +5,4 @@ export { router as nativeRouter } from '@ray-js/api'
5
5
  export { default as router } from '@ray-js/router'
6
6
  export { default as location } from '@ray-js/location'
7
7
  export { default as platform } from '@ray-js/env'
8
+ export * from '@ray-js/capability'