-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
61 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env node | ||
// This script tries to get the version of the app from three sources: | ||
// | ||
// 1. The VUE_APP_GIT_VERSION environment variable | ||
// 2. The latest git tag | ||
// 3. The version field in package.JSON | ||
// | ||
// It can be used as part of the build system to set the | ||
// `VUE_APP_GIT_VERSION` environment variable itself. | ||
|
||
const { execSync } = require("child_process"); | ||
const fs = require("fs"); | ||
|
||
function getPackageJsonVersion() { | ||
try { | ||
const packageJson = JSON.parse(fs.readFileSync("package.json", "utf8")); | ||
return packageJson.version || "unknown"; | ||
} catch (error) { | ||
console.error("Error reading package.json:", error); | ||
return "unknown"; | ||
} | ||
} | ||
|
||
function getGitVersion() { | ||
try { | ||
const tag = execSync("git describe --tags").toString().trim(); | ||
return tag; | ||
} catch (error) { | ||
console.error("Error getting git version:", error); | ||
return null; | ||
} | ||
} | ||
|
||
function getVersion() { | ||
// Check if VUE_APP_GIT_VERSION is already set (e.g., by build system) | ||
if (process.env.VUE_APP_GIT_VERSION) { | ||
return process.env.VUE_APP_GIT_VERSION; | ||
} | ||
|
||
// Try to get git version | ||
const gitVersion = getGitVersion(); | ||
if (gitVersion) { | ||
return gitVersion; | ||
} | ||
|
||
// Fall back to package.json version | ||
return getPackageJsonVersion(); | ||
} | ||
|
||
// Get and log the version | ||
const version = getVersion(); | ||
console.log(version); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters