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