@dcloudio/uni-cli-shared 2.0.0-32620210831002 → 2.0.0-32920211029001

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.
@@ -34,6 +34,7 @@ const loadMode = {
34
34
  const attrs = [
35
35
  'pageCurrent',
36
36
  'pageSize',
37
+ 'spaceInfo',
37
38
  'collection',
38
39
  'action',
39
40
  'field',
@@ -54,6 +55,12 @@ export default {
54
55
  return {}
55
56
  }
56
57
  },
58
+ spaceInfo: {
59
+ type: Object,
60
+ default () {
61
+ return {}
62
+ }
63
+ },
57
64
  collection: {
58
65
  type: [String, Array],
59
66
  default: ''
@@ -178,12 +185,14 @@ export default {
178
185
  })
179
186
  return al
180
187
  }, (newValue, oldValue) => {
188
+ this.paginationInternal.size = this.pageSize
189
+ if (newValue[0] !== oldValue[0]) {
190
+ this.paginationInternal.current = this.pageCurrent
191
+ }
181
192
  if (this.loadtime === loadMode.manual) {
182
193
  return
183
194
  }
184
195
 
185
- this.paginationInternal.size = this.pageSize
186
-
187
196
  let needReset = false
188
197
  for (let i = 2; i < newValue.length; i++) {
189
198
  if (newValue[i] !== oldValue[i]) {
@@ -195,9 +204,6 @@ export default {
195
204
  this.clear()
196
205
  this.reset()
197
206
  }
198
- if (newValue[0] !== oldValue[0]) {
199
- this.paginationInternal.current = this.pageCurrent
200
- }
201
207
 
202
208
  this._execLoadData()
203
209
  })
@@ -324,7 +330,7 @@ export default {
324
330
  })
325
331
  }
326
332
  /* eslint-disable no-undef */
327
- let db = uniCloud.database()
333
+ let db = uniCloud.database(this.spaceInfo)
328
334
  if (action) {
329
335
  db = db.action(action)
330
336
  }
@@ -398,7 +404,7 @@ export default {
398
404
  })
399
405
  }
400
406
  /* eslint-disable no-undef */
401
- let db = uniCloud.database()
407
+ let db = uniCloud.database(this.spaceInfo)
402
408
  if (action) {
403
409
  db = db.action(action)
404
410
  }
@@ -427,7 +433,7 @@ export default {
427
433
  },
428
434
  getTemp (isTemp = true) {
429
435
  /* eslint-disable no-undef */
430
- let db = uniCloud.database()
436
+ let db = uniCloud.database(this.spaceInfo)
431
437
 
432
438
  if (this.action) {
433
439
  db = db.action(this.action)
@@ -576,7 +582,7 @@ export default {
576
582
  }
577
583
 
578
584
  /* eslint-disable no-undef */
579
- const db = uniCloud.database()
585
+ const db = uniCloud.database(this.spaceInfo)
580
586
  const dbCmd = db.command
581
587
 
582
588
  let exec = db
@@ -0,0 +1,17 @@
1
+ const path = require('path')
2
+
3
+ const isWin = /^win/.test(process.platform)
4
+
5
+ const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path)
6
+
7
+ module.exports = {
8
+ loader: 'file-loader',
9
+ options: {
10
+ publicPath (url, resourcePath, context) {
11
+ return '/' + normalizePath(path.relative(process.env.UNI_INPUT_DIR, resourcePath))
12
+ },
13
+ outputPath (url, resourcePath, context) {
14
+ return normalizePath(path.relative(process.env.UNI_INPUT_DIR, resourcePath))
15
+ }
16
+ }
17
+ }
package/lib/i18n.js ADDED
@@ -0,0 +1,99 @@
1
+ const fs = require('fs')
2
+ const path = require('path')
3
+ const {
4
+ parseJson
5
+ } = require('./json')
6
+ const {
7
+ getManifestJson
8
+ } = require('./manifest')
9
+
10
+ const delimiters = ['%', '%']
11
+
12
+ function initI18nOptions (
13
+ platform,
14
+ inputDir,
15
+ warning = false,
16
+ withMessages = true
17
+ ) {
18
+ const locales = initLocales(path.resolve(inputDir, 'locale'), withMessages)
19
+ if (!Object.keys(locales).length) {
20
+ return
21
+ }
22
+ const manifestJson = getManifestJson()
23
+ const fallbackLocale = manifestJson.fallbackLocale || manifestJson.locale
24
+ const locale = resolveI18nLocale(
25
+ platform,
26
+ Object.keys(locales),
27
+ fallbackLocale
28
+ )
29
+ if (warning) {
30
+ if (!fallbackLocale) {
31
+ console.warn()
32
+ } else if (locale !== fallbackLocale) {
33
+ console.warn()
34
+ }
35
+ }
36
+ return {
37
+ locale,
38
+ locales,
39
+ delimiters
40
+ }
41
+ }
42
+
43
+ const localeJsonRE = /uni-app.*.json/
44
+
45
+ function isUniAppLocaleFile (filepath) {
46
+ if (!filepath) {
47
+ return false
48
+ }
49
+ return localeJsonRE.test(path.basename(filepath))
50
+ }
51
+
52
+ function parseLocaleJson (filepath) {
53
+ let jsonObj = parseJson(fs.readFileSync(filepath, 'utf8'))
54
+ if (isUniAppLocaleFile(filepath)) {
55
+ jsonObj = jsonObj.common || {}
56
+ }
57
+ return jsonObj
58
+ }
59
+
60
+ function initLocales (dir, withMessages = true) {
61
+ if (!fs.existsSync(dir)) {
62
+ return {}
63
+ }
64
+ return fs.readdirSync(dir).reduce((res, filename) => {
65
+ if (path.extname(filename) === '.json') {
66
+ const locale = path
67
+ .basename(filename)
68
+ .replace(/(uni-app.)?(.*).json/, '$2')
69
+ if (withMessages) {
70
+ Object.assign(
71
+ res[locale] || (res[locale] = {}),
72
+ parseLocaleJson(path.join(dir, filename))
73
+ )
74
+ } else {
75
+ res[locale] = {}
76
+ }
77
+ }
78
+ return res
79
+ }, {})
80
+ }
81
+
82
+ function resolveI18nLocale (platfrom, locales, locale) {
83
+ if (locale && locales.includes(locale)) {
84
+ return locale
85
+ }
86
+ const defaultLocales = ['zh-Hans', 'zh-Hant']
87
+ if (platfrom === 'app' || platfrom === 'h5') {
88
+ defaultLocales.unshift('en')
89
+ } else {
90
+ // 小程序
91
+ defaultLocales.push('en')
92
+ }
93
+ return defaultLocales.find(locale => locales.includes(locale)) || locales[0]
94
+ }
95
+
96
+ module.exports = {
97
+ initLocales,
98
+ initI18nOptions
99
+ }
package/lib/url-loader.js CHANGED
@@ -1,22 +1,8 @@
1
- const path = require('path')
2
-
3
- const isWin = /^win/.test(process.platform)
4
-
5
- const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path)
1
+ const fileLoader = require('./file-loader.js')
6
2
 
7
3
  const defaultOptions = {
8
4
  limit: -1,
9
- fallback: {
10
- loader: 'file-loader',
11
- options: {
12
- publicPath (url, resourcePath, context) {
13
- return '/' + normalizePath(path.relative(process.env.UNI_INPUT_DIR, resourcePath))
14
- },
15
- outputPath (url, resourcePath, context) {
16
- return normalizePath(path.relative(process.env.UNI_INPUT_DIR, resourcePath))
17
- }
18
- }
19
- }
5
+ fallback: fileLoader
20
6
  }
21
7
 
22
8
  const inlineLimit =
@@ -60,4 +46,4 @@ module.exports = {
60
46
  }
61
47
  },
62
48
  rewriteUrl
63
- }
49
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "2.0.0-32620210831002",
3
+ "version": "2.0.0-32920211029001",
4
4
  "description": "uni-cli-shared",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -23,5 +23,5 @@
23
23
  "postcss-urlrewrite": "^0.2.2",
24
24
  "strip-json-comments": "^2.0.1"
25
25
  },
26
- "gitHead": "7c737dd6ca9e9001216a91e0bd98362200bff617"
26
+ "gitHead": "9577a22e00e4b90c8830d34f5966f1d379b455ea"
27
27
  }