derived components endpoints
This commit is contained in:
parent
ebf5dfeeea
commit
af2fc95a6b
|
@ -344,17 +344,13 @@ const saveDerivedComponent = store => (derivedComponent) => {
|
||||||
|
|
||||||
s.derivedComponents = derivedComponents;
|
s.derivedComponents = derivedComponents;
|
||||||
|
|
||||||
const forSave = pipe(derivedComponents, [
|
fetch(`/_builder/api/${s.appname}/derivedcomponent`, {
|
||||||
cloneDeep,
|
method: 'POST',
|
||||||
keyBy("_name")
|
headers: {
|
||||||
]);
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
for(let c of forSave) {
|
body: JSON.stringify(derivedComponent),
|
||||||
delete c._name;
|
});
|
||||||
}
|
|
||||||
|
|
||||||
s.pages.derivedComponents = forSave;
|
|
||||||
savePackage(store, s);
|
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
})
|
})
|
||||||
|
|
|
@ -4,8 +4,17 @@ import ComingSoon from "../common/ComingSoon.svelte";
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ComingSoon name="User Interface Designer"/>
|
<div class="root">
|
||||||
|
<div class="uiNav">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
|
.root {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: [uiNav] 200px [preview] auto;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
|
@ -11,6 +11,5 @@ export const defaultPagesObject = () => ({
|
||||||
},
|
},
|
||||||
appBody: "bbapp.unauthenticated.json"
|
appBody: "bbapp.unauthenticated.json"
|
||||||
},
|
},
|
||||||
componentLibraries: ["./components"],
|
componentLibraries: ["./components"]
|
||||||
derivedComponents:[]
|
|
||||||
});
|
});
|
|
@ -5,7 +5,7 @@ const { take, takeRight, last } = require("lodash/fp");
|
||||||
const { splitKey, $, joinKey } = require("budibase-core").common;
|
const { splitKey, $, joinKey } = require("budibase-core").common;
|
||||||
const { unzipTarGzPackageToRuntime } = require("../../utilities/targzAppPackage");
|
const { unzipTarGzPackageToRuntime } = require("../../utilities/targzAppPackage");
|
||||||
const { getRuntimePackageDirectory } = require("../../utilities/runtimePackages");
|
const { getRuntimePackageDirectory } = require("../../utilities/runtimePackages");
|
||||||
const { exists } = require("../../utilities/fsawait");
|
const { pathExists } = require("fs-extra");
|
||||||
const createInstanceDb = require("../../initialise/createInstanceDb");
|
const createInstanceDb = require("../../initialise/createInstanceDb");
|
||||||
const { createWriteStream } = require("fs");
|
const { createWriteStream } = require("fs");
|
||||||
const { applictionVersionPackage } = require("../../utilities/createAppPackage");
|
const { applictionVersionPackage } = require("../../utilities/createAppPackage");
|
||||||
|
@ -33,7 +33,7 @@ module.exports = (context) => {
|
||||||
application.name,
|
application.name,
|
||||||
versionId);
|
versionId);
|
||||||
|
|
||||||
if(!await exists(runtimeDir))
|
if(!await pathExists(runtimeDir))
|
||||||
await downloadAppPackage(apis, instance, application.name, versionId);
|
await downloadAppPackage(apis, instance, application.name, versionId);
|
||||||
|
|
||||||
const dbConfig = await createInstanceDb(
|
const dbConfig = await createInstanceDb(
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
{"_name":"newTextBox","_component":"./customComponents/textbox","label":"something else"}
|
|
@ -0,0 +1 @@
|
||||||
|
{"oldname":"newTextBox","newName":"anotherSubFolder/newTextBox"}
|
Binary file not shown.
|
@ -2,7 +2,7 @@ const create = require("./createMasterDb");
|
||||||
const argv = require("yargs").argv
|
const argv = require("yargs").argv
|
||||||
const readline = require('readline');
|
const readline = require('readline');
|
||||||
const { promisify } = require('util');
|
const { promisify } = require('util');
|
||||||
const { mkdir, rimraf } = require("../utilities/fsawait");
|
const { mkdir, remove } = require("fs-extra");
|
||||||
const budibaseConfig = require("../config");
|
const budibaseConfig = require("../config");
|
||||||
const buildAppContext = require("../initialise/buildAppContext");
|
const buildAppContext = require("../initialise/buildAppContext");
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ const question = async (q) => {
|
||||||
|
|
||||||
if(cleanDev) {
|
if(cleanDev) {
|
||||||
try {
|
try {
|
||||||
await rimraf(rootconfig.rootPath);
|
await remove(rootconfig.rootPath);
|
||||||
}
|
}
|
||||||
catch(_){}
|
catch(_){}
|
||||||
await mkdir(rootconfig.rootPath);
|
await mkdir(rootconfig.rootPath);
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
const { ncp } = require('ncp');
|
|
||||||
const { masterAppPackage } = require("../utilities/createAppPackage");
|
const { masterAppPackage } = require("../utilities/createAppPackage");
|
||||||
const { mkdir, rimraf, exists } = require("../utilities/fsawait");
|
const { mkdir, remove, pathExists, copy } = require("fs-extra");
|
||||||
const { runtimePackagesDirectory } = require("../utilities/runtimePackages");
|
const { runtimePackagesDirectory } = require("../utilities/runtimePackages");
|
||||||
|
|
||||||
const copyfolder = (source, destination) =>
|
const copyfolder = (source, destination) =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
ncp(source, destination, function (err) {
|
copy(source, destination, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
|
@ -19,9 +18,9 @@ module.exports = async (context, bbMaster, latestAppsFolder) => {
|
||||||
|
|
||||||
// create runtime folder
|
// create runtime folder
|
||||||
// copy master into /master/latest
|
// copy master into /master/latest
|
||||||
if(await exists(runtimePackagesDirectory)) {
|
if(await pathExists(runtimePackagesDirectory)) {
|
||||||
try {
|
try {
|
||||||
await rimraf(runtimePackagesDirectory);
|
await remove(runtimePackagesDirectory);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,14 @@ const StatusCodes = require("../utilities/statusCodes");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const { resolve } = require("path");
|
const { resolve } = require("path");
|
||||||
const send = require('koa-send');
|
const send = require('koa-send');
|
||||||
const { getPackageForBuilder, getRootComponents: getComponents,
|
const {
|
||||||
savePackage, getApps } = require("../utilities/builder");
|
getPackageForBuilder,
|
||||||
|
getRootComponents,
|
||||||
|
savePackage,
|
||||||
|
getApps,
|
||||||
|
saveDerivedComponent,
|
||||||
|
renameDerivedComponent
|
||||||
|
} = require("../utilities/builder");
|
||||||
|
|
||||||
const builderPath = resolve(__dirname, "../builder");
|
const builderPath = resolve(__dirname, "../builder");
|
||||||
|
|
||||||
|
@ -119,23 +125,11 @@ module.exports = (config, app) => {
|
||||||
ctx.response.status = StatusCodes.OK;
|
ctx.response.status = StatusCodes.OK;
|
||||||
})
|
})
|
||||||
.get("/_builder/api/apps", async (ctx) => {
|
.get("/_builder/api/apps", async (ctx) => {
|
||||||
if(!config.dev) {
|
|
||||||
ctx.response.status = StatusCodes.FORBIDDEN;
|
|
||||||
ctx.response.body = "run in dev mode to access builder";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.body = await getApps(config);
|
ctx.body = await getApps(config);
|
||||||
ctx.response.status = StatusCodes.OK;
|
ctx.response.status = StatusCodes.OK;
|
||||||
|
|
||||||
})
|
})
|
||||||
.get("/_builder/api/:appname/appPackage", async (ctx) => {
|
.get("/_builder/api/:appname/appPackage", async (ctx) => {
|
||||||
if(!config.dev) {
|
|
||||||
ctx.response.status = StatusCodes.FORBIDDEN;
|
|
||||||
ctx.body = "run in dev mode to access builder";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.body = await getPackageForBuilder(
|
ctx.body = await getPackageForBuilder(
|
||||||
config,
|
config,
|
||||||
ctx.params.appname);
|
ctx.params.appname);
|
||||||
|
@ -143,11 +137,6 @@ module.exports = (config, app) => {
|
||||||
|
|
||||||
})
|
})
|
||||||
.post("/_builder/api/:appname/appPackage", async (ctx) => {
|
.post("/_builder/api/:appname/appPackage", async (ctx) => {
|
||||||
if(!config.dev) {
|
|
||||||
ctx.response.status = StatusCodes.FORBIDDEN;
|
|
||||||
ctx.body = "run in dev mode to access builder";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.body = await savePackage(
|
ctx.body = await savePackage(
|
||||||
config,
|
config,
|
||||||
|
@ -155,15 +144,9 @@ module.exports = (config, app) => {
|
||||||
ctx.request.body);
|
ctx.request.body);
|
||||||
ctx.response.status = StatusCodes.OK;
|
ctx.response.status = StatusCodes.OK;
|
||||||
})
|
})
|
||||||
.get("/_builder/api/:appname/components", async (ctx) => {
|
.get("/_builder/api/:appname/rootcomponents", async (ctx) => {
|
||||||
if(!config.dev) {
|
|
||||||
ctx.response.status = StatusCodes.FORBIDDEN;
|
|
||||||
ctx.body = "run in dev mode to access builder";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ctx.body = getComponents(
|
ctx.body = getRootComponents(
|
||||||
config,
|
config,
|
||||||
ctx.params.appname,
|
ctx.params.appname,
|
||||||
ctx.query.lib);
|
ctx.query.lib);
|
||||||
|
@ -176,6 +159,28 @@ module.exports = (config, app) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.post("/_builder/api/:appname/derivedcomponent", async (ctx) => {
|
||||||
|
await saveDerivedComponent(
|
||||||
|
config,
|
||||||
|
ctx.params.appname,
|
||||||
|
ctx.request.body);
|
||||||
|
ctx.response.status = StatusCodes.OK;
|
||||||
|
})
|
||||||
|
.patch("/_builder/api/:appname/derivedcomponent", async (ctx) => {
|
||||||
|
await renameDerivedComponent(
|
||||||
|
config,
|
||||||
|
ctx.params.appname,
|
||||||
|
ctx.request.body.oldname,
|
||||||
|
ctx.request.body.newname);
|
||||||
|
ctx.response.status = StatusCodes.OK;
|
||||||
|
})
|
||||||
|
.delete("/_builder/api/:appname/derivedcomponent", async (ctx) => {
|
||||||
|
await deleteDerivedComponent(
|
||||||
|
config,
|
||||||
|
ctx.params.appname,
|
||||||
|
ctx.request.body.name);
|
||||||
|
ctx.response.status = StatusCodes.OK;
|
||||||
|
})
|
||||||
.get("/:appname", async (ctx) => {
|
.get("/:appname", async (ctx) => {
|
||||||
await send(ctx, "/index.html", { root: ctx.publicPath });
|
await send(ctx, "/index.html", { root: ctx.publicPath });
|
||||||
})
|
})
|
||||||
|
|
|
@ -15,14 +15,13 @@
|
||||||
"@koa/router": "^8.0.0",
|
"@koa/router": "^8.0.0",
|
||||||
"argon2": "^0.23.0",
|
"argon2": "^0.23.0",
|
||||||
"budibase-core": "file:../core/dist",
|
"budibase-core": "file:../core/dist",
|
||||||
|
"fs-extra": "^8.1.0",
|
||||||
"koa": "^2.7.0",
|
"koa": "^2.7.0",
|
||||||
"koa-body": "^4.1.0",
|
"koa-body": "^4.1.0",
|
||||||
"koa-send": "^5.0.0",
|
"koa-send": "^5.0.0",
|
||||||
"koa-session": "^5.12.0",
|
"koa-session": "^5.12.0",
|
||||||
"koa-static": "^5.0.0",
|
"koa-static": "^5.0.0",
|
||||||
"lodash": "^4.17.13",
|
"lodash": "^4.17.13",
|
||||||
"ncp": "^2.0.0",
|
|
||||||
"rimraf": "^2.6.3",
|
|
||||||
"tar-fs": "^2.0.0",
|
"tar-fs": "^2.0.0",
|
||||||
"uuid": "^3.3.2",
|
"uuid": "^3.3.2",
|
||||||
"yargs": "^13.2.4"
|
"yargs": "^13.2.4"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const statusCodes = require("../utilities/statusCodes");
|
const statusCodes = require("../utilities/statusCodes");
|
||||||
const { readFile } = require("../utilities/fsawait");
|
const { readFile } = require("fs-extra");
|
||||||
const { timeout } = require("./helpers");
|
const { timeout } = require("./helpers");
|
||||||
|
|
||||||
module.exports = (app, appName, userName) => {
|
module.exports = (app, appName, userName) => {
|
||||||
|
|
|
@ -7,6 +7,7 @@ const testMoreComponents = require("../appPackages/testApp/moreCustomComponents/
|
||||||
const statusCodes = require("../utilities/statusCodes");
|
const statusCodes = require("../utilities/statusCodes");
|
||||||
const derivedComponent1 = require("../appPackages/testApp/components/myTextBox.json");
|
const derivedComponent1 = require("../appPackages/testApp/components/myTextBox.json");
|
||||||
const derivedComponent2 = require("../appPackages/testApp/components/subfolder/otherTextBox.json");
|
const derivedComponent2 = require("../appPackages/testApp/components/subfolder/otherTextBox.json");
|
||||||
|
const { readJSON, pathExists } = require("fs-extra");
|
||||||
|
|
||||||
const app = require("./testApp")();
|
const app = require("./testApp")();
|
||||||
|
|
||||||
|
@ -64,3 +65,48 @@ it("/apppackage should get derivedComponents", async () => {
|
||||||
|
|
||||||
expect(body.derivedComponents).toEqual(expectedComponents);
|
expect(body.derivedComponents).toEqual(expectedComponents);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should be able to create new derived component", async () => {
|
||||||
|
const newDerivedComponent = {
|
||||||
|
_name: "newTextBox",
|
||||||
|
_component: "./customComponents/textbox",
|
||||||
|
label: "something"
|
||||||
|
};
|
||||||
|
|
||||||
|
await app.post("/_builder/api/testApp/derivedcomponent", newDerivedComponent)
|
||||||
|
.expect(statusCodes.OK);
|
||||||
|
|
||||||
|
const componentFile = "./appPackages/testApp/components/newTextBox.json";
|
||||||
|
expect(await pathExists(componentFile)).toBe(true);
|
||||||
|
expect(await readJSON(componentFile)).toEqual(newDerivedComponent);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should be able to update derived component", async () => {
|
||||||
|
const updatedDerivedComponent = {
|
||||||
|
_name: "newTextBox",
|
||||||
|
_component: "./customComponents/textbox",
|
||||||
|
label: "something else"
|
||||||
|
};
|
||||||
|
|
||||||
|
await app.post("/_builder/api/testApp/derivedcomponent", updatedDerivedComponent)
|
||||||
|
.expect(statusCodes.OK);
|
||||||
|
|
||||||
|
const componentFile = "./appPackages/testApp/components/newTextBox.json";
|
||||||
|
expect(await readJSON(componentFile)).toEqual(updatedDerivedComponent);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should be able to rename derived component", async () => {
|
||||||
|
await app.post("/_builder/api/testApp/derivedcomponent", {
|
||||||
|
oldname: "newTextBox", newName: "anotherSubFolder/newTextBox"
|
||||||
|
}).expect(statusCodes.OK);
|
||||||
|
const oldcomponentFile = "./appPackages/testApp/components/newTextBox.json";
|
||||||
|
const newcomponentFile = "./appPackages/testApp/components/anotherSubFolder/newTextBox.json";
|
||||||
|
expect(await pathExists(oldcomponentFile)).toBe(false);
|
||||||
|
expect(await pathExists(newcomponentFile)).toBe(true);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should be able to delete derived component", async () => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const statusCodes = require("../utilities/statusCodes");
|
const statusCodes = require("../utilities/statusCodes");
|
||||||
const constructHierarchy = require("../utilities/constructHierarchy");
|
const constructHierarchy = require("../utilities/constructHierarchy");
|
||||||
const { readFile } = require("../utilities/fsawait");
|
const { readFile } = require("fs-extra");
|
||||||
const { hierarchy } = require("budibase-core");
|
const { hierarchy } = require("budibase-core");
|
||||||
const { take } = require("lodash/fp");
|
const { take } = require("lodash/fp");
|
||||||
const masterAppDefinition = constructHierarchy(
|
const masterAppDefinition = constructHierarchy(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const statusCodes = require("../utilities/statusCodes");
|
const statusCodes = require("../utilities/statusCodes");
|
||||||
const constructHierarchy = require("../utilities/constructHierarchy");
|
const constructHierarchy = require("../utilities/constructHierarchy");
|
||||||
const { readFile } = require("../utilities/fsawait");
|
const { readFile } = require("fs-extra");
|
||||||
const {getRecordApi, getAuthApi} = require("budibase-core");
|
const {getRecordApi, getAuthApi} = require("budibase-core");
|
||||||
const masterAppDefinition = constructHierarchy(
|
const masterAppDefinition = constructHierarchy(
|
||||||
require("../appPackages/master/appDefinition.json"));
|
require("../appPackages/master/appDefinition.json"));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const statusCodes = require("../utilities/statusCodes");
|
const statusCodes = require("../utilities/statusCodes");
|
||||||
const { readFile } = require("../utilities/fsawait");
|
const { readFile } = require("fs-extra");
|
||||||
|
|
||||||
module.exports = (app) => {
|
module.exports = (app) => {
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const app = require("../app");
|
const app = require("../app");
|
||||||
const { rimraf, mkdir } = require("../utilities/fsawait");
|
const { remove, mkdir } = require("fs-extra");
|
||||||
const createMasterDb = require("../initialise/createMasterDb");
|
const createMasterDb = require("../initialise/createMasterDb");
|
||||||
const request = require("supertest");
|
const request = require("supertest");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
@ -123,7 +123,7 @@ const getRequest = (server, url) =>
|
||||||
|
|
||||||
const reInitialize = async () => {
|
const reInitialize = async () => {
|
||||||
try {
|
try {
|
||||||
await rimraf(config.datastoreConfig.rootPath);
|
await remove(config.datastoreConfig.rootPath);
|
||||||
} catch(_){}
|
} catch(_){}
|
||||||
|
|
||||||
await mkdir(config.datastoreConfig.rootPath);
|
await mkdir(config.datastoreConfig.rootPath);
|
||||||
|
|
|
@ -3,15 +3,19 @@ const {
|
||||||
appsFolder
|
appsFolder
|
||||||
} = require("./createAppPackage");
|
} = require("./createAppPackage");
|
||||||
const {
|
const {
|
||||||
writeFile,
|
readJSON,
|
||||||
readFile,
|
writeJSON,
|
||||||
readdir,
|
readdir,
|
||||||
exists,
|
exists,
|
||||||
stat
|
stat,
|
||||||
} = require("./fsawait");
|
ensureDir,
|
||||||
|
rename,
|
||||||
|
unlink
|
||||||
|
} = require("fs-extra");
|
||||||
const {
|
const {
|
||||||
resolve,
|
resolve,
|
||||||
join
|
join,
|
||||||
|
dirname
|
||||||
} = require("path");
|
} = require("path");
|
||||||
const { $ } = require("budibase-core").common;
|
const { $ } = require("budibase-core").common;
|
||||||
const {
|
const {
|
||||||
|
@ -25,18 +29,12 @@ const {merge} = require("lodash");
|
||||||
module.exports.getPackageForBuilder = async (config, appname) => {
|
module.exports.getPackageForBuilder = async (config, appname) => {
|
||||||
const appPath = appPackageFolder(config, appname);
|
const appPath = appPackageFolder(config, appname);
|
||||||
|
|
||||||
const pages = JSON.parse(await readFile(
|
const pages = await readJSON(`${appPath}/pages.json`);
|
||||||
`${appPath}/pages.json`,
|
|
||||||
"utf8"));
|
|
||||||
|
|
||||||
return ({
|
return ({
|
||||||
appDefinition: JSON.parse(await readFile(
|
appDefinition: await readJSON(`${appPath}/appDefinition.json`),
|
||||||
`${appPath}/appDefinition.json`,
|
|
||||||
"utf8")),
|
|
||||||
|
|
||||||
accessLevels: JSON.parse(await readFile(
|
accessLevels: await readJSON(`${appPath}/access_levels.json`),
|
||||||
`${appPath}/access_levels.json`,
|
|
||||||
"utf8")),
|
|
||||||
|
|
||||||
pages,
|
pages,
|
||||||
|
|
||||||
|
@ -50,26 +48,55 @@ module.exports.getPackageForBuilder = async (config, appname) => {
|
||||||
|
|
||||||
module.exports.savePackage = async (config, appname, pkg) => {
|
module.exports.savePackage = async (config, appname, pkg) => {
|
||||||
const appPath = appPackageFolder(config, appname);
|
const appPath = appPackageFolder(config, appname);
|
||||||
await writeFile(
|
await writeJSON(
|
||||||
`${appPath}/appDefinition.json`,
|
`${appPath}/appDefinition.json`,
|
||||||
JSON.stringify(pkg.appDefinition),
|
pkg.appDefinition);
|
||||||
"utf8");
|
|
||||||
|
|
||||||
await writeFile(
|
await writeJSON(
|
||||||
`${appPath}/access_levels.json`,
|
`${appPath}/access_levels.json`,
|
||||||
JSON.stringify(pkg.accessLevels),
|
pkg.accessLevels);
|
||||||
"utf8");
|
|
||||||
|
|
||||||
await writeFile(
|
await writeJSON(
|
||||||
`${appPath}/pages.json`,
|
`${appPath}/pages.json`,
|
||||||
JSON.stringify(pkg.pages),
|
pkg.pages);
|
||||||
"utf8");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.getApps = async (config) =>
|
module.exports.getApps = async (config) =>
|
||||||
await readdir(appsFolder(config));
|
await readdir(appsFolder(config));
|
||||||
|
|
||||||
|
|
||||||
|
const componentPath = (appPath, name) =>
|
||||||
|
join(appPath, "components", name + ".json");
|
||||||
|
|
||||||
|
module.exports.saveDerivedComponent = async (config, appname, component) => {
|
||||||
|
const appPath = appPackageFolder(config, appname);
|
||||||
|
|
||||||
|
await writeJSON(
|
||||||
|
componentPath(appPath, component._name),
|
||||||
|
component,
|
||||||
|
{encoding:"utf8", flag:"w"});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.renameDerivedComponent = async (config, appname, oldName, newName) => {
|
||||||
|
const appPath = appPackageFolder(config, appname);
|
||||||
|
|
||||||
|
const oldComponentPath = componentPath(
|
||||||
|
appPath, oldName);
|
||||||
|
|
||||||
|
const newComponentPath = join(
|
||||||
|
appPath, newName);
|
||||||
|
|
||||||
|
await ensureDir(dirname(newComponentPath));
|
||||||
|
await rename(
|
||||||
|
oldComponentPath,
|
||||||
|
newComponentPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.deleteDerivedComponent = async (config, appname, name) => {
|
||||||
|
const appPath = appPackageFolder(config, appname);
|
||||||
|
await unlink(componentPath(appPath, name));
|
||||||
|
}
|
||||||
|
|
||||||
const getRootComponents = async (appPath, pages ,lib) => {
|
const getRootComponents = async (appPath, pages ,lib) => {
|
||||||
|
|
||||||
const componentsInLibrary = async (libname) => {
|
const componentsInLibrary = async (libname) => {
|
||||||
|
@ -88,8 +115,7 @@ const getRootComponents = async (appPath, pages ,lib) => {
|
||||||
|
|
||||||
let components;
|
let components;
|
||||||
try {
|
try {
|
||||||
components = JSON.parse(
|
components = await readJSON(componentsPath);
|
||||||
await readFile(componentsPath, "utf8"));
|
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
const err = `could not parse JSON - ${componentsPath} : ${e.message}`;
|
const err = `could not parse JSON - ${componentsPath} : ${e.message}`;
|
||||||
throw new Error(err);
|
throw new Error(err);
|
||||||
|
@ -106,9 +132,8 @@ const getRootComponents = async (appPath, pages ,lib) => {
|
||||||
|
|
||||||
let libs;
|
let libs;
|
||||||
if(!lib) {
|
if(!lib) {
|
||||||
pages = pages || JSON.parse(await readFile(
|
pages = pages || await readJSON(
|
||||||
`${appPath}/pages.json`,
|
`${appPath}/pages.json`);
|
||||||
"utf8"));
|
|
||||||
|
|
||||||
if(!pages.componentLibraries) return [];
|
if(!pages.componentLibraries) return [];
|
||||||
|
|
||||||
|
@ -142,8 +167,8 @@ const fetchDerivedComponents = async (appPath, relativePath = "") => {
|
||||||
|
|
||||||
if(!item.endsWith(".json")) continue;
|
if(!item.endsWith(".json")) continue;
|
||||||
|
|
||||||
const component = JSON.parse(
|
const component =
|
||||||
await readFile(itemFullPath, "utf8"));
|
await readJSON(itemFullPath);
|
||||||
|
|
||||||
component._name = itemRelativePath
|
component._name = itemRelativePath
|
||||||
.substring(0, itemRelativePath.length - 5)
|
.substring(0, itemRelativePath.length - 5)
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
const util = require("util");
|
|
||||||
const fs = require("fs");
|
|
||||||
|
|
||||||
module.exports.readFile = util.promisify(fs.readFile);
|
|
||||||
module.exports.readdir = util.promisify(fs.readdir);
|
|
||||||
module.exports.writeFile = util.promisify(fs.writeFile);
|
|
||||||
module.exports.rimraf = util.promisify(require("rimraf"));
|
|
||||||
module.exports.mkdir = util.promisify(fs.mkdir);
|
|
||||||
module.exports.unlink = util.promisify(fs.unlink);
|
|
||||||
module.exports.stat = util.promisify(fs.stat);
|
|
||||||
module.exports.exists = async (path) => {
|
|
||||||
try {
|
|
||||||
await util.promisify(fs.access)(
|
|
||||||
path
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ const fs = require("fs");
|
||||||
const tar = require('tar-fs');
|
const tar = require('tar-fs');
|
||||||
const zlib = require("zlib");
|
const zlib = require("zlib");
|
||||||
const { join, dirname, sep } = require("path");
|
const { join, dirname, sep } = require("path");
|
||||||
const { exists, mkdir, unlink, stat } = require("../utilities/fsawait");
|
const { exists, mkdir, unlink, stat } = require("fs-extra");
|
||||||
const { getRuntimePackageDirectory, getRuntimeAppsDirectory } = require("./runtimePackages");
|
const { getRuntimePackageDirectory, getRuntimeAppsDirectory } = require("./runtimePackages");
|
||||||
|
|
||||||
module.exports.createTarGzPackage = async (config, appName) => {
|
module.exports.createTarGzPackage = async (config, appName) => {
|
||||||
|
@ -33,7 +33,7 @@ module.exports.unzipTarGzPackageToRuntime = async (src, appName, versionId) => {
|
||||||
|
|
||||||
if(await exists(appDir)) {
|
if(await exists(appDir)) {
|
||||||
if(await exists(versionDir)) {
|
if(await exists(versionDir)) {
|
||||||
await rimraf(versionDir);
|
await remove(versionDir);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await mkdir(appDir);
|
await mkdir(appDir);
|
||||||
|
|
|
@ -1373,6 +1373,15 @@ fs-constants@^1.0.0:
|
||||||
resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad"
|
resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad"
|
||||||
integrity sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==
|
integrity sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==
|
||||||
|
|
||||||
|
fs-extra@^8.1.0:
|
||||||
|
version "8.1.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0"
|
||||||
|
integrity sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==
|
||||||
|
dependencies:
|
||||||
|
graceful-fs "^4.2.0"
|
||||||
|
jsonfile "^4.0.0"
|
||||||
|
universalify "^0.1.0"
|
||||||
|
|
||||||
fs-minipass@^1.2.5:
|
fs-minipass@^1.2.5:
|
||||||
version "1.2.6"
|
version "1.2.6"
|
||||||
resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-1.2.6.tgz#2c5cc30ded81282bfe8a0d7c7c1853ddeb102c07"
|
resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-1.2.6.tgz#2c5cc30ded81282bfe8a0d7c7c1853ddeb102c07"
|
||||||
|
@ -1458,7 +1467,7 @@ globals@^11.1.0:
|
||||||
resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
|
resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
|
||||||
integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==
|
integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==
|
||||||
|
|
||||||
graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2:
|
graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0:
|
||||||
version "4.2.0"
|
version "4.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.0.tgz#8d8fdc73977cb04104721cb53666c1ca64cd328b"
|
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.0.tgz#8d8fdc73977cb04104721cb53666c1ca64cd328b"
|
||||||
integrity sha512-jpSvDPV4Cq/bgtpndIWbI5hmYxhQGHPC4d4cqBPb4DLniCfhJokdXhwhaDuLBGLQdvvRum/UiX6ECVIPvDXqdg==
|
integrity sha512-jpSvDPV4Cq/bgtpndIWbI5hmYxhQGHPC4d4cqBPb4DLniCfhJokdXhwhaDuLBGLQdvvRum/UiX6ECVIPvDXqdg==
|
||||||
|
@ -2339,6 +2348,13 @@ json5@^2.1.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
minimist "^1.2.0"
|
minimist "^1.2.0"
|
||||||
|
|
||||||
|
jsonfile@^4.0.0:
|
||||||
|
version "4.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"
|
||||||
|
integrity sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=
|
||||||
|
optionalDependencies:
|
||||||
|
graceful-fs "^4.1.6"
|
||||||
|
|
||||||
jsprim@^1.2.2:
|
jsprim@^1.2.2:
|
||||||
version "1.4.1"
|
version "1.4.1"
|
||||||
resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.1.tgz#313e66bc1e5cc06e438bc1b7499c2e5c56acb6a2"
|
resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.1.tgz#313e66bc1e5cc06e438bc1b7499c2e5c56acb6a2"
|
||||||
|
@ -2744,11 +2760,6 @@ natural-compare@^1.4.0:
|
||||||
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
|
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
|
||||||
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=
|
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=
|
||||||
|
|
||||||
ncp@^2.0.0:
|
|
||||||
version "2.0.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/ncp/-/ncp-2.0.0.tgz#195a21d6c46e361d2fb1281ba38b91e9df7bdbb3"
|
|
||||||
integrity sha1-GVoh1sRuNh0vsSgbo4uR6d9727M=
|
|
||||||
|
|
||||||
needle@^2.2.1:
|
needle@^2.2.1:
|
||||||
version "2.4.0"
|
version "2.4.0"
|
||||||
resolved "https://registry.yarnpkg.com/needle/-/needle-2.4.0.tgz#6833e74975c444642590e15a750288c5f939b57c"
|
resolved "https://registry.yarnpkg.com/needle/-/needle-2.4.0.tgz#6833e74975c444642590e15a750288c5f939b57c"
|
||||||
|
@ -3964,6 +3975,11 @@ union-value@^1.0.0:
|
||||||
is-extendable "^0.1.1"
|
is-extendable "^0.1.1"
|
||||||
set-value "^2.0.1"
|
set-value "^2.0.1"
|
||||||
|
|
||||||
|
universalify@^0.1.0:
|
||||||
|
version "0.1.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66"
|
||||||
|
integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==
|
||||||
|
|
||||||
unpipe@1.0.0:
|
unpipe@1.0.0:
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
|
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
|
||||||
|
|
Loading…
Reference in New Issue