diff --git a/common/scripts/minify-common-locales.js b/common/scripts/minify-common-locales.js new file mode 100644 index 0000000000..d80ab9d962 --- /dev/null +++ b/common/scripts/minify-common-locales.js @@ -0,0 +1,43 @@ +const { join } = require("path"); +const { readdirSync, readFileSync, writeFileSync } = require("fs"); +const minifyJson = require("../../packages/common/utils/minifyJson.js"); + +const localesDir = join( + __dirname, + "../../../publish", + "web", + "public", + "locales" +); + +//console.log("localesDir", localesDir); + +const getFileList = (dirName) => { + let files = []; + + const items = readdirSync(dirName, { withFileTypes: true }); + + for (const item of items) { + if (item.isDirectory()) { + files = [...files, ...getFileList(`${dirName}/${item.name}`)]; + } else { + files.push(`${dirName}/${item.name}`); + } + } + + return files; +}; + +const files = getFileList(localesDir); + +files.forEach((filePath) => { + try { + if (filePath.endsWith(".DS_Store")) return; + + let content = readFileSync(filePath); + writeFileSync(filePath, minifyJson(content, filePath)); + //console.log(`File '${filePath}' minified`); + } catch (e) { + console.error("Unable to minify file ", filePath, e); + } +}); diff --git a/package.json b/package.json index d90a893716..a6b884305c 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "build": "yarn workspaces foreach -vptiR --from '{@docspace/client,@docspace/login,@docspace/editor}' run build", "bump": "yarn version apply --all", "clean": "yarn workspaces foreach -vptiR run clean", - "deploy": "shx rm -rf ../publish/web && yarn workspaces foreach -ptR --from '{@docspace/client,@docspace/login,@docspace/editor}' run deploy && shx cp -r public ../publish/web/", + "deploy": "shx rm -rf ../publish/web && yarn workspaces foreach -ptR --from '{@docspace/client,@docspace/login,@docspace/editor}' run deploy && shx cp -r public ../publish/web/ && node common/scripts/minify-common-locales.js", "start": "yarn workspaces foreach -vptiR --from '{@docspace/client,@docspace/login,@docspace/editor}' run start", "start-prod": "yarn workspaces foreach -vptiR --from '{@docspace/client,@docspace/login,@docspace/editor}' run start-prod", "storybook": "yarn workspace @docspace/components storybook",