2020-02-03 10:24:25 +01:00
|
|
|
const { join } = require("path")
|
|
|
|
const { isString, last } = require("lodash/fp")
|
|
|
|
const { common } = require("@budibase/core")
|
|
|
|
const runtimePackagesDirectory = "./runtime_apps"
|
|
|
|
const LATEST_VERSIONID = "##LATEST##"
|
|
|
|
const { $, splitKey } = common
|
2019-06-28 23:59:27 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
const getRuntimeAppsDirectory = appName =>
|
|
|
|
join(runtimePackagesDirectory, appName)
|
2019-07-01 23:49:13 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
const getLatestDirectory = (appContext, appname) =>
|
|
|
|
join(appContext.config.latestPackagesFolder, appname)
|
2019-10-11 18:14:23 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
module.exports.LATEST_VERSIONID = LATEST_VERSIONID
|
2019-10-11 18:14:23 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
module.exports.runtimePackagesDirectory = runtimePackagesDirectory
|
2019-06-28 23:59:27 +02:00
|
|
|
|
2020-04-28 15:39:35 +02:00
|
|
|
module.exports.getRuntimePackageDirectory = (appId, versionId) =>
|
2020-02-03 10:24:25 +01:00
|
|
|
versionId === LATEST_VERSIONID
|
2020-04-28 15:39:35 +02:00
|
|
|
? getLatestDirectory(appId)
|
2020-02-03 10:24:25 +01:00
|
|
|
: join(getRuntimeAppsDirectory(appName), versionId)
|
2019-07-01 23:49:13 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
module.exports.getRuntimeAppsDirectory = getRuntimeAppsDirectory
|
2019-10-11 18:14:23 +02:00
|
|
|
|
|
|
|
// the point of this in mainly to support running in dev
|
|
|
|
// i.e. if no "versions" are in use, then it will route
|
|
|
|
// to the latest package
|
2020-02-03 10:24:25 +01:00
|
|
|
module.exports.determineVersionId = version => {
|
|
|
|
let versionKey = isString(version) ? version : null
|
|
|
|
|
|
|
|
if (!versionKey && version && version.key) versionKey = version.key
|
|
|
|
|
|
|
|
return versionKey ? $(versionKey, [splitKey, last]) : LATEST_VERSIONID
|
|
|
|
}
|