From f76c84c3f1d4c7f540ba8c3bfbd70f15bbb399f4 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sun, 4 Aug 2019 15:52:36 +0200 Subject: [PATCH] Move node_modules/_app/ into lib/ as a package (#190) Move the contents of node_modules/_app into lib/ as there shouldn't be any content in node_modules. This directory is automatically managed and pruned by npm. Add lib/ as a local package in package.json, this allows scripts everywhere to require it's content as "lib/path" instead of relying on local paths. This shadows the StdLib Node.js Bindings package, but I could care less. Change all requires with lib as a local path and _app to use just lib. --- .gitignore | 1 - client.js | 16 ++++++++-------- .../clusterTools/checkHotpatchInstallation.js | 0 .../_app => lib}/clusterTools/getCommand.js | 0 .../_app => lib}/clusterTools/getInstanceName.js | 2 +- .../_app => lib}/clusterTools/getLua.js | 0 {node_modules/_app => lib}/clusterTools/index.js | 0 .../_app => lib}/factorioServer/index.js | 4 ++-- .../_app => lib}/factorioServer/index.spec.js | 0 {node_modules/_app => lib}/fileOps/fileOps.js | 0 .../_app => lib}/fileOps/fileOps.spec.js | 0 {node_modules/_app => lib}/fileOps/index.js | 0 lib/generateSSLcert.spec.js | 2 +- lib/getInstances.js | 2 +- .../_app => lib}/isFactorioCommand/index.js | 0 .../isFactorioCommand/isFactorioCommand.js | 0 .../isFactorioCommand/isFactorioCommand.spec.js | 0 lib/manager/modManager.js | 2 +- lib/package.json | 5 +++++ master.js | 10 +++++----- package.json | 5 +++-- routes/api/remove.js | 2 +- sharedPlugins/clusterioMod/index.js | 6 +++--- .../inventoryImports/interfacingFunctions.js | 2 +- .../interfacingFunctions.spec.js | 2 +- sharedPlugins/remoteMap/chunkStore.js | 2 +- sharedPlugins/researchSync/index.spec.js | 2 +- sharedPlugins/scenario_loader/index.js | 2 +- sharedPlugins/serverManager/index.js | 6 +++--- sharedPlugins/statisticsExporter/index.js | 2 +- sharedPlugins/statisticsExporter/masterPlugin.js | 2 +- static/remoteMap.js | 4 ++-- 32 files changed, 43 insertions(+), 38 deletions(-) rename {node_modules/_app => lib}/clusterTools/checkHotpatchInstallation.js (100%) rename {node_modules/_app => lib}/clusterTools/getCommand.js (100%) rename {node_modules/_app => lib}/clusterTools/getInstanceName.js (91%) rename {node_modules/_app => lib}/clusterTools/getLua.js (100%) rename {node_modules/_app => lib}/clusterTools/index.js (100%) rename {node_modules/_app => lib}/factorioServer/index.js (99%) rename {node_modules/_app => lib}/factorioServer/index.spec.js (100%) rename {node_modules/_app => lib}/fileOps/fileOps.js (100%) rename {node_modules/_app => lib}/fileOps/fileOps.spec.js (100%) rename {node_modules/_app => lib}/fileOps/index.js (100%) rename {node_modules/_app => lib}/isFactorioCommand/index.js (100%) rename {node_modules/_app => lib}/isFactorioCommand/isFactorioCommand.js (100%) rename {node_modules/_app => lib}/isFactorioCommand/isFactorioCommand.spec.js (100%) create mode 100644 lib/package.json diff --git a/.gitignore b/.gitignore index a7049f1f..043bbd5c 100644 --- a/.gitignore +++ b/.gitignore @@ -25,7 +25,6 @@ build/Release dist/ node_modules/* -!node_modules/_app Factorio* /factorio diff --git a/client.js b/client.js index 56b970b8..cb1d9853 100644 --- a/client.js +++ b/client.js @@ -15,10 +15,10 @@ const rmdirSync = require('rmdir-sync'); const ioClient = require("socket.io-client"); // internal libraries -const objectOps = require("./lib/objectOps.js"); -const fileOps = require("_app/fileOps"); -const stringUtils = require("./lib/stringUtils.js"); -const configManager = require("./lib/manager/configManager.js"); +const objectOps = require("lib/objectOps.js"); +const fileOps = require("lib/fileOps"); +const stringUtils = require("lib/stringUtils.js"); +const configManager = require("lib/manager/configManager.js"); // argument parsing const args = require('minimist')(process.argv.slice(2)); @@ -187,7 +187,7 @@ if (!command || command == "help" || command == "--help") { if(tool == "mods"){ (async function(){try{ // do require down here to reduce master load time - const modManager = require("./lib/manager/modManager.js")(config); + const modManager = require("lib/manager/modManager.js")(config); // allow managing mods if(action == "list"){ @@ -227,7 +227,7 @@ if (!command || command == "help" || command == "--help") { } } else if(tool == "plugins"){ (async function(){try{ - const pluginManager = require("./lib/manager/pluginManager.js")(config); + const pluginManager = require("lib/manager/pluginManager.js")(config); if(action == "list"){ await pluginManager.listPlugins(); } else if(action == "add" || action == "install" || action == "download"){ @@ -300,7 +300,7 @@ if (!command || command == "help" || command == "--help") { fs.mkdirSync(instancedirectory + "/mods/"); fs.mkdirSync(instancedirectory + "/instanceMods/"); fs.mkdirSync(instancedirectory + "/scenarios/"); - ncp("./lib/scenarios", path.resolve(instancedirectory, "scenarios"), err => { + ncp("lib/scenarios", path.resolve(instancedirectory, "scenarios"), err => { if (err) console.error(err) }); @@ -576,7 +576,7 @@ async function instanceManagement(instanceconfig) { setInterval(B=> socket.emit("heartbeat"), 10000); // load plugins and execute onLoad event - const pluginManager = require("./lib/manager/pluginManager.js")(config); + const pluginManager = require("lib/manager/pluginManager.js")(config); let pluginsToLoad = await pluginManager.getPlugins(); let plugins = []; diff --git a/node_modules/_app/clusterTools/checkHotpatchInstallation.js b/lib/clusterTools/checkHotpatchInstallation.js similarity index 100% rename from node_modules/_app/clusterTools/checkHotpatchInstallation.js rename to lib/clusterTools/checkHotpatchInstallation.js diff --git a/node_modules/_app/clusterTools/getCommand.js b/lib/clusterTools/getCommand.js similarity index 100% rename from node_modules/_app/clusterTools/getCommand.js rename to lib/clusterTools/getCommand.js diff --git a/node_modules/_app/clusterTools/getInstanceName.js b/lib/clusterTools/getInstanceName.js similarity index 91% rename from node_modules/_app/clusterTools/getInstanceName.js rename to lib/clusterTools/getInstanceName.js index 018242a7..70a6b524 100644 --- a/node_modules/_app/clusterTools/getInstanceName.js +++ b/lib/clusterTools/getInstanceName.js @@ -32,7 +32,7 @@ module.exports = function(config){ } } else { return async function thisAintGonnaWork(){ - let err = new Error("getInstanceName from _app/clusterTools needs to be called with {config} to work"); + let err = new Error("getInstanceName from lib/clusterTools needs to be called with {config} to work"); console.log(err); throw err; } diff --git a/node_modules/_app/clusterTools/getLua.js b/lib/clusterTools/getLua.js similarity index 100% rename from node_modules/_app/clusterTools/getLua.js rename to lib/clusterTools/getLua.js diff --git a/node_modules/_app/clusterTools/index.js b/lib/clusterTools/index.js similarity index 100% rename from node_modules/_app/clusterTools/index.js rename to lib/clusterTools/index.js diff --git a/node_modules/_app/factorioServer/index.js b/lib/factorioServer/index.js similarity index 99% rename from node_modules/_app/factorioServer/index.js rename to lib/factorioServer/index.js index 7407866e..0dd4c602 100644 --- a/node_modules/_app/factorioServer/index.js +++ b/lib/factorioServer/index.js @@ -17,7 +17,7 @@ const path = require("path"); const mkdirp = require("mkdirp"); const appRootPath = require("app-root-path"); -const fileOps = require("_app/fileOps"); +const fileOps = require("lib/fileOps"); module.exports = class factorioServer { constructor({ @@ -165,4 +165,4 @@ module.exports = class factorioServer { }); }); } -} \ No newline at end of file +} diff --git a/node_modules/_app/factorioServer/index.spec.js b/lib/factorioServer/index.spec.js similarity index 100% rename from node_modules/_app/factorioServer/index.spec.js rename to lib/factorioServer/index.spec.js diff --git a/node_modules/_app/fileOps/fileOps.js b/lib/fileOps/fileOps.js similarity index 100% rename from node_modules/_app/fileOps/fileOps.js rename to lib/fileOps/fileOps.js diff --git a/node_modules/_app/fileOps/fileOps.spec.js b/lib/fileOps/fileOps.spec.js similarity index 100% rename from node_modules/_app/fileOps/fileOps.spec.js rename to lib/fileOps/fileOps.spec.js diff --git a/node_modules/_app/fileOps/index.js b/lib/fileOps/index.js similarity index 100% rename from node_modules/_app/fileOps/index.js rename to lib/fileOps/index.js diff --git a/lib/generateSSLcert.spec.js b/lib/generateSSLcert.spec.js index d56402c1..d65a35ee 100644 --- a/lib/generateSSLcert.spec.js +++ b/lib/generateSSLcert.spec.js @@ -1,7 +1,7 @@ var assert = require("assert"); var fs = require("fs"); -var fileOps = require("_app/fileOps"); +var fileOps = require("lib/fileOps"); var generateSSLcert = require("./generateSSLcert.js") describe("generateSSLcert.js(options)", ()=>{ diff --git a/lib/getInstances.js b/lib/getInstances.js index 3565c0e2..ca819a76 100644 --- a/lib/getInstances.js +++ b/lib/getInstances.js @@ -1,4 +1,4 @@ -const fileOps = require("_app/fileOps"); +const fileOps = require("fileOps"); // const config = require("./../config"); module.exports = function(config) { diff --git a/node_modules/_app/isFactorioCommand/index.js b/lib/isFactorioCommand/index.js similarity index 100% rename from node_modules/_app/isFactorioCommand/index.js rename to lib/isFactorioCommand/index.js diff --git a/node_modules/_app/isFactorioCommand/isFactorioCommand.js b/lib/isFactorioCommand/isFactorioCommand.js similarity index 100% rename from node_modules/_app/isFactorioCommand/isFactorioCommand.js rename to lib/isFactorioCommand/isFactorioCommand.js diff --git a/node_modules/_app/isFactorioCommand/isFactorioCommand.spec.js b/lib/isFactorioCommand/isFactorioCommand.spec.js similarity index 100% rename from node_modules/_app/isFactorioCommand/isFactorioCommand.spec.js rename to lib/isFactorioCommand/isFactorioCommand.spec.js diff --git a/lib/manager/modManager.js b/lib/manager/modManager.js index 78a07ca4..b4fc2279 100644 --- a/lib/manager/modManager.js +++ b/lib/manager/modManager.js @@ -13,7 +13,7 @@ const factorioAPI = require("node-factorio-api"); const sLog = require("single-line-log").stdout; const query = require('cli-interact').getYesNo; -const fileOps = require("_app/fileOps"); +const fileOps = require("lib/fileOps"); // const config = require("./../../config"); diff --git a/lib/package.json b/lib/package.json new file mode 100644 index 00000000..269ff388 --- /dev/null +++ b/lib/package.json @@ -0,0 +1,5 @@ +{ + "name": "lib", + "description": "Internal library for factorioClusterio" +} + diff --git a/master.js b/master.js index 6ed5e4a7..e08631dc 100644 --- a/master.js +++ b/master.js @@ -55,12 +55,12 @@ mkdirp.sync(config.databaseDirectory); mkdirp.sync(masterModFolder); // homebrew modules -const getFactorioLocale = require("./lib/getFactorioLocale"); -const stringUtils = require("./lib/stringUtils"); -const fileOps = require("_app/fileOps"); +const getFactorioLocale = require("lib/getFactorioLocale"); +const stringUtils = require("lib/stringUtils"); +const fileOps = require("lib/fileOps"); // homemade express middleware for token auth -const authenticate = require("./lib/authenticate")(config); +const authenticate = require("lib/authenticate")(config); /** Sync */ function randomStringAsBase64Url(size) { @@ -991,7 +991,7 @@ async function pluginManagement(){ } async function getPlugins(){ - const pluginManager = require("./lib/manager/pluginManager.js")(config); + const pluginManager = require("lib/manager/pluginManager.js")(config); let plugins = []; let pluginsToLoad = await pluginManager.getPlugins(); for(let i = 0; i < pluginsToLoad.length; i++){ diff --git a/package.json b/package.json index b900e060..3c3ef4dd 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "repository": "https://github.com/Danielv123/factorioClusterio", "main": "master.js", "scripts": { - "test": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- \"./{{,node_modules/_app/**/},!(node_modules)/**/}*.spec.js\" -R spec || echo .", + "test": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- \"./{,!(node_modules)/**/}*.spec.js\" -R spec || echo .", "start": "echo Run node client.js start [instance] to start slaves && node master.js", - "cover": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- \"./{{,node_modules/_app/**/},!(node_modules)/**/}*.spec.js\" -R spec || echo . && codecov -t f7b38085-36eb-4d72-84e6-64721910171e", + "cover": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- \"./{,!(node_modules)/**/}*.spec.js\" -R spec || echo . && codecov -t f7b38085-36eb-4d72-84e6-64721910171e", "docs": "documentation build index.js --config documentation.yml -f html -o docs", "livedocs": "documentation serve --watch *.js lib/** --config documentation.yml", "install": "node lib/npmPostinstall.js", @@ -47,6 +47,7 @@ "html5-validator": "^1.0.7", "ini": "^1.3.5", "jsonwebtoken": "^8.2.1", + "lib": "file:./lib", "luamin": "^1.0.4", "minimist": "^1.2.0", "mkdirp": "^0.5.1", diff --git a/routes/api/remove.js b/routes/api/remove.js index a29d1165..e9d1952c 100644 --- a/routes/api/remove.js +++ b/routes/api/remove.js @@ -1,6 +1,6 @@ const averagedTimeSeries = require("averaged-timeseries") -const doleNN = require("./../../lib/dole_nn_base.js") +const doleNN = require("lib/dole_nn_base.js") const Prometheus = require('prom-client'); diff --git a/sharedPlugins/clusterioMod/index.js b/sharedPlugins/clusterioMod/index.js index 240bc2ba..4b591025 100644 --- a/sharedPlugins/clusterioMod/index.js +++ b/sharedPlugins/clusterioMod/index.js @@ -1,9 +1,9 @@ const needle = require("needle"); const fs = require("fs-extra"); -const objectOps = require("./../../lib/objectOps.js"); -const fileOps = require("_app/fileOps"); -const stringUtils = require("./../../lib/stringUtils.js"); +const objectOps = require("lib/objectOps.js"); +const fileOps = require("lib/fileOps"); +const stringUtils = require("lib/stringUtils.js"); const pluginConfig = require("./config"); const COMPRESS_LUA = false; diff --git a/sharedPlugins/inventoryImports/interfacingFunctions.js b/sharedPlugins/inventoryImports/interfacingFunctions.js index de9b6d54..b5ed13ff 100644 --- a/sharedPlugins/inventoryImports/interfacingFunctions.js +++ b/sharedPlugins/inventoryImports/interfacingFunctions.js @@ -1,4 +1,4 @@ -const objectOps = require("../../lib/objectOps.js"); +const objectOps = require("lib/objectOps.js"); const needle = require("needle"); const pluginConfig = require("./config") const isJson = require("./isJson") diff --git a/sharedPlugins/inventoryImports/interfacingFunctions.spec.js b/sharedPlugins/inventoryImports/interfacingFunctions.spec.js index 799c5304..e8237f71 100644 --- a/sharedPlugins/inventoryImports/interfacingFunctions.spec.js +++ b/sharedPlugins/inventoryImports/interfacingFunctions.spec.js @@ -2,7 +2,7 @@ const assert = require("assert"); const child_process = require("child_process"); const functions = require("./interfacingFunctions"); const luamin = require("luamin"); -const isFactorioCommand = require("_app/isFactorioCommand"); +const isFactorioCommand = require("lib/isFactorioCommand"); const nock = require("nock"); // sinon does weird prototype manipulation and so doen't need to be saved to anything. diff --git a/sharedPlugins/remoteMap/chunkStore.js b/sharedPlugins/remoteMap/chunkStore.js index 330ab601..4e33b1f3 100644 --- a/sharedPlugins/remoteMap/chunkStore.js +++ b/sharedPlugins/remoteMap/chunkStore.js @@ -4,7 +4,7 @@ var fs = require("fs"); var events = require("events"); var path = require("path"); -var objectOps = require("./../../lib/objectOps"); +var objectOps = require("lib/objectOps"); var LinvoDB = require("linvodb3"); // LinvoDB.dbPath = "./database/linvodb/"; diff --git a/sharedPlugins/researchSync/index.spec.js b/sharedPlugins/researchSync/index.spec.js index 372bf01e..6722e602 100644 --- a/sharedPlugins/researchSync/index.spec.js +++ b/sharedPlugins/researchSync/index.spec.js @@ -1,6 +1,6 @@ const assert = require("assert"); -const isFactorioCommand = require("_app/isFactorioCommand"); +const isFactorioCommand = require("lib/isFactorioCommand"); const researchSync = require("./index.js"); diff --git a/sharedPlugins/scenario_loader/index.js b/sharedPlugins/scenario_loader/index.js index 319ffe2b..afe0cb1f 100644 --- a/sharedPlugins/scenario_loader/index.js +++ b/sharedPlugins/scenario_loader/index.js @@ -1,6 +1,6 @@ const fs = require("fs-extra"); const path = require("path"); -const clusterTools = require("_app/clusterTools")(); +const clusterTools = require("lib/clusterTools")(); module.exports = class remoteCommands { constructor(mergedConfig, messageInterface, extras){ diff --git a/sharedPlugins/serverManager/index.js b/sharedPlugins/serverManager/index.js index 7b519b3d..065033ee 100644 --- a/sharedPlugins/serverManager/index.js +++ b/sharedPlugins/serverManager/index.js @@ -9,9 +9,9 @@ module.exports = class remoteCommands { this.messageInterface = messageInterface; this.config = mergedConfig; this.socket = extras.socket; - const pluginManager = require("./../../lib/manager/pluginManager.js")(this.config); - const configManager = require("./../../lib/manager/configManager.js"); - // const modManager = require("./../../lib/manager/modManager.js")(this.config); + const pluginManager = require("lib/manager/pluginManager.js")(this.config); + const configManager = require("lib/manager/configManager.js"); + // const modManager = require("lib/manager/modManager.js")(this.config); this.socket.on("hello", () => { this.socket.emit("registerServerManager"); }); diff --git a/sharedPlugins/statisticsExporter/index.js b/sharedPlugins/statisticsExporter/index.js index 93062f9e..fe03b9a1 100644 --- a/sharedPlugins/statisticsExporter/index.js +++ b/sharedPlugins/statisticsExporter/index.js @@ -2,7 +2,7 @@ const needle = require("needle"); const fs = require("fs-extra"); const path = require("path"); -const clusterTools = require("_app/clusterTools")(); +const clusterTools = require("lib/clusterTools")(); const pluginConfig = require("./config"); module.exports = class remoteCommands { diff --git a/sharedPlugins/statisticsExporter/masterPlugin.js b/sharedPlugins/statisticsExporter/masterPlugin.js index 689dd2eb..eb6fe31b 100644 --- a/sharedPlugins/statisticsExporter/masterPlugin.js +++ b/sharedPlugins/statisticsExporter/masterPlugin.js @@ -3,7 +3,7 @@ const path = require("path"); class masterPlugin { constructor({config, socketio, express, Prometheus}){ - const authenticate = require("./../../lib/authenticate")(config); + const authenticate = require("lib/authenticate")(config); this.config = config; this.io = socketio; diff --git a/static/remoteMap.js b/static/remoteMap.js index 5cfe1db3..d966d908 100644 --- a/static/remoteMap.js +++ b/static/remoteMap.js @@ -19,8 +19,8 @@ console.log(":)") /// ES6 imports // rules for how entities are drawn (sizes, offset etc) -import {entityDrawRules} from "./lib/entityDrawRules.js"; -import {getParameterByName, drawImageWithRotation, isImageOk} from "./lib/utility.js"; +import {entityDrawRules} from "lib/entityDrawRules.js"; +import {getParameterByName, drawImageWithRotation, isImageOk} from "lib/utility.js"; import spritesheetJson from "./pictures/spritesheet.js"; import {itemSelector} from "./remoteMap/itemSelection.js"; var global = {};