budibase/packages/server/initialise/initialiseRuntimePackages.js

55 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-06-25 23:48:22 +02:00
const { ncp } = require('ncp');
const { masterAppPackage } = require("../utilities/createAppPackage");
2019-06-28 23:59:27 +02:00
const { mkdir, rimraf, exists } = require("../utilities/fsawait");
const { runtimePackagesDirectory } = require("../utilities/runtimePackages");
2019-06-25 23:48:22 +02:00
const copyfolder = (source, destination) =>
new Promise((resolve, reject) => {
ncp(source, destination, function (err) {
if (err) {
reject(err);
} else {
resolve();
}
});
});
2019-06-28 23:59:27 +02:00
2019-07-09 08:29:50 +02:00
module.exports = async (context, bbMaster, latestAppsFolder) => {
2019-06-25 23:48:22 +02:00
// create runtime folder
// copy master into /master/latest
2019-06-28 23:59:27 +02:00
if(await exists(runtimePackagesDirectory)) {
2019-06-25 23:48:22 +02:00
try {
2019-06-28 23:59:27 +02:00
await rimraf(runtimePackagesDirectory);
2019-06-25 23:48:22 +02:00
} catch(err) {
console.log(err);
}
}
2019-06-28 23:59:27 +02:00
await mkdir(runtimePackagesDirectory);
2019-06-25 23:48:22 +02:00
/*
const allApps = await bbMaster
.indexApi
.listItems("/all_applications");
for(let app of allApps) {
app.
}
*/
const apps = {
2019-07-09 08:29:50 +02:00
"_master": masterAppPackage(context)
2019-06-25 23:48:22 +02:00
}
return ((appName, versionId) => {
if(appName === "_master") {
return apps[appName];
}
return apps[appName][versionId];
});
}