Skip to content

Commit

Permalink
handle distro strings res in dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
baurine committed Dec 13, 2021
1 parent bf366b6 commit be284ab
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 224 deletions.
213 changes: 0 additions & 213 deletions ui/builder.js

This file was deleted.

33 changes: 24 additions & 9 deletions ui/config-overrides.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('path')
const fs = require('fs')
const fs = require('fs-extra')
const os = require('os')
const {
override,
Expand All @@ -17,16 +17,31 @@ const WebpackBar = require('webpackbar')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const rewireHtmlWebpackPlugin = require('react-app-rewire-html-webpack-plugin')

function copyDistroRes() {
const distroResPath = '../bin/distro-res'
if (fs.existsSync(distroResPath)) {
fs.copySync(distroResPath, './public/distro-res')
}
}

function injectDistroToHTML(config, env) {
const distroInfo = Object.entries(require('./lib/distribution.json')).reduce(
(prev, [k, v]) => {
return {
...prev,
[`distro_${k}`]: v,
}
let distroStringsResMeta = '__DISTRO_STRINGS_RES__'

if (isBuildAsDevServer()) {
copyDistroRes()

const distroStringsResFilePath = './public/distro-res/strings.json'
if (fs.existsSync(distroStringsResFilePath)) {
const distroStringsRes = require(distroStringsResFilePath)
distroStringsResMeta = btoa(JSON.stringify(distroStringsRes))
}
}

const distroInfo = {
meta: {
'x-distro-strings-res': distroStringsResMeta,
},
{}
)
}
return rewireHtmlWebpackPlugin(config, env, distroInfo)
}

Expand Down
1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"browserslist-useragent-regexp": "^2.1.0",
"customize-cra": "^1.0.0",
"esm": "^3.2.25",
"fs-extra": "^10.0.0",
"gulp": "^4.0.2",
"gulp-cli": "^2.3.0",
"gulp-shell": "^0.8.0",
Expand Down
1 change: 0 additions & 1 deletion ui/public/diagnoseReport.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html>
<head>
<meta charset="utf-8" />
<meta name="x-distro-strings-res" content="__DISTRO_STRINGS_RES__" />
<link rel="icon" href="%PUBLIC_URL%/distro-res/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="./data.js"></script>
Expand Down
1 change: 0 additions & 1 deletion ui/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<head>
<meta charset="utf-8" />
<meta name="x-public-path-prefix" content="__PUBLIC_PATH_PREFIX__" />
<meta name="x-distro-strings-res" content="__DISTRO_STRINGS_RES__" />
<link rel="icon" href="%PUBLIC_URL%/distro-res/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
Expand Down
9 changes: 9 additions & 0 deletions ui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8216,6 +8216,15 @@ fs-extra@^0.30.0:
path-is-absolute "^1.0.0"
rimraf "^2.2.8"

fs-extra@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1"
integrity sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^2.0.0"

fs-extra@^7.0.0:
version "7.0.1"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9"
Expand Down

0 comments on commit be284ab

Please sign in to comment.