Skip to content

Commit

Permalink
Adding version details to the PWA (betaflight#3606)
Browse files Browse the repository at this point in the history
* Adding version details to the PWA

* Created a coded version.js that can be loaded as a module.

* Reverting, and simply identifying the permissible global vars for Vite

* Update .eslintrc.js

Removing whitespace

* Update vite.config.js
  • Loading branch information
blckmn authored Oct 17, 2023
1 parent 16df951 commit d6575e1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ 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/*"],
Expand Down
4 changes: 4 additions & 0 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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__;
}
}

Expand Down
8 changes: 8 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d6575e1

Please sign in to comment.