Skip to content

Instantly share code, notes, and snippets.

@AlinaNova21
Created October 27, 2016 05:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlinaNova21/980c51f58098923577e944c687abf580 to your computer and use it in GitHub Desktop.
Save AlinaNova21/980c51f58098923577e944c687abf580 to your computer and use it in GitHub Desktop.
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