Commit 4ea9df4b authored by Aral Balkan's avatar Aral Balkan

Add Hugo version to the manifest and display in version command

parent 58560da9
......@@ -17,6 +17,7 @@ const { compile } = require('nexe')
const minimist = require('minimist')
const package = require('../package.json')
const moment = require('moment')
const Hugo = require('@small-tech/node-hugo')
const cpuArchitecture = os.arch()
// Parse the command-line arguments.
......@@ -42,10 +43,11 @@ if (commandLineOptions.deploy && childProcess.execSync('git status').toString().
}
//
// There are five elements that go into uniquely identifying a build:
// There are six elements that go into uniquely identifying a build:
//
// releaseChannel : alpha, beta, or release. Releases on a releaseChannel check for updates on that releaseChannel.
// nodeVersion : the version of Node that’s bundled in the build.
// hugoVersion : the version of Hugo that’s bundled in the build.
// binaryVersion : unique version for the binary, a calendar version determined at build time.
// packageVersion: the semantic version specified in the npm package.
// sourceVersion : the commit hash that corresponds to the source bundled in this build.
......@@ -56,6 +58,8 @@ if (commandLineOptions.deploy && childProcess.execSync('git status').toString().
const releaseChannel = commandLineOptions.alpha ? 'alpha' : (commandLineOptions.beta ? 'beta' : 'release')
const nodeVersion = process.version.slice(1)
const hugoVersion = (new Hugo()).version
function presentBinaryVersion (binaryVersion) {
const m = moment(binaryVersion, 'YYYYMMDDHHmmss')
return `${m.format('MMMM Do YYYY')} at ${m.format('HH:mm:ss')}`
......@@ -73,13 +77,16 @@ console.log(`\n ⚙️ Site.js build started on ${presentBinaryVersion(binaryVer
Binary version : ${binaryVersion}
Package version: ${packageVersion}
Source version : ${sourceVersion}
Node version : ${nodeVersion}\n`)
Node version : ${nodeVersion}
Hugo version : ${hugoVersion}
\n`)
// Write out the manifest file. This will be included in the build so that the binary knows what type of release it is.
// This allows it to modify its behaviour at runtime (e.g., auto-update from beta releases if it’s a beta release).
const manifest = {
binaryVersion,
packageVersion,
hugoVersion,
sourceVersion,
releaseChannel
}
......
......@@ -70,33 +70,18 @@ class Site {
this.#manifest = JSON.parse(fs.readFileSync(path.join(__dirname, './manifest.json'), 'utf-8'))
}
static get releaseChannel () {
static getFromManifest (key) {
if (this.#manifest === null) {
this.readAndCacheManifest()
}
return this.#manifest.releaseChannel
return this.#manifest[key]
}
static get binaryVersion () {
if (this.#manifest === null) {
this.readAndCacheManifest()
}
return this.#manifest.binaryVersion
}
static get packageVersion () {
if (this.#manifest === null) {
this.readAndCacheManifest()
}
return this.#manifest.packageVersion
}
static get sourceVersion () {
if (this.#manifest === null) {
this.readAndCacheManifest()
}
return this.#manifest.sourceVersion
}
static get releaseChannel () { return this.getFromManifest('releaseChannel') }
static get binaryVersion () { return this.getFromManifest('binaryVersion') }
static get packageVersion () { return this.getFromManifest('packageVersion') }
static get sourceVersion () { return this.getFromManifest('sourceVersion') }
static get hugoVersion () { return this.getFromManifest('hugoVersion') }
static binaryVersionToHumanReadableDateString (binaryVersion) {
const m = moment(binaryVersion, 'YYYYMMDDHHmmss')
......@@ -116,7 +101,7 @@ class Site {
}
switch(this.#manifest.releaseChannel) {
// Spells ALPHA in large red block letters.
case 'alpha': return clr(`\n
case this.RELEASE_CHANNEL.alpha: return clr(`\n
█████  ██  ██████  ██  ██  █████ 
██   ██ ██  ██   ██ ██  ██ ██   ██ 
███████ ██  ██████  ███████ ███████ 
......@@ -124,7 +109,7 @@ class Site {
██  ██ ███████ ██  ██  ██ ██  ██`, 'red')
// Spells BETA in large yellow block letters.
case 'beta': return clr(`\n
case this.RELEASE_CHANNEL.beta: return clr(`\n
██████  ███████ ████████  █████ 
██   ██ ██         ██    ██   ██ 
██████  █████  ██  ███████ 
......@@ -159,10 +144,12 @@ class Site {
let message = [
`\n${prefix1}Site.js ${this.releaseChannelFormattedForConsole}\n\n`,
`${prefix2}Version: ${clr(this.humanReadableBinaryVersion, 'green')}\n`,
`${prefix2}Engine : ${clr(`Node.js ${process.version}`, 'green')}\n`,
`${prefix2}Base : ${clr(`https://sitejs.org/nexe/${process.platform}-${process.arch}-${process.version.replace('v', '')}`, 'cyan')}\n`,
`${prefix2}Source : ${clr(`https://source.small-tech.org/site.js/app/-/tree/${this.sourceVersion}`, 'cyan')}\n\n`,
`${prefix2}Version ${clr(`${this.humanReadableBinaryVersion} (${this.packageVersion}-${this.sourceVersion})`, 'green')}\n`,
'\n',
`${prefix2}Node.js ${clr(`${process.version.replace('v', '')}`, 'green')}\n`,
`${prefix2}Hugo ${clr(`${this.hugoVersion}`, 'green')}\n`,
`${prefix2}Base ${clr(`https://sitejs.org/nexe/${process.platform}-${process.arch}-${process.version.replace('v', '')}`, 'cyan')}\n`,
`${prefix2}Source ${clr(`https://source.small-tech.org/site.js/app/-/tree/${this.sourceVersion}`, 'cyan')}\n\n`,
`${prefix2}╔═══════════════════════════════════════════╗\n`,
`${prefix2}║ Like this? Fund us! ║\n`,
`${prefix2}║ ║\n`,
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment