2020-02-03 10:24:25 +01:00
|
|
|
const { resolve, join } = require("path")
|
|
|
|
const constructHierarchy = require("./constructHierarchy")
|
|
|
|
const { common } = require("@budibase/core")
|
|
|
|
const { getRuntimePackageDirectory } = require("../utilities/runtimePackages")
|
|
|
|
const injectPlugins = require("./injectedPlugins")
|
|
|
|
const { cwd } = require("process")
|
2019-07-09 08:29:50 +02:00
|
|
|
|
2020-03-25 13:38:04 +01:00
|
|
|
const appDefinitionPath = appPath => join(appPath, "appDefinition.json")
|
|
|
|
const pluginsPath = appPath => join(appPath, "plugins.js")
|
|
|
|
const accessLevelsPath = appPath => join(appPath, "access_levels.json")
|
|
|
|
|
2019-07-09 08:29:50 +02:00
|
|
|
const createAppPackage = (context, appPath) => {
|
2020-03-25 13:38:04 +01:00
|
|
|
const appDefModule = require(appDefinitionPath(appPath))
|
2019-07-05 17:56:53 +02:00
|
|
|
|
2020-03-25 13:38:04 +01:00
|
|
|
const pluginsModule = require(pluginsPath(appPath))
|
2020-02-03 10:24:25 +01:00
|
|
|
|
2020-03-25 13:38:04 +01:00
|
|
|
const accessLevels = require(accessLevelsPath(appPath))
|
2020-02-03 10:24:25 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
appDefinition: appDefModule,
|
|
|
|
behaviourSources: pluginsModule(context),
|
|
|
|
appPath,
|
|
|
|
accessLevels,
|
|
|
|
...publicPaths(appPath),
|
|
|
|
}
|
2019-07-05 17:56:53 +02:00
|
|
|
}
|
2019-06-25 23:48:22 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
const appPackageFolder = (config, appname) =>
|
|
|
|
resolve(cwd(), config.latestPackagesFolder, appname)
|
2019-07-13 11:35:57 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
module.exports.appPackageFolder = appPackageFolder
|
2019-07-13 11:35:57 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
module.exports.appsFolder = config => appPackageFolder(config, "")
|
2019-07-14 08:46:36 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
module.exports.masterAppPackage = context => {
|
|
|
|
const { config } = context
|
2020-02-27 17:45:24 +01:00
|
|
|
const standardPackage = createAppPackage(
|
|
|
|
context,
|
|
|
|
`${__dirname}/../appPackages/_master`
|
|
|
|
)
|
2019-06-25 23:48:22 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
const customizeMaster =
|
|
|
|
config && config.customizeMaster ? config.customizeMaster : a => a
|
2019-06-25 23:48:22 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
const appDefinition = common.$(standardPackage.appDefinition, [
|
|
|
|
customizeMaster,
|
|
|
|
constructHierarchy,
|
|
|
|
])
|
2019-06-28 23:59:27 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
const plugins = standardPackage.behaviourSources
|
2019-06-25 23:48:22 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
return {
|
|
|
|
appDefinition,
|
|
|
|
behaviourSources:
|
|
|
|
config && config.extraMasterPlugins
|
|
|
|
? { ...plugins, ...config.extraMasterPlugins }
|
|
|
|
: plugins,
|
|
|
|
appPath: standardPackage.appPath,
|
|
|
|
unauthenticatedUiPath: standardPackage.unauthenticatedUiPath,
|
|
|
|
mainUiPath: standardPackage.mainUiPath,
|
|
|
|
sharedPath: standardPackage.sharedPath,
|
|
|
|
}
|
2019-06-25 23:48:22 +02:00
|
|
|
}
|
2019-07-16 23:14:57 +02:00
|
|
|
|
2019-10-11 18:14:23 +02:00
|
|
|
const applictionVersionPath = (context, appname, versionId) =>
|
2020-02-03 10:24:25 +01:00
|
|
|
join(cwd(), getRuntimePackageDirectory(context, appname, versionId))
|
|
|
|
|
|
|
|
const publicPaths = appPath => ({
|
|
|
|
mainUiPath: resolve(join(appPath, "public", "main")),
|
|
|
|
unauthenticatedUiPath: resolve(join(appPath, "public", "unauthenticated")),
|
|
|
|
sharedPath: resolve(join(appPath, "public", "_shared")),
|
|
|
|
})
|
2019-07-16 23:14:57 +02:00
|
|
|
|
2019-10-11 18:14:23 +02:00
|
|
|
module.exports.applictionVersionPublicPaths = (context, appname, versionId) => {
|
2020-02-03 10:24:25 +01:00
|
|
|
const appPath = applictionVersionPath(context, appname, versionId)
|
|
|
|
return publicPaths(appPath)
|
2019-07-16 23:14:57 +02:00
|
|
|
}
|
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
module.exports.applictionVersionPackage = async (
|
|
|
|
context,
|
|
|
|
appname,
|
|
|
|
versionId,
|
|
|
|
instanceKey
|
|
|
|
) => {
|
|
|
|
const pkg = createAppPackage(
|
|
|
|
context,
|
|
|
|
applictionVersionPath(context, appname, versionId)
|
|
|
|
)
|
|
|
|
|
|
|
|
pkg.appDefinition = constructHierarchy(pkg.appDefinition)
|
|
|
|
await injectPlugins(pkg, context.master, appname, instanceKey)
|
|
|
|
return pkg
|
2019-06-28 23:59:27 +02:00
|
|
|
}
|
2020-03-25 13:38:04 +01:00
|
|
|
|
|
|
|
module.exports.deleteCachedPackage = (context, appname, versionId) => {
|
|
|
|
const appPath = applictionVersionPath(context, appname, versionId)
|
|
|
|
|
|
|
|
delete require.cache[resolve(appDefinitionPath(appPath))]
|
|
|
|
delete require.cache[resolve(pluginsPath(appPath))]
|
|
|
|
delete require.cache[resolve(accessLevelsPath(appPath))]
|
|
|
|
}
|