Created
October 27, 2016 05:19
-
-
Save AlinaNova21/980c51f58098923577e944c687abf580 to your computer and use it in GitHub Desktop.
This file contains 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 fs = require('fs') | |
const path = require('path') | |
const modsDir = `${__dirname}/node_modules` | |
module.exports = function (config) { | |
log('Loading mods') | |
getMods().forEach(mod => { | |
console.log(' --', mod.package.name) | |
mod.module(config) | |
}) | |
} | |
function getMods (cb) { | |
try { | |
fs.accessSync(modsDir) | |
} catch(e) { | |
log('No mods folder, are any mods installed?') | |
return [] | |
} | |
try { | |
let files = fs.readdirSync(modsDir) | |
let mods = files.map(f => ({ | |
package: require(path.join(f, 'package.json')) | |
})).filter(m => !!~m.package.keywords.indexOf('screeps') && !!~m.package.keywords.indexOf('mod')) | |
mods.forEach(m => m.module = require(m.package.name)) | |
return mods | |
} catch(e) { | |
log('failed to load mods') | |
throw e | |
} | |
} | |
function log (...args) { | |
console.log('ModLoader', ...args) | |
} | |
function err (...args) { | |
console.error('ModLoader', ...args) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment