2018-06-23 12:17:26 -07:00
|
|
|
const AdmZip = require('adm-zip')
|
2017-11-30 00:00:06 -08:00
|
|
|
const {AssetGuard, Library} = require('./assetguard.js')
|
2018-06-23 12:17:26 -07:00
|
|
|
const child_process = require('child_process')
|
|
|
|
const ConfigManager = require('./configmanager.js')
|
|
|
|
const crypto = require('crypto')
|
|
|
|
const fs = require('fs')
|
|
|
|
const mkpath = require('mkdirp')
|
|
|
|
const os = require('os')
|
|
|
|
const path = require('path')
|
|
|
|
const rimraf = require('rimraf')
|
|
|
|
const {URL} = require('url')
|
2017-11-19 00:48:21 -08:00
|
|
|
|
|
|
|
class ProcessBuilder {
|
|
|
|
|
2018-06-03 21:17:20 -07:00
|
|
|
constructor(distroServer, versionData, forgeData, authUser){
|
|
|
|
this.gameDir = path.join(ConfigManager.getInstanceDirectory(), distroServer.id)
|
|
|
|
this.commonDir = ConfigManager.getCommonDirectory()
|
2017-11-19 00:48:21 -08:00
|
|
|
this.server = distroServer
|
|
|
|
this.versionData = versionData
|
|
|
|
this.forgeData = forgeData
|
|
|
|
this.authUser = authUser
|
2018-06-23 18:03:49 -07:00
|
|
|
this.fmlDir = path.join(this.gameDir, 'forgeModList.json')
|
|
|
|
this.llDir = path.join(this.gameDir, 'liteloaderModList.json')
|
2018-06-03 21:17:20 -07:00
|
|
|
this.libPath = path.join(this.commonDir, 'libraries')
|
2018-06-23 18:03:49 -07:00
|
|
|
|
|
|
|
this.usingLiteLoader = false
|
|
|
|
this.llPath = null
|
2017-11-19 00:48:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convienence method to run the functions typically used to build a process.
|
|
|
|
*/
|
|
|
|
build(){
|
2018-06-03 21:17:20 -07:00
|
|
|
mkpath.sync(this.gameDir)
|
2018-04-14 21:00:08 -07:00
|
|
|
const tempNativePath = path.join(os.tmpdir(), ConfigManager.getTempNativeFolder(), crypto.pseudoRandomBytes(16).toString('hex'))
|
2017-11-29 22:40:56 -08:00
|
|
|
process.throwDeprecation = true
|
2018-06-23 18:03:49 -07:00
|
|
|
this.setupLiteLoader()
|
|
|
|
const modObj = this.resolveModConfiguration(ConfigManager.getModConfiguration(this.server.id).mods, this.server.modules)
|
|
|
|
this.constructModList('forge', modObj.fMods, true)
|
|
|
|
if(this.usingLiteLoader){
|
|
|
|
this.constructModList('liteloader', modObj.lMods, true)
|
|
|
|
}
|
|
|
|
const uberModArr = modObj.fMods.concat(modObj.lMods)
|
|
|
|
const args = this.constructJVMArguments(uberModArr, tempNativePath)
|
2017-11-19 00:48:21 -08:00
|
|
|
|
2017-11-29 22:40:56 -08:00
|
|
|
console.log(args)
|
2017-11-19 00:48:21 -08:00
|
|
|
|
2018-03-31 10:05:05 -07:00
|
|
|
const child = child_process.spawn(ConfigManager.getJavaExecutable(), args, {
|
2018-06-03 21:17:20 -07:00
|
|
|
cwd: this.gameDir,
|
2018-06-04 13:28:17 -07:00
|
|
|
detached: ConfigManager.getLaunchDetached()
|
2018-03-31 10:05:05 -07:00
|
|
|
})
|
2017-11-19 00:48:21 -08:00
|
|
|
|
2018-06-04 13:28:17 -07:00
|
|
|
if(ConfigManager.getLaunchDetached()){
|
2018-05-09 21:01:38 -07:00
|
|
|
child.unref()
|
|
|
|
}
|
|
|
|
|
2017-11-19 00:48:21 -08:00
|
|
|
child.stdout.on('data', (data) => {
|
|
|
|
console.log('Minecraft:', data.toString('utf8'))
|
|
|
|
})
|
|
|
|
child.stderr.on('data', (data) => {
|
|
|
|
console.log('Minecraft:', data.toString('utf8'))
|
|
|
|
})
|
|
|
|
child.on('close', (code, signal) => {
|
|
|
|
console.log('Exited with code', code)
|
2018-04-14 21:00:08 -07:00
|
|
|
rimraf(tempNativePath, (err) => {
|
|
|
|
if(err){
|
|
|
|
console.warn('Error while deleting temp dir', err)
|
|
|
|
} else {
|
|
|
|
console.log('Temp dir deleted successfully.')
|
|
|
|
}
|
|
|
|
})
|
2017-11-19 00:48:21 -08:00
|
|
|
})
|
|
|
|
|
|
|
|
return child
|
|
|
|
}
|
|
|
|
|
2018-06-23 18:03:49 -07:00
|
|
|
static isModEnabled(modCfg, required = null){
|
|
|
|
return modCfg != null ? ((typeof modCfg === 'boolean' && modCfg) || (typeof modCfg === 'object' && modCfg.value)) : required != null && required.def != null ? required.def : true
|
|
|
|
}
|
|
|
|
|
|
|
|
static isModOptional(mdl){
|
|
|
|
mdl.required != null && mdl.required.value != null && mdl.required.value === false
|
|
|
|
}
|
|
|
|
|
|
|
|
setupLiteLoader(){
|
2018-06-23 12:17:26 -07:00
|
|
|
const mdls = this.server.modules
|
2018-06-23 18:03:49 -07:00
|
|
|
for(let i=0; i<mdls.length; i++){
|
|
|
|
if(mdls[i].type === 'liteloader'){
|
|
|
|
const ll = mdls[i]
|
|
|
|
if(ProcessBuilder.isModOptional(ll)){
|
|
|
|
const modCfg = ConfigManager.getModConfiguration(this.server.id).mods
|
|
|
|
if(ProcessBuilder.isModEnabled(modCfg[AssetGuard._resolveWithoutVersion(ll.id)], ll.required)){
|
|
|
|
this.usingLiteLoader = true
|
|
|
|
this.llPath = path.join(this.libPath, ll.artifact.path == null ? AssetGuard._resolvePath(ll.id, ll.artifact.extension) : ll.artifact.path)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.usingLiteLoader = true
|
|
|
|
this.llPath = path.join(this.libPath, ll.artifact.path == null ? AssetGuard._resolvePath(ll.id, ll.artifact.extension) : ll.artifact.path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resolveModConfiguration(modCfg, mdls){
|
|
|
|
let fMods = []
|
|
|
|
let lMods = []
|
|
|
|
|
|
|
|
for(let i=0; i<mdls.length; i++){
|
2018-06-23 12:17:26 -07:00
|
|
|
const mdl = mdls[i]
|
2018-06-23 18:03:49 -07:00
|
|
|
if(mdl.type != null && (mdl.type === 'forgemod' || mdl.type === 'litemod' || mdl.type === 'liteloader')){
|
|
|
|
if(mdl.sub_modules != null){
|
|
|
|
const v = this.resolveModConfiguration(modCfg[AssetGuard._resolveWithoutVersion(mdl.id)], mdl.sub_modules)
|
|
|
|
fMods = fMods.concat(v.fMods)
|
|
|
|
lMods = lMods.concat(v.lMods)
|
|
|
|
if(mdl.type === 'liteloader'){
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(ProcessBuilder.isModOptional(mdl)){
|
|
|
|
if(ProcessBuilder.isModEnabled(modCfg[AssetGuard._resolveWithoutVersion(mdl.id)]), mdl.required){
|
|
|
|
if(mdl.type === 'forgemod'){
|
|
|
|
fMods.push(mdl)
|
|
|
|
} else {
|
|
|
|
lMods.push(mdl)
|
|
|
|
}
|
2018-06-23 12:17:26 -07:00
|
|
|
}
|
|
|
|
} else {
|
2018-06-23 18:03:49 -07:00
|
|
|
if(mdl.type === 'forgemod'){
|
|
|
|
fMods.push(mdl)
|
|
|
|
} else {
|
|
|
|
lMods.push(mdl)
|
|
|
|
}
|
2017-11-19 00:48:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-23 18:03:49 -07:00
|
|
|
return {
|
|
|
|
fMods,
|
|
|
|
lMods
|
|
|
|
}
|
2017-11-19 00:48:21 -08:00
|
|
|
}
|
|
|
|
|
2018-06-23 18:03:49 -07:00
|
|
|
constructModList(type, mods, save = false){
|
|
|
|
const modList = {
|
|
|
|
repositoryRoot: path.join(this.commonDir, 'modstore')
|
|
|
|
}
|
|
|
|
|
2017-11-19 00:48:21 -08:00
|
|
|
const ids = []
|
|
|
|
for(let i=0; i<mods.length; ++i){
|
2018-06-23 18:03:49 -07:00
|
|
|
if(type === 'forge'){
|
|
|
|
ids.push(mods[i].id)
|
|
|
|
} else {
|
|
|
|
ids.push(mods[i].id + '@' + (mods[i].artifact.extension != null ? mods[i].artifact.extension.substring(1) : 'jar'))
|
|
|
|
}
|
2017-11-19 00:48:21 -08:00
|
|
|
}
|
|
|
|
modList.modRef = ids
|
|
|
|
|
|
|
|
if(save){
|
|
|
|
const json = JSON.stringify(modList, null, 4)
|
2018-06-23 18:03:49 -07:00
|
|
|
fs.writeFileSync(type === 'forge' ? this.fmlDir : this.llDir, json, 'UTF-8')
|
2017-11-19 00:48:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return modList
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the argument array that will be passed to the JVM process.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {Array.<Object>} mods An array of enabled mods which will be launched with this process.
|
2018-04-14 21:00:08 -07:00
|
|
|
* @param {string} tempNativePath The path to store the native libraries.
|
2018-03-28 13:42:10 -07:00
|
|
|
* @returns {Array.<string>} An array containing the full JVM arguments for this process.
|
2017-11-19 00:48:21 -08:00
|
|
|
*/
|
2018-04-14 21:00:08 -07:00
|
|
|
constructJVMArguments(mods, tempNativePath){
|
|
|
|
|
2017-12-02 21:38:22 -08:00
|
|
|
let args = ['-Xmx' + ConfigManager.getMaxRAM(),
|
2018-04-14 22:26:40 -07:00
|
|
|
'-Xms' + ConfigManager.getMinRAM(),
|
2018-04-14 21:00:08 -07:00
|
|
|
'-Djava.library.path=' + tempNativePath,
|
2017-11-19 00:48:21 -08:00
|
|
|
'-cp',
|
2018-04-14 21:21:26 -07:00
|
|
|
this.classpathArg(mods, tempNativePath).join(process.platform === 'win32' ? ';' : ':'),
|
2017-11-19 00:48:21 -08:00
|
|
|
this.forgeData.mainClass]
|
|
|
|
|
2018-04-14 21:49:20 -07:00
|
|
|
if(process.platform === 'darwin'){
|
|
|
|
args.unshift('-Xdock:name=WesterosCraft')
|
|
|
|
args.unshift('-Xdock:icon=' + path.join(__dirname, '..', 'images', 'minecraft.icns'))
|
|
|
|
}
|
|
|
|
|
2018-04-14 22:26:40 -07:00
|
|
|
args.splice(2, 0, ...ConfigManager.getJVMOptions())
|
2017-11-29 22:40:56 -08:00
|
|
|
|
2017-11-19 00:48:21 -08:00
|
|
|
args = args.concat(this._resolveForgeArgs())
|
|
|
|
|
|
|
|
return args
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve the arguments required by forge.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @returns {Array.<string>} An array containing the arguments required by forge.
|
2017-11-19 00:48:21 -08:00
|
|
|
*/
|
|
|
|
_resolveForgeArgs(){
|
|
|
|
const mcArgs = this.forgeData.minecraftArguments.split(' ')
|
|
|
|
const argDiscovery = /\${*(.*)}/
|
|
|
|
|
|
|
|
// Replace the declared variables with their proper values.
|
|
|
|
for(let i=0; i<mcArgs.length; ++i){
|
|
|
|
if(argDiscovery.test(mcArgs[i])){
|
|
|
|
const identifier = mcArgs[i].match(argDiscovery)[1]
|
|
|
|
let val = null;
|
|
|
|
switch(identifier){
|
|
|
|
case 'auth_player_name':
|
2017-12-03 05:12:55 -08:00
|
|
|
val = this.authUser.displayName
|
2017-11-19 00:48:21 -08:00
|
|
|
break
|
|
|
|
case 'version_name':
|
|
|
|
//val = versionData.id
|
|
|
|
val = this.server.id
|
|
|
|
break
|
|
|
|
case 'game_directory':
|
2018-06-03 21:17:20 -07:00
|
|
|
val = this.gameDir
|
2017-11-19 00:48:21 -08:00
|
|
|
break
|
|
|
|
case 'assets_root':
|
2018-06-03 21:17:20 -07:00
|
|
|
val = path.join(this.commonDir, 'assets')
|
2017-11-19 00:48:21 -08:00
|
|
|
break
|
|
|
|
case 'assets_index_name':
|
|
|
|
val = this.versionData.assets
|
|
|
|
break
|
|
|
|
case 'auth_uuid':
|
2017-12-03 05:12:55 -08:00
|
|
|
val = this.authUser.uuid
|
2017-11-19 00:48:21 -08:00
|
|
|
break
|
|
|
|
case 'auth_access_token':
|
|
|
|
val = this.authUser.accessToken
|
|
|
|
break
|
|
|
|
case 'user_type':
|
|
|
|
val = 'MOJANG'
|
|
|
|
break
|
|
|
|
case 'version_type':
|
|
|
|
val = this.versionData.type
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if(val != null){
|
|
|
|
mcArgs[i] = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mcArgs.push('--modListFile')
|
|
|
|
mcArgs.push('absolute:' + this.fmlDir)
|
2017-11-29 22:40:56 -08:00
|
|
|
|
2018-06-23 18:03:49 -07:00
|
|
|
if(this.usingLiteLoader){
|
|
|
|
mcArgs.push('--modRepo')
|
|
|
|
mcArgs.push(this.llDir)
|
|
|
|
|
|
|
|
mcArgs.unshift('com.mumfrey.liteloader.launch.LiteLoaderTweaker')
|
|
|
|
mcArgs.unshift('--tweakClass')
|
|
|
|
}
|
|
|
|
|
2017-11-29 22:40:56 -08:00
|
|
|
// Prepare game resolution
|
2018-06-04 13:28:17 -07:00
|
|
|
if(ConfigManager.getFullscreen()){
|
2017-11-29 22:40:56 -08:00
|
|
|
mcArgs.unshift('--fullscreen')
|
|
|
|
} else {
|
2017-12-02 21:38:22 -08:00
|
|
|
mcArgs.unshift(ConfigManager.getGameWidth())
|
2017-11-29 22:40:56 -08:00
|
|
|
mcArgs.unshift('--width')
|
2017-12-02 21:38:22 -08:00
|
|
|
mcArgs.unshift(ConfigManager.getGameHeight())
|
2017-11-29 22:40:56 -08:00
|
|
|
mcArgs.unshift('--height')
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare autoconnect
|
2018-06-04 13:28:17 -07:00
|
|
|
if(ConfigManager.getAutoConnect() && this.server.autoconnect){
|
2017-11-29 22:40:56 -08:00
|
|
|
const serverURL = new URL('my://' + this.server.server_ip)
|
|
|
|
mcArgs.unshift(serverURL.hostname)
|
|
|
|
mcArgs.unshift('--server')
|
|
|
|
if(serverURL.port){
|
|
|
|
mcArgs.unshift(serverURL.port)
|
|
|
|
mcArgs.unshift('--port')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-19 00:48:21 -08:00
|
|
|
return mcArgs
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve the full classpath argument list for this process. This method will resolve all Mojang-declared
|
|
|
|
* libraries as well as the libraries declared by the server. Since mods are permitted to declare libraries,
|
|
|
|
* this method requires all enabled mods as an input
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {Array.<Object>} mods An array of enabled mods which will be launched with this process.
|
2018-04-14 21:00:08 -07:00
|
|
|
* @param {string} tempNativePath The path to store the native libraries.
|
2018-03-28 13:42:10 -07:00
|
|
|
* @returns {Array.<string>} An array containing the paths of each library required by this process.
|
2017-11-19 00:48:21 -08:00
|
|
|
*/
|
2018-04-14 21:00:08 -07:00
|
|
|
classpathArg(mods, tempNativePath){
|
2017-11-19 00:48:21 -08:00
|
|
|
let cpArgs = []
|
|
|
|
|
|
|
|
// Add the version.jar to the classpath.
|
|
|
|
const version = this.versionData.id
|
2018-06-03 21:17:20 -07:00
|
|
|
cpArgs.push(path.join(this.commonDir, 'versions', version, version + '.jar'))
|
2017-11-19 00:48:21 -08:00
|
|
|
|
2018-06-23 18:03:49 -07:00
|
|
|
if(this.usingLiteLoader){
|
|
|
|
cpArgs.push(this.llPath)
|
|
|
|
}
|
|
|
|
|
2017-11-19 00:48:21 -08:00
|
|
|
// Resolve the Mojang declared libraries.
|
2018-04-14 21:00:08 -07:00
|
|
|
const mojangLibs = this._resolveMojangLibraries(tempNativePath)
|
2017-11-19 00:48:21 -08:00
|
|
|
cpArgs = cpArgs.concat(mojangLibs)
|
|
|
|
|
|
|
|
// Resolve the server declared libraries.
|
|
|
|
const servLibs = this._resolveServerLibraries(mods)
|
|
|
|
cpArgs = cpArgs.concat(servLibs)
|
|
|
|
|
|
|
|
return cpArgs
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve the libraries defined by Mojang's version data. This method will also extract
|
|
|
|
* native libraries and point to the correct location for its classpath.
|
|
|
|
*
|
|
|
|
* TODO - clean up function
|
|
|
|
*
|
2018-04-14 21:00:08 -07:00
|
|
|
* @param {string} tempNativePath The path to store the native libraries.
|
2018-03-28 13:42:10 -07:00
|
|
|
* @returns {Array.<string>} An array containing the paths of each library mojang declares.
|
2017-11-19 00:48:21 -08:00
|
|
|
*/
|
2018-04-14 21:00:08 -07:00
|
|
|
_resolveMojangLibraries(tempNativePath){
|
2017-11-19 00:48:21 -08:00
|
|
|
const libs = []
|
|
|
|
|
|
|
|
const libArr = this.versionData.libraries
|
2018-04-14 21:00:08 -07:00
|
|
|
mkpath.sync(tempNativePath)
|
2017-11-19 00:48:21 -08:00
|
|
|
for(let i=0; i<libArr.length; i++){
|
|
|
|
const lib = libArr[i]
|
2017-11-30 00:00:06 -08:00
|
|
|
if(Library.validateRules(lib.rules)){
|
2017-11-19 00:48:21 -08:00
|
|
|
if(lib.natives == null){
|
|
|
|
const dlInfo = lib.downloads
|
|
|
|
const artifact = dlInfo.artifact
|
|
|
|
const to = path.join(this.libPath, artifact.path)
|
|
|
|
libs.push(to)
|
|
|
|
} else {
|
|
|
|
// Extract the native library.
|
|
|
|
const natives = lib.natives
|
|
|
|
const extractInst = lib.extract
|
|
|
|
const exclusionArr = extractInst.exclude
|
2017-11-30 00:00:06 -08:00
|
|
|
const opSys = Library.mojangFriendlyOS()
|
2017-11-19 00:48:21 -08:00
|
|
|
const indexId = natives[opSys]
|
|
|
|
const dlInfo = lib.downloads
|
|
|
|
const classifiers = dlInfo.classifiers
|
|
|
|
const artifact = classifiers[indexId]
|
|
|
|
|
|
|
|
// Location of native zip.
|
|
|
|
const to = path.join(this.libPath, artifact.path)
|
|
|
|
|
|
|
|
let zip = new AdmZip(to)
|
|
|
|
let zipEntries = zip.getEntries()
|
|
|
|
|
|
|
|
// Unzip the native zip.
|
|
|
|
for(let i=0; i<zipEntries.length; i++){
|
|
|
|
const fileName = zipEntries[i].entryName
|
|
|
|
|
|
|
|
let shouldExclude = false
|
|
|
|
|
|
|
|
// Exclude noted files.
|
|
|
|
exclusionArr.forEach(function(exclusion){
|
2017-11-27 01:31:54 -08:00
|
|
|
if(fileName.indexOf(exclusion) > -1){
|
2017-11-19 00:48:21 -08:00
|
|
|
shouldExclude = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// Extract the file.
|
|
|
|
if(!shouldExclude){
|
2018-04-14 21:00:08 -07:00
|
|
|
fs.writeFile(path.join(tempNativePath, fileName), zipEntries[i].getData(), (err) => {
|
2017-11-29 22:40:56 -08:00
|
|
|
if(err){
|
|
|
|
console.error('Error while extracting native library:', err)
|
|
|
|
}
|
|
|
|
})
|
2017-11-19 00:48:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return libs
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve the libraries declared by this server in order to add them to the classpath.
|
|
|
|
* This method will also check each enabled mod for libraries, as mods are permitted to
|
|
|
|
* declare libraries.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {Array.<Object>} mods An array of enabled mods which will be launched with this process.
|
|
|
|
* @returns {Array.<string>} An array containing the paths of each library this server requires.
|
2017-11-19 00:48:21 -08:00
|
|
|
*/
|
|
|
|
_resolveServerLibraries(mods){
|
|
|
|
const mdles = this.server.modules
|
|
|
|
let libs = []
|
|
|
|
|
2017-11-19 01:12:41 -08:00
|
|
|
// Locate Forge/Libraries
|
2017-11-19 00:48:21 -08:00
|
|
|
for(let i=0; i<mdles.length; i++){
|
2017-11-19 01:12:41 -08:00
|
|
|
if(mdles[i].type != null && (mdles[i].type === 'forge-hosted' || mdles[i].type === 'library')){
|
|
|
|
let lib = mdles[i]
|
2017-11-30 00:00:06 -08:00
|
|
|
libs.push(path.join(this.libPath, lib.artifact.path == null ? AssetGuard._resolvePath(lib.id, lib.artifact.extension) : lib.artifact.path))
|
2017-11-19 01:12:41 -08:00
|
|
|
if(lib.sub_modules != null){
|
|
|
|
const res = this._resolveModuleLibraries(lib)
|
|
|
|
if(res.length > 0){
|
|
|
|
libs = libs.concat(res)
|
|
|
|
}
|
2017-11-19 00:48:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Check for any libraries in our mod list.
|
|
|
|
for(let i=0; i<mods.length; i++){
|
|
|
|
if(mods.sub_modules != null){
|
|
|
|
const res = this._resolveModuleLibraries(mods[i])
|
|
|
|
if(res.length > 0){
|
|
|
|
libs = libs.concat(res)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return libs
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recursively resolve the path of each library required by this module.
|
|
|
|
*
|
2018-03-28 13:42:10 -07:00
|
|
|
* @param {Object} mdle A module object from the server distro index.
|
|
|
|
* @returns {Array.<string>} An array containing the paths of each library this module requires.
|
2017-11-19 00:48:21 -08:00
|
|
|
*/
|
|
|
|
_resolveModuleLibraries(mdle){
|
|
|
|
if(mdle.sub_modules == null){
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
let libs = []
|
|
|
|
for(let i=0; i<mdle.sub_modules.length; i++){
|
|
|
|
const sm = mdle.sub_modules[i]
|
|
|
|
if(sm.type != null && sm.type == 'library'){
|
2017-11-30 00:00:06 -08:00
|
|
|
libs.push(path.join(this.libPath, sm.artifact.path == null ? AssetGuard._resolvePath(sm.id, sm.artifact.extension) : sm.artifact.path))
|
2017-11-19 00:48:21 -08:00
|
|
|
}
|
|
|
|
// If this module has submodules, we need to resolve the libraries for those.
|
|
|
|
// To avoid unnecessary recursive calls, base case is checked here.
|
|
|
|
if(mdle.sub_modules != null){
|
|
|
|
const res = this._resolveModuleLibraries(sm)
|
|
|
|
if(res.length > 0){
|
|
|
|
libs = libs.concat(res)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return libs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = ProcessBuilder
|