diff --git a/.gitignore b/.gitignore index 043bbd5c..50b1c745 100644 --- a/.gitignore +++ b/.gitignore @@ -62,7 +62,5 @@ sharedPlugins/scenario_loader/scenarios # File used for marking plugins as disabled sharedPlugins/*/DISABLED -\.cache-require-paths\.json - # IDE .idea/ diff --git a/.snyk b/.snyk deleted file mode 100644 index d7f0b403..00000000 --- a/.snyk +++ /dev/null @@ -1,45 +0,0 @@ -# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. -version: v1.13.3 -ignore: {} -# patches apply the minimum changes required to fix a vulnerability -patch: - 'npm:lodash:20180130': - - html5-validator > caporal > cli-table2 > lodash: - patched: '2018-07-03T06:07:55.532Z' - 'npm:hawk:20160119': - - node-factorio-api > documentation > highlight.js > gear-lib > less > request > hawk: - patched: '2019-02-25T06:48:21.845Z' - 'npm:http-signature:20150122': - - node-factorio-api > documentation > highlight.js > gear-lib > less > request > http-signature: - patched: '2019-02-25T06:48:21.845Z' - 'npm:mime:20170907': - - node-factorio-api > documentation > highlight.js > gear-lib > mime: - patched: '2019-02-25T06:48:21.845Z' - - node-factorio-api > documentation > highlight.js > gear-lib > less > mime: - patched: '2019-02-25T06:48:21.845Z' - - node-factorio-api > documentation > highlight.js > gear-lib > less > request > form-data > mime: - patched: '2019-02-25T06:48:21.845Z' - 'npm:minimatch:20160620': - - node-factorio-api > documentation > highlight.js > gear > liftoff > findup-sync > glob > minimatch: - patched: '2019-02-25T06:48:21.845Z' - - node-factorio-api > documentation > highlight.js > gear-lib > gear > liftoff > findup-sync > glob > minimatch: - patched: '2019-02-25T06:48:21.845Z' - - node-factorio-api > documentation > highlight.js > gear-lib > glob > minimatch: - patched: '2019-02-25T06:48:21.845Z' - - node-factorio-api > documentation > highlight.js > gear-lib > jslint > glob > minimatch: - patched: '2019-02-25T06:48:21.845Z' - - node-factorio-api > documentation > highlight.js > gear-lib > jshint > cli > glob > minimatch: - patched: '2019-02-25T06:48:21.845Z' - - node-factorio-api > documentation > highlight.js > gear-lib > jshint > minimatch: - patched: '2019-02-25T06:48:21.845Z' - 'npm:request:20160119': - - node-factorio-api > documentation > highlight.js > gear-lib > less > request: - patched: '2019-02-25T06:48:21.845Z' - 'npm:tunnel-agent:20170305': - - node-factorio-api > documentation > highlight.js > gear-lib > less > request > tunnel-agent: - patched: '2019-02-25T06:48:21.845Z' - 'npm:uglify-js:20151024': - - node-factorio-api > documentation > highlight.js > gear-lib > handlebars > uglify-js: - patched: '2019-02-25T06:48:21.845Z' - - node-factorio-api > documentation > highlight.js > gear-lib > uglify-js: - patched: '2019-02-25T06:48:21.845Z' diff --git a/Dockerfile b/Dockerfile index 399c1259..b754a329 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM node:9.11.2 RUN apt-get update && apt install git curl tar -y RUN mkdir factorioClusterio -RUN git clone -b master https://github.com/Danielv123/factorioClusterio.git && cd factorioClusterio && npm install +RUN git clone -b master https://github.com/Danielv123/factorioClusterio.git && cd factorioClusterio && npm install --only=production RUN cd factorioClusterio && curl -o factorio.tar.gz -L https://www.factorio.com/get-download/latest/headless/linux64 && tar -xf factorio.tar.gz WORKDIR factorioClusterio diff --git a/README.md b/README.md index 99a9995e..68efdcbe 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ Master and all slaves: cd factorioClusterio curl -o factorio.tar.gz -L https://www.factorio.com/get-download/latest/headless/linux64 tar -xf factorio.tar.gz - npm install + npm install --only=production cp config.json.dist config.json node ./lib/npmPostinstall.js @@ -283,7 +283,7 @@ node client.js list ``` git pull -npm install +npm install --only=production ``` 3. Download the latest version of the factorioClusterioMod from its github repo diff --git a/client.js b/client.js index adcc8cab..6434ba22 100644 --- a/client.js +++ b/client.js @@ -8,8 +8,6 @@ const syncRequest = require('sync-request'); const request = require("request"); const ncp = require('ncp').ncp; const Rcon = require('rcon-client-fork').Rcon; -const hashFiles = require('hash-files'); -const _ = require('underscore'); const deepmerge = require("deepmerge"); const getMac = require('getmac').getMac; const rmdirSync = require('rmdir-sync'); @@ -20,6 +18,7 @@ const objectOps = require("lib/objectOps.js"); const fileOps = require("lib/fileOps"); const stringUtils = require("lib/stringUtils.js"); const configManager = require("lib/manager/configManager.js"); +const hashFile = require('lib/hash').hashFile; // argument parsing const args = require('minimist')(process.argv.slice(2)); @@ -563,8 +562,11 @@ write-data=${ path.resolve(config.instanceDirectory, instance) }\r\n } // ensure instancemanagement only ever runs once -_.once(instanceManagement); +var _instanceInitialized; async function instanceManagement(instanceconfig) { + if (_instanceInitialized) return; + _instanceInitialized = true; + console.log("Started instanceManagement();"); /* Open websocket connection to master */ @@ -773,42 +775,22 @@ function hashMods(instanceName, callback) { if(!callback) { throw new Error("ERROR in function hashMods NO CALLBACK"); } - function callback2(hash, modName){ - hashedMods[hashedMods.length] = { - modName: modName, - hash: hash, - }; - // check if this callback has ran once for each mod - if(hashedMods.length == instanceMods.length) { - callback(hashedMods); - } - //console.log(modname); - } - let hashedMods = []; - /*let mods = fs.readdirSync("./sharedMods/")*/ - let instanceMods = fs.readdirSync(config.instanceDirectory+"/"+instanceName+"/mods/"); - if(instanceMods.length == 0){ - callback({}); // there are no mods installed, return an empty object - } - for(let o=0;o ( + {modName: name, hash: hash} + )); } } - for(let i=0; i { + // Remove null entries from hashMod + callback(hashes.filter(entry => entry !== null)); + }); } diff --git a/documentation.yml b/documentation.yml deleted file mode 100644 index f5ff75a1..00000000 --- a/documentation.yml +++ /dev/null @@ -1,10 +0,0 @@ -toc: - - name: Master Server API - - clusterioMaster - - name: Type declarations - - itemStack - - name: Internal modules - description: | - Here are some helper functions for navigation. - - modManager - - getFactorioLocale \ No newline at end of file diff --git a/lib/factorioServer/index.js b/lib/factorioServer/index.js index 0dd4c602..b6e175f8 100644 --- a/lib/factorioServer/index.js +++ b/lib/factorioServer/index.js @@ -15,7 +15,6 @@ const child_process = require("child_process"); const path = require("path"); const mkdirp = require("mkdirp"); -const appRootPath = require("app-root-path"); const fileOps = require("lib/fileOps"); diff --git a/lib/factorioServer/index.spec.js b/lib/factorioServer/index.spec.js index 0a63fbcb..1caf2afb 100644 --- a/lib/factorioServer/index.spec.js +++ b/lib/factorioServer/index.spec.js @@ -2,7 +2,6 @@ const assert = require("assert"); const fs = require("fs"); const path = require("path"); -const appRootPath = require("app-root-path"); const parallel = require("mocha.parallel"); const mkdirp = require("mkdirp"); @@ -75,7 +74,7 @@ describe("class factorioServer/index.js", ()=>{ describe(".createMap(mapName.zip)", ()=>{ it("creates a map file as instanceDirectory/saves/map.zip", async function(){ this.timeout(20000); // these test often takes a lot of time in the map creation step (4500 ms on i3 dev system) - let relativePath = __dirname.replace(appRootPath, "").substr(1); + let relativePath = path.relative('.', __dirname); let server = new factorioServer({ instanceDirectory: path.join(relativePath, "_testData_createMap"), instanceName: "Unit testing instance", @@ -93,7 +92,7 @@ describe("class factorioServer/index.js", ()=>{ }); it("supports custom filenames", async function(){ this.timeout(20000); - let relativePath = __dirname.replace(appRootPath, "").substr(1); + let relativePath = path.relative('.', __dirname); let server = new factorioServer({ instanceDirectory: path.join(relativePath, "_testData_createMap_2"), instanceName: "Unit testing instance", diff --git a/lib/hash.js b/lib/hash.js new file mode 100644 index 00000000..f0bdfd7a --- /dev/null +++ b/lib/hash.js @@ -0,0 +1,22 @@ +const crypto = require('crypto'); +const fs = require('fs'); + +/** + * Returns a promise that resolves to the SHA1 hash of the file given by path + */ +exports.hashFile = function(path) { + return new Promise(function(resolve, reject) { + let hasher = crypto.createHash('sha1') + hasher.setEncoding('hex') + hasher.on('finish', function() { + resolve(hasher.read()); + }); + + let stream = fs.createReadStream(path); + stream.on('error', function(error) { + // the docs doesn't say anything about what's passed on error + reject(error); + }); + stream.pipe(hasher); + }); +} diff --git a/lib/manager/modManager.js b/lib/manager/modManager.js index b4fc2279..999c81d8 100644 --- a/lib/manager/modManager.js +++ b/lib/manager/modManager.js @@ -3,7 +3,6 @@ Provides tools to manage mods in a clusterio install @module modManager */ -const rightpad = require("right-pad"); const asTable = require("as-table").configure({delimiter: ' | '}); const moment = require("moment"); const syncRequest = require("sync-request"); diff --git a/master.js b/master.js index 02f3e36f..db1ef173 100644 --- a/master.js +++ b/master.js @@ -26,10 +26,6 @@ process.on('unhandledRejection', r => console.log(r)); // configgy stuff debug = false; -// reduces loadtime from 1700 ms to 1200 ms on my i3 + SSD -// tested by logging Date.now() here and when the webserver started listening -require('cache-require-paths'); - // argument parsing const args = require('minimist')(process.argv.slice(2)); diff --git a/package.json b/package.json index 2f817d0f..08fa33f3 100644 --- a/package.json +++ b/package.json @@ -8,12 +8,8 @@ "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)/**/}*.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", - "bundle-dependencies": "bundle-dependencies", - "snyk-protect": "snyk protect", - "prepublish": "npm run snyk-protect" + "bundle-dependencies": "bundle-dependencies" }, "keywords": [ "factorio" @@ -21,15 +17,12 @@ "author": "Danielv123", "license": "ISC", "dependencies": { - "app-root-path": "^2.0.1", "as-table": "^1.0.31", "averaged-timeseries": "^1.4.0", "base64url": "^3.0.0", "bcrypt": "^2.0.1", "bcrypt-promise": "^2.0.0", - "bcryptjs": "^2.4.3", "body-parser": "^1.18.2", - "cache-require-paths": "^0.3.0", "cli": "^1.0.1", "cli-interact": "^0.1.9", "codecov": "^3.0.1", @@ -43,8 +36,6 @@ "follow-redirects": "^1.5.0", "fs-extra": "^6.0.1", "getmac": "^1.4.0", - "hash-files": "^1.1.1", - "html5-validator": "^1.0.7", "ini": "^1.3.5", "jsonwebtoken": "^8.2.1", "lib": "file:./lib", @@ -55,27 +46,24 @@ "moment": "^2.22.2", "ncp": "^2.0.0", "needle": "^2.2.4", - "node-factorio-api": "^0.3.1-alpha", + "node-factorio-api": "^0.3.5", "node-forge": "^0.7.1", "prom-client": "^10.2.3", "rcon-client-fork": "^3.2.0", "request": "^2.83.0", - "right-pad": "^1.0.1", "rmdir-sync": "^1.0.1", "sanitizer": "^0.1.3", "simple-git": "^1.96.0", "single-line-log": "^1.1.2", - "snyk": "^1.134.2", "socket.io": "^2.0.4", "socket.io-client": "^2.0.4", "socket.io-prometheus": "^0.2.1", "sync-request": "^4.0.1", "tail": "^2.0.2", - "typescript-collections": "^1.3.2", - "underscore": "^1.8.3" + "typescript-collections": "^1.3.2" }, "devDependencies": { - "documentation": "^5.4.0", + "html5-validator": "^1.0.7", "istanbul": "^0.4.5", "mocha": "^3.5.3", "mocha-sinon": "^2.0.0", @@ -83,6 +71,5 @@ "nock": "^9.1.6", "sinon": "^2.4.1", "supertest": "^3.0.0" - }, - "snyk": true + } }