提交 33d31247 编写于 作者: D DCloud_LXH

chore: mp theme.json copy

上级 f10317a0
const fs = require('fs')
const path = require('path')
const { parseJson } = require('./json')
const {
getJson
} = require('./json')
const { parseJson, getJson } = require('./json')
let themeConfig = {}
let manifestJsonDarkmode = false
function parseThemeByJsonStr (jsonStr, keys, theme) {
if (jsonStr.indexOf('@') === -1) {
......@@ -27,7 +22,7 @@ function hasTheme (themeLocation = 'theme.json') {
}
function darkmode () {
return manifestJsonDarkmode && !!(global.uniPlugin.options || {}).darkmode
return !!(global.uniPlugin.options || {}).darkmode
}
module.exports = {
......@@ -37,7 +32,6 @@ module.exports = {
initTheme (manifestJson = {}) {
const platform = process.env.UNI_PLATFORM
const themeLocation = (manifestJson[platform] || {}).themeLocation || 'theme.json'
manifestJsonDarkmode = (manifestJson[platform] || {}).darkmode || false
if (!hasTheme(themeLocation)) {
return
}
......@@ -66,11 +60,14 @@ module.exports = {
return JSON.parse(parseThemeByJsonStr(JSON.stringify(json), keys, theme))
},
copyMiniProgramThemeJson (platformOptions, vueOptions) {
platformOptions.themeLocation || (platformOptions.themeLocation = 'theme.json')
return {
from: path.resolve(process.env.UNI_INPUT_DIR, platformOptions.themeLocation),
to: path.resolve(process.env.UNI_OUTPUT_DIR, platformOptions.themeLocation),
transform: content => JSON.stringify(parseJson(content.toString(), true))
const themeLocation = platformOptions.themeLocation || 'theme.json'
if (hasTheme(themeLocation)) {
platformOptions.themeLocation = themeLocation
return {
from: path.resolve(process.env.UNI_INPUT_DIR, platformOptions.themeLocation),
to: path.resolve(process.env.UNI_OUTPUT_DIR, platformOptions.themeLocation),
transform: content => JSON.stringify(parseJson(content.toString(), true))
}
}
}
}
......@@ -18,7 +18,8 @@ const {
const {
initTheme,
parseTheme
parseTheme,
darkmode
} = require('@dcloudio/uni-cli-shared/lib/theme')
const {
......@@ -123,9 +124,12 @@ module.exports = function (content, map) {
process.UNI_TRANSFORM_PX = true
}
if (process.env.VUE_APP_DARK_MODE !== 'true') {
if (
(process.env.UNI_PLATFORM.indexOf('mp') !== -1 && !darkmode()) ||
process.env.VUE_APP_DARK_MODE !== 'true'
) {
const { pages, globalStyle, tabBar } = parseTheme(pagesJson)
Object.assign(pagesJson, { pages, globalStyle, tabBar })
Object.assign(pagesJson, JSON.parse(JSON.stringify({ pages, globalStyle, tabBar })))
}
if (process.env.UNI_PLATFORM === 'h5') {
......
......@@ -258,9 +258,9 @@ module.exports = function (pagesJson, manifestJson, project = {}) {
updateAppJsonUsingComponents(app.usingComponents)
}
if (darkmode() && hasTheme()) {
app.darkmode = true
app.themeLocation = 'theme.json'
const themeLocation = (manifestJson[process.env.UNI_PLATFORM] || {}).themeLocation
if (darkmode() && hasTheme(themeLocation)) {
app.themeLocation = themeLocation || 'theme.json'
}
const projectName = getPlatformProject()
......@@ -376,4 +376,4 @@ module.exports = function (pagesJson, manifestJson, project = {}) {
}
}
}
}
}
......@@ -13,7 +13,7 @@ onThemeChange(() => {
__uniConfig.tabBar.color = tabBarStyle.color
__uniConfig.tabBar.selectedColor = tabBarStyle.selectedColor
__uniConfig.tabBar.blurEffect = tabBarStyle.blurEffect
if (tabBarStyle.list.length && __uniConfig.tabBar.list.length) {
if (tabBarStyle.list && tabBarStyle.list.length && __uniConfig.tabBar.list.length) {
tabBarStyle.list.forEach((item, index) => {
__uniConfig.tabBar.list[index].iconPath = item.iconPath
__uniConfig.tabBar.list[index].selectedIconPath = item.selectedIconPath
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册