Skip to content

Commit 82c77c9

Browse files
feat: add lottie resources for widgets (#107)
Signed-off-by: Yingchun <zhangyingchun@oppo.com>
1 parent 6e010d4 commit 82c77c9

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

packages/hap-packager/src/plugins/resource-plugin.js

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function getSpecifiedJSONFiles(sourceDir, specifiedDirArray) {
9292
return filesArray
9393
}
9494

95-
function getWidgetI18nJSONFiles(sourceDir) {
95+
function getWidgetJSONFiles(sourceDir, specifiedDirArray) {
9696
let widgetsOption = {}
9797
try {
9898
const manifestFile = path.join(sourceDir, 'manifest.json')
@@ -107,16 +107,20 @@ function getWidgetI18nJSONFiles(sourceDir) {
107107
widgetsOption[key].path = key
108108
}
109109
const widgetPath = widgetsOption[key].path
110-
const dir = path.join(sourceDir, widgetPath, 'i18n')
111-
// const jsonPath = onlyRoot ? '*.json' : '**/**.json'
112-
if (fs.existsSync(dir)) {
113-
filesArray = filesArray.concat(getFiles('*.json', dir))
114-
}
110+
specifiedDirArray.map((specifiedDir) => {
111+
const { directoryName, onlyRoot = false } = specifiedDir
112+
const dir = path.join(sourceDir, widgetPath, directoryName)
113+
if (fs.existsSync(dir)) {
114+
// onlyRoot: 是否仅遍历根目录
115+
const jsonPath = onlyRoot ? '*.json' : '**/**.json'
116+
filesArray = filesArray.concat(getFiles(jsonPath, dir))
117+
}
118+
})
115119
}
116120
return filesArray
117121
}
118122

119-
function minifyWidgetI18nJSONFiles(targetDir) {
123+
function minifyWidgetJSONFiles(targetDir, specifiedDirArray) {
120124
let widgetsOption = {}
121125
try {
122126
const manifestFile = path.join(targetDir, 'manifest.json')
@@ -131,17 +135,23 @@ function minifyWidgetI18nJSONFiles(targetDir) {
131135
widgetsOption[key].path = key
132136
}
133137
const widgetPath = widgetsOption[key].path
134-
const dir = path.join(targetDir, widgetPath, 'i18n')
135-
// 轻卡和写了minCardPlatformVersion的新打包格式的JS卡会进行多语言扁平化处理
136-
const needFlatten =
137-
widgetsOption[key].type === 'lite' || widgetsOption[key].minCardPlatformVersion
138-
if (fs.existsSync(dir)) {
139-
const jsonFiles = getFiles('*.json', dir)
140-
jsonFiles.forEach((filePath) => {
141-
arr.push(filePath)
142-
minifyJson(filePath, filePath, needFlatten)
143-
})
144-
}
138+
specifiedDirArray.map((specifiedDir) => {
139+
const { directoryName, onlyRoot = false } = specifiedDir
140+
const dir = path.join(targetDir, widgetPath, directoryName)
141+
// 轻卡和写了minCardPlatformVersion的新打包格式的JS卡会进行多语言扁平化处理
142+
const needFlatten =
143+
directoryName === I18N_DIRECTORY &&
144+
(widgetsOption[key].type === 'lite' || widgetsOption[key].minCardPlatformVersion)
145+
if (fs.existsSync(dir)) {
146+
// onlyRoot: 是否仅遍历根目录
147+
const jsonPath = onlyRoot ? '*.json' : '**/**.json'
148+
const jsonFiles = getFiles(jsonPath, dir)
149+
jsonFiles.forEach((filePath) => {
150+
arr.push(filePath)
151+
minifyJson(filePath, filePath, needFlatten)
152+
})
153+
}
154+
})
145155
}
146156
}
147157

@@ -240,7 +250,7 @@ ResourcePlugin.prototype.apply = function (compiler) {
240250
let files = getFiles(`**/+(!(${EXT_PATTERN})|manifest.json|sitemap.json)`, sourceDir)
241251
files = files.concat(
242252
getSpecifiedJSONFiles(sourceDir, JSON_DIRECTORY_NEED_PACKAGING),
243-
getWidgetI18nJSONFiles(sourceDir),
253+
getWidgetJSONFiles(sourceDir, JSON_DIRECTORY_NEED_PACKAGING),
244254
getSkeletonConfigFile(sourceDir)
245255
)
246256
let iconPath
@@ -375,7 +385,7 @@ ResourcePlugin.prototype.apply = function (compiler) {
375385

376386
minifySpecifiedJSONFiles(targetDir, JSON_DIRECTORY_NEED_PACKAGING)
377387

378-
minifyWidgetI18nJSONFiles(targetDir)
388+
minifyWidgetJSONFiles(targetDir, JSON_DIRECTORY_NEED_PACKAGING)
379389

380390
minifySitemap(targetDir)
381391

0 commit comments

Comments
 (0)