Created
September 2, 2017 15:21
-
-
Save maple3142/9955d3e1113e5122ac3cdcd0d178be9c to your computer and use it in GitHub Desktop.
coolapk v8 cli
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@node index.js %* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const prog = require('commander') | |
const fuzzy = require('fuzzy') | |
const colors = require('colors') | |
const prompt = require('prompt') | |
const sleep = ms => new Promise(res => setTimeout(() => res(), ms)) | |
const db = { | |
'com.coolapk.market': '酷市場', | |
'com.android.vending': 'play商店', | |
'de.robv.android.xposed.installer': 'Xposed', | |
'com.topjohnwu.magisk': 'Magisk manager', | |
'projekt.substratum': 'substratum', | |
'com.netease.cloudmusic': '網易雲音樂' | |
} | |
prog | |
.version('8.0.0') | |
.option('install <package_name> ', '安裝應用') | |
.option('search <app_name>', '搜索應用') | |
.option('login', '登入酷安') | |
.parse(process.argv) | |
if (prog.install) { | |
(async () => { | |
await sleep(500) | |
if (!(prog.install in db)) { | |
console.log(`應用 ${prog.install} 未收錄或是已下架`.red) | |
return | |
} | |
console.log(`下載 ${db[prog.install]} 中....`) | |
await sleep(Math.random() * 5000) | |
console.log(`${db[prog.install]} 下載完成!`.green) | |
console.log(`準備開始安裝...`) | |
await sleep(500) | |
console.log(`安裝中...`) | |
await sleep(Math.random() * 5000) | |
console.log(`${db[prog.install]} 安裝完成!`.green) | |
})() | |
} | |
else if (prog.search) { | |
let result = fuzzy.filter(prog.search, Object.values(db)).map(l => l.string) | |
console.log(`找到 ${result.length} 項結果`.green) | |
result.forEach(r => console.log(` - ${r}`.blue, `\n ${Object.keys(db).filter(k => db[k] === r)[0]}`.green)) | |
} | |
else if (prog.login) { | |
prompt.start() | |
prompt.get([{ | |
name: 'account', | |
required: true | |
}, { | |
name: 'password', | |
required: true, | |
hidden: true | |
}],async (err, r) => { | |
await sleep(1000) | |
console.log(`${r.account} 已登入`.green) | |
}) | |
} | |
else { | |
prog.outputHelp() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "coolapk", | |
"version": "1.0.0", | |
"main": "index.js", | |
"license": "MIT", | |
"dependencies": { | |
"colors": "^1.1.2", | |
"commander": "^2.11.0", | |
"fuzzy": "^0.1.3", | |
"prompt": "^1.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment