@dcloudio/uni-cli-shared 2.0.1-alpha-36820221027001 → 2.0.1-alpha-36920221111002

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.
@@ -161,13 +161,6 @@ export default {
161
161
  },
162
162
  isLookup () {
163
163
  return (Array.isArray(this.collection) && this.collection.length > 1) || (typeof this.collection === 'string' && this.collection.indexOf(',') > -1)
164
- },
165
- mainCollection () {
166
- if (typeof this.collection === 'string') {
167
- return this.collection.split(',')[0]
168
- }
169
- const mainQuery = JSON.parse(JSON.stringify(this.collection[0]))
170
- return mainQuery.$db[0].$param[0]
171
164
  }
172
165
  },
173
166
  created () {
@@ -335,7 +328,7 @@ export default {
335
328
  db = db.action(action)
336
329
  }
337
330
 
338
- db.collection(this.mainCollection).add(value).then((res) => {
331
+ db.collection(this.getMainCollection()).add(value).then((res) => {
339
332
  success && success(res)
340
333
  if (showToast) {
341
334
  uni.showToast({
@@ -409,7 +402,7 @@ export default {
409
402
  db = db.action(action)
410
403
  }
411
404
 
412
- return db.collection(this.mainCollection).doc(id).update(value).then((res) => {
405
+ return db.collection(this.getMainCollection()).doc(id).update(value).then((res) => {
413
406
  success && success(res)
414
407
  if (showToast) {
415
408
  uni.showToast({
@@ -431,6 +424,13 @@ export default {
431
424
  complete && complete()
432
425
  })
433
426
  },
427
+ getMainCollection () {
428
+ if (typeof this.collection === 'string') {
429
+ return this.collection.split(',')[0]
430
+ }
431
+ const mainQuery = JSON.parse(JSON.stringify(this.collection[0]))
432
+ return mainQuery.$db[0].$param[0]
433
+ },
434
434
  getTemp (isTemp = true) {
435
435
  /* eslint-disable no-undef */
436
436
  let db = uniCloud.database(this.spaceInfo)
@@ -590,7 +590,7 @@ export default {
590
590
  exec = exec.action(action)
591
591
  }
592
592
 
593
- exec.collection(this.mainCollection).where({
593
+ exec.collection(this.getMainCollection()).where({
594
594
  _id: dbCmd.in(ids)
595
595
  }).remove().then((res) => {
596
596
  success && success(res.result)
package/lib/index.js CHANGED
@@ -65,6 +65,8 @@ const {
65
65
 
66
66
  const uts = require('./uts')
67
67
 
68
+ const { parseTheme, initTheme } = require('./theme')
69
+
68
70
  module.exports = {
69
71
  uts,
70
72
  md5,
@@ -115,5 +117,7 @@ module.exports = {
115
117
  getPlatformGlobal,
116
118
  getPlatformStat,
117
119
  getPlatformPush,
118
- getPlatformUniCloud
119
- }
120
+ getPlatformUniCloud,
121
+ parseTheme,
122
+ initTheme
123
+ }
package/lib/theme.js CHANGED
@@ -1,23 +1,23 @@
1
1
  const fs = require('fs')
2
2
  const path = require('path')
3
+ const { parseJson, getJson } = require('./json')
3
4
 
4
- const {
5
- getJson
6
- } = require('./json')
5
+ let themeConfig = {}
7
6
 
8
7
  function parseThemeByJsonStr (jsonStr, keys, theme) {
9
8
  if (jsonStr.indexOf('@') === -1) {
10
9
  return jsonStr
11
10
  }
12
11
  keys.forEach(key => {
13
- jsonStr = jsonStr.replace(new RegExp('@' + key, 'g'), theme[key])
12
+ jsonStr = jsonStr.replace(new RegExp('@' + key, 'g'), $1 => {
13
+ return theme[key] || $1
14
+ })
14
15
  })
15
16
  return jsonStr
16
17
  }
17
18
 
18
- const themeJsonPath = path.join(process.env.UNI_INPUT_DIR, 'theme.json')
19
-
20
- function hasTheme () {
19
+ function hasTheme (themeLocation = 'theme.json') {
20
+ const themeJsonPath = path.join(process.env.UNI_INPUT_DIR, themeLocation)
21
21
  return fs.existsSync(themeJsonPath)
22
22
  }
23
23
 
@@ -26,24 +26,27 @@ function darkmode () {
26
26
  }
27
27
 
28
28
  module.exports = {
29
+ getTheme: () => themeConfig,
29
30
  darkmode,
30
31
  hasTheme,
31
- initTheme () {
32
- if (!hasTheme()) {
32
+ initTheme (manifestJson = {}) {
33
+ const platform = process.env.UNI_PLATFORM
34
+ const themeLocation = (manifestJson[platform] || {}).themeLocation || 'theme.json'
35
+ if (!hasTheme(themeLocation)) {
33
36
  return
34
37
  }
35
38
  if (darkmode()) {
36
39
  return
37
40
  }
38
41
  try {
39
- const theme = getJson('theme.json', true)
40
- global.uniPlugin.defaultTheme = theme.light
42
+ themeConfig = Object.keys(themeConfig).length ? themeConfig : getJson(themeLocation, true)
43
+ global.uniPlugin.defaultTheme = themeConfig.light
41
44
  } catch (e) {
42
45
  console.error(e)
43
46
  }
44
47
  },
45
- parseTheme (json) {
46
- const theme = global.uniPlugin.defaultTheme
48
+ parseTheme (json, _theme) {
49
+ const theme = themeConfig[_theme] || global.uniPlugin.defaultTheme
47
50
  if (!theme) {
48
51
  return json
49
52
  }
@@ -55,5 +58,16 @@ module.exports = {
55
58
  return parseThemeByJsonStr(json, keys, theme)
56
59
  }
57
60
  return JSON.parse(parseThemeByJsonStr(JSON.stringify(json), keys, theme))
61
+ },
62
+ copyMiniProgramThemeJson (platformOptions, vueOptions) {
63
+ const themeLocation = platformOptions.themeLocation || 'theme.json'
64
+ if (hasTheme(themeLocation)) {
65
+ platformOptions.themeLocation = themeLocation
66
+ return {
67
+ from: path.resolve(process.env.UNI_INPUT_DIR, platformOptions.themeLocation),
68
+ to: path.resolve(process.env.UNI_OUTPUT_DIR, platformOptions.themeLocation),
69
+ transform: content => JSON.stringify(parseJson(content.toString(), true))
70
+ }
71
+ }
58
72
  }
59
- }
73
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "2.0.1-alpha-36820221027001",
3
+ "version": "2.0.1-alpha-36920221111002",
4
4
  "description": "uni-cli-shared",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -25,5 +25,5 @@
25
25
  "postcss-urlrewrite": "^0.2.2",
26
26
  "strip-json-comments": "^2.0.1"
27
27
  },
28
- "gitHead": "40924371d61653884f7ca66ee0b301fef31bd59d"
28
+ "gitHead": "dc2bac7acb55d4569841b7487b4968ff7dc834c6"
29
29
  }