1
0
Fork 0
mirror of synced 2024-07-07 07:15:43 +12:00
budibase/packages/server/utilities/createAppPackage.js

96 lines
2.9 KiB
JavaScript
Raw Normal View History

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