提交 a5e95f2c 编写于 作者: Q qiang

fix: 统一 androidPrivacy.json 文件拷贝逻辑

上级 6c994bec
......@@ -13,6 +13,12 @@ const {
getTemplatePath
} = require('@dcloudio/uni-cli-shared')
const fileLoader = require('@dcloudio/uni-cli-shared/lib/file-loader')
const {
compileI18nJsonStr
} = require('@dcloudio/uni-i18n')
const {
initI18nOptions
} = require('@dcloudio/uni-cli-shared/lib/i18n')
const WebpackAppPlusNVuePlugin = process.env.UNI_USING_V3
? require('../packages/webpack-app-plus-plugin')
: require('../packages/webpack-app-plus-nvue-plugin')
......@@ -226,11 +232,25 @@ if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) {
}]
// 自动化测试时,不启用androidPrivacy.json
if (!process.env.UNI_AUTOMATOR_WS_ENDPOINT) {
const androidPrivacyPath = path.resolve(process.env.UNI_INPUT_DIR, 'androidPrivacy.json')
if (fs.existsSync(androidPrivacyPath)) {
const fileName = 'androidPrivacy.json'
const context = path.resolve(process.env.UNI_INPUT_DIR)
if (fs.existsSync(path.join(context, fileName))) {
patterns.push({
from: androidPrivacyPath,
to: 'androidPrivacy.json'
from: fileName,
context,
to: fileName,
transform (content) {
const options = initI18nOptions(
process.env.UNI_PLATFORM,
process.env.UNI_INPUT_DIR,
false,
true
)
if (!options) {
return content
}
return compileI18nJsonStr(content.toString(), options)
}
})
}
}
......
......@@ -92,16 +92,14 @@ function getCopyWebpackPluginOptions (platformOptions, vueOptions) {
})
// 自动化测试时,不启用androidPrivacy.json
if (process.env.UNI_PLATFORM === 'app-plus' && !process.env.UNI_AUTOMATOR_WS_ENDPOINT) {
const from = 'android*.json'
const fileName = 'androidPrivacy.json'
const context = path.resolve(process.env.UNI_INPUT_DIR)
const options = {
from,
context,
to: `[name]${CopyWebpackPluginVersion > 5 ? '' : '.'}[ext]`,
noErrorOnMissing: true,
transform (content, path) {
if (path.endsWith(fileName)) {
if (fs.existsSync(path.join(context, fileName))) {
copyOptions.push({
from: fileName,
context,
to: fileName,
transform (content) {
const options = initI18nOptions(
process.env.UNI_PLATFORM,
process.env.UNI_INPUT_DIR,
......@@ -113,22 +111,7 @@ function getCopyWebpackPluginOptions (platformOptions, vueOptions) {
}
return compileI18nJsonStr(content.toString(), options)
}
return content
}
}
// copy-webpack-plugin/glob-parent 存在 Bug,例如:/test/dir(1
const globParent = require(require.resolve('glob-parent', { paths: [require.resolve('copy-webpack-plugin')] }))
const parent = globParent(path.join(context, from))
let canNotWatch
if (parent !== context) {
options.from = fileName
if (!fs.existsSync(path.join(context, fileName))) {
canNotWatch = true
// console.warn(`invalid path: ${context}, can not watch ${fileName}`)
}
}
if (!canNotWatch) {
copyOptions.push(options)
})
}
}
return copyOptions
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册