From d0b0493b163b272b20bcffe9f944938b1b3395ea Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Fri, 4 Dec 2020 13:08:37 +1100 Subject: [PATCH] upgrade check.js to handle unpacked notion installations --- package.json | 2 +- pkg/check.js | 28 +++++++++++++++++++--------- pkg/helpers.js | 3 +++ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 0fba4de..bdf6778 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "notion-enhancer", - "version": "0.10.1", + "version": "0.10.2-wip", "description": "an enhancer/customiser for the all-in-one productivity workspace notion.so", "main": "index.js", "bin": { diff --git a/pkg/check.js b/pkg/check.js index 3093a57..a792b5a 100644 --- a/pkg/check.js +++ b/pkg/check.js @@ -9,29 +9,39 @@ const fs = require('fs-extra'), path = require('path'), helpers = require('./helpers.js'), - { version } = require('../package.json'); + { version } = require('../package.json'), + pathExists = (filepath) => fs.pathExists(path.resolve(filepath)); -// handle pre-existing installations: app.asar modded? with which enhancer version? module.exports = async function () { - const version_path = path.resolve( - `${helpers.__notion}/app/ENHANCER_VERSION.txt` - ), - installed_version = (await fs.pathExists(version_path)) - ? await fs.readFile(version_path, 'utf8') - : '?.?.?'; - if (await fs.pathExists(path.resolve(`${helpers.__notion}/app.asar`))) { + const version_path = `${helpers.__notion}/app/ENHANCER_VERSION.txt`; + if (!(await pathExists(version_path))) { return { msg: `notion-enhancer has not been applied.`, code: 0, }; } + const installed_version = await fs.readFile(version_path, 'utf8'), + packed = await pathExists(`${helpers.__notion}/app.asar`), + backup = packed + ? (await pathExists(`${helpers.__notion}/app.asar.bak`)) + ? `${helpers.__notion}/app.asar.bak` + : undefined + : (await pathExists(`${helpers.__notion}/app.bak`)) + ? `${helpers.__notion}/app.bak` + : undefined; return installed_version === version ? { msg: `notion-enhancer v${version} applied.`, + version: installed_version, + packed, + backup, code: 1, } : { msg: `notion-enhancer v${installed_version} found applied != v${version} package.`, + version: installed_version, + packed, + backup, code: 2, }; }; diff --git a/pkg/helpers.js b/pkg/helpers.js index eb2d37e..fbe376b 100644 --- a/pkg/helpers.js +++ b/pkg/helpers.js @@ -94,6 +94,9 @@ const is_wsl = return folder; })(); +// safely backup & transform either an app folder or an app.asar file into a folder +function enhanceableApp() {} + // transform a wsl filepath to its relative windows filepath if necessary. function realpath(hack_path) { if (!is_wsl) return hack_path.replace(/\\/g, '/');