arma-server-web-admin/lib/mods.js

44 lines
827 B
JavaScript
Raw Normal View History

var events = require('events')
var fs = require('fs.extra')
var path = require('path')
var Mods = function (config) {
this.config = config
this.mods = []
}
Mods.prototype = new events.EventEmitter()
2015-07-22 18:16:30 +00:00
Mods.prototype.delete = function (mod, cb) {
var self = this
2015-07-22 18:16:30 +00:00
fs.rmrf(path.join(this.config.path, mod), function (err) {
cb(err)
if (!err) {
self.updateMods()
}
})
}
2015-07-22 18:16:30 +00:00
Mods.prototype.updateMods = function () {
var self = this
fs.readdir(self.config.path, function (err, files) {
if (err) {
console.log(err)
} else {
var mods = files.filter(function (file) {
return file.charAt(0) === '@'
2017-02-21 19:22:28 +00:00
}).map(function (name) {
return {
name: name
}
})
2017-02-21 19:22:28 +00:00
self.mods = mods
self.emit('mods', mods)
2015-02-04 23:42:18 +00:00
}
})
}
2015-02-01 04:01:50 +00:00
module.exports = Mods