Skip to content

Commit 6302bb3

Browse files
feat: support i18n for cards (rfc:0001) (#53)
* feat: support i18n for cards * fix: prettier check err
1 parent 3a1915a commit 6302bb3

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,50 @@ function getSpecifiedJSONFiles(sourceDir, specifiedDirArray) {
8989
return filesArray
9090
}
9191

92+
function getWidgetI18nJSONFiles(sourceDir) {
93+
let widgetsOption = {}
94+
try {
95+
const manifestFile = path.join(sourceDir, 'manifest.json')
96+
const manifest = readJson(manifestFile)
97+
widgetsOption = manifest?.router.widgets || {}
98+
} catch (err) {
99+
console.error(err)
100+
}
101+
let filesArray = []
102+
for (let key in widgetsOption) {
103+
const widgetPath = widgetsOption[key].path
104+
const dir = path.join(sourceDir, widgetPath, 'i18n')
105+
// const jsonPath = onlyRoot ? '*.json' : '**/**.json'
106+
if (fs.existsSync(dir)) {
107+
filesArray = filesArray.concat(getFiles('*.json', dir))
108+
}
109+
}
110+
return filesArray
111+
}
112+
113+
function minifyWidgetI18nJSONFiles(targetDir) {
114+
let widgetsOption = {}
115+
try {
116+
const manifestFile = path.join(targetDir, 'manifest.json')
117+
const manifest = readJson(manifestFile)
118+
widgetsOption = manifest?.router.widgets || {}
119+
} catch (err) {
120+
console.error(err)
121+
}
122+
let arr = []
123+
for (let key in widgetsOption) {
124+
const widgetPath = widgetsOption[key].path
125+
const dir = path.join(targetDir, widgetPath, 'i18n')
126+
if (fs.existsSync(dir)) {
127+
const jsonFiles = getFiles('*.json', dir)
128+
jsonFiles.forEach((filePath) => {
129+
arr.push(filePath)
130+
minifyJson(filePath, filePath)
131+
})
132+
}
133+
}
134+
}
135+
92136
function minifyJson(source, target) {
93137
try {
94138
const contentStr = fs.readFileSync(source, 'utf8')
@@ -181,6 +225,7 @@ ResourcePlugin.prototype.apply = function (compiler) {
181225
let files = getFiles(`**/+(!(${EXT_PATTERN})|manifest.json|sitemap.json)`, sourceDir)
182226
files = files.concat(
183227
getSpecifiedJSONFiles(sourceDir, JSON_DIRECTORY_NEED_PACKAGING),
228+
getWidgetI18nJSONFiles(sourceDir),
184229
getSkeletonConfigFile(sourceDir)
185230
)
186231
let iconPath
@@ -307,6 +352,8 @@ ResourcePlugin.prototype.apply = function (compiler) {
307352

308353
minifySpecifiedJSONFiles(targetDir, JSON_DIRECTORY_NEED_PACKAGING)
309354

355+
minifyWidgetI18nJSONFiles(targetDir)
356+
310357
minifySitemap(targetDir)
311358

312359
minifySkeletonConfig(targetDir)

0 commit comments

Comments
 (0)