2017-08-24 09:15:06 +00:00
|
|
|
var events = require('events')
|
|
|
|
var fs = require('fs.extra')
|
2020-12-26 12:56:59 +00:00
|
|
|
var glob = require('glob')
|
2017-08-24 09:15:06 +00:00
|
|
|
var path = require('path')
|
2015-01-21 03:00:09 +00:00
|
|
|
|
|
|
|
var Mods = function (config) {
|
2017-08-24 09:15:06 +00:00
|
|
|
this.config = config
|
|
|
|
this.mods = []
|
|
|
|
}
|
2015-02-01 04:27:12 +00:00
|
|
|
|
2017-08-24 09:15:06 +00:00
|
|
|
Mods.prototype = new events.EventEmitter()
|
2015-02-01 04:27:12 +00:00
|
|
|
|
2015-07-22 18:16:30 +00:00
|
|
|
Mods.prototype.delete = function (mod, cb) {
|
2017-08-24 09:15:06 +00:00
|
|
|
var self = this
|
2015-07-22 18:16:30 +00:00
|
|
|
fs.rmrf(path.join(this.config.path, mod), function (err) {
|
2017-08-24 09:15:06 +00:00
|
|
|
cb(err)
|
2015-07-22 19:20:05 +00:00
|
|
|
|
|
|
|
if (!err) {
|
2017-08-24 09:15:06 +00:00
|
|
|
self.updateMods()
|
2015-07-22 19:20:05 +00:00
|
|
|
}
|
2017-08-24 09:15:06 +00:00
|
|
|
})
|
|
|
|
}
|
2015-07-22 18:16:30 +00:00
|
|
|
|
2015-02-01 04:27:12 +00:00
|
|
|
Mods.prototype.updateMods = function () {
|
2017-08-24 09:15:06 +00:00
|
|
|
var self = this
|
2021-06-16 12:32:41 +00:00
|
|
|
glob('**/{@*,csla,gm,vn}/addons', { cwd: self.config.path }, function (err, files) {
|
2015-01-21 03:00:09 +00:00
|
|
|
if (err) {
|
2017-08-24 09:15:06 +00:00
|
|
|
console.log(err)
|
2015-01-21 03:00:09 +00:00
|
|
|
} else {
|
2020-12-26 12:56:59 +00:00
|
|
|
var mods = files.map(function (file) {
|
2017-02-21 19:22:28 +00:00
|
|
|
return {
|
2020-12-26 12:56:59 +00:00
|
|
|
// Find actual parent mod folder from addons folder
|
|
|
|
name: path.join(file, '..')
|
2017-08-24 09:15:06 +00:00
|
|
|
}
|
|
|
|
})
|
2015-01-21 03:00:09 +00:00
|
|
|
|
2017-02-21 19:22:28 +00:00
|
|
|
self.mods = mods
|
|
|
|
self.emit('mods', mods)
|
2015-02-04 23:42:18 +00:00
|
|
|
}
|
2017-08-24 09:15:06 +00:00
|
|
|
})
|
|
|
|
}
|
2015-02-01 04:01:50 +00:00
|
|
|
|
2017-08-24 09:15:06 +00:00
|
|
|
module.exports = Mods
|