From 1e8f13f9cffc290f949662aa2f112b3c41f4c34e Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Mon, 9 Nov 2020 15:24:29 +0000 Subject: [PATCH 01/10] start server render index.html --- packages/server/package.json | 3 +- .../{static.js => static/index.js} | 37 ++++ .../static/templates/BudibaseApp.svelte | 0 .../static/templates/index.template.html | 63 ++++++ packages/server/yarn.lock | 205 +++++++++++++++++- 5 files changed, 304 insertions(+), 4 deletions(-) rename packages/server/src/api/controllers/{static.js => static/index.js} (87%) create mode 100644 packages/server/src/api/controllers/static/templates/BudibaseApp.svelte create mode 100644 packages/server/src/api/controllers/static/templates/index.template.html diff --git a/packages/server/package.json b/packages/server/package.json index 1c7c23f287..3774123cf8 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -38,7 +38,7 @@ "keywords": [ "budibase" ], - "author": "Michael Shanks", + "author": "Budibase", "license": "AGPL-3.0-or-later", "dependencies": { "@budibase/client": "^0.3.4", @@ -78,6 +78,7 @@ "pouchdb-replication-stream": "^1.2.9", "sanitize-s3-objectkey": "^0.0.1", "squirrelly": "^7.5.0", + "svelte": "^3.29.4", "tar-fs": "^2.1.0", "to-json-schema": "^0.2.5", "uuid": "^3.3.2", diff --git a/packages/server/src/api/controllers/static.js b/packages/server/src/api/controllers/static/index.js similarity index 87% rename from packages/server/src/api/controllers/static.js rename to packages/server/src/api/controllers/static/index.js index 2c8bba7790..0a342a2e24 100644 --- a/packages/server/src/api/controllers/static.js +++ b/packages/server/src/api/controllers/static/index.js @@ -1,3 +1,5 @@ +require("svelte/register") + const send = require("koa-send") const { resolve, join } = require("../../utilities/centralPath") const fetch = require("node-fetch") @@ -137,6 +139,41 @@ exports.performLocalFileProcessing = async function(ctx) { } } +exports.serveAppNew = async function(ctx) { + const App = require("./templates/BudibaseApp.svelte").default + + const { html } = App.render({ + name: "Budibase", + authenticated: + ctx.auth.authenticated === AuthTypes.APP ? "main" : "unauthenticated", + production: env.CLOUD, + }) + + // // default to homedir + // const appPath = resolve( + // budibaseAppsDir(), + // ctx.params.appId, + // "public", + // mainOrAuth + // ) + + ctx.body = html + + // const appId = ctx.user.appId + + // if (env.CLOUD) { + // const S3_URL = `https://${appId}.app.budi.live/assets/${appId}/${mainOrAuth}/${ctx.file || + // "index.production.html"}` + + // const response = await fetch(S3_URL) + // const body = await response.text() + // ctx.body = body + // return + // } + + // await send(ctx, ctx.file || "index.html", { root: ctx.devPath || appPath }) +} + exports.serveApp = async function(ctx) { const mainOrAuth = ctx.auth.authenticated === AuthTypes.APP ? "main" : "unauthenticated" diff --git a/packages/server/src/api/controllers/static/templates/BudibaseApp.svelte b/packages/server/src/api/controllers/static/templates/BudibaseApp.svelte new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/server/src/api/controllers/static/templates/index.template.html b/packages/server/src/api/controllers/static/templates/index.template.html new file mode 100644 index 0000000000..e7cf633277 --- /dev/null +++ b/packages/server/src/api/controllers/static/templates/index.template.html @@ -0,0 +1,63 @@ + + + + + + + + {{ title }} + + + + + {{ each(options.stylesheets) }} + + {{ /each }} + + {{ each(options.screenStyles) }} + {{ if(options.production) }} + + {{#else}} + + {{ /if }} + {{ /each }} + + {{ if(options.pageStyle) }} + {{ if(options.production) }} + + {{#else}} + + {{ /if }} + {{ /if }} + + + + + {{ if(options.production) }} + + + {{#else}} + + + {{ /if }} + + + + + + + \ No newline at end of file diff --git a/packages/server/yarn.lock b/packages/server/yarn.lock index 941f02e5e8..048694e6de 100644 --- a/packages/server/yarn.lock +++ b/packages/server/yarn.lock @@ -200,6 +200,15 @@ lodash "^4.17.19" to-fast-properties "^2.0.0" +"@budibase/client@^0.3.4": + version "0.3.4" + resolved "https://registry.yarnpkg.com/@budibase/client/-/client-0.3.4.tgz#aca2d13170dae870d069a56f53519d9fbb4bdc00" + integrity sha512-zs9Jnr1CzvgZY4NrliatqDUm0gVhlcQkpdsMblO+3zRcwBzRXAeFyzwMtGpcbiQm29zHjPBOivmQQUMxgi3lUg== + dependencies: + deep-equal "^2.0.1" + mustache "^4.0.1" + regexparam "^1.3.0" + "@cnakazawa/watch@^1.0.3": version "1.0.4" resolved "https://registry.yarnpkg.com/@cnakazawa/watch/-/watch-1.0.4.tgz#f864ae85004d0fcab6f50be9141c4da368d1656a" @@ -1227,6 +1236,11 @@ array-equal@^1.0.0: resolved "https://registry.yarnpkg.com/array-equal/-/array-equal-1.0.0.tgz#8c2a5ef2472fd9ea742b04c77a75093ba2757c93" integrity sha1-jCpe8kcv2ep0KwTHenUJO6J1fJM= +array-filter@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/array-filter/-/array-filter-1.0.0.tgz#baf79e62e6ef4c2a4c0b831232daffec251f9d83" + integrity sha1-uveeYubvTCpMC4MSMtr/7CUfnYM= + array-unique@^0.3.2: version "0.3.2" resolved "https://registry.yarnpkg.com/array-unique/-/array-unique-0.3.2.tgz#a894b75d4bc4f6cd679ef3244a9fd8f46ae2d428" @@ -1299,6 +1313,13 @@ atomic-sleep@^1.0.0: resolved "https://registry.yarnpkg.com/atomic-sleep/-/atomic-sleep-1.0.0.tgz#eb85b77a601fc932cfe432c5acd364a9e2c9075b" integrity sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ== +available-typed-arrays@^1.0.0, available-typed-arrays@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.2.tgz#6b098ca9d8039079ee3f77f7b783c4480ba513f5" + integrity sha512-XWX3OX8Onv97LMk/ftVyBibpGwY5a8SmuxZPzeOxqmuEqUCOM9ZE+uIaD1VNJ5QnvU2UQusvmKbuM1FR8QWGfQ== + dependencies: + array-filter "^1.0.0" + aws-sdk@^2.767.0: version "2.771.0" resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.771.0.tgz#ff4beb0a04d6ab1ae962c85dfb42e3e9bfe2b93b" @@ -1666,6 +1687,14 @@ cacheable-request@^6.0.0: normalize-url "^4.1.0" responselike "^1.0.2" +call-bind@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/call-bind/-/call-bind-1.0.0.tgz#24127054bb3f9bdcb4b1fb82418186072f77b8ce" + integrity sha512-AEXsYIyyDY3MCzbwdhzG3Jx1R0J2wetQyUynn6dYHAO+bg8l1k7jwZtRv4ryryFs7EP+NDlikJlVe59jr0cM2w== + dependencies: + function-bind "^1.1.1" + get-intrinsic "^1.0.0" + callsites@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73" @@ -2164,6 +2193,26 @@ decompress@^4.2.1: pify "^2.3.0" strip-dirs "^2.0.0" +deep-equal@^2.0.1: + version "2.0.4" + resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-2.0.4.tgz#6b0b407a074666033169df3acaf128e1c6f3eab6" + integrity sha512-BUfaXrVoCfgkOQY/b09QdO9L3XNoF2XH0A3aY9IQwQL/ZjLOe8FQgCNVl1wiolhsFo8kFdO9zdPViCPbmaJA5w== + dependencies: + es-abstract "^1.18.0-next.1" + es-get-iterator "^1.1.0" + is-arguments "^1.0.4" + is-date-object "^1.0.2" + is-regex "^1.1.1" + isarray "^2.0.5" + object-is "^1.1.3" + object-keys "^1.1.1" + object.assign "^4.1.1" + regexp.prototype.flags "^1.3.0" + side-channel "^1.0.3" + which-boxed-primitive "^1.0.1" + which-collection "^1.0.1" + which-typed-array "^1.1.2" + deep-equal@~1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-1.0.1.tgz#f5d260292b660e084eff4cdbc9f08ad3247448b5" @@ -2545,7 +2594,7 @@ error-ex@^1.3.1: dependencies: is-arrayish "^0.2.1" -es-abstract@^1.17.0-next.1, es-abstract@^1.17.2, es-abstract@^1.17.5: +es-abstract@^1.17.0-next.1, es-abstract@^1.17.2, es-abstract@^1.17.4, es-abstract@^1.17.5: version "1.17.7" resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.17.7.tgz#a4de61b2f66989fc7421676c1cb9787573ace54c" integrity sha512-VBl/gnfcJ7OercKA9MVaegWsBHFjV492syMudcnQZvt/Dw8ezpcOHYZXa/J96O8vx+g4x65YKhxOwDUh63aS5g== @@ -2562,7 +2611,7 @@ es-abstract@^1.17.0-next.1, es-abstract@^1.17.2, es-abstract@^1.17.5: string.prototype.trimend "^1.0.1" string.prototype.trimstart "^1.0.1" -es-abstract@^1.18.0-next.0: +es-abstract@^1.18.0-next.0, es-abstract@^1.18.0-next.1: version "1.18.0-next.1" resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.18.0-next.1.tgz#6e3a0a4bda717e5023ab3b8e90bec36108d22c68" integrity sha512-I4UGspA0wpZXWENrdA0uHbnhte683t3qT/1VFH9aX2dA5PPSf6QW5HHXf5HImaqPmjXaVeVk4RGWnaylmV7uAA== @@ -2580,6 +2629,20 @@ es-abstract@^1.18.0-next.0: string.prototype.trimend "^1.0.1" string.prototype.trimstart "^1.0.1" +es-get-iterator@^1.1.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/es-get-iterator/-/es-get-iterator-1.1.1.tgz#b93ddd867af16d5118e00881396533c1c6647ad9" + integrity sha512-qorBw8Y7B15DVLaJWy6WdEV/ZkieBcu6QCq/xzWzGOKJqgG1j754vXRfZ3NY7HSShneqU43mPB4OkQBTkvHhFw== + dependencies: + call-bind "^1.0.0" + get-intrinsic "^1.0.1" + has-symbols "^1.0.1" + is-arguments "^1.0.4" + is-map "^2.0.1" + is-set "^2.0.1" + is-string "^1.0.5" + isarray "^2.0.5" + es-to-primitive@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/es-to-primitive/-/es-to-primitive-1.2.1.tgz#e55cd4c9cdc188bcefb03b366c736323fc5c898a" @@ -3252,6 +3315,15 @@ get-caller-file@^2.0.1: resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== +get-intrinsic@^1.0.0, get-intrinsic@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/get-intrinsic/-/get-intrinsic-1.0.1.tgz#94a9768fcbdd0595a1c9273aacf4c89d075631be" + integrity sha512-ZnWP+AmS1VUaLgTRy47+zKtjTxz+0xMpx3I52i+aalBK1QP19ggLF3Db89KJX7kjfOfP2eoa01qc++GwPgufPg== + dependencies: + function-bind "^1.1.1" + has "^1.0.3" + has-symbols "^1.0.1" + get-stream@3.0.0, get-stream@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14" @@ -3776,11 +3848,21 @@ is-accessor-descriptor@^1.0.0: dependencies: kind-of "^6.0.0" +is-arguments@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/is-arguments/-/is-arguments-1.0.4.tgz#3faf966c7cba0ff437fb31f6250082fcf0448cf3" + integrity sha512-xPh0Rmt8NE65sNzvyUmWgI1tz3mKq74lGA0mL8LYZcoIzKOzDh6HmrYm3d18k60nHerC8A9Km8kYu87zfSFnLA== + is-arrayish@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d" integrity sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0= +is-bigint@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-bigint/-/is-bigint-1.0.0.tgz#73da8c33208d00f130e9b5e15d23eac9215601c4" + integrity sha512-t5mGUXC/xRheCK431ylNiSkGGpBp8bHENBcENTkDT6ppwPzEVxNGZRvgvmOEfbWkFhA7D2GEuE2mmQTr78sl2g== + is-binary-path@~2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-2.1.0.tgz#ea1f7f3b80f064236e83470f86c09c254fb45b09" @@ -3788,6 +3870,11 @@ is-binary-path@~2.1.0: dependencies: binary-extensions "^2.0.0" +is-boolean-object@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/is-boolean-object/-/is-boolean-object-1.0.1.tgz#10edc0900dd127697a92f6f9807c7617d68ac48e" + integrity sha512-TqZuVwa/sppcrhUCAYkGBk7w0yxfQQnxq28fjkO53tnK9FQXmdwz2JS5+GjsWQ6RByES1K40nI+yDic5c9/aAQ== + is-buffer@^1.1.5: version "1.1.6" resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be" @@ -3824,7 +3911,7 @@ is-data-descriptor@^1.0.0: dependencies: kind-of "^6.0.0" -is-date-object@^1.0.1: +is-date-object@^1.0.1, is-date-object@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/is-date-object/-/is-date-object-1.0.2.tgz#bda736f2cd8fd06d32844e7743bfa7494c3bfd7e" integrity sha512-USlDT524woQ08aoZFzh3/Z6ch9Y/EWXEHQ/AaRN0SkKq4t2Jw2R2339tSXmwuVoY7LLlBCbOIlx2myP/L5zk0g== @@ -3904,6 +3991,11 @@ is-installed-globally@^0.3.1: global-dirs "^2.0.1" is-path-inside "^3.0.1" +is-map@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/is-map/-/is-map-2.0.1.tgz#520dafc4307bb8ebc33b813de5ce7c9400d644a1" + integrity sha512-T/S49scO8plUiAOA2DBTBG3JHpn1yiw0kRp6dgiZ0v2/6twi5eiB0rHtHFH9ZIrvlWc6+4O+m4zg5+Z833aXgw== + is-natural-number@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/is-natural-number/-/is-natural-number-4.0.1.tgz#ab9d76e1db4ced51e35de0c72ebecf09f734cde8" @@ -3919,6 +4011,11 @@ is-npm@^4.0.0: resolved "https://registry.yarnpkg.com/is-npm/-/is-npm-4.0.0.tgz#c90dd8380696df87a7a6d823c20d0b12bbe3c84d" integrity sha512-96ECIfh9xtDDlPylNPXhzjsykHsMJZ18ASpaWzQyBr4YRTcVjUvzaHayDAES2oU/3KpljhHUjtSRNiDwi0F0ig== +is-number-object@^1.0.3: + version "1.0.4" + resolved "https://registry.yarnpkg.com/is-number-object/-/is-number-object-1.0.4.tgz#36ac95e741cf18b283fc1ddf5e83da798e3ec197" + integrity sha512-zohwelOAur+5uXtk8O3GPQ1eAcu4ZX3UwxQhUlfFFMNpUd83gXgjbhJh6HmB6LUNV/ieOLQuDwJO3dWJosUeMw== + is-number@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/is-number/-/is-number-3.0.0.tgz#24fd6201a4782cf50561c810276afc7d12d71195" @@ -3970,11 +4067,21 @@ is-retry-allowed@^1.1.0: resolved "https://registry.yarnpkg.com/is-retry-allowed/-/is-retry-allowed-1.2.0.tgz#d778488bd0a4666a3be8a1482b9f2baafedea8b4" integrity sha512-RUbUeKwvm3XG2VYamhJL1xFktgjvPzL0Hq8C+6yrWIswDy3BIXGqCxhxkc30N9jqK311gVU137K8Ei55/zVJRg== +is-set@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/is-set/-/is-set-2.0.1.tgz#d1604afdab1724986d30091575f54945da7e5f43" + integrity sha512-eJEzOtVyenDs1TMzSQ3kU3K+E0GUS9sno+F0OBT97xsgcJsF9nXMBtkT9/kut5JEpM7oL7X/0qxR17K3mcwIAA== + is-stream@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" integrity sha1-EtSj3U5o4Lec6428hBc66A2RykQ= +is-string@^1.0.4, is-string@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/is-string/-/is-string-1.0.5.tgz#40493ed198ef3ff477b8c7f92f644ec82a5cd3a6" + integrity sha512-buY6VNRjhQMiF1qWDouloZlQbRhDPCebwxSjxMjxgemYT46YMd2NR0/H+fBhEfWX4A/w9TBJ+ol+okqJKFE6vQ== + is-symbol@^1.0.2: version "1.0.3" resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.3.tgz#38e1014b9e6329be0de9d24a414fd7441ec61937" @@ -3991,6 +4098,16 @@ is-type-of@^1.0.0: is-class-hotfix "~0.0.6" isstream "~0.1.2" +is-typed-array@^1.1.3: + version "1.1.3" + resolved "https://registry.yarnpkg.com/is-typed-array/-/is-typed-array-1.1.3.tgz#a4ff5a5e672e1a55f99c7f54e59597af5c1df04d" + integrity sha512-BSYUBOK/HJibQ30wWkWold5txYwMUXQct9YHAQJr8fSwvZoiglcqB0pd7vEN23+Tsi9IUEjztdOSzl4qLVYGTQ== + dependencies: + available-typed-arrays "^1.0.0" + es-abstract "^1.17.4" + foreach "^2.0.5" + has-symbols "^1.0.1" + is-typedarray@^1.0.0, is-typedarray@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a" @@ -4001,6 +4118,16 @@ is-utf8@^0.2.0: resolved "https://registry.yarnpkg.com/is-utf8/-/is-utf8-0.2.1.tgz#4b0da1442104d1b336340e80797e865cf39f7d72" integrity sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI= +is-weakmap@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/is-weakmap/-/is-weakmap-2.0.1.tgz#5008b59bdc43b698201d18f62b37b2ca243e8cf2" + integrity sha512-NSBR4kH5oVj1Uwvv970ruUkCV7O1mzgVFO4/rev2cLRda9Tm9HrL70ZPut4rOHgY0FNrUu9BCbXA2sdQ+x0chA== + +is-weakset@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/is-weakset/-/is-weakset-2.0.1.tgz#e9a0af88dbd751589f5e50d80f4c98b780884f83" + integrity sha512-pi4vhbhVHGLxohUw7PhGsueT4vRGFoXhP7+RGN0jKIv9+8PWYCQTqtADngrxOm2g46hoH0+g8uZZBzMrvVGDmw== + is-windows@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d" @@ -4026,6 +4153,11 @@ isarray@1.0.0, isarray@^1.0.0, isarray@~1.0.0: resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE= +isarray@^2.0.5: + version "2.0.5" + resolved "https://registry.yarnpkg.com/isarray/-/isarray-2.0.5.tgz#8af1e4c1221244cc62459faf38940d4e644a5723" + integrity sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw== + isbinaryfile@^4.0.6: version "4.0.6" resolved "https://registry.yarnpkg.com/isbinaryfile/-/isbinaryfile-4.0.6.tgz#edcb62b224e2b4710830b67498c8e4e5a4d2610b" @@ -5564,6 +5696,14 @@ object-inspect@^1.8.0: resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.8.0.tgz#df807e5ecf53a609cc6bfe93eac3cc7be5b3a9d0" integrity sha512-jLdtEOB112fORuypAyl/50VRVIBIdVQOSUUGQHzJ4xBSbit81zRarz7GThkEFZy1RceYrWYcPcBFPQwHyAc1gA== +object-is@^1.1.3: + version "1.1.3" + resolved "https://registry.yarnpkg.com/object-is/-/object-is-1.1.3.tgz#2e3b9e65560137455ee3bd62aec4d90a2ea1cc81" + integrity sha512-teyqLvFWzLkq5B9ki8FVWA902UER2qkxmdA4nLf+wjOLAWgxzCWZNCxpDq9MvE8MmhWNr+I8w3BN49Vx36Y6Xg== + dependencies: + define-properties "^1.1.3" + es-abstract "^1.18.0-next.1" + object-keys@^1.0.12, object-keys@^1.0.6, object-keys@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.1.1.tgz#1c47f272df277f3b1daf061677d9c82e2322c60e" @@ -6433,6 +6573,19 @@ regex-not@^1.0.0, regex-not@^1.0.2: extend-shallow "^3.0.2" safe-regex "^1.1.0" +regexp.prototype.flags@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/regexp.prototype.flags/-/regexp.prototype.flags-1.3.0.tgz#7aba89b3c13a64509dabcf3ca8d9fbb9bdf5cb75" + integrity sha512-2+Q0C5g951OlYlJz6yu5/M33IcsESLlLfsyIaLJaG4FA2r4yP8MvVMJUUP/fVBkSpbbbZlS5gynbEWLipiiXiQ== + dependencies: + define-properties "^1.1.3" + es-abstract "^1.17.0-next.1" + +regexparam@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/regexparam/-/regexparam-1.3.0.tgz#2fe42c93e32a40eff6235d635e0ffa344b92965f" + integrity sha512-6IQpFBv6e5vz1QAqI+V4k8P2e/3gRrqfCJ9FI+O1FLQTO+Uz6RXZEZOPmTJ6hlGj7gkERzY5BRCv09whKP96/g== + regexpp@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-2.0.1.tgz#8d19d31cf632482b589049f8281f93dbcba4d07f" @@ -6792,6 +6945,14 @@ shellwords@^0.1.1: resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b" integrity sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww== +side-channel@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.3.tgz#cdc46b057550bbab63706210838df5d4c19519c3" + integrity sha512-A6+ByhlLkksFoUepsGxfj5x1gTSrs+OydsRptUxeNCabQpCFUvcwIczgOigI8vhY/OJCnPnyE9rGiwgvr9cS1g== + dependencies: + es-abstract "^1.18.0-next.0" + object-inspect "^1.8.0" + signal-exit@^3.0.0, signal-exit@^3.0.2: version "3.0.3" resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c" @@ -7235,6 +7396,11 @@ supports-color@^7.1.0: dependencies: has-flag "^4.0.0" +svelte@^3.29.4: + version "3.29.4" + resolved "https://registry.yarnpkg.com/svelte/-/svelte-3.29.4.tgz#d0f80cb58109ef52963855c23496f7153bb2eb7e" + integrity sha512-oW0fGHlyFFMvzRtIvOs84b0fOc0gmZNQcL5Is3hxuTpvaYX3pfd8oHy4KnOvbq4Ca6SG6AHdRMk7OhApTo0NqA== + symbol-tree@^3.2.2: version "3.2.4" resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.4.tgz#430637d248ba77e078883951fb9aa0eed7c63fa2" @@ -7819,11 +7985,44 @@ whatwg-url@^7.0.0: tr46 "^1.0.1" webidl-conversions "^4.0.2" +which-boxed-primitive@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/which-boxed-primitive/-/which-boxed-primitive-1.0.1.tgz#cbe8f838ebe91ba2471bb69e9edbda67ab5a5ec1" + integrity sha512-7BT4TwISdDGBgaemWU0N0OU7FeAEJ9Oo2P1PHRm/FCWoEi2VLWC9b6xvxAA3C/NMpxg3HXVgi0sMmGbNUbNepQ== + dependencies: + is-bigint "^1.0.0" + is-boolean-object "^1.0.0" + is-number-object "^1.0.3" + is-string "^1.0.4" + is-symbol "^1.0.2" + +which-collection@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/which-collection/-/which-collection-1.0.1.tgz#70eab71ebbbd2aefaf32f917082fc62cdcb70906" + integrity sha512-W8xeTUwaln8i3K/cY1nGXzdnVZlidBcagyNFtBdD5kxnb4TvGKR7FfSIS3mYpwWS1QUCutfKz8IY8RjftB0+1A== + dependencies: + is-map "^2.0.1" + is-set "^2.0.1" + is-weakmap "^2.0.1" + is-weakset "^2.0.1" + which-module@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a" integrity sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho= +which-typed-array@^1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/which-typed-array/-/which-typed-array-1.1.2.tgz#e5f98e56bda93e3dac196b01d47c1156679c00b2" + integrity sha512-KT6okrd1tE6JdZAy3o2VhMoYPh3+J6EMZLyrxBQsZflI1QCZIxMrIYLkosd8Twf+YfknVIHmYQPgJt238p8dnQ== + dependencies: + available-typed-arrays "^1.0.2" + es-abstract "^1.17.5" + foreach "^2.0.5" + function-bind "^1.1.1" + has-symbols "^1.0.1" + is-typed-array "^1.1.3" + which@^1.2.9, which@^1.3.0: version "1.3.1" resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a" From f19a20a02d394291f95375050d0e05e7938eda35 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 10 Nov 2020 17:08:02 +0000 Subject: [PATCH 02/10] remove cf invalidation, adding validation around successful deploys only --- .../deploy/DeploymentHistory.svelte | 11 +++-- .../pages/[application]/deploy/index.svelte | 14 +----- .../server/src/api/controllers/deploy/aws.js | 45 +------------------ .../src/api/controllers/deploy/index.js | 43 ++---------------- packages/server/src/api/index.js | 2 + 5 files changed, 17 insertions(+), 98 deletions(-) diff --git a/packages/builder/src/components/deploy/DeploymentHistory.svelte b/packages/builder/src/components/deploy/DeploymentHistory.svelte index 417423a985..05a2e40fa6 100644 --- a/packages/builder/src/components/deploy/DeploymentHistory.svelte +++ b/packages/builder/src/components/deploy/DeploymentHistory.svelte @@ -44,6 +44,7 @@ } onMount(() => { + fetchDeployments() poll = setInterval(fetchDeployments, POLL_INTERVAL) }) @@ -55,10 +56,12 @@

Deployment History

- - View Your Deployed App → - - + {#if deployments.some(deployment => deployment.status === 'SUCCESS')} + + View Your Deployed App → + + + {/if}
diff --git a/packages/builder/src/pages/[application]/deploy/index.svelte b/packages/builder/src/pages/[application]/deploy/index.svelte index 0563c4e2cc..462601ff48 100644 --- a/packages/builder/src/pages/[application]/deploy/index.svelte +++ b/packages/builder/src/pages/[application]/deploy/index.svelte @@ -17,19 +17,16 @@ $: appId = $store.appId async function deployApp() { - loading = true const DEPLOY_URL = `/api/deploy` try { - notifier.info("Starting Deployment..") + notifier.info(`Deployment started. Please wait.`) const response = await api.post(DEPLOY_URL) const json = await response.json() if (response.status !== 200) { throw new Error() } - notifier.info(`Deployment started. Please wait.`) - loading = false analytics.captureEvent("Deployed App", { appId, }) @@ -43,7 +40,6 @@ }) analytics.captureException(err) notifier.danger("Deployment unsuccessful. Please try again later.") - loading = false } } @@ -51,13 +47,7 @@

It's time to shine!

- +
{ } }) +router.get("/health", ctx => (ctx.status = 200)) + router.use(authRoutes.routes()) router.use(authRoutes.allowedMethods()) From 449f8980098cdc54dfb1973b0bb41f1fa436c076 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 10 Nov 2020 17:16:40 +0000 Subject: [PATCH 03/10] increasing log level in production --- packages/server/.env.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/.env.template b/packages/server/.env.template index 4895d0309c..1b1ff2e854 100644 --- a/packages/server/.env.template +++ b/packages/server/.env.template @@ -12,7 +12,7 @@ JWT_SECRET={{cookieKey1}} PORT=4001 # error level for koa-pino -LOG_LEVEL=error +LOG_LEVEL=info DEPLOYMENT_CREDENTIALS_URL="https://dt4mpwwap8.execute-api.eu-west-1.amazonaws.com/prod/" DEPLOYMENT_DB_URL="https://couchdb.budi.live:5984" From fb0f7b0c73ab958173548bfe7484c359b70a37af Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 10 Nov 2020 20:23:36 +0000 Subject: [PATCH 04/10] v0.3.7 --- lerna.json | 2 +- packages/builder/package.json | 4 ++-- packages/client/package.json | 2 +- packages/server/package.json | 4 ++-- packages/standard-components/package.json | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lerna.json b/lerna.json index c04ca6923f..2b9d044aa5 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "0.3.6", + "version": "0.3.7", "npmClient": "yarn", "packages": [ "packages/*" diff --git a/packages/builder/package.json b/packages/builder/package.json index b15b3e6b0f..226d69f863 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/builder", - "version": "0.3.6", + "version": "0.3.7", "license": "AGPL-3.0", "private": true, "scripts": { @@ -64,7 +64,7 @@ }, "dependencies": { "@budibase/bbui": "^1.50.1", - "@budibase/client": "^0.3.6", + "@budibase/client": "^0.3.7", "@budibase/colorpicker": "^1.0.1", "@budibase/svelte-ag-grid": "^0.0.16", "@fortawesome/fontawesome-free": "^5.14.0", diff --git a/packages/client/package.json b/packages/client/package.json index 7456bd74b2..a66ac002f8 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/client", - "version": "0.3.6", + "version": "0.3.7", "license": "MPL-2.0", "main": "dist/budibase-client.js", "module": "dist/budibase-client.esm.mjs", diff --git a/packages/server/package.json b/packages/server/package.json index 752c0163e6..0ca07d5b22 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -1,6 +1,6 @@ { "name": "@budibase/server", - "version": "0.3.6", + "version": "0.3.7", "description": "Budibase Web Server", "main": "src/electron.js", "repository": { @@ -41,7 +41,7 @@ "author": "Michael Shanks", "license": "AGPL-3.0-or-later", "dependencies": { - "@budibase/client": "^0.3.6", + "@budibase/client": "^0.3.7", "@koa/router": "^8.0.0", "@sendgrid/mail": "^7.1.1", "@sentry/node": "^5.19.2", diff --git a/packages/standard-components/package.json b/packages/standard-components/package.json index cf175b4652..e384c3c2aa 100644 --- a/packages/standard-components/package.json +++ b/packages/standard-components/package.json @@ -13,7 +13,7 @@ "dev:builder": "rollup -cw" }, "devDependencies": { - "@budibase/client": "^0.3.6", + "@budibase/client": "^0.3.7", "@rollup/plugin-commonjs": "^11.1.0", "lodash": "^4.17.15", "rollup": "^2.11.2", @@ -31,7 +31,7 @@ "keywords": [ "svelte" ], - "version": "0.3.6", + "version": "0.3.7", "license": "MIT", "gitHead": "284cceb9b703c38566c6e6363c022f79a08d5691", "dependencies": { From 46fc8eb30f21b24014745d644a00b8ff55942cd9 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 11 Nov 2020 09:45:21 +0000 Subject: [PATCH 05/10] config for windows signing cert --- .github/workflows/release.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 290f614e20..10232c569d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -52,6 +52,8 @@ jobs: mac_certs: ${{ secrets.mac_certs }} mac_certs_password: ${{ secrets.mac_certs_password }} + windows_certs: ${{ secrets.windows_certs }} + mac_certs_password: ${{ secrets.windows_certs_password }} # release the app after building release: ${{ startsWith(github.ref, 'refs/tags/v') }} From 0f1c338f509cf3cd87bec78687b5da0f6a5f1eaa Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 11 Nov 2020 09:47:56 +0000 Subject: [PATCH 06/10] typo --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 10232c569d..817cd17652 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -53,7 +53,7 @@ jobs: mac_certs: ${{ secrets.mac_certs }} mac_certs_password: ${{ secrets.mac_certs_password }} windows_certs: ${{ secrets.windows_certs }} - mac_certs_password: ${{ secrets.windows_certs_password }} + windows_certs_password: ${{ secrets.windows_certs_password }} # release the app after building release: ${{ startsWith(github.ref, 'refs/tags/v') }} From c2aa9eebfc271cd0d58095774e5303fb4b27c131 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Thu, 12 Nov 2020 10:25:25 +0000 Subject: [PATCH 07/10] remove squirrelly, compile a single bundle.css for each page, svelte and hbs server rendering --- packages/server/package.json | 1 - .../src/api/controllers/static/index.js | 64 +++++++++---------- .../static/templates/BudibaseApp.svelte | 62 ++++++++++++++++++ .../api/controllers/static/templates/app.hbs | 10 +++ .../static/templates/index.template.html | 63 ------------------ packages/server/src/api/routes/static.js | 2 +- packages/server/src/db/client.js | 2 +- .../builder/compileStaticAssetsForPage.js | 62 ++++-------------- .../utilities/builder/convertCssToFiles.js | 45 ++++--------- .../src/utilities/builder/publicPath.js | 3 - .../src/utilities/initialiseBudibase.js | 5 +- packages/server/yarn.lock | 13 ++-- 12 files changed, 137 insertions(+), 195 deletions(-) create mode 100644 packages/server/src/api/controllers/static/templates/app.hbs delete mode 100644 packages/server/src/api/controllers/static/templates/index.template.html delete mode 100644 packages/server/src/utilities/builder/publicPath.js diff --git a/packages/server/package.json b/packages/server/package.json index 699efbc56e..259e292c80 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -77,7 +77,6 @@ "pouchdb-all-dbs": "^1.0.2", "pouchdb-replication-stream": "^1.2.9", "sanitize-s3-objectkey": "^0.0.1", - "squirrelly": "^7.5.0", "svelte": "^3.29.4", "tar-fs": "^2.1.0", "to-json-schema": "^0.2.5", diff --git a/packages/server/src/api/controllers/static/index.js b/packages/server/src/api/controllers/static/index.js index 0a342a2e24..19f51a06cb 100644 --- a/packages/server/src/api/controllers/static/index.js +++ b/packages/server/src/api/controllers/static/index.js @@ -1,27 +1,29 @@ require("svelte/register") const send = require("koa-send") -const { resolve, join } = require("../../utilities/centralPath") +const { resolve, join } = require("../../../utilities/centralPath") const fetch = require("node-fetch") const fs = require("fs-extra") const uuid = require("uuid") const AWS = require("aws-sdk") -const { prepareUploadForS3 } = require("./deploy/aws") +const { prepareUploadForS3 } = require("../deploy/aws") +const handlebars = require("handlebars") const { budibaseAppsDir, budibaseTempDir, -} = require("../../utilities/budibaseDir") -const CouchDB = require("../../db") -const setBuilderToken = require("../../utilities/builder/setBuilderToken") -const fileProcessor = require("../../utilities/fileProcessor") -const { AuthTypes } = require("../../constants") -const env = require("../../environment") +} = require("../../../utilities/budibaseDir") +const { getPageParams } = require("../../../db/utils") +const CouchDB = require("../../../db") +const setBuilderToken = require("../../../utilities/builder/setBuilderToken") +const fileProcessor = require("../../../utilities/fileProcessor") +const { AuthTypes } = require("../../../constants") +const env = require("../../../environment") // this was the version before we started versioning the component library const COMP_LIB_BASE_APP_VERSION = "0.2.5" exports.serveBuilder = async function(ctx) { - let builderPath = resolve(__dirname, "../../../builder") + let builderPath = resolve(__dirname, "../../../../builder") if (ctx.file === "index.html") { await setBuilderToken(ctx) } @@ -141,37 +143,31 @@ exports.performLocalFileProcessing = async function(ctx) { exports.serveAppNew = async function(ctx) { const App = require("./templates/BudibaseApp.svelte").default + // Need to get app information here - const { html } = App.render({ - name: "Budibase", - authenticated: + const db = new CouchDB(ctx.params.appId) + + const appInfo = await db.get(ctx.params.appId) + + console.log("INFO", appInfo) + + const { head, html, css } = App.render({ + title: appInfo.name, + pageName: ctx.auth.authenticated === AuthTypes.APP ? "main" : "unauthenticated", production: env.CLOUD, + appId: ctx.params.appId, }) - // // default to homedir - // const appPath = resolve( - // budibaseAppsDir(), - // ctx.params.appId, - // "public", - // mainOrAuth - // ) + const template = handlebars.compile( + fs.readFileSync(`${__dirname}/templates/app.hbs`, "utf8") + ) - ctx.body = html - - // const appId = ctx.user.appId - - // if (env.CLOUD) { - // const S3_URL = `https://${appId}.app.budi.live/assets/${appId}/${mainOrAuth}/${ctx.file || - // "index.production.html"}` - - // const response = await fetch(S3_URL) - // const body = await response.text() - // ctx.body = body - // return - // } - - // await send(ctx, ctx.file || "index.html", { root: ctx.devPath || appPath }) + ctx.body = template({ + head, + body: html, + style: css.code, + }) } exports.serveApp = async function(ctx) { diff --git a/packages/server/src/api/controllers/static/templates/BudibaseApp.svelte b/packages/server/src/api/controllers/static/templates/BudibaseApp.svelte index e69de29bb2..648829891e 100644 --- a/packages/server/src/api/controllers/static/templates/BudibaseApp.svelte +++ b/packages/server/src/api/controllers/static/templates/BudibaseApp.svelte @@ -0,0 +1,62 @@ + + + + + + + {title} + + + + + + + + + + + + + + + diff --git a/packages/server/src/api/controllers/static/templates/app.hbs b/packages/server/src/api/controllers/static/templates/app.hbs new file mode 100644 index 0000000000..cce07180ae --- /dev/null +++ b/packages/server/src/api/controllers/static/templates/app.hbs @@ -0,0 +1,10 @@ + + + + + {{{head}}} + + + {{{body}}} + + \ No newline at end of file diff --git a/packages/server/src/api/controllers/static/templates/index.template.html b/packages/server/src/api/controllers/static/templates/index.template.html deleted file mode 100644 index e7cf633277..0000000000 --- a/packages/server/src/api/controllers/static/templates/index.template.html +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - {{ title }} - - - - - {{ each(options.stylesheets) }} - - {{ /each }} - - {{ each(options.screenStyles) }} - {{ if(options.production) }} - - {{#else}} - - {{ /if }} - {{ /each }} - - {{ if(options.pageStyle) }} - {{ if(options.production) }} - - {{#else}} - - {{ /if }} - {{ /if }} - - - - - {{ if(options.production) }} - - - {{#else}} - - - {{ /if }} - - - - - - - \ No newline at end of file diff --git a/packages/server/src/api/routes/static.js b/packages/server/src/api/routes/static.js index 5c33900eca..e832df17c4 100644 --- a/packages/server/src/api/routes/static.js +++ b/packages/server/src/api/routes/static.js @@ -33,6 +33,6 @@ router .get("/componentlibrary", controller.serveComponentLibrary) .get("/assets/:file*", controller.serveAppAsset) .get("/attachments/:file*", controller.serveAttachment) - .get("/:appId/:path*", controller.serveApp) + .get("/:appId/:path*", controller.serveAppNew) module.exports = router diff --git a/packages/server/src/db/client.js b/packages/server/src/db/client.js index c796ab0160..1d025a1402 100644 --- a/packages/server/src/db/client.js +++ b/packages/server/src/db/client.js @@ -38,6 +38,6 @@ function replicateLocal() { }) } -//replicateLocal() +replicateLocal() module.exports = Pouch diff --git a/packages/server/src/utilities/builder/compileStaticAssetsForPage.js b/packages/server/src/utilities/builder/compileStaticAssetsForPage.js index 598f7745fb..4e3b7ea75e 100644 --- a/packages/server/src/utilities/builder/compileStaticAssetsForPage.js +++ b/packages/server/src/utilities/builder/compileStaticAssetsForPage.js @@ -1,27 +1,25 @@ -const { constants, copyFile, writeFile, readFile } = require("fs-extra") -const { join, resolve } = require("../centralPath") -const sqrl = require("squirrelly") -const { convertCssToFiles } = require("./convertCssToFiles") -const publicPath = require("./publicPath") +const { ensureDir, constants, copyFile, writeFile } = require("fs-extra") +const { join } = require("../centralPath") +const { convertCssToBundle } = require("./convertCssToFiles") const { budibaseAppsDir } = require("../budibaseDir") module.exports = async (appId, pageName, pkg) => { - const appPath = join(budibaseAppsDir(), appId) + const pagePath = join(budibaseAppsDir(), appId, "public", pageName) pkg.screens = pkg.screens || [] - await convertCssToFiles(publicPath(appPath, pageName), pkg) + await ensureDir(pagePath) - await buildIndexHtml(appId, pageName, appPath, pkg) + await convertCssToBundle(pagePath, pkg) - await buildFrontendAppDefinition(appId, pageName, pkg, appPath) + await buildFrontendAppDefinition(pagePath, pkg) - await copyClientLib(appPath, pageName) + await copyClientLib(pagePath) } -const copyClientLib = async (appPath, pageName) => { +const copyClientLib = async pagePath => { const sourcepath = require.resolve("@budibase/client") - const destPath = join(publicPath(appPath, pageName), "budibase-client.js") + const destPath = join(pagePath, "budibase-client.js") await copyFile(sourcepath, destPath, constants.COPYFILE_FICLONE) @@ -32,44 +30,8 @@ const copyClientLib = async (appPath, pageName) => { ) } -const buildIndexHtml = async (appId, pageName, appPath, pkg) => { - const appPublicPath = publicPath(appPath, pageName) - - const stylesheetUrl = s => (s.startsWith("http") ? s : `/${appId}/${s}`) - - const templateObj = { - title: pkg.page.title || "Budibase App", - favicon: `${pkg.page.favicon || "/_shared/favicon.png"}`, - stylesheets: (pkg.page.stylesheets || []).map(stylesheetUrl), - screenStyles: pkg.screens.filter(s => s._css).map(s => s._css), - pageStyle: pkg.page._css, - appId, - pageName, - } - - const indexHtmlTemplate = await readFile( - resolve(__dirname, "index.template.html"), - "utf8" - ) - - const indexHtmlPath = join(appPublicPath, "index.html") - const deployableHtmlPath = join(appPublicPath, "index.production.html") - - const indexHtml = sqrl.Render(indexHtmlTemplate, templateObj) - const deployableHtml = sqrl.Render(indexHtmlTemplate, { - ...templateObj, - production: true, - }) - - await writeFile(indexHtmlPath, indexHtml, { flag: "w+" }) - await writeFile(deployableHtmlPath, deployableHtml, { flag: "w+" }) -} - -const buildFrontendAppDefinition = async (appId, pageName, pkg) => { - const appPath = join(budibaseAppsDir(), appId) - const appPublicPath = publicPath(appPath, pageName) - - const filename = join(appPublicPath, "clientFrontendDefinition.js") +const buildFrontendAppDefinition = async (pagePath, pkg) => { + const filename = join(pagePath, "clientFrontendDefinition.js") delete pkg.page._css diff --git a/packages/server/src/utilities/builder/convertCssToFiles.js b/packages/server/src/utilities/builder/convertCssToFiles.js index c81f9497ec..6146dea91f 100644 --- a/packages/server/src/utilities/builder/convertCssToFiles.js +++ b/packages/server/src/utilities/builder/convertCssToFiles.js @@ -1,11 +1,15 @@ -const crypto = require("crypto") -const { ensureDir, emptyDir, writeFile } = require("fs-extra") +const { writeFile } = require("fs-extra") const { join } = require("../centralPath") -module.exports.convertCssToFiles = async (publicPagePath, pkg) => { - const cssDir = join(publicPagePath, "css") - await ensureDir(cssDir) - await emptyDir(cssDir) +/** + * Reads the _css property of all pages and screens in the budibase application, and creates a singlular CSS + * bundle for the app at /public/bundle.css. + * @param {*} publicPagePath - path to the public assets directory of the budibase application + * @param {*} pkg - app package information + * @param {*} pageName - the pagename of the page we are compiling CSS for. + */ +module.exports.convertCssToBundle = async (publicPagePath, pkg) => { + let cssString = "" for (let screen of pkg.screens || []) { if (!screen._css) continue @@ -13,31 +17,10 @@ module.exports.convertCssToFiles = async (publicPagePath, pkg) => { delete screen._css continue } - screen._css = await createCssFile(cssDir, screen._css) + cssString += screen._css } - if (pkg.page._css) { - pkg.page._css = await createCssFile(cssDir, pkg.page._css) - } -} - -module.exports.getHashedCssPaths = (cssDir, _css) => { - const fileName = - crypto - .createHash("md5") - .update(_css) - .digest("hex") + ".css" - - const filePath = join(cssDir, fileName) - const url = `/css/${fileName}` - - return { filePath, url } -} - -const createCssFile = async (cssDir, _css) => { - const { filePath, url } = module.exports.getHashedCssPaths(cssDir, _css) - - await writeFile(filePath, _css) - - return url + if (pkg.page._css) cssString += pkg.page._css + + writeFile(join(publicPagePath, "bundle.css"), cssString) } diff --git a/packages/server/src/utilities/builder/publicPath.js b/packages/server/src/utilities/builder/publicPath.js deleted file mode 100644 index 03917d4370..0000000000 --- a/packages/server/src/utilities/builder/publicPath.js +++ /dev/null @@ -1,3 +0,0 @@ -const { join } = require("../centralPath") - -module.exports = (appPath, pageName) => join(appPath, "public", pageName) diff --git a/packages/server/src/utilities/initialiseBudibase.js b/packages/server/src/utilities/initialiseBudibase.js index 4e6902a50f..1a88b4d1c2 100644 --- a/packages/server/src/utilities/initialiseBudibase.js +++ b/packages/server/src/utilities/initialiseBudibase.js @@ -1,6 +1,6 @@ const { existsSync, readFile, writeFile, ensureDir } = require("fs-extra") const { join, resolve } = require("./centralPath") -const Sqrl = require("squirrelly") +const handlebars = require("handlebars") const uuid = require("uuid") module.exports = async opts => { @@ -31,7 +31,8 @@ const createDevEnvFile = async opts => { } ) opts.cookieKey1 = opts.cookieKey1 || uuid.v4() - const config = Sqrl.Render(template, opts) + const hbTemplate = handlebars.compile(template) + const config = hbTemplate.render(opts) await writeFile(destConfigFile, config, { flag: "w+" }) } } diff --git a/packages/server/yarn.lock b/packages/server/yarn.lock index 048694e6de..9e6b472dac 100644 --- a/packages/server/yarn.lock +++ b/packages/server/yarn.lock @@ -200,10 +200,10 @@ lodash "^4.17.19" to-fast-properties "^2.0.0" -"@budibase/client@^0.3.4": - version "0.3.4" - resolved "https://registry.yarnpkg.com/@budibase/client/-/client-0.3.4.tgz#aca2d13170dae870d069a56f53519d9fbb4bdc00" - integrity sha512-zs9Jnr1CzvgZY4NrliatqDUm0gVhlcQkpdsMblO+3zRcwBzRXAeFyzwMtGpcbiQm29zHjPBOivmQQUMxgi3lUg== +"@budibase/client@^0.3.6": + version "0.3.7" + resolved "https://registry.yarnpkg.com/@budibase/client/-/client-0.3.7.tgz#8ed2d40d91ba3788a69ee5db5078f757adb4187f" + integrity sha512-EgpHfw/WOUYeCG4cILDbaN2WFBDSPS698Z+So7FP5l+4E1fvmqtpXVKJYsviwYEx8AKKYyU3nuDi0l6xzb5Flg== dependencies: deep-equal "^2.0.1" mustache "^4.0.1" @@ -7146,11 +7146,6 @@ sprintf-js@~1.0.2: resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw= -squirrelly@^7.5.0: - version "7.9.2" - resolved "https://registry.yarnpkg.com/squirrelly/-/squirrelly-7.9.2.tgz#f8b0a08201b73653351afe9f7f24878237d2751a" - integrity sha512-QsLQ43p7/p5LfhqMsUM1PP0DU/YuirA/pZ1RQKU8/qZjWHD8uTblpfPoCVkD9VLrS1jCJ+2gqECv3amlPgrLCA== - sshpk@^1.7.0: version "1.16.1" resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.16.1.tgz#fb661c0bef29b39db40769ee39fa70093d6f6877" From cd5dd2d21d18e65871e2f5bc82054c910033aae8 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Thu, 12 Nov 2020 10:36:15 +0000 Subject: [PATCH 08/10] JSDoc for static asset compilation --- .../builder/compileStaticAssetsForPage.js | 47 ++++++++++++++ .../utilities/builder/convertCssToFiles.js | 26 -------- .../src/utilities/builder/index.template.html | 63 ------------------- 3 files changed, 47 insertions(+), 89 deletions(-) delete mode 100644 packages/server/src/utilities/builder/convertCssToFiles.js delete mode 100644 packages/server/src/utilities/builder/index.template.html diff --git a/packages/server/src/utilities/builder/compileStaticAssetsForPage.js b/packages/server/src/utilities/builder/compileStaticAssetsForPage.js index 4e3b7ea75e..9e2dc23ede 100644 --- a/packages/server/src/utilities/builder/compileStaticAssetsForPage.js +++ b/packages/server/src/utilities/builder/compileStaticAssetsForPage.js @@ -3,6 +3,15 @@ const { join } = require("../centralPath") const { convertCssToBundle } = require("./convertCssToFiles") const { budibaseAppsDir } = require("../budibaseDir") +/** + * Compile all the non-db static web assets that are required for the running of + * a budibase application. This includes CSS, the JSON structure of the DOM and + * the client library, a script responsible for reading the JSON structure + * and rendering the application. + * @param {} appId - id of the application we want to compile static assets for + * @param {*} pageName - name of the page that the assets will be served for + * @param {*} pkg - app package information/metadata + */ module.exports = async (appId, pageName, pkg) => { const pagePath = join(budibaseAppsDir(), appId, "public", pageName) @@ -17,6 +26,36 @@ module.exports = async (appId, pageName, pkg) => { await copyClientLib(pagePath) } +/** + * Reads the _css property of a page and its screens, and creates a singular CSS + * bundle for the page at /public//bundle.css + * @param {String} publicPagePath - path to the public assets directory of the budibase application + * @param {Object} pkg - app package information + * @param {"main" | "unauthenticated"} pageName - the pagename of the page we are compiling CSS for. + */ +module.exports.convertCssToBundle = async (publicPagePath, pkg) => { + let cssString = "" + + for (let screen of pkg.screens || []) { + if (!screen._css) continue + if (screen._css.trim().length === 0) { + delete screen._css + continue + } + cssString += screen._css + } + + if (pkg.page._css) cssString += pkg.page._css + + writeFile(join(publicPagePath, "bundle.css"), cssString) +} + +/** + * Copy the budibase client library and sourcemap from NPM to /public/. + * The client library is then served as a static asset when the budibase application + * is running in preview or prod + * @param {String} pagePath - path to write the client library to + */ const copyClientLib = async pagePath => { const sourcepath = require.resolve("@budibase/client") const destPath = join(pagePath, "budibase-client.js") @@ -30,9 +69,17 @@ const copyClientLib = async pagePath => { ) } +/** + * Build the frontend definition for a budibase application. This includes all page and screen information, + * and is injected into the budibase client library to tell it how to start constructing + * the DOM from components defined in the frontendDefinition. + * @param {String} pagePath - path to the public folder of the page where the definition will be written + * @param {Object} pkg - app package information from which the frontendDefinition will be built. + */ const buildFrontendAppDefinition = async (pagePath, pkg) => { const filename = join(pagePath, "clientFrontendDefinition.js") + // Delete CSS code from the page and screens so it's not injected delete pkg.page._css for (let screen of pkg.screens) { diff --git a/packages/server/src/utilities/builder/convertCssToFiles.js b/packages/server/src/utilities/builder/convertCssToFiles.js deleted file mode 100644 index 6146dea91f..0000000000 --- a/packages/server/src/utilities/builder/convertCssToFiles.js +++ /dev/null @@ -1,26 +0,0 @@ -const { writeFile } = require("fs-extra") -const { join } = require("../centralPath") - -/** - * Reads the _css property of all pages and screens in the budibase application, and creates a singlular CSS - * bundle for the app at /public/bundle.css. - * @param {*} publicPagePath - path to the public assets directory of the budibase application - * @param {*} pkg - app package information - * @param {*} pageName - the pagename of the page we are compiling CSS for. - */ -module.exports.convertCssToBundle = async (publicPagePath, pkg) => { - let cssString = "" - - for (let screen of pkg.screens || []) { - if (!screen._css) continue - if (screen._css.trim().length === 0) { - delete screen._css - continue - } - cssString += screen._css - } - - if (pkg.page._css) cssString += pkg.page._css - - writeFile(join(publicPagePath, "bundle.css"), cssString) -} diff --git a/packages/server/src/utilities/builder/index.template.html b/packages/server/src/utilities/builder/index.template.html deleted file mode 100644 index e7cf633277..0000000000 --- a/packages/server/src/utilities/builder/index.template.html +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - {{ title }} - - - - - {{ each(options.stylesheets) }} - - {{ /each }} - - {{ each(options.screenStyles) }} - {{ if(options.production) }} - - {{#else}} - - {{ /if }} - {{ /each }} - - {{ if(options.pageStyle) }} - {{ if(options.production) }} - - {{#else}} - - {{ /if }} - {{ /if }} - - - - - {{ if(options.production) }} - - - {{#else}} - - - {{ /if }} - - - - - - - \ No newline at end of file From ff66ed35c6631349017a73208243e868f2f33fcc Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Thu, 12 Nov 2020 10:41:49 +0000 Subject: [PATCH 09/10] tidy up --- .../src/api/controllers/static/index.js | 32 +------------------ packages/server/src/api/routes/static.js | 2 +- packages/server/src/db/client.js | 2 +- .../builder/compileStaticAssetsForPage.js | 5 ++- .../src/utilities/initialiseBudibase.js | 4 +-- 5 files changed, 7 insertions(+), 38 deletions(-) diff --git a/packages/server/src/api/controllers/static/index.js b/packages/server/src/api/controllers/static/index.js index 19f51a06cb..462a65ad9b 100644 --- a/packages/server/src/api/controllers/static/index.js +++ b/packages/server/src/api/controllers/static/index.js @@ -141,16 +141,13 @@ exports.performLocalFileProcessing = async function(ctx) { } } -exports.serveAppNew = async function(ctx) { +exports.serveApp = async function(ctx) { const App = require("./templates/BudibaseApp.svelte").default - // Need to get app information here const db = new CouchDB(ctx.params.appId) const appInfo = await db.get(ctx.params.appId) - console.log("INFO", appInfo) - const { head, html, css } = App.render({ title: appInfo.name, pageName: @@ -170,33 +167,6 @@ exports.serveAppNew = async function(ctx) { }) } -exports.serveApp = async function(ctx) { - const mainOrAuth = - ctx.auth.authenticated === AuthTypes.APP ? "main" : "unauthenticated" - - // default to homedir - const appPath = resolve( - budibaseAppsDir(), - ctx.params.appId, - "public", - mainOrAuth - ) - - const appId = ctx.user.appId - - if (env.CLOUD) { - const S3_URL = `https://${appId}.app.budi.live/assets/${appId}/${mainOrAuth}/${ctx.file || - "index.production.html"}` - - const response = await fetch(S3_URL) - const body = await response.text() - ctx.body = body - return - } - - await send(ctx, ctx.file || "index.html", { root: ctx.devPath || appPath }) -} - exports.serveAttachment = async function(ctx) { const appId = ctx.user.appId const attachmentsPath = resolve(budibaseAppsDir(), appId, "attachments") diff --git a/packages/server/src/api/routes/static.js b/packages/server/src/api/routes/static.js index e832df17c4..5c33900eca 100644 --- a/packages/server/src/api/routes/static.js +++ b/packages/server/src/api/routes/static.js @@ -33,6 +33,6 @@ router .get("/componentlibrary", controller.serveComponentLibrary) .get("/assets/:file*", controller.serveAppAsset) .get("/attachments/:file*", controller.serveAttachment) - .get("/:appId/:path*", controller.serveAppNew) + .get("/:appId/:path*", controller.serveApp) module.exports = router diff --git a/packages/server/src/db/client.js b/packages/server/src/db/client.js index 1d025a1402..1477ee4315 100644 --- a/packages/server/src/db/client.js +++ b/packages/server/src/db/client.js @@ -38,6 +38,6 @@ function replicateLocal() { }) } -replicateLocal() +// replicateLocal() module.exports = Pouch diff --git a/packages/server/src/utilities/builder/compileStaticAssetsForPage.js b/packages/server/src/utilities/builder/compileStaticAssetsForPage.js index 9e2dc23ede..c91ba24bb3 100644 --- a/packages/server/src/utilities/builder/compileStaticAssetsForPage.js +++ b/packages/server/src/utilities/builder/compileStaticAssetsForPage.js @@ -1,6 +1,5 @@ const { ensureDir, constants, copyFile, writeFile } = require("fs-extra") const { join } = require("../centralPath") -const { convertCssToBundle } = require("./convertCssToFiles") const { budibaseAppsDir } = require("../budibaseDir") /** @@ -19,7 +18,7 @@ module.exports = async (appId, pageName, pkg) => { await ensureDir(pagePath) - await convertCssToBundle(pagePath, pkg) + await buildPageCssBundle(pagePath, pkg) await buildFrontendAppDefinition(pagePath, pkg) @@ -33,7 +32,7 @@ module.exports = async (appId, pageName, pkg) => { * @param {Object} pkg - app package information * @param {"main" | "unauthenticated"} pageName - the pagename of the page we are compiling CSS for. */ -module.exports.convertCssToBundle = async (publicPagePath, pkg) => { +const buildPageCssBundle = async (publicPagePath, pkg) => { let cssString = "" for (let screen of pkg.screens || []) { diff --git a/packages/server/src/utilities/initialiseBudibase.js b/packages/server/src/utilities/initialiseBudibase.js index 1a88b4d1c2..4073c2be69 100644 --- a/packages/server/src/utilities/initialiseBudibase.js +++ b/packages/server/src/utilities/initialiseBudibase.js @@ -31,8 +31,8 @@ const createDevEnvFile = async opts => { } ) opts.cookieKey1 = opts.cookieKey1 || uuid.v4() - const hbTemplate = handlebars.compile(template) - const config = hbTemplate.render(opts) + const envTemplate = handlebars.compile(template) + const config = envTemplate(opts) await writeFile(destConfigFile, config, { flag: "w+" }) } } From 070b0c8c0a927d3d5be80eb1448e06d154a7fc13 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Thu, 12 Nov 2020 10:45:05 +0000 Subject: [PATCH 10/10] lint :sparkles: --- packages/server/src/api/controllers/static/index.js | 1 - .../src/api/controllers/static/templates/BudibaseApp.svelte | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/server/src/api/controllers/static/index.js b/packages/server/src/api/controllers/static/index.js index 462a65ad9b..b048bbd9fe 100644 --- a/packages/server/src/api/controllers/static/index.js +++ b/packages/server/src/api/controllers/static/index.js @@ -12,7 +12,6 @@ const { budibaseAppsDir, budibaseTempDir, } = require("../../../utilities/budibaseDir") -const { getPageParams } = require("../../../db/utils") const CouchDB = require("../../../db") const setBuilderToken = require("../../../utilities/builder/setBuilderToken") const fileProcessor = require("../../../utilities/fileProcessor") diff --git a/packages/server/src/api/controllers/static/templates/BudibaseApp.svelte b/packages/server/src/api/controllers/static/templates/BudibaseApp.svelte index 648829891e..7d6ad8141c 100644 --- a/packages/server/src/api/controllers/static/templates/BudibaseApp.svelte +++ b/packages/server/src/api/controllers/static/templates/BudibaseApp.svelte @@ -24,13 +24,12 @@ {title} - + -