require passing resources <path> to apply/remove/check commands

This commit is contained in:
David Bailey 2020-12-07 21:45:41 +00:00
parent 9bc15847c4
commit ae7c2b6212
4 changed files with 31 additions and 19 deletions

21
bin.js
View File

@ -24,30 +24,37 @@ cli.option('-n, --no', ': skip prompts (may cause failures)');
cli.option('-d, --dev', ': show detailed error messages (for debug purposes)'); cli.option('-d, --dev', ': show detailed error messages (for debug purposes)');
cli cli
.command('apply', ': add the enhancer to the notion app') .command('apply <path>', ': add the enhancer to the notion app')
.action(async (options) => { .action(async (path, options) => {
console.info('=== NOTION ENHANCEMENT LOG ==='); console.info('=== NOTION ENHANCEMENT LOG ===');
await require('./pkg/apply.js')({ await require('./pkg/apply.js')({
__notion: path,
overwrite_version: options.yes ? 'y' : options.no ? 'n' : undefined, overwrite_version: options.yes ? 'y' : options.no ? 'n' : undefined,
friendly_errors: !options.dev, friendly_errors: !options.dev,
}); });
console.info('=== END OF LOG ==='); console.info('=== END OF LOG ===');
}); });
cli cli
.command('remove', ': return notion to its pre-enhanced/pre-modded state') .command(
.action(async (options) => { 'remove <path>',
': return notion to its pre-enhanced/pre-modded state'
)
.action(async (path, options) => {
console.info('=== NOTION RESTORATION LOG ==='); console.info('=== NOTION RESTORATION LOG ===');
await require('./pkg/remove.js')({ await require('./pkg/remove.js')({
__notion: path,
delete_data: options.yes ? 'y' : options.no ? 'n' : undefined, delete_data: options.yes ? 'y' : options.no ? 'n' : undefined,
friendly_errors: !options.dev, friendly_errors: !options.dev,
}); });
console.info('=== END OF LOG ==='); console.info('=== END OF LOG ===');
}); });
cli cli
.command('check', ': check the current state of the notion app') .command('check <path>', ': check the current state of the notion app')
.action(async (options) => { .action(async (path, options) => {
try { try {
const status = await require('./pkg/check.js')(); const status = await require('./pkg/check.js')({
__notion: path,
});
console.info(options.dev ? status : status.msg); console.info(options.dev ? status : status.msg);
} catch (err) { } catch (err) {
console.error( console.error(

View File

@ -10,7 +10,7 @@ const fs = require('fs-extra'),
path = require('path'), path = require('path'),
{ readdirIterator } = require('readdir-enhanced'), { readdirIterator } = require('readdir-enhanced'),
{ extractAll } = require('asar'), { extractAll } = require('asar'),
{ readline, getNotionResources } = require('./helpers.js'), { readline } = require('./helpers.js'),
{ version } = require('../package.json'); { version } = require('../package.json');
// === title === // === title ===
@ -21,11 +21,14 @@ const fs = require('fs-extra'),
// ~~ exit // ~~ exit
// ### error ### // ### error ###
module.exports = async function ({ overwrite_version, friendly_errors } = {}) { module.exports = async function ({
const __notion = getNotionResources(); __notion,
overwrite_version,
friendly_errors,
} = {}) {
try { try {
// handle pre-existing installations: app.asar present? version set in data folder? overwrite? // handle pre-existing installations: app.asar present? version set in data folder? overwrite?
const check_app = await require('./check.js')(); const check_app = await require('./check.js')({ __notion });
switch (check_app.code) { switch (check_app.code) {
case 1: case 1:
throw Error(check_app.msg); throw Error(check_app.msg);
@ -55,6 +58,7 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) {
); );
if ( if (
!(await require('./remove.js')({ !(await require('./remove.js')({
__notion,
delete_data: 'n', delete_data: 'n',
friendly_errors, friendly_errors,
})) }))

View File

@ -8,12 +8,10 @@
const fs = require('fs-extra'), const fs = require('fs-extra'),
path = require('path'), path = require('path'),
{ getNotionResources } = require('./helpers.js'),
{ version } = require('../package.json'); { version } = require('../package.json');
module.exports = async function () { module.exports = async function ({ __notion }) {
const __notion = getNotionResources(), const resolvePath = (filepath) => path.resolve(`${__notion}/${filepath}`),
resolvePath = (filepath) => path.resolve(`${__notion}/${filepath}`),
pathExists = (filepath) => fs.pathExists(resolvePath(filepath)), pathExists = (filepath) => fs.pathExists(resolvePath(filepath)),
version_path = 'app/ENHANCER_VERSION.txt', version_path = 'app/ENHANCER_VERSION.txt',
packed = await pathExists('app.asar.bak'); packed = await pathExists('app.asar.bak');

View File

@ -8,7 +8,7 @@
const fs = require('fs-extra'), const fs = require('fs-extra'),
path = require('path'), path = require('path'),
{ readline, getNotionResources, __data } = require('./helpers.js'); { readline, __data } = require('./helpers.js');
// === title === // === title ===
// ...information // ...information
@ -18,10 +18,13 @@ const fs = require('fs-extra'),
// ~~ exit // ~~ exit
// ### error ### // ### error ###
module.exports = async function ({ delete_data, friendly_errors } = {}) { module.exports = async function ({
__notion,
delete_data,
friendly_errors,
} = {}) {
try { try {
const __notion = getNotionResources(), const check_app = await require('./check.js')({ __notion });
check_app = await require('./check.js')();
// extracted asar: modded // extracted asar: modded
if (check_app.code > 1 && check_app.executable) { if (check_app.code > 1 && check_app.executable) {
console.info(` ...removing enhancements`); console.info(` ...removing enhancements`);