Skip to content
This repository has been archived by the owner on Jun 6, 2022. It is now read-only.

Support for installing addons from search results #58

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -282,7 +282,7 @@ 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 => {
Expand All @@ -305,7 +305,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',
Expand All @@ -314,8 +314,25 @@ let core = {
)
// log('\n ' + v.desc)
})

log()

if(i === true) {
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()
core.add(keys)
})
}

if (done) done(info)
})
},
Expand Down
264 changes: 134 additions & 130 deletions index.js
Original file line number Diff line number Diff line change
@@ -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('<command> [option] <addon ...>')

cli
.command('add <addons...>')
.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 <addon...>')
.description('remove addons from local installation')
.alias('delete')
.alias('uninstall')
.alias('remove')
.alias('del')
.action(key => core.rm(key))

cli
.command('search <text>')
.description('search addons whose name contain <text>')
.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 <addon>')
.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 <addon...>')
.description("pin an addon to it's current version, prevent it from updating")
.action(key => core.pin(key, 1))

cli
.command('unpin <addon...>')
.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 <org/repo> 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('<command> [option] <addon ...>')

cli
.command('add <addons...>')
.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 <addon...>')
.description('remove addons from local installation')
.alias('delete')
.alias('uninstall')
.alias('remove')
.alias('del')
.action(key => core.rm(key))

cli
.command('search <text>')
.description('search addons whose name contain <text>')
.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 <addon>')
.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 <addon...>')
.description("pin an addon to it's current version, prevent it from updating")
.action(key => core.pin(key, 1))

cli
.command('unpin <addon...>')
.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 <org/repo> 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)
})