From df58c81d07739d388113e8d9b921d4fe071e6b3f Mon Sep 17 00:00:00 2001 From: oreomanfan <30590662+oreomanfan@users.noreply.github.com> Date: Sun, 27 Jun 2021 13:25:44 -0400 Subject: [PATCH 1/4] support for installing addons from search results --- core.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/core.js b/core.js index 4da2a78..08a6fe2 100644 --- a/core.js +++ b/core.js @@ -11,7 +11,7 @@ const Listr = require('listr') const _ = require('underscore') const g = require('got') const pi = require('package-info') - +const readline = require('readline') const api = require('./source') const cfg = require('./lib/config') const unzip = require('./lib/unzip') @@ -285,6 +285,11 @@ let core = { search(text, done) { // log(text) + const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout + }); + api.search(api.parseName(text), info => { if (!info) { log('\nNothing is found\n') @@ -305,7 +310,7 @@ let core = { data.forEach((v, i) => { log() - log(cl.h(v.name) + ' ' + cl.x('(' + v.page + ')')) + log(i+1 + ' ' + cl.h(v.name) + ' ' + cl.x('(' + v.page + ')')) log( ` ${kv('key', v.key)} ${kv( 'download', @@ -314,7 +319,20 @@ let core = { ) // log('\n ' + v.desc) }) - + log() + rl.question('Install one or more of these?\nEnter result #\'s separated by spaces or \'N\' to exit', res => { + if (res.toUpperCase() === 'N') { + rl.close() + return + } + const indices = res.split(' ') + const keys = [] + indices.forEach(e => { + keys.push(data[e-1].key) + }) + rl.close() + core.add(keys) + }) log() if (done) done(info) }) From 47d6261fb4a3948d0062dea840b4c6a9501271f4 Mon Sep 17 00:00:00 2001 From: oreomanfan <30590662+oreomanfan@users.noreply.github.com> Date: Mon, 28 Jun 2021 16:29:56 -0400 Subject: [PATCH 2/4] Fixed hanging on failed search request --- core.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/core.js b/core.js index 08a6fe2..65b5518 100644 --- a/core.js +++ b/core.js @@ -284,12 +284,7 @@ let core = { search(text, done) { // log(text) - - const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout - }); - + api.search(api.parseName(text), info => { if (!info) { log('\nNothing is found\n') @@ -320,6 +315,12 @@ let core = { // log('\n ' + v.desc) }) log() + + const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout + }); + rl.question('Install one or more of these?\nEnter result #\'s separated by spaces or \'N\' to exit', res => { if (res.toUpperCase() === 'N') { rl.close() From e83ca36b24957f7ab17e821e1a1237dd1d61f2c2 Mon Sep 17 00:00:00 2001 From: oreomanfan <30590662+oreomanfan@users.noreply.github.com> Date: Thu, 1 Jul 2021 09:46:10 -0400 Subject: [PATCH 3/4] Search install moved to an option, prompt changed --- core.js | 38 ++++---- index.js | 264 ++++++++++++++++++++++++++++--------------------------- 2 files changed, 152 insertions(+), 150 deletions(-) diff --git a/core.js b/core.js index 65b5518..d6b7039 100644 --- a/core.js +++ b/core.js @@ -282,9 +282,9 @@ let core = { log(`✨ ${n} addon${n > 1 ? 's' : ''} ${pup ? '' : 'un'}pinned.`) }, - search(text, done) { + search(text, i, done) { // log(text) - + api.search(api.parseName(text), info => { if (!info) { log('\nNothing is found\n') @@ -315,26 +315,24 @@ let core = { // log('\n ' + v.desc) }) log() - - const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout - }); - - rl.question('Install one or more of these?\nEnter result #\'s separated by spaces or \'N\' to exit', res => { - if (res.toUpperCase() === 'N') { + + if(i) { + const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout + }); + + rl.question('Quick install by inputting indexes (separate by \',\' or space): \n', res => { + const indices = res.split(/[\s,]+/) + const keys = [] + indices.forEach(e => { + keys.push(data[e-1].key) + }) rl.close() - return - } - const indices = res.split(' ') - const keys = [] - indices.forEach(e => { - keys.push(data[e-1].key) + core.add(keys) }) - rl.close() - core.add(keys) - }) - log() + } + if (done) done(info) }) }, diff --git a/index.js b/index.js index d808fb5..e8c3977 100755 --- a/index.js +++ b/index.js @@ -1,130 +1,134 @@ -#!/usr/bin/env node - -const cli = require('commander') -const pkg = require('./package.json') -const cfg = require('./lib/config') -const core = require('./core') - -cli.version(pkg.version).usage(' [option] ') - -cli - .command('add ') - .description('install one or more addons locally') - .alias('install') - .alias('get') - .option('--anyway', 'install latest addon release for _classic_ mode anyway') - .action((aa, cmd) => { - cfg.anyway(cmd.anyway) - core.add(aa) - }) - -cli - .command('rm ') - .description('remove addons from local installation') - .alias('delete') - .alias('uninstall') - .alias('remove') - .alias('del') - .action(key => core.rm(key)) - -cli - .command('search ') - .description('search addons whose name contain ') - .option( - '--anyway', - 'search for latest addon release for _classic_ mode anyway' - ) - .action((text, cmd) => { - cfg.anyway(cmd.anyway) - core.search(text) - }) - -cli - .command('ls') - .description('list all installed addons') - .option('-l, --long', 'show detailed addon information') - .option('-t, --time', 'sort by updated time') - .alias('list') - .action(core.ls) - -cli - .command('info ') - .description( - 'show info of an addon, the addon does not have to be an installed locally' - ) - .option( - '--anyway', - 'show info of latest addon release for _classic_ mode anyway' - ) - .action((ad, cmd) => { - cfg.anyway(cmd.anyway) - core.info(ad) - }) - -cli - .command('update') - .description('update all installed addons') - .option('--anyway', 'update latest addon release for _classic_ mode anyway') - .option( - '--db', - 'for update addon database, no addon will be updated if this option is specified' - ) - .action(cmd => { - cfg.anyway(cmd.anyway) - core.update(cli.args.length > 1 ? cli.args.slice(0, -1) : null, cmd) - }) - -cli - .command('import') - .description('import local addons') - .action(() => core.pickup()) - -cli - .command('pin ') - .description("pin an addon to it's current version, prevent it from updating") - .action(key => core.pin(key, 1)) - -cli - .command('unpin ') - .description("unpin an addon, allow it to be updated") - .action(key => core.pin(key, 0)) - -cli - .command('switch') - .alias('sw') - .description('switch mode between retail and classic') - .option('--ptr', 'switch mode to: retail PTR') - .option('--beta', 'switch mode to: retail BETA') - .option('--retail', 'switch mode to: retail formal') - .option('--retail-ptr', 'switch mode to: retail PTR') - .option('--retail-beta', 'switch mode to: retail BETA') - .option('--classic', 'switch mode to: classic formal') - .option('--classic-tbc', 'switch mode to: classic TBC') - .option('--classic-ptr', 'switch mode to: classic PTR') - .option('--classic-beta', 'switch mode to: classic BETA') - .action(core.switch) - -cli - .command('restore [repo]') - .description( - 'restore addons from github repo, only is required, not the full URL. (e.g. antiwinter/wowui)' - ) - .option( - '-f, --full', - 'not only restore addons, but also restore addons settings' - ) - .action(repo => core.restore(repo)) - -cli.on('command:*', () => { - cli.help() -}) - -if (process.argv.length < 3) return cli.help() - -// do the job - -if (!cfg.checkPath()) return - -core.checkUpdate(() => { - cli.parse(process.argv) -}) +#!/usr/bin/env node + +const cli = require('commander') +const pkg = require('./package.json') +const cfg = require('./lib/config') +const core = require('./core') + +cli.version(pkg.version).usage(' [option] ') + +cli + .command('add ') + .description('install one or more addons locally') + .alias('install') + .alias('get') + .option('--anyway', 'install latest addon release for _classic_ mode anyway') + .action((aa, cmd) => { + cfg.anyway(cmd.anyway) + core.add(aa) + }) + +cli + .command('rm ') + .description('remove addons from local installation') + .alias('delete') + .alias('uninstall') + .alias('remove') + .alias('del') + .action(key => core.rm(key)) + +cli + .command('search ') + .description('search addons whose name contain ') + .option( + '--anyway', + 'search for latest addon release for _classic_ mode anyway' + ) + .option( + '-i', + 'Install from search result indexes' + ) + .action((text, cmd) => { + cfg.anyway(cmd.anyway) + core.search(text, cmd.i) + }) + +cli + .command('ls') + .description('list all installed addons') + .option('-l, --long', 'show detailed addon information') + .option('-t, --time', 'sort by updated time') + .alias('list') + .action(core.ls) + +cli + .command('info ') + .description( + 'show info of an addon, the addon does not have to be an installed locally' + ) + .option( + '--anyway', + 'show info of latest addon release for _classic_ mode anyway' + ) + .action((ad, cmd) => { + cfg.anyway(cmd.anyway) + core.info(ad) + }) + +cli + .command('update') + .description('update all installed addons') + .option('--anyway', 'update latest addon release for _classic_ mode anyway') + .option( + '--db', + 'for update addon database, no addon will be updated if this option is specified' + ) + .action(cmd => { + cfg.anyway(cmd.anyway) + core.update(cli.args.length > 1 ? cli.args.slice(0, -1) : null, cmd) + }) + +cli + .command('import') + .description('import local addons') + .action(() => core.pickup()) + +cli + .command('pin ') + .description("pin an addon to it's current version, prevent it from updating") + .action(key => core.pin(key, 1)) + +cli + .command('unpin ') + .description("unpin an addon, allow it to be updated") + .action(key => core.pin(key, 0)) + +cli + .command('switch') + .alias('sw') + .description('switch mode between retail and classic') + .option('--ptr', 'switch mode to: retail PTR') + .option('--beta', 'switch mode to: retail BETA') + .option('--retail', 'switch mode to: retail formal') + .option('--retail-ptr', 'switch mode to: retail PTR') + .option('--retail-beta', 'switch mode to: retail BETA') + .option('--classic', 'switch mode to: classic formal') + .option('--classic-tbc', 'switch mode to: classic TBC') + .option('--classic-ptr', 'switch mode to: classic PTR') + .option('--classic-beta', 'switch mode to: classic BETA') + .action(core.switch) + +cli + .command('restore [repo]') + .description( + 'restore addons from github repo, only is required, not the full URL. (e.g. antiwinter/wowui)' + ) + .option( + '-f, --full', + 'not only restore addons, but also restore addons settings' + ) + .action(repo => core.restore(repo)) + +cli.on('command:*', () => { + cli.help() +}) + +if (process.argv.length < 3) return cli.help() + +// do the job + +if (!cfg.checkPath()) return + +core.checkUpdate(() => { + cli.parse(process.argv) +}) From 74ba0e7a6d38a2d938198410499569d5fbf2ffb8 Mon Sep 17 00:00:00 2001 From: oreomanfan <30590662+oreomanfan@users.noreply.github.com> Date: Fri, 2 Jul 2021 11:06:56 -0400 Subject: [PATCH 4/4] Fixed tests hanging --- core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core.js b/core.js index d6b7039..59e3675 100644 --- a/core.js +++ b/core.js @@ -316,7 +316,7 @@ let core = { }) log() - if(i) { + if(i === true) { const rl = readline.createInterface({ input: process.stdin, output: process.stdout