From a57d97c43e557ef12c5fd6ad0f31060522f56106 Mon Sep 17 00:00:00 2001 From: Idan Stark Date: Mon, 16 Sep 2019 20:52:18 +0300 Subject: [PATCH 01/14] Using userData from the electron API --- src/main/configurator/index.js | 3 ++- src/main/mongo.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/configurator/index.js b/src/main/configurator/index.js index 83a3e04..47ddfd4 100644 --- a/src/main/configurator/index.js +++ b/src/main/configurator/index.js @@ -4,12 +4,13 @@ const path = require('path') const mkdirp = require('mkdirp') const Promise = require('bluebird') const EventEmitter = require('events') +const { app } = require('electron') const { getDefaultValue, getUpdatedValue, isValidValue } = require('./types') const mkdirpAsync = Promise.promisify(mkdirp) -const STORAGE_PATH = exports.STORAGE_PATH = path.resolve('./data/$config.sqlite') +const STORAGE_PATH = exports.STORAGE_PATH = path.resolve(app.getPath('userData'), '$config.sqlite') exports.Configurator = class extends EventEmitter { constructor () { diff --git a/src/main/mongo.js b/src/main/mongo.js index fad43e8..936302a 100644 --- a/src/main/mongo.js +++ b/src/main/mongo.js @@ -4,6 +4,7 @@ const path = require('path') const mkdirp = require('mkdirp') const Promise = require('bluebird') const { spawn } = require('child_process') +const { app } = require('electron') const { logger } = require('./logs') @@ -14,7 +15,7 @@ const mkdirpAsync = Promise.promisify(mkdirp) const FILE_EXTENSION = (process.platform === 'win32') ? '.exe' : '' const MONGO_BIN_DIR = path.resolve(`./internals/mongo/bin`) const MONGO_EXECUTABLE_PATH = path.resolve(MONGO_BIN_DIR, `mongod${FILE_EXTENSION}`) -const MONGO_ARGUMENTS = ['--dbpath', './data/$mongo'] +const MONGO_ARGUMENTS = ['--dbpath', path.resolve(app.getPath('userData'), '$mongo')] .concat((process.arch === 'ia32') ? ['--storageEngine=mmapv1'] : []) const MONGODUMP_EXECUTABLE_PATH = path.resolve(MONGO_BIN_DIR, `mongodump${FILE_EXTENSION}`) From e635234b390de1787cb1fe474d216e5540b93bac Mon Sep 17 00:00:00 2001 From: Roy Shmueli <2903801+2roy999@users.noreply.github.com> Date: Thu, 3 Oct 2019 00:29:55 +0300 Subject: [PATCH 02/14] Adding new paths for all data files --- appveyor.yml | 9 ++++++++- package.json | 1 - src/main/app-paths.js | 13 +++++++++++++ src/main/caddy/index.js | 14 ++++++++------ src/main/configurator/index.js | 6 ++++-- src/main/logs.js | 7 ++++--- src/main/mhub/index.js | 3 ++- src/main/mongo.js | 13 +++++++------ src/main/server.js | 13 ++++++------- src/main/version.js | 28 ++++++++++++++++++++++++++++ 10 files changed, 80 insertions(+), 27 deletions(-) create mode 100644 src/main/app-paths.js create mode 100644 src/main/version.js diff --git a/appveyor.yml b/appveyor.yml index 89fb91a..8e74120 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -37,7 +37,14 @@ install: build_script: - yarn run build:dir -w --c.directories.output=./dist/ -- SET BUILD_VERSION=%APPVEYOR_BUILD_VERSION% + - SET BUILD_VERSION=%APPVEYOR_BUILD_VERSION% + - SET GIT_COMMIT=%APPVEYOR_REPO_COMMIT% +- >- + node -e "console.log(JSON.stringify({ + semver: process.env.BUILD_VERSION, + timestamp: Date.now(), + commit: process.env.GIT_COMMIT + }))" >> ./dist/version.json - >- "C:\\Program Files (x86)\\Inno Setup 5\\ISCC.exe" /Odist /FFIRST_LEGO_League_TMS_Setup_%BUILD_VERSION%_%PLATFORM% .\\windows\\setup\\main.iss diff --git a/package.json b/package.json index 97c8dcd..af8a561 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,5 @@ { "name": "fll-launcher", - "version": "2.0.0", "author": "Roy Shmueli <2903801+2roy999@users.noreply.github.com>", "description": "A Launcher to the FIRST LEGO League tournament managment system", "main": "./dist/electron/main.js", diff --git a/src/main/app-paths.js b/src/main/app-paths.js new file mode 100644 index 0000000..1f6acfe --- /dev/null +++ b/src/main/app-paths.js @@ -0,0 +1,13 @@ + +const { app } = require('electron') +const path = require('path') + +const version = require('./version') + +const useDevPaths = (process.env.NODE_ENV !== 'development') || Boolean(process.env.PRODUCTION_DIRS) + +const versionHash = `${version.semver}$${version.timestamp}$${version.commit}` + +exports.DATA_DIR = useDevPaths ? path.join(app.getPath('userData'), versionHash, 'data') : path.resolve('./data') +exports.LOG_DIR = useDevPaths ? path.join(app.getPath('userData'), versionHash, 'logs') : path.resolve('./logs') +exports.TEMP_DIR = useDevPaths ? path.join(app.getPath('temp'), versionHash) : path.resolve('./tmp') diff --git a/src/main/caddy/index.js b/src/main/caddy/index.js index 447406b..4fd7b14 100644 --- a/src/main/caddy/index.js +++ b/src/main/caddy/index.js @@ -1,11 +1,13 @@ -const fs = require('fs') +const Promise = require('bluebird') const ejs = require('ejs') -const path = require('path') +const fs = require('fs') const mkdirp = require('mkdirp') -const rimraf = require('rimraf') -const Promise = require('bluebird') +const path = require('path') const randomatic = require('randomatic') +const rimraf = require('rimraf') + +const { TEMP_DIR } = require('../app-paths') Promise.promisifyAll(fs) Promise.promisifyAll(ejs) @@ -15,8 +17,8 @@ const rimrafAsync = Promise.promisify(rimraf) const FILE_EXTENSION = (process.platform === 'win32') ? '.exe' : '' const CADDY_EXECUTABLE_PATH = path.resolve(`./internals/caddy/caddy${FILE_EXTENSION}`) const CADDY_FILE_TEMPLATE = path.join(__static, 'caddy-file.ejs') -const CADDY_FILE_PATH = path.resolve('./tmp/$CaddyFile') -const CADDY_ENV_DIR = path.resolve('./tmp/$caddy/') +const CADDY_FILE_PATH = path.resolve(TEMP_DIR, '$CaddyFile') +const CADDY_ENV_DIR = path.resolve(TEMP_DIR, '$caddy') function generateCaddyFileContent (caddyFile, sites) { return mkdirpAsync(path.dirname(caddyFile)) diff --git a/src/main/configurator/index.js b/src/main/configurator/index.js index 47ddfd4..e2646ee 100644 --- a/src/main/configurator/index.js +++ b/src/main/configurator/index.js @@ -4,13 +4,14 @@ const path = require('path') const mkdirp = require('mkdirp') const Promise = require('bluebird') const EventEmitter = require('events') -const { app } = require('electron') const { getDefaultValue, getUpdatedValue, isValidValue } = require('./types') +const { DATA_DIR } = require('../app-paths') + const mkdirpAsync = Promise.promisify(mkdirp) -const STORAGE_PATH = exports.STORAGE_PATH = path.resolve(app.getPath('userData'), '$config.sqlite') +const STORAGE_PATH = exports.STORAGE_PATH = path.join(DATA_DIR, '$config.sqlite') exports.Configurator = class extends EventEmitter { constructor () { @@ -18,6 +19,7 @@ exports.Configurator = class extends EventEmitter { this.configMetadata = {} this.sealed = false this.started = false + this.storagePath = path.join(DATA_DIR, '$config.sqlite') this.storagePromise = mkdirpAsync(path.dirname(STORAGE_PATH)) .then(() => new Keyv(`sqlite://${STORAGE_PATH}`)) diff --git a/src/main/logs.js b/src/main/logs.js index d15328f..edfe803 100644 --- a/src/main/logs.js +++ b/src/main/logs.js @@ -1,13 +1,14 @@ -const path = require('path') +const Promise = require('bluebird') const mkdirp = require('mkdirp') +const path = require('path') const rotate = require('rotating-file-stream') const winston = require('winston') -const Promise = require('bluebird') + +const { LOG_DIR } = require('./app-paths') const LOG_SIZE = '10M' const LOG_INTERVAL = '1d' -const LOG_DIR = exports.LOG_DIR = path.resolve('./logs/') const { combine, timestamp, json } = winston.format diff --git a/src/main/mhub/index.js b/src/main/mhub/index.js index fc6701a..783f696 100644 --- a/src/main/mhub/index.js +++ b/src/main/mhub/index.js @@ -11,6 +11,7 @@ const randomatic = require('randomatic') const { MClient } = require('mhub') const { logger } = require('../logs') +const { TEMP_DIR } = require('../app-paths') Promise.promisifyAll(fs) Promise.promisifyAll(ejs) @@ -21,7 +22,7 @@ const MHUB_CONNECTION_STRING = 'ws://127.0.0.1:13900' // const MHUB_NODE_NAME = 'default' const MHUB_EXECUTABLE_PATH = path.resolve('./internals/mhub/bin/mhub-server') const MHUB_FILE_TEMPLATE = path.join(__static, 'mhub-config.ejs') -const MHUB_FILE_PATH = path.resolve('./tmp/$mhub.config.json') +const MHUB_FILE_PATH = path.join(TEMP_DIR, '$mhub.config.json') const MAX_RETRIES = 5 diff --git a/src/main/mongo.js b/src/main/mongo.js index 936302a..b492cc5 100644 --- a/src/main/mongo.js +++ b/src/main/mongo.js @@ -4,9 +4,9 @@ const path = require('path') const mkdirp = require('mkdirp') const Promise = require('bluebird') const { spawn } = require('child_process') -const { app } = require('electron') const { logger } = require('./logs') +const { TEMP_DIR, DATA_DIR } = require('./app-paths') Promise.promisifyAll(fs) @@ -14,12 +14,13 @@ const mkdirpAsync = Promise.promisify(mkdirp) const FILE_EXTENSION = (process.platform === 'win32') ? '.exe' : '' const MONGO_BIN_DIR = path.resolve(`./internals/mongo/bin`) -const MONGO_EXECUTABLE_PATH = path.resolve(MONGO_BIN_DIR, `mongod${FILE_EXTENSION}`) -const MONGO_ARGUMENTS = ['--dbpath', path.resolve(app.getPath('userData'), '$mongo')] +const MONGO_EXECUTABLE_PATH = path.join(MONGO_BIN_DIR, `mongod${FILE_EXTENSION}`) +const MONGO_DATA_PATH = path.join(DATA_DIR, '$mongo') +const MONGO_ARGUMENTS = ['--dbpath', MONGO_DATA_PATH] .concat((process.arch === 'ia32') ? ['--storageEngine=mmapv1'] : []) -const MONGODUMP_EXECUTABLE_PATH = path.resolve(MONGO_BIN_DIR, `mongodump${FILE_EXTENSION}`) -const DUMP_PATH = exports.DUMP_PATH = path.resolve('./dump') +const MONGODUMP_EXECUTABLE_PATH = path.join(MONGO_BIN_DIR, `mongodump${FILE_EXTENSION}`) +const DUMP_PATH = exports.DUMP_PATH = path.join(TEMP_DIR, 'dump') exports.dump = function () { return mkdirpAsync(DUMP_PATH).then(() => { @@ -64,7 +65,7 @@ class Mongo { start () { logger.info(`process.arch:${process.arch} MONGO_ARGUMENTS:${MONGO_ARGUMENTS}`) - return mkdirpAsync('./data/$mongo') + return mkdirpAsync(MONGO_DATA_PATH) .then(() => this.serviceManager.startService({ serviceName: 'mongo', serviceId: this.serviceId, diff --git a/src/main/server.js b/src/main/server.js index e1091cc..d970950 100644 --- a/src/main/server.js +++ b/src/main/server.js @@ -1,24 +1,23 @@ const fs = require('fs') -const path = require('path') const Promise = require('bluebird') const randomatic = require('randomatic') -const { Mhub } = require('./mhub') +const { DATA_DIR } = require('./app-paths') const { Caddy } = require('./caddy') +const { Configurator } = require('./configurator') +const { loadLogsOptions, createLogStream, logger } = require('./logs') +const { globalModuleConfig } = require('./global-config') +const { Mhub } = require('./mhub') +const { loadModules } = require('./module-loader') const { Mongo } = require('./mongo') const { getIp } = require('./network') -const { loadModules } = require('./module-loader') -const { loadLogsOptions, createLogStream, logger } = require('./logs') const { ServiceManager } = require('./services') -const { Configurator } = require('./configurator') -const { globalModuleConfig } = require('./global-config') Promise.promisifyAll(fs) const STARTING_PORT = 2828 const SECRET_LENGTH = 12 -const DATA_DIR = path.resolve('./data/') exports.Server = class { constructor (modulesFile) { diff --git a/src/main/version.js b/src/main/version.js new file mode 100644 index 0000000..89140f6 --- /dev/null +++ b/src/main/version.js @@ -0,0 +1,28 @@ +/* eslint-disable node/exports-style */ + +function getGitCommit () { + try { + const fs = require('fs') + const path = require('path') + + const gitHead = fs.readFileSync(path.resolve('./.git/HEAD'), 'utf8').trim() + return fs.readFileSync(path.resolve('./.git', gitHead.substring('ref: '.length)), 'utf8').trim() + } catch (e) { + console.log('WARNING: Error getting current git commit') + return 'N/A' + } +} + +function getDefaultVersionObject () { + return { + semver: 'snapshot', + timestamp: Date.now(), + commit: getGitCommit() + } +} + +try { + module.exports = require('../../version.json') +} catch (e) { + module.exports = getDefaultVersionObject() +} From c685cc14a06788f0a72716278f30b1ca0365cbd2 Mon Sep 17 00:00:00 2001 From: Roy Shmueli <2903801+2roy999@users.noreply.github.com> Date: Thu, 3 Oct 2019 10:09:50 +0300 Subject: [PATCH 03/14] Adding version field --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index af8a561..fe76792 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "name": "fll-launcher", + "version": "0.0.0", "author": "Roy Shmueli <2903801+2roy999@users.noreply.github.com>", "description": "A Launcher to the FIRST LEGO League tournament managment system", "main": "./dist/electron/main.js", From 1106d94b644c9eef8109692af0e9502178c9eb11 Mon Sep 17 00:00:00 2001 From: Roy Shmueli <2903801+2roy999@users.noreply.github.com> Date: Thu, 3 Oct 2019 10:31:19 +0300 Subject: [PATCH 04/14] Fixing version file creation --- appveyor.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 8e74120..e7f3e20 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -40,11 +40,13 @@ build_script: - SET BUILD_VERSION=%APPVEYOR_BUILD_VERSION% - SET GIT_COMMIT=%APPVEYOR_REPO_COMMIT% - >- - node -e "console.log(JSON.stringify({ - semver: process.env.BUILD_VERSION, - timestamp: Date.now(), - commit: process.env.GIT_COMMIT - }))" >> ./dist/version.json + node << CODE + console.log(JSON.stringify({ + semver: process.env.BUILD_VERSION, + timestamp: Date.now(), + commit: process.env.GIT_COMMIT + })) + CODE >> ./dist/version.json - >- "C:\\Program Files (x86)\\Inno Setup 5\\ISCC.exe" /Odist /FFIRST_LEGO_League_TMS_Setup_%BUILD_VERSION%_%PLATFORM% .\\windows\\setup\\main.iss From 334afdea7a640e03ada408293d3ed58cdc69310e Mon Sep 17 00:00:00 2001 From: Roy Shmueli <2903801+2roy999@users.noreply.github.com> Date: Thu, 3 Oct 2019 10:39:06 +0300 Subject: [PATCH 05/14] Fixing version file creation --- appveyor.yml | 8 +------- src/main/version.js | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index e7f3e20..d6053e7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -40,13 +40,7 @@ build_script: - SET BUILD_VERSION=%APPVEYOR_BUILD_VERSION% - SET GIT_COMMIT=%APPVEYOR_REPO_COMMIT% - >- - node << CODE - console.log(JSON.stringify({ - semver: process.env.BUILD_VERSION, - timestamp: Date.now(), - commit: process.env.GIT_COMMIT - })) - CODE >> ./dist/version.json + node -e "console.log(JSON.stringify(require('./src/main/version.js')))" >> ./dist/version.json - >- "C:\\Program Files (x86)\\Inno Setup 5\\ISCC.exe" /Odist /FFIRST_LEGO_League_TMS_Setup_%BUILD_VERSION%_%PLATFORM% .\\windows\\setup\\main.iss diff --git a/src/main/version.js b/src/main/version.js index 89140f6..7eddb70 100644 --- a/src/main/version.js +++ b/src/main/version.js @@ -15,7 +15,7 @@ function getGitCommit () { function getDefaultVersionObject () { return { - semver: 'snapshot', + semver: process.env.BUILD_VERSION || 'snapshot', timestamp: Date.now(), commit: getGitCommit() } From cd024a6fb1a55f73fe6da1a63d9ee0e29ea403da Mon Sep 17 00:00:00 2001 From: Roy Shmueli <2903801+2roy999@users.noreply.github.com> Date: Thu, 3 Oct 2019 11:41:56 +0300 Subject: [PATCH 06/14] fix yml indentation --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index d6053e7..1926376 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -37,8 +37,8 @@ install: build_script: - yarn run build:dir -w --c.directories.output=./dist/ - - SET BUILD_VERSION=%APPVEYOR_BUILD_VERSION% - - SET GIT_COMMIT=%APPVEYOR_REPO_COMMIT% +- SET BUILD_VERSION=%APPVEYOR_BUILD_VERSION% +- SET GIT_COMMIT=%APPVEYOR_REPO_COMMIT% - >- node -e "console.log(JSON.stringify(require('./src/main/version.js')))" >> ./dist/version.json - >- From 923f6b1c643d0556c25bffcf4a3bda095d4548f8 Mon Sep 17 00:00:00 2001 From: Roy Shmueli <2903801+2roy999@users.noreply.github.com> Date: Thu, 3 Oct 2019 11:52:37 +0300 Subject: [PATCH 07/14] Adding version.json into the installer --- windows/setup/main.iss | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/windows/setup/main.iss b/windows/setup/main.iss index c49a364..ea8e285 100644 --- a/windows/setup/main.iss +++ b/windows/setup/main.iss @@ -9,6 +9,7 @@ #define modules "..\..\modules" #define internals "..\..\internals" #define static "..\..\static" +#define dist "..\..\dist" #define executable "FIRST LEGO League TMS.exe" #define add_firewall_rule "advfirewall firewall add rule protocol=tcp dir=in enable=yes action=allow profile=private" @@ -23,16 +24,12 @@ DisableProgramGroupPage=yes ArchitecturesInstallIn64BitMode=x64 #endif -[Dirs] -Name: "{app}\data" -Name: "{app}\logs" -Name: "{app}\tmp" - [Files] Source: "{#app}\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs; Source: "{#modules}\*"; DestDir: "{app}\modules"; Flags: ignoreversion recursesubdirs; Source: "{#internals}\*"; DestDir: "{app}\internals"; Flags: ignoreversion recursesubdirs; Source: "{#static}\repair-mongo.bat"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs; +Source: "{#dist}\version.json"; DestDir: "{app}"; Flags: ignoreversion; [Run] Filename: "{sys}\netsh.exe"; StatusMsg: "Adding firewall rules..."; Parameters: "{#add_firewall_rule} name=""FIRST LEGO League TMS"" program=""{app}\{#executable}""" From 70b1cdd580b3578c9c9839be4531456a1d386b05 Mon Sep 17 00:00:00 2001 From: Roy Shmueli <2903801+2roy999@users.noreply.github.com> Date: Thu, 3 Oct 2019 12:42:33 +0300 Subject: [PATCH 08/14] Fixing version file --- src/main/version.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/version.js b/src/main/version.js index 7eddb70..770cadf 100644 --- a/src/main/version.js +++ b/src/main/version.js @@ -8,8 +8,7 @@ function getGitCommit () { const gitHead = fs.readFileSync(path.resolve('./.git/HEAD'), 'utf8').trim() return fs.readFileSync(path.resolve('./.git', gitHead.substring('ref: '.length)), 'utf8').trim() } catch (e) { - console.log('WARNING: Error getting current git commit') - return 'N/A' + console.error('WARNING: Error getting current git commit') } } @@ -17,7 +16,7 @@ function getDefaultVersionObject () { return { semver: process.env.BUILD_VERSION || 'snapshot', timestamp: Date.now(), - commit: getGitCommit() + commit: process.env.GIT_COMMIT || getGitCommit() || 'N/A' } } From a864a73f076916dc8aacdf1f89d63b31cc67be5f Mon Sep 17 00:00:00 2001 From: Roy Shmueli <2903801+2roy999@users.noreply.github.com> Date: Thu, 3 Oct 2019 13:20:21 +0300 Subject: [PATCH 09/14] Fixing reading of version file --- appveyor.yml | 4 +--- dev-scripts/create-version-file.js | 25 +++++++++++++++++++++++++ package.json | 3 ++- src/main/version.js | 18 ++++++++---------- 4 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 dev-scripts/create-version-file.js diff --git a/appveyor.yml b/appveyor.yml index 1926376..6fc54f1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -38,9 +38,7 @@ install: build_script: - yarn run build:dir -w --c.directories.output=./dist/ - SET BUILD_VERSION=%APPVEYOR_BUILD_VERSION% -- SET GIT_COMMIT=%APPVEYOR_REPO_COMMIT% -- >- - node -e "console.log(JSON.stringify(require('./src/main/version.js')))" >> ./dist/version.json +- yarn run create-version-file %BUILD_VERSION% --commit %APPVEYOR_REPO_COMMIT% - >- "C:\\Program Files (x86)\\Inno Setup 5\\ISCC.exe" /Odist /FFIRST_LEGO_League_TMS_Setup_%BUILD_VERSION%_%PLATFORM% .\\windows\\setup\\main.iss diff --git a/dev-scripts/create-version-file.js b/dev-scripts/create-version-file.js new file mode 100644 index 0000000..60f12e5 --- /dev/null +++ b/dev-scripts/create-version-file.js @@ -0,0 +1,25 @@ + +const caporal = require('caporal') + +caporal + .name('create-version-file') + .version('v1') + .option('--commit, -c ', 'The git commit of the version') + .option('--ts ', 'The timestamp of the build') + .argument('', 'The semver version for the file') + .action((args, options) => { + const timestamp = (options.ts) ? Number(options.ts) : Date.now() + + if (Number.isNaN(timestamp)) { + console.error('ERROR: timestamp should be in unix timestamp format') + return + } + + console.log(JSON.stringify({ + semver: args.semver || 'none', + timestamp: timestamp, + commit: options.commit || 'NA' + })) + }) + +caporal.parse(process.argv) diff --git a/package.json b/package.json index fe76792..b7511ac 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ "pack:main": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.main.config.js", "pack:renderer": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.renderer.config.js", "postinstall": "electron-builder install-app-deps", - "start": "node .electron-vue/dev-runner.js" + "start": "node .electron-vue/dev-runner.js", + "create-vesion-file": "node ./dev-scripts/create-version-file.js" }, "build": { "appId": "com.fll-tools.launcher", diff --git a/src/main/version.js b/src/main/version.js index 770cadf..304589b 100644 --- a/src/main/version.js +++ b/src/main/version.js @@ -1,10 +1,8 @@ -/* eslint-disable node/exports-style */ +const fs = require('fs') +const path = require('path') function getGitCommit () { try { - const fs = require('fs') - const path = require('path') - const gitHead = fs.readFileSync(path.resolve('./.git/HEAD'), 'utf8').trim() return fs.readFileSync(path.resolve('./.git', gitHead.substring('ref: '.length)), 'utf8').trim() } catch (e) { @@ -14,14 +12,14 @@ function getGitCommit () { function getDefaultVersionObject () { return { - semver: process.env.BUILD_VERSION || 'snapshot', + semver: 'snapshot', timestamp: Date.now(), - commit: process.env.GIT_COMMIT || getGitCommit() || 'N/A' + commit: getGitCommit() || 'NA' } } -try { - module.exports = require('../../version.json') -} catch (e) { - module.exports = getDefaultVersionObject() +if (process.env.NODE_ENV !== 'development') { + Object.assign(exports, JSON.parse(fs.readFileSync(path.resolve('./version.json')))) +} else { + Object.assign(exports, getDefaultVersionObject()) } From 53200a21af3bf42c8bd307b98a92ba32c568b465 Mon Sep 17 00:00:00 2001 From: Roy Shmueli <2903801+2roy999@users.noreply.github.com> Date: Thu, 3 Oct 2019 13:51:01 +0300 Subject: [PATCH 10/14] Fixing typos --- appveyor.yml | 2 +- dev-scripts/{create-version-file.js => version-file.js} | 2 +- package.json | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) rename dev-scripts/{create-version-file.js => version-file.js} (95%) diff --git a/appveyor.yml b/appveyor.yml index 6fc54f1..4ef5d69 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -38,7 +38,7 @@ install: build_script: - yarn run build:dir -w --c.directories.output=./dist/ - SET BUILD_VERSION=%APPVEYOR_BUILD_VERSION% -- yarn run create-version-file %BUILD_VERSION% --commit %APPVEYOR_REPO_COMMIT% +- yarn run version-file %BUILD_VERSION% --commit %APPVEYOR_REPO_COMMIT% - >- "C:\\Program Files (x86)\\Inno Setup 5\\ISCC.exe" /Odist /FFIRST_LEGO_League_TMS_Setup_%BUILD_VERSION%_%PLATFORM% .\\windows\\setup\\main.iss diff --git a/dev-scripts/create-version-file.js b/dev-scripts/version-file.js similarity index 95% rename from dev-scripts/create-version-file.js rename to dev-scripts/version-file.js index 60f12e5..8dc8d12 100644 --- a/dev-scripts/create-version-file.js +++ b/dev-scripts/version-file.js @@ -2,7 +2,7 @@ const caporal = require('caporal') caporal - .name('create-version-file') + .name('version-file') .version('v1') .option('--commit, -c ', 'The git commit of the version') .option('--ts ', 'The timestamp of the build') diff --git a/package.json b/package.json index b7511ac..c30cfc4 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "fll-launcher", + "name": "first-lego-league-tms", "version": "0.0.0", "author": "Roy Shmueli <2903801+2roy999@users.noreply.github.com>", "description": "A Launcher to the FIRST LEGO League tournament managment system", @@ -21,12 +21,12 @@ "pack:renderer": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.renderer.config.js", "postinstall": "electron-builder install-app-deps", "start": "node .electron-vue/dev-runner.js", - "create-vesion-file": "node ./dev-scripts/create-version-file.js" + "version-file": "node ./dev-scripts/version-file.js" }, "build": { "appId": "com.fll-tools.launcher", "productName": "FIRST LEGO League TMS", - "artifactName": "fll-launcher-${version}", + "artifactName": "fll-launcher-${env.BUILD_VERSION || 'snapshot'}", "directories": { "buildResources": "resources", "output": "dist" From cf1f833a1cd6cb2aacef48a87d21c436fb6b0324 Mon Sep 17 00:00:00 2001 From: Roy Shmueli <2903801+2roy999@users.noreply.github.com> Date: Thu, 3 Oct 2019 13:56:46 +0300 Subject: [PATCH 11/14] fix --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 4ef5d69..d76cae8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -38,7 +38,7 @@ install: build_script: - yarn run build:dir -w --c.directories.output=./dist/ - SET BUILD_VERSION=%APPVEYOR_BUILD_VERSION% -- yarn run version-file %BUILD_VERSION% --commit %APPVEYOR_REPO_COMMIT% +- yarn run version-file %BUILD_VERSION% --commit %APPVEYOR_REPO_COMMIT% >> .\\dist\\version.json - >- "C:\\Program Files (x86)\\Inno Setup 5\\ISCC.exe" /Odist /FFIRST_LEGO_League_TMS_Setup_%BUILD_VERSION%_%PLATFORM% .\\windows\\setup\\main.iss From 2265d380bff1ebddcd11bd0622fb40a6c4a7cf16 Mon Sep 17 00:00:00 2001 From: Roy Shmueli <2903801+2roy999@users.noreply.github.com> Date: Thu, 3 Oct 2019 14:44:17 +0300 Subject: [PATCH 12/14] fix --- dev-scripts/version-file.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dev-scripts/version-file.js b/dev-scripts/version-file.js index 8dc8d12..b67d493 100644 --- a/dev-scripts/version-file.js +++ b/dev-scripts/version-file.js @@ -1,11 +1,14 @@ const caporal = require('caporal') +const fs = require('fs') +const path = require('path') caporal .name('version-file') .version('v1') .option('--commit, -c ', 'The git commit of the version') .option('--ts ', 'The timestamp of the build') + .option('--output ', 'The output file') .argument('', 'The semver version for the file') .action((args, options) => { const timestamp = (options.ts) ? Number(options.ts) : Date.now() @@ -15,7 +18,7 @@ caporal return } - console.log(JSON.stringify({ + fs.writeFileSync(path.resolve(options.output), JSON.stringify({ semver: args.semver || 'none', timestamp: timestamp, commit: options.commit || 'NA' From 4b32b7bc6682fcdcc6b8e8fd2d15c4b85e7531f5 Mon Sep 17 00:00:00 2001 From: Roy Shmueli <2903801+2roy999@users.noreply.github.com> Date: Thu, 3 Oct 2019 14:46:13 +0300 Subject: [PATCH 13/14] fix --- dev-scripts/version-file.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dev-scripts/version-file.js b/dev-scripts/version-file.js index b67d493..0cae5dc 100644 --- a/dev-scripts/version-file.js +++ b/dev-scripts/version-file.js @@ -11,14 +11,16 @@ caporal .option('--output ', 'The output file') .argument('', 'The semver version for the file') .action((args, options) => { - const timestamp = (options.ts) ? Number(options.ts) : Date.now() + const timestamp = options.ts ? Number(options.ts) : Date.now() if (Number.isNaN(timestamp)) { console.error('ERROR: timestamp should be in unix timestamp format') return } - fs.writeFileSync(path.resolve(options.output), JSON.stringify({ + const outputFile = path.resolve(options.output || './dist/version.json') + + fs.writeFileSync(outputFile, JSON.stringify({ semver: args.semver || 'none', timestamp: timestamp, commit: options.commit || 'NA' From 9430286fc4fef710e96bf47e84e58ad521c712d7 Mon Sep 17 00:00:00 2001 From: Roy Shmueli <2903801+2roy999@users.noreply.github.com> Date: Thu, 3 Oct 2019 14:51:50 +0300 Subject: [PATCH 14/14] fix --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index d76cae8..4ef5d69 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -38,7 +38,7 @@ install: build_script: - yarn run build:dir -w --c.directories.output=./dist/ - SET BUILD_VERSION=%APPVEYOR_BUILD_VERSION% -- yarn run version-file %BUILD_VERSION% --commit %APPVEYOR_REPO_COMMIT% >> .\\dist\\version.json +- yarn run version-file %BUILD_VERSION% --commit %APPVEYOR_REPO_COMMIT% - >- "C:\\Program Files (x86)\\Inno Setup 5\\ISCC.exe" /Odist /FFIRST_LEGO_League_TMS_Setup_%BUILD_VERSION%_%PLATFORM% .\\windows\\setup\\main.iss