build app... probably not orking yet..

This commit is contained in:
michael shanks 2019-09-07 06:50:35 +01:00
parent dc0ad5c0d1
commit 5ee72b1d87
44 changed files with 231 additions and 148 deletions

View File

@ -24,6 +24,7 @@ import {
} from "../common/core"; } from "../common/core";
import {writable} from "svelte/store"; import {writable} from "svelte/store";
import { defaultPagesObject } from "../userInterface/pagesParsing/defaultPagesObject" import { defaultPagesObject } from "../userInterface/pagesParsing/defaultPagesObject"
import { buildPropsHierarchy } from "../userInterface/pagesParsing/buildPropsHierarchy"
import api from "./api"; import api from "./api";
import { isRootComponent } from "../userInterface/pagesParsing/searchComponents"; import { isRootComponent } from "../userInterface/pagesParsing/searchComponents";
import { import {
@ -579,8 +580,10 @@ const savePackage = (store, s) => {
hierarchy:s.hierarchy, hierarchy:s.hierarchy,
triggers:s.triggers, triggers:s.triggers,
actions: groupBy("name")(s.actions), actions: groupBy("name")(s.actions),
mainUi: s.mainUi, props: {
unauthenticatedUi: s.unauthenticatedUi main: buildPropsHierarchy(s.allComponents, s.pages.main.appBody),
unauthenticated: buildPropsHierarchy(s.allComponents, s.pages.unauthenticated.appBody)
}
}; };
const data = { const data = {

View File

@ -1,7 +1,7 @@
{ {
"name": "budibase-builder", "name": "budibase-client",
"version": "0.0.1", "version": "0.0.1",
"license": "AGPL-3.0", "license": "MPL-2.0",
"scripts": { "scripts": {
"build": "rollup -c", "build": "rollup -c",
"test": "jest" "test": "jest"

View File

@ -1,3 +1,5 @@
import { initialise } from "./initialise"; import { initialise } from "./initialise";
initialise(); const appDefinition = window["##BUDIBASE_APPDEFINITION##"];
initialise(appDefinition);

View File

@ -1,10 +1,7 @@
import { writable } from "svelte/store"; import { writable } from "svelte/store";
import { initialiseComponent } from "./initialiseComponent"; import { initialiseComponent } from "./initialiseComponent";
export const initialise = async (document, appDefinition, pageDefinition) => { export const initialise = async (document, appDefinition) => {
for(let stylesheet of pageDefinition.stylesheets) {
addStylesheet(document, stylesheet);
}
const componentLibraries = {}; const componentLibraries = {};
@ -16,20 +13,9 @@ export const initialise = async (document, appDefinition, pageDefinition) => {
const store = writable({}); const store = writable({});
initialiseComponent(allComponents, componentLibraries, store)( initialiseComponent(allComponents, componentLibraries, store)(
appDefinition.rootProps, appDefinition.props,
document.body); document.body);
} }
const componentLibraryUrl = (lib, rootUrlPath) => const componentLibraryUrl = (lib, appRootPath) =>
`${rootPath}/api/componentlibrary?lib=${encodeURI(lib)}` `${appRootPath}/componentlibrary?lib=${encodeURI(lib)}`
const addStylesheet = (document, url) => {
const head = document.head;
const link = document.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = url;
head.appendChild(link);
}

View File

@ -9,8 +9,9 @@ import { $ } from "./core/common";
export const initialiseComponent = (allComponents, componentLibraries, store) => (props, htmlElement) => { export const initialiseComponent = (allComponents, componentLibraries, store) => (props, htmlElement) => {
const rootComponent = getRootComponent( const component = getComponent(
props._component, allComponents); props._component,
allComponents);
const _app = { const _app = {
initialiseComponent: initialiseComponent(allComponents, componentLibraries, store), initialiseComponent: initialiseComponent(allComponents, componentLibraries, store),
@ -18,7 +19,7 @@ export const initialiseComponent = (allComponents, componentLibraries, store) =>
}; };
const {componentName, libName} = splitName( const {componentName, libName} = splitName(
rootComponent.name); component.name);
new (componentLibraries[libName][componentName])({ new (componentLibraries[libName][componentName])({
target: htmlElement, target: htmlElement,
@ -27,13 +28,8 @@ export const initialiseComponent = (allComponents, componentLibraries, store) =>
} }
const getRootComponent = (componentName, allComponents) => { const getComponent = (componentName, allComponents) =>
const component = find(c => c.name === componentName)(allComponents); find(c => c.name === componentName)(allComponents);
if(isRootComponent(component)) return component;
return getRootComponent(component.inherits, allComponents);
}
const isRootComponent = c => isUndefined(c.inherits); const isRootComponent = c => isUndefined(c.inherits);

View File

@ -0,0 +1,11 @@
{
"name": "Joes Button",
"description": "",
"inherits": "./standard-components/button",
"props": {
"className": "btn btn-danger"
},
"tags": [
"button"
]
}

View File

@ -0,0 +1,11 @@
{
"name": "another noubtbtk",
"description": "",
"inherits": "./standard-components/button",
"props": {
"contentText": "Mike"
},
"tags": [
"button"
]
}

View File

@ -0,0 +1,41 @@
{
"name": "listofstuff",
"description": "",
"inherits": "./standard-components/stackpanel",
"props": {
"children": [
{
"_component": "listofstuff:children",
"control": {
"_component": "Primary Button",
"contentText": "Button",
"contentComponent": {
"_component": ""
},
"className": "btn btn-primary",
"disabled": false
}
},
{
"_component": "listofstuff:children",
"control": {
"_component": "Joes Button",
"contentText": "Button",
"contentComponent": {
"_component": ""
},
"className": "btn btn-danger",
"disabled": false
}
}
],
"_component": "listofstuff",
"direction": "vertical"
},
"tags": [
"div",
"container",
"layout",
"panel"
]
}

View File

@ -0,0 +1,14 @@
{
"name": "login2",
"description": "",
"inherits": "./standard-components/login",
"props": {
"usernameLabel": "User"
},
"tags": [
"login",
"credentials",
"password",
"logon"
]
}

View File

@ -0,0 +1,15 @@
{
"name": "testapp2",
"version": "1.0.0",
"description": "",
"main": "plugins.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"budibase-client": "file:../../../client/dist",
"budibase-standard-components": "file:../../../standard-components/dist"
}
}

View File

@ -1,20 +1,12 @@
{ {
"main": { "main": {
"index": { "index": {},
"title": "yyyaaa" "appBody": ""
},
"appBody": "Random Button"
}, },
"unauthenticated": { "unauthenticated": {
"index": { "index": {},
"title": "Test App 1 - Login" "appBody": ""
}, },
"appBody": "login_screen" "componentLibraries": [],
}, "stylesheets": []
"componentLibraries": [
"./standard-components"
],
"stylesheets": [
"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
]
} }

View File

@ -1,53 +0,0 @@
<script>
export let className = "default";
export let disabled = false;
export let contentText;
export let contentComponent;
export let _app;
let contentComponentContainer;
$:{
if(_app && contentComponentContainer)
_app.initialiseComponent(contentComponent, contentComponentContainer);
}
</script>
<button class={className} {disabled} on:click>
{#if contentComponent && contentComponent._component}
<div bind:this={contentComponentContainer}>
</div>
{:else if contentText}
{contentText}
{:else}
<slot />
{/if}
</button>
<style>
.default {
font-family: inherit;
font-size: inherit;
padding: 0.4em;
margin: 0 0 0.5em 0;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 2px;
color: #333;
background-color: #f4f4f4;
outline: none;
}
.default:active {
background-color: #ddd;
}
.default:focus {
border-color: #666;
}
</style>

View File

@ -0,0 +1,9 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"budibase-client@file:../../../client/dist":
version "0.0.1"
"budibase-standard-components@file:../../../standard-components/dist":
version "1.0.0"

View File

@ -10,6 +10,8 @@ const derivedComponent2 = require("../appPackages/testApp/components/subfolder/o
const { readJSON, pathExists, unlink } = require("fs-extra"); const { readJSON, pathExists, unlink } = require("fs-extra");
const app = require("./testApp")(); const app = require("./testApp")();
testComponents.textbox.name = `./customComponents/textbox`;
testMoreComponents.textbox.name = `./moreCustomComponents/textbox`;
beforeAll(async () => { beforeAll(async () => {

View File

@ -10,40 +10,50 @@ const {
const { join } = require("path"); const { join } = require("path");
const sqrl = require('squirrelly'); const sqrl = require('squirrelly');
module.exports = async (config, appname, pageName, pages, appdefinition) => { module.exports = async (config, appname, pages, appdefinition) => {
const appPath = appPackageFolder(config, appname); const appPath = appPackageFolder(config, appname);
await buildClientAppDefinition( await buildClientAppDefinition(
config, appname, config, appname,
appdefinition, componentLibraries, appdefinition, componentLibraries,
appPath, appRootPath) appPath, pages, "main");
await buildClientAppDefinition(
config, appname,
appdefinition, componentLibraries,
appPath, pages, "unauthenticated")
await buildIndexHtml( await buildIndexHtml(
config, appname, appPath, config, appname, appPath,
pageName, pages); pages, "main");
await copyClientLib(appPath); await buildIndexHtml(
config, appname, appPath,
pages, "unauthenticated");
await copyClientLib(appPath, "main");
await copyClientLib(appPath, "unauthenticated");
} }
const publicPath = async appPath => join(appPath, "public"); const publicPath = async (appPath, pageName) => join(appPath, "public", pageName);
const rootPath = (config, appname) => config.useAppRootPath ? `/${appname}` : ""; const rootPath = (config, appname) => config.useAppRootPath ? `/${appname}` : "";
const copyClientLib = async appPath => { const copyClientLib = async (appPath, pageName) => {
var sourcepath = require.resolve("budibase-client",{ var sourcepath = require.resolve("budibase-client",{
basedir: appPath paths: [appPath]
}); });
var destPath = join(publicPath(appPath), "budibase-client.js"); var destPath = join(publicPath(appPath, pageName), "budibase-client.js");
await copyFile(sourcepath, destPath, constants.COPYFILE_FICLONE); await copyFile(sourcepath, destPath, constants.COPYFILE_FICLONE);
} }
const buildIndexHtml = async (config, appname, appPath, pageName, pages) => { const buildIndexHtml = async (config, appname, appPath, pages, pageName) => {
const appPublicPath = publicPath(appPath); const appPublicPath = publicPath(appPath, pageName);
const appRootPath = rootPath(config, appname); const appRootPath = rootPath(config, appname);
const stylesheetUrl = s => const stylesheetUrl = s =>
@ -51,11 +61,10 @@ const buildIndexHtml = async (config, appname, appPath, pageName, pages) => {
? s ? s
: `/${rootPath(config, appname)}/${s}`; : `/${rootPath(config, appname)}/${s}`;
const templateObj = { const templateObj = {
title = pages[pageName].index.title || "Budibase App", title: pages[pageName].index.title || "Budibase App",
favicon = `${appRootPath}/${pages[pageName].index.favicon || "/assets/favicon.png"}`, favicon: `${appRootPath}/${pages[pageName].index.favicon || "/assets/favicon.png"}`,
stylesheets = pages.stylesheets.map(stylesheetUrl), stylesheets: pages.stylesheets.map(stylesheetUrl),
appRootPath appRootPath
} }
@ -71,11 +80,14 @@ const buildIndexHtml = async (config, appname, appPath, pageName, pages) => {
} }
const buildClientAppDefinition = async (config, appname, appdefinition, pages, appPath) => { const buildClientAppDefinition = async (config, appname, appdefinition, appPath, pages, pageName) => {
const appPublicPath = publicPath(appPath, pageName);
const appRootPath = rootPath(config, appname);
const componentLibraries = []; const componentLibraries = [];
const appPublicPath = publicPath(appPath);
const appRootPath = rootPath(config, appname);
for(let lib of pages.componentLibraries) { for(let lib of pages.componentLibraries) {
const info = await componentLibraryInfo(appPath, lib); const info = await componentLibraryInfo(appPath, lib);
@ -101,11 +113,14 @@ const buildClientAppDefinition = async (config, appname, appdefinition, pages, a
const filename = join(appPublicPath, "clientAppDefinition.js"); const filename = join(appPublicPath, "clientAppDefinition.js");
const clientAppDefObj = {
hierarchy: appdefinition.hierarchy,
componentLibraries: pages.componentLibraries,
appRootPath: appRootPath,
props: appdefinition.props[pageName]
}
await writeFile(filename, await writeFile(filename,
`window['##BUDIBASE_APPDEFINITION##'] = { `window['##BUDIBASE_APPDEFINITION##'] = ${JSON.stringify(clientAppDefObj)}`);
hierarchy: ${JSON.stringify(appdefinition.hierarchy)},
componentLibraries: ${JSON.stringify(componentLibraries)},
appRootPath: '${appRootPath}'
}`);
} }

View File

@ -1,11 +1,20 @@
const { const {
readJSON, exists readJSON, exists
} = require("fs-extra"); } = require("fs-extra");
const { resolve } = require("path"); const {
resolve, join , dirname
} = require("path");
const getLibDir = (appPath, libname) => require.resolve(libname, { const getLibDir = (appPath, libname) => {
basedir: appPath try {
}); const componentsFile = require.resolve(
join(libname, "components.json"),
{ paths: [appPath]});
return dirname(componentsFile);
} catch(e) {
console.log(e);
}
}
const getComponentsFilepath = libPath => const getComponentsFilepath = libPath =>
resolve(libPath, "components.json"); resolve(libPath, "components.json");

View File

@ -26,6 +26,9 @@ const {
const {merge} = require("lodash"); const {merge} = require("lodash");
const { componentLibraryInfo } = require("./componentLibraryInfo"); const { componentLibraryInfo } = require("./componentLibraryInfo");
const savePackage = require("./savePackage");
module.exports.savePackage = savePackage;
module.exports.getPackageForBuilder = async (config, appname) => { module.exports.getPackageForBuilder = async (config, appname) => {
const appPath = appPackageFolder(config, appname); const appPath = appPackageFolder(config, appname);
@ -47,23 +50,7 @@ module.exports.getPackageForBuilder = async (config, appname) => {
} }
module.exports.savePackage = async (config, appname, pkg) => {
const appPath = appPackageFolder(config, appname);
await writeJSON(
`${appPath}/appDefinition.json`,
pkg.appDefinition,
{spaces:2});
await writeJSON(
`${appPath}/access_levels.json`,
pkg.accessLevels,
{spaces:2});
await writeJSON(
`${appPath}/pages.json`,
pkg.pages,
{spaces:2});
}
module.exports.getApps = async (config) => module.exports.getApps = async (config) =>
await readdir(appsFolder(config)); await readdir(appsFolder(config));
@ -173,7 +160,6 @@ const fetchDerivedComponents = async (appPath, relativePath = "") => {
.replace(/\\/g, "/"); .replace(/\\/g, "/");
component.props = component.props || {}; component.props = component.props || {};
component.props._component = component.name;
components.push(component); components.push(component);
} else { } else {

View File

@ -0,0 +1,25 @@
const { appPackageFolder } = require("../createAppPackage");
const { writeJSON } = require("fs-extra");
const buildApp = require("./buildApp");
module.exports = async (config, appname, pkg) => {
const appPath = appPackageFolder(config, appname);
await writeJSON(
`${appPath}/appDefinition.json`,
pkg.appDefinition,
{spaces:2});
await writeJSON(
`${appPath}/access_levels.json`,
pkg.accessLevels,
{spaces:2});
await writeJSON(
`${appPath}/pages.json`,
pkg.pages,
{spaces:2});
await buildApp(
config, appname,
pkg.pages, pkg.appDefinition);
}

View File

@ -2,5 +2,4 @@
node_modules node_modules
yarn.lock yarn.lock
package-lock.json package-lock.json
index.js dist/index.js
index.mjs

View File

@ -0,0 +1,14 @@
{
"name": "budibase-standard-components",
"svelte": "src/index.svelte",
"main": "index.js",
"devDependencies": {},
"keywords": [
"budibase"
],
"files": [
"dist"
],
"version": "1.0.0",
"license": "MPL-2.0"
}

View File

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -0,0 +1,6 @@
export {default as button} from "./Button.svelte";
export {default as login} from "./Login.svelte";
export {default as form} from "./Form.svelte";
export {default as formControl} from "./FormControl.svelte";
export {default as textbox} from "./Textbox.svelte";
export {default as stackpanel} from "./StackPanel.svelte";