mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 07:43:12 +09:00
Added list and delete commands to client.js for managing instances
client.js list client.js delete [instance] also adde --help to show usage
This commit is contained in:
1 parent
964bc76b53
commit
a896b032aa
2 files changed
+45
-3
No files matched your search
@@ -1,20 +1,61 @@
|
|||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var needle = require("needle");
|
var needle = require("needle");
|
||||||
var child_process = require('child_process');
|
var child_process = require('child_process');
|
||||||
|
var path = require('path')
|
||||||
|
|
||||||
// require config.json
|
// require config.json
|
||||||
var config = require('./config');
|
var config = require('./config');
|
||||||
|
|
||||||
var instance = process.argv[2];
|
var instance = process.argv[2];
|
||||||
if (!instance) {
|
if (!instance || instance == "help" || instance == "--help") {
|
||||||
console.error("Usage: node client.js [instance name]")
|
console.error("Usage: ")
|
||||||
|
console.error("node client.js [instance name]")
|
||||||
|
console.error("node client.js list")
|
||||||
|
console.error("node client.js delete [instance]")
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
if (process.argv[2] == "list") {
|
||||||
|
console.dir(getDirectories("./instances/"));
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
var deleteFolderRecursive = function (path) {
|
||||||
|
if (fs.existsSync(path)) {
|
||||||
|
fs.readdirSync(path).forEach(function (file, index) {
|
||||||
|
var curPath = path + "/" + file;
|
||||||
|
if (fs.lstatSync(curPath).isDirectory()) { // recurse
|
||||||
|
deleteFolderRecursive(curPath);
|
||||||
|
} else { // delete file
|
||||||
|
fs.unlinkSync(curPath);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
fs.rmdirSync(path);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (process.argv[2] == "delete") {
|
||||||
|
if (!process.argv[3]) {
|
||||||
|
console.error("Usage: node client.js delete [instance]");
|
||||||
|
process.exit(1)
|
||||||
|
} else if (typeof process.argv[3] == "string" && fs.existsSync("./instances/"+process.argv[3]) && process.argv[3] != "/" && process.argv[3] != "") {
|
||||||
|
deleteFolderRecursive("./instances/"+process.argv[3]);
|
||||||
|
console.log("Deleted instance " + process.argv[3])
|
||||||
|
process.exit(1)
|
||||||
|
} else {
|
||||||
|
console.error("Instance not found: " + process.argv[3]);
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function getDirectories(srcpath) {
|
||||||
|
return fs.readdirSync(srcpath).filter(function (file) {
|
||||||
|
return fs.statSync(path.join(srcpath, file)).isDirectory();
|
||||||
|
});
|
||||||
|
}
|
||||||
if (!fs.existsSync("./instances/")) {
|
if (!fs.existsSync("./instances/")) {
|
||||||
fs.mkdirSync("instances");
|
fs.mkdirSync("instances");
|
||||||
}
|
}
|
||||||
var instancedirectory = './instances/' + instance;
|
var instancedirectory = './instances/' + instance;
|
||||||
|
// if instance does not exist, create it
|
||||||
if (!fs.existsSync(instancedirectory)) {
|
if (!fs.existsSync(instancedirectory)) {
|
||||||
|
console.log("Creating instance...")
|
||||||
fs.mkdirSync(instancedirectory);
|
fs.mkdirSync(instancedirectory);
|
||||||
fs.mkdirSync(instancedirectory + "/script-output/");
|
fs.mkdirSync(instancedirectory + "/script-output/");
|
||||||
fs.writeFileSync(instancedirectory + "/script-output/output.txt", "")
|
fs.writeFileSync(instancedirectory + "/script-output/output.txt", "")
|
||||||
|
|||||||
+2
-1
@@ -4,7 +4,8 @@
|
|||||||
"description": "Factorio cluster???",
|
"description": "Factorio cluster???",
|
||||||
"main": "master.js",
|
"main": "master.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "nodemon master.js"
|
"test": "nodemon master.js",
|
||||||
|
"start": "echo Run node client.js [instance] to start slaves && node master.js"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"factorio"
|
"factorio"
|
||||||
|
|||||||
Reference in new issue
Block a user