From d195ef281d42c5da5140cb1a18adba3c238e2f91 Mon Sep 17 00:00:00 2001 From: blckmn Date: Sat, 14 Oct 2023 18:01:23 +1100 Subject: [PATCH 1/5] Adding version details to the PWA --- src/js/main.js | 4 ++++ vite.config.js | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/src/js/main.js b/src/js/main.js index a3b1366e46..270ddc8c38 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -55,6 +55,10 @@ function readConfiguratorVersionMetadata() { CONFIGURATOR.productName = manifest.productName; CONFIGURATOR.version = manifest.version; CONFIGURATOR.gitRevision = manifest.gitRevision; + } else { + CONFIGURATOR.productName = __APP_PRODUCTNAME__; + CONFIGURATOR.version = __APP_VERSION__; + CONFIGURATOR.gitRevision = __APP_REVISION__; } } diff --git a/vite.config.js b/vite.config.js index 3baee1093b..bdc1084340 100644 --- a/vite.config.js +++ b/vite.config.js @@ -4,6 +4,9 @@ import vue from "@vitejs/plugin-vue2"; import path from "node:path"; import { readFileSync } from "node:fs"; import copy from "rollup-plugin-copy"; +import pkg from './package.json' + +const childProcess = require('child_process'); function serveFileFromDirectory(directory) { return (req, res, next) => { @@ -46,6 +49,11 @@ function serveLocalesPlugin() { } export default defineConfig({ + define: { + '__APP_VERSION__': JSON.stringify(pkg.version), + '__APP_PRODUCTNAME__': JSON.stringify(pkg.productName), + '__APP_REVISION__': JSON.stringify(childProcess.execSync("git rev-parse --short HEAD").toString().trim()), + }, test: { // NOTE: this is a replacement location for karma tests. // moving forward we should colocate tests with the From b313423d666349c6708b61b664ab05a9d7170adf Mon Sep 17 00:00:00 2001 From: blckmn Date: Mon, 16 Oct 2023 14:08:06 +1100 Subject: [PATCH 2/5] Created a coded version.js that can be loaded as a module. --- .eslintrc.js | 2 +- .gitignore | 2 ++ gulpfile.js | 10 ++++++++++ src/js/main.js | 7 ++++--- vite.config.js | 22 +++++++++++++++------- 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 9d35205b6b..e804e07863 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -39,5 +39,5 @@ module.exports = { // end cordova bindings }, // ignore src/dist folders - ignorePatterns: ["src/dist/*"], + ignorePatterns: ["src/dist/*", "src/js/version.js"], }; diff --git a/.gitignore b/.gitignore index 6bc82eee84..47a05ccdd6 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,5 @@ nbproject/ .settings/ test-results-junit/ /src/package.json +/src/version.json +/src/js/version.js diff --git a/gulpfile.js b/gulpfile.js index 0925af6e4c..580fad94a1 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -297,6 +297,16 @@ function processPackage(done, gitRevision, isReleaseBuild) { metadata.packageId = pkg.name; } + const version = { + productName: pkg.productName, + version: pkg.version, + gitRevision: gitRevision, + buildDate: new Date(), + }; + + const output = `const version = ${JSON.stringify(version, null, 2)};\nexport default version;\n`; + fs.writeFileSync('./src/js/version.js', output); + function version_prompt() { return gulp.src('.') .pipe(prompt.prompt([{ diff --git a/src/js/main.js b/src/js/main.js index 270ddc8c38..1e95322a6d 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -21,6 +21,7 @@ import { updateTabList } from './utils/updateTabList.js'; import { checkForConfiguratorUpdates } from './utils/checkForConfiguratorUpdates.js'; import * as THREE from 'three'; import * as d3 from 'd3'; +import version from './version.js'; if (typeof String.prototype.replaceAll === "undefined") { String.prototype.replaceAll = function(match, replace) { @@ -56,9 +57,9 @@ function readConfiguratorVersionMetadata() { CONFIGURATOR.version = manifest.version; CONFIGURATOR.gitRevision = manifest.gitRevision; } else { - CONFIGURATOR.productName = __APP_PRODUCTNAME__; - CONFIGURATOR.version = __APP_VERSION__; - CONFIGURATOR.gitRevision = __APP_REVISION__; + CONFIGURATOR.productName = version.productName; + CONFIGURATOR.version = version.version; + CONFIGURATOR.gitRevision = version.gitRevision; } } diff --git a/vite.config.js b/vite.config.js index bdc1084340..8b97755413 100644 --- a/vite.config.js +++ b/vite.config.js @@ -2,11 +2,23 @@ import { defineConfig } from "vite"; import vue from "@vitejs/plugin-vue2"; import path from "node:path"; -import { readFileSync } from "node:fs"; +import { readFileSync, writeFileSync } from "node:fs"; import copy from "rollup-plugin-copy"; import pkg from './package.json' -const childProcess = require('child_process'); +function appVersion() { + const childProcess = require('child_process'); + + const version = { + productName: pkg.productName, + version: pkg.version, + gitRevision: childProcess.execSync("git rev-parse --short HEAD").toString().trim(), + buildDate: new Date(), + }; + + const output = `const version = ${JSON.stringify(version, null, 2)};\nexport default version;\n`; + writeFileSync('./src/js/version.js', output); +} function serveFileFromDirectory(directory) { return (req, res, next) => { @@ -49,11 +61,6 @@ function serveLocalesPlugin() { } export default defineConfig({ - define: { - '__APP_VERSION__': JSON.stringify(pkg.version), - '__APP_PRODUCTNAME__': JSON.stringify(pkg.productName), - '__APP_REVISION__': JSON.stringify(childProcess.execSync("git rev-parse --short HEAD").toString().trim()), - }, test: { // NOTE: this is a replacement location for karma tests. // moving forward we should colocate tests with the @@ -65,6 +72,7 @@ export default defineConfig({ }, plugins: [ vue(), + appVersion(), serveLocalesPlugin(), copy({ targets: [ From 8ca7e971030d523c02f48b59e01aa9745d9576f3 Mon Sep 17 00:00:00 2001 From: blckmn Date: Tue, 17 Oct 2023 07:05:57 +1100 Subject: [PATCH 3/5] Reverting, and simply identifying the permissible global vars for Vite --- .eslintrc.js | 7 ++++++- .gitignore | 2 -- gulpfile.js | 10 ---------- src/js/main.js | 7 +++---- vite.config.js | 22 +++++++--------------- 5 files changed, 16 insertions(+), 32 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index e804e07863..62cd563da7 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -37,7 +37,12 @@ module.exports = { cordovaChromeapi: true, appAvailability: true, // end cordova bindings + + // globals for vite + __APP_PRODUCTNAME__: "readonly", + __APP_VERSION__: "readonly", + __APP_REVISION__: "readonly", }, // ignore src/dist folders - ignorePatterns: ["src/dist/*", "src/js/version.js"], + ignorePatterns: ["src/dist/*"], }; diff --git a/.gitignore b/.gitignore index 47a05ccdd6..6bc82eee84 100644 --- a/.gitignore +++ b/.gitignore @@ -33,5 +33,3 @@ nbproject/ .settings/ test-results-junit/ /src/package.json -/src/version.json -/src/js/version.js diff --git a/gulpfile.js b/gulpfile.js index 580fad94a1..0925af6e4c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -297,16 +297,6 @@ function processPackage(done, gitRevision, isReleaseBuild) { metadata.packageId = pkg.name; } - const version = { - productName: pkg.productName, - version: pkg.version, - gitRevision: gitRevision, - buildDate: new Date(), - }; - - const output = `const version = ${JSON.stringify(version, null, 2)};\nexport default version;\n`; - fs.writeFileSync('./src/js/version.js', output); - function version_prompt() { return gulp.src('.') .pipe(prompt.prompt([{ diff --git a/src/js/main.js b/src/js/main.js index 1e95322a6d..270ddc8c38 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -21,7 +21,6 @@ import { updateTabList } from './utils/updateTabList.js'; import { checkForConfiguratorUpdates } from './utils/checkForConfiguratorUpdates.js'; import * as THREE from 'three'; import * as d3 from 'd3'; -import version from './version.js'; if (typeof String.prototype.replaceAll === "undefined") { String.prototype.replaceAll = function(match, replace) { @@ -57,9 +56,9 @@ function readConfiguratorVersionMetadata() { CONFIGURATOR.version = manifest.version; CONFIGURATOR.gitRevision = manifest.gitRevision; } else { - CONFIGURATOR.productName = version.productName; - CONFIGURATOR.version = version.version; - CONFIGURATOR.gitRevision = version.gitRevision; + CONFIGURATOR.productName = __APP_PRODUCTNAME__; + CONFIGURATOR.version = __APP_VERSION__; + CONFIGURATOR.gitRevision = __APP_REVISION__; } } diff --git a/vite.config.js b/vite.config.js index 8b97755413..bdc1084340 100644 --- a/vite.config.js +++ b/vite.config.js @@ -2,23 +2,11 @@ import { defineConfig } from "vite"; import vue from "@vitejs/plugin-vue2"; import path from "node:path"; -import { readFileSync, writeFileSync } from "node:fs"; +import { readFileSync } from "node:fs"; import copy from "rollup-plugin-copy"; import pkg from './package.json' -function appVersion() { - const childProcess = require('child_process'); - - const version = { - productName: pkg.productName, - version: pkg.version, - gitRevision: childProcess.execSync("git rev-parse --short HEAD").toString().trim(), - buildDate: new Date(), - }; - - const output = `const version = ${JSON.stringify(version, null, 2)};\nexport default version;\n`; - writeFileSync('./src/js/version.js', output); -} +const childProcess = require('child_process'); function serveFileFromDirectory(directory) { return (req, res, next) => { @@ -61,6 +49,11 @@ function serveLocalesPlugin() { } export default defineConfig({ + define: { + '__APP_VERSION__': JSON.stringify(pkg.version), + '__APP_PRODUCTNAME__': JSON.stringify(pkg.productName), + '__APP_REVISION__': JSON.stringify(childProcess.execSync("git rev-parse --short HEAD").toString().trim()), + }, test: { // NOTE: this is a replacement location for karma tests. // moving forward we should colocate tests with the @@ -72,7 +65,6 @@ export default defineConfig({ }, plugins: [ vue(), - appVersion(), serveLocalesPlugin(), copy({ targets: [ From ed82a810a2a80146bbdd82c19b2c7b26e03cf2ef Mon Sep 17 00:00:00 2001 From: J Blackman Date: Tue, 17 Oct 2023 07:10:57 +1100 Subject: [PATCH 4/5] Update .eslintrc.js Removing whitespace --- .eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 62cd563da7..ffd9f2ef1c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -39,7 +39,7 @@ module.exports = { // end cordova bindings // globals for vite - __APP_PRODUCTNAME__: "readonly", + __APP_PRODUCTNAME__: "readonly", __APP_VERSION__: "readonly", __APP_REVISION__: "readonly", }, From d0f08caf4462040f882829567ae9a6da675dfab9 Mon Sep 17 00:00:00 2001 From: J Blackman Date: Tue, 17 Oct 2023 11:43:19 +1100 Subject: [PATCH 5/5] Update vite.config.js --- vite.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vite.config.js b/vite.config.js index bdc1084340..131677365a 100644 --- a/vite.config.js +++ b/vite.config.js @@ -4,7 +4,7 @@ import vue from "@vitejs/plugin-vue2"; import path from "node:path"; import { readFileSync } from "node:fs"; import copy from "rollup-plugin-copy"; -import pkg from './package.json' +import pkg from './package.json'; const childProcess = require('child_process');