forked from mystiq/hydrogen-web
use vite define option to inject version number everywhere
This commit is contained in:
parent
216afd45cc
commit
923a1a2057
6 changed files with 15 additions and 11 deletions
|
@ -10,6 +10,7 @@ function contentHash(str) {
|
||||||
|
|
||||||
module.exports = function injectServiceWorker(swFile) {
|
module.exports = function injectServiceWorker(swFile) {
|
||||||
let root;
|
let root;
|
||||||
|
let version;
|
||||||
let manifestHref;
|
let manifestHref;
|
||||||
return {
|
return {
|
||||||
name: "injectServiceWorker",
|
name: "injectServiceWorker",
|
||||||
|
@ -17,11 +18,11 @@ module.exports = function injectServiceWorker(swFile) {
|
||||||
enforce: "post",
|
enforce: "post",
|
||||||
configResolved: config => {
|
configResolved: config => {
|
||||||
root = config.root;
|
root = config.root;
|
||||||
|
version = JSON.parse(config.define.HYDROGEN_VERSION); // unquote
|
||||||
},
|
},
|
||||||
generateBundle: async function(_, bundle) {
|
generateBundle: async function(_, bundle) {
|
||||||
const absoluteSwFile = path.resolve(root, swFile);
|
const absoluteSwFile = path.resolve(root, swFile);
|
||||||
const packageManifest = path.resolve(path.join(__dirname, "../../package.json"));
|
const packageManifest = path.resolve(path.join(__dirname, "../../package.json"));
|
||||||
const version = JSON.parse(await fs.readFile(packageManifest, "utf8")).version;
|
|
||||||
let swSource = await fs.readFile(absoluteSwFile, {encoding: "utf8"});
|
let swSource = await fs.readFile(absoluteSwFile, {encoding: "utf8"});
|
||||||
const assets = Object.values(bundle).filter(a => a.type === "asset");
|
const assets = Object.values(bundle).filter(a => a.type === "asset");
|
||||||
const cachedFileNames = assets.map(o => o.fileName).filter(fileName => fileName !== "index.html");
|
const cachedFileNames = assets.map(o => o.fileName).filter(fileName => fileName !== "index.html");
|
||||||
|
|
|
@ -265,7 +265,7 @@ export class Platform {
|
||||||
}
|
}
|
||||||
|
|
||||||
get version() {
|
get version() {
|
||||||
return window.HYDROGEN_VERSION;
|
return HYDROGEN_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
|
|
|
@ -181,7 +181,7 @@ export class ServiceWorkerHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
get version() {
|
get version() {
|
||||||
return window.HYDROGEN_VERSION;
|
return HYDROGEN_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
get buildHash() {
|
get buildHash() {
|
||||||
|
|
|
@ -16,10 +16,6 @@
|
||||||
<link rel="alternate stylesheet" type="text/css" href="./ui/css/themes/bubbles/theme.css" title="Bubbles Theme">
|
<link rel="alternate stylesheet" type="text/css" href="./ui/css/themes/bubbles/theme.css" title="Bubbles Theme">
|
||||||
</head>
|
</head>
|
||||||
<body class="hydrogen">
|
<body class="hydrogen">
|
||||||
<script id="version" type="disabled">
|
|
||||||
window.HYDROGEN_VERSION = "%%VERSION%%";
|
|
||||||
window.HYDROGEN_GLOBAL_HASH = "%%GLOBAL_HASH%%";
|
|
||||||
</script>
|
|
||||||
<script id="main" type="module">
|
<script id="main" type="module">
|
||||||
import {main} from "./main";
|
import {main} from "./main";
|
||||||
import {Platform} from "./Platform";
|
import {Platform} from "./Platform";
|
||||||
|
|
|
@ -15,10 +15,10 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function hydrogenGithubLink(t) {
|
export function hydrogenGithubLink(t) {
|
||||||
if (window.HYDROGEN_VERSION) {
|
if (HYDROGEN_VERSION) {
|
||||||
return t.a({target: "_blank",
|
return t.a({target: "_blank",
|
||||||
href: `https://github.com/vector-im/hydrogen-web/releases/tag/v${window.HYDROGEN_VERSION}`},
|
href: `https://github.com/vector-im/hydrogen-web/releases/tag/v${HYDROGEN_VERSION}`},
|
||||||
`Hydrogen v${window.HYDROGEN_VERSION} (${window.HYDROGEN_GLOBAL_HASH}) on Github`);
|
`Hydrogen v${HYDROGEN_VERSION} (${window.HYDROGEN_GLOBAL_HASH}) on Github`);
|
||||||
} else {
|
} else {
|
||||||
return t.a({target: "_blank", href: "https://github.com/vector-im/hydrogen-web"},
|
return t.a({target: "_blank", href: "https://github.com/vector-im/hydrogen-web"},
|
||||||
"Hydrogen on Github");
|
"Hydrogen on Github");
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
const injectWebManifest = require("./scripts/build-plugins/manifest");
|
const injectWebManifest = require("./scripts/build-plugins/manifest");
|
||||||
const injectServiceWorker = require("./scripts/build-plugins/service-worker");
|
const injectServiceWorker = require("./scripts/build-plugins/service-worker");
|
||||||
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
const version = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8")).version;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
public: false,
|
public: false,
|
||||||
|
@ -22,5 +26,8 @@ export default {
|
||||||
plugins: [
|
plugins: [
|
||||||
injectWebManifest("assets/manifest.json"),
|
injectWebManifest("assets/manifest.json"),
|
||||||
injectServiceWorker("sw.js")
|
injectServiceWorker("sw.js")
|
||||||
]
|
],
|
||||||
|
define: {
|
||||||
|
"HYDROGEN_VERSION": JSON.stringify(version)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue