From 74e3605ec64e0bd91ac37afb51b728f1bf45f6c5 Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Wed, 21 Mar 2018 20:47:46 +0000 Subject: [PATCH] Get version from package.json --- client/src/builtin/EmoteModule.js | 2 ++ core/src/main.js | 28 ++++++++++++++++------------ core/src/modules/config.js | 5 +++++ gulpfile.js | 10 +++++++++- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/client/src/builtin/EmoteModule.js b/client/src/builtin/EmoteModule.js index 7c901607..df3e2337 100644 --- a/client/src/builtin/EmoteModule.js +++ b/client/src/builtin/EmoteModule.js @@ -7,10 +7,12 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ + import { FileUtils, ClientLogger as Logger } from 'common'; import { Events, Globals, WebpackModules, ReactComponents, MonkeyPatch } from 'modules'; import { DOM, VueInjector, Reflection } from 'ui'; import EmoteComponent from './EmoteComponent.vue'; + let emotes = null; const emotesEnabled = true; diff --git a/core/src/main.js b/core/src/main.js index 8aad0c90..3f58fd1c 100644 --- a/core/src/main.js +++ b/core/src/main.js @@ -10,9 +10,9 @@ const path = require('path'); const sass = require('node-sass'); +const { BrowserWindow, dialog } = require('electron'); const { FileUtils, BDIpc, Config, WindowUtils, CSSEditor, Database } = require('./modules'); -const { BrowserWindow, dialog } = require('electron'); const tests = true; @@ -34,6 +34,8 @@ const _pluginPath = path.resolve(_extPath, 'plugins'); const _themePath = path.resolve(_extPath, 'themes'); const _modulePath = path.resolve(_extPath, 'modules'); +const version = require(path.resolve(_basePath, 'package.json')).version; + const paths = [ { id: 'base', path: _basePath }, { id: 'cs', path: _clientScript }, @@ -46,7 +48,7 @@ const paths = [ ]; const globals = { - version: '2.0.0a', + version, paths }; @@ -115,7 +117,7 @@ class BetterDiscord { this.ignite = this.ignite.bind(this); this.config = new Config(args || globals); - this.dbInstance = new Database(this.config.paths.find(path => path.id === 'data').path); + this.dbInstance = new Database(this.config.getPath('data')); this.comms = new Comms(this); this.init(); @@ -124,12 +126,19 @@ class BetterDiscord { async init() { await this.waitForWindowUtils(); - await FileUtils.ensureDirectory(this.config.paths.find(path => path.id === 'ext').path); + if (!tests) { + const basePath = this.config.getPath('base'); + const files = await FileUtils.listDirectory(basePath); + const latestCs = FileUtils.resolveLatest(files, file => file.endsWith('.js') && file.startsWith('client.'), file => file.replace('client.', '').replace('.js', ''), 'client.', '.js'); + this.config.getPath('cs', true).path = path.resolve(basePath, latestCs); + } - this.csseditor = new CSSEditor(this, this.config.paths.find(path => path.id === 'csseditor').path); + await FileUtils.ensureDirectory(this.config.getPath('ext')); + + this.csseditor = new CSSEditor(this, this.config.getPath('csseditor')); this.windowUtils.on('did-get-response-details', () => this.ignite()); - this.windowUtils.on('did-finish-load', e => this.injectScripts(true)); + this.windowUtils.on('did-finish-load', () => this.injectScripts(true)); this.windowUtils.on('did-navigate-in-page', (event, url, isMainFrame) => { this.windowUtils.send('did-navigate-in-page', { event, url, isMainFrame }); @@ -189,12 +198,7 @@ class BetterDiscord { */ async injectScripts(reload = false) { console.log(`RELOAD? ${reload}`); - if (!tests) { - const files = await FileUtils.listDirectory(this.config.paths.find(path => path.id === 'base').path); - const latestCs = FileUtils.resolveLatest(files, file => file.endsWith('.js') && file.startsWith('client.'), file => file.replace('client.', '').replace('.js', ''), 'client.', '.js'); - this.config.paths.find(path => path.id === 'cs').path = path.resolve(this.config.paths.find(path => path.id === 'base').path, latestCs); - } - return this.windowUtils.injectScript(this.config.paths.find(path => path.id === 'cs').path); + return this.windowUtils.injectScript(this.config.getPath('cs')); } } diff --git a/core/src/modules/config.js b/core/src/modules/config.js index 417de899..b9df602b 100644 --- a/core/src/modules/config.js +++ b/core/src/modules/config.js @@ -20,6 +20,11 @@ class Config extends Module { return this.args.paths; } + getPath(id, full) { + const path = this.paths.find(path => path.id === id); + return full ? path : path.path; + } + get config() { return { version: this.version, diff --git a/gulpfile.js b/gulpfile.js index 68f9401d..1640468f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -8,10 +8,18 @@ const rename = require('gulp-rename'), copydeps = require('gulp-npm-copy-deps'); +const mainpkg = require('./package.json'); const corepkg = require('./core/package.json'); const clientpkg = require('./client/package.json'); const editorpkg = require('./csseditor/package.json'); +const releasepkg = function() { + delete mainpkg.main; + delete mainpkg.devDependencies; + delete mainpkg.scripts; + return fs.writeFileSync('./release/package.json', JSON.stringify(mainpkg, null, 2)); +}; + const client = function() { return pump([ gulp.src('./client/dist/*.client.js'), @@ -65,5 +73,5 @@ const node_sass_bindings = function() { }; gulp.task('release', function () { - del(['./release/**/*']).then(() => merge(client(), core(), sparkplug(), core_modules(), index(), cssEditor(), deps(), node_sass_bindings())); + del(['./release/**/*']).then(() => merge(releasepkg(), client(), core(), sparkplug(), core_modules(), index(), cssEditor(), deps(), node_sass_bindings())); });