feat: Add automatic version.js generation

This commit is contained in:
2024-06-22 12:01:59 -04:00
parent cb3c1ab05f
commit 68c242ae81
7 changed files with 38 additions and 12 deletions

3
.gitignore vendored
View File

@@ -35,3 +35,6 @@ yarn-error.log*
# local .env files
.env*
# version file
src/version.js

26
generate-version.js Normal file
View File

@@ -0,0 +1,26 @@
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
try {
// Run semantic-release to get the next version number
const dryRunOutput = execSync('npx semantic-release --dry-run').toString();
// Extract the version number from the semantic-release output
const versionMatch = dryRunOutput.match(/next version in .* is ([\d.]+)/);
if (!versionMatch) {
throw new Error('Version number not found in semantic-release output');
}
const version = versionMatch[1];
// Create version content
const versionContent = `export const APP_VERSION = '${version}';\n`;
const versionFilePath = path.resolve(__dirname, 'src/version.js');
// Write version to file
fs.writeFileSync(versionFilePath, versionContent, 'utf8');
console.log(`Version file generated with version: ${version}`);
} catch (error) {
console.error('Error generating version file:', error);
process.exit(1);
}

View File

@@ -6,11 +6,12 @@
"author": "Patrick Toal <ptoal@takeflight.ca>",
"private": true,
"scripts": {
"generate-version": "node generate-version.js",
"lint": "eslint --ext .js,.ts,.vue ./",
"format": "prettier --write \"**/*.{js,ts,vue,scss,html,md,json}\" --ignore-path .gitignore",
"test": "echo \"No test specified\" && exit 0",
"dev": "quasar dev",
"build": "quasar build"
"dev": "npm run generate-version && quasar dev",
"build": "npm run generate-version && quasar build"
},
"dependencies": {
"@quasar/extras": "^1.16.11",

View File

@@ -50,11 +50,6 @@ module.exports = configure(function ({ dev }) {
// Full list of options: https://v2.quasar.dev/quasar-cli-vite/quasar-config-js#build
build: {
env: {
VUE_APP_VERSION: dev
? 'dev-' + gitCommitInfo().shortHash
: packageJson.version,
},
target: {
browser: ['es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1'],
node: 'node16',

View File

@@ -11,7 +11,7 @@
<q-toolbar-title>{{ pageTitle }}</q-toolbar-title>
<q-space />
<div>v{{ VERSION }}</div>
<div>v{{ APP_VERSION }}</div>
</q-toolbar>
</q-header>
<LeftDrawer
@@ -22,8 +22,7 @@
<script setup lang="ts">
import { ref } from 'vue';
import LeftDrawer from 'components/LeftDrawer.vue';
const VERSION = process.env.VUE_APP_VERSION;
import APP_VERSION from 'version.js';
const leftDrawerOpen = ref(false);
function toggleLeftDrawer() {

View File

@@ -83,13 +83,14 @@ import { Dialog, Notify } from 'quasar';
import { useAuthStore } from 'src/stores/auth';
import { useRouter } from 'vue-router';
import { AppwriteException } from 'appwrite';
import { APP_VERSION } from 'version.js';
const email = ref('');
const token = ref('');
const userId = ref();
const router = useRouter();
console.log('version:' + process.env.VUE_APP_VERSION);
console.log('version:' + APP_VERSION);
const doTokenLogin = async () => {
const authStore = useAuthStore();

View File

@@ -61,12 +61,13 @@ import { useAuthStore } from 'src/stores/auth';
import NewPasswordComponent from 'src/components/NewPasswordComponent.vue';
import { Dialog } from 'quasar';
import { useRouter } from 'vue-router';
import { APP_VERSION } from 'version.js';
const email = ref('');
const password = ref('');
const router = useRouter();
console.log('version:' + process.env.VUE_APP_VERSION);
console.log('version:' + APP_VERSION);
const doRegister = async () => {
if (email.value && password.value) {