Added search functionality to mod manager #59

This commit is contained in:
Danielv123 committed 2017-11-06 21:12:25 +01:00
1 parent 88ff90262d
commit 2fd47434bb
6 files changed
+71 -12

No files matched your search

+32 -6
View File
@@ -17,6 +17,7 @@ const objectOps = require("./lib/objectOps.js");
const fileOps = require("./lib/fileOps.js"); const fileOps = require("./lib/fileOps.js");
const stringUtils = require("./lib/stringUtils.js"); const stringUtils = require("./lib/stringUtils.js");
const modManager = require("./lib/manager/modManager.js"); const modManager = require("./lib/manager/modManager.js");
const configManager = require("./lib/manager/configManager.js");
// require config.json // require config.json
var config = require('./config'); var config = require('./config');
@@ -124,12 +125,37 @@ if (!command || command == "help" || command == "--help") {
process.exit(1); process.exit(1);
} else if (command == "manage"){ } else if (command == "manage"){
// console.log("Launching mod manager"); // console.log("Launching mod manager");
const action = process.argv[4]; //const fullUsage = 'node client.js manage [instance, "shared"] ["mods", "config"] ...';
if(instance && action && action == "list"){ function usage(instance, tool){
modManager.listMods(instance); return 'node client.js manage '+(instance || '[instance, "shared"]') +' '+ (tool || '["mods", "config"]') + ' ...';
}
const modManagerUsage1 = 'node client.js manage ';
const modManagerUsage2 = ' mods ["list", "update"]';
const tool = process.argv[4] || "";
const action = process.argv[5] || "";
if(instance){
if(tool == "mods"){
if(action == "list"){
modManager.listMods(instance);
} else if(action == "search"){
modManager.findMods(process.argv[6]);
} else {
console.log(modManagerUsage1 + instance + modManagerUsage2);
}
} else if(tool == "config"){
if(action == "list" || action == "show" || action == "display"){
configManager.displayConfig(instance);
} else if(action == "edit"){
} else {
console.log()
}
} else {
console.log(usage(instance));
}
} else { } else {
console.log('Usage:'); console.log('Usage:');
console.log('node client.js manage [instance, "shared"] ["list"]'); console.log(usage(instance));
} }
// process.exit(1); // process.exit(1);
} else if (command == "delete") { } else if (command == "delete") {
@@ -152,8 +178,8 @@ if (!command || command == "help" || command == "--help") {
let name = JSON.parse(res.getBody())[0].assets[0].name; let name = JSON.parse(res.getBody())[0].assets[0].name;
if(url) { if(url) {
console.log(url); console.log(url);
var file = fs.createWriteStream("sharedMods/"+name); let file = fs.createWriteStream("sharedMods/"+name);
var req = https.get(url, function(response) { https.get(url, function(response) {
response.pipe(file); response.pipe(file);
console.log("Downloaded "+name); console.log("Downloaded "+name);
}); });
View File
Whitespace-only changes.
View File
Whitespace-only changes.
+33 -6
View File
@@ -1,8 +1,10 @@
const rightpad = require("right-pad"); const rightpad = require("right-pad");
const asTable = require("as-table").configure({delimiter: ' | '}); const asTable = require("as-table").configure({delimiter: ' | '});
const moment = require("moment");
const factorioAPI = require("node-factorio-api"); const factorioAPI = require("node-factorio-api");
const fileOps = require("./../fileOps.js"); const fileOps = require("./../fileOps.js");
const config = require("./../../config");
const instances = fileOps.getDirectoriesSync("./instances/"); const instances = fileOps.getDirectoriesSync("./instances/");
@@ -11,8 +13,8 @@ module.exports.listMods = function(instance){
factorioAPI.init(false, 'instances/'+instance+'/mods', 'instances/'+instance+'/saves', '0.15.37'); factorioAPI.init(false, 'instances/'+instance+'/mods', 'instances/'+instance+'/saves', '0.15.37');
console.log("Authenticating to factorio.com...") console.log("Authenticating to factorio.com...")
factorioAPI.authenticate({ factorioAPI.authenticate({
username: 'Danielv123', username: config.username,
token: '53faebce0a608b1195f01dcfd95ee1', token: config.token,
require_ownership: false require_ownership: false
}).then(token => { }).then(token => {
console.log("Currently installed:"); console.log("Currently installed:");
@@ -40,8 +42,8 @@ module.exports.listMods = function(instance){
factorioAPI.init(false, 'sharedMods/', '', '0.15.37'); factorioAPI.init(false, 'sharedMods/', '', '0.15.37');
console.log("Authenticating to factorio.com...") console.log("Authenticating to factorio.com...")
factorioAPI.authenticate({ factorioAPI.authenticate({
username: 'Danielv123', username: config.username,
token: '53faebce0a608b1195f01dcfd95ee1', token: config.token,
require_ownership: false require_ownership: false
}).then(() => { }).then(() => {
factorioAPI.getInstalledMods().then(mods => { factorioAPI.getInstalledMods().then(mods => {
@@ -57,6 +59,31 @@ module.exports.listMods = function(instance){
console.log(JSON.parse(res.getBody())) console.log(JSON.parse(res.getBody()))
*/ */
} }
module.exports.findMods = function(searchTerm){
factorioAPI.init(false);
console.log("Authenticating to factorio.com...")
factorioAPI.authenticate({
username: config.username,
token: config.token,
require_ownership: false
}).then(token => {
factorioAPI.searchMods(
{q: searchTerm, order: 'top', page_size: 20}
).then(body => {
let mods = body.results;
console.log(asTable(mods.map(mod => {
return {
title:mod.title,
name:mod.name,
downloads:mod.downloads_count,
updated: moment(mod.updated_at).format("DD.MM.YY"),
owner:mod.owner,
//license: mod.license_name,
}
})))
})
});
}
// 'https://api.github.com/repos/Danielv123/factorioClusterioMod/releases' // 'https://api.github.com/repos/Danielv123/factorioClusterioMod/releases'
module.exports.downloadFromGitURL = function(url){ module.exports.downloadFromGitURL = function(url){
@@ -68,8 +95,8 @@ module.exports.downloadFromGitURL = function(url){
console.log(JSON.parse(res.getBody())) console.log(JSON.parse(res.getBody()))
if(downloadUrl) { if(downloadUrl) {
console.log(downloadUrl); console.log(downloadUrl);
var file = fs.createWriteStream("sharedMods/"+name); let file = fs.createWriteStream("sharedMods/"+name);
var request = https.get(downloadUrl, function(response) { https.get(downloadUrl, function(response) {
response.pipe(file); response.pipe(file);
console.log("Downloaded "+name); console.log("Downloaded "+name);
}); });
+5
View File
@@ -2770,6 +2770,11 @@
"integrity": "sha512-dF+yxZSojSiI8AXGoxj5qdFWpucndc54Ug+TwlpHFaV7j22MGG+OML2+FVa6xAZtjb/OFFQhOC37Jegx2GbEwA==", "integrity": "sha512-dF+yxZSojSiI8AXGoxj5qdFWpucndc54Ug+TwlpHFaV7j22MGG+OML2+FVa6xAZtjb/OFFQhOC37Jegx2GbEwA==",
"dev": true "dev": true
}, },
"moment": {
"version": "2.19.1",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.19.1.tgz",
"integrity": "sha1-VtoaLRy/AdOLfhr8McELz6GSkWc="
},
"ms": { "ms": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
+1
View File
@@ -38,6 +38,7 @@
"linvodb3": "^3.25.0", "linvodb3": "^3.25.0",
"luamin": "^1.0.4", "luamin": "^1.0.4",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"moment": "^2.19.1",
"ncp": "^2.0.0", "ncp": "^2.0.0",
"nedb": "^1.8.0", "nedb": "^1.8.0",
"needle": "^1.1.0", "needle": "^1.1.0",