From 77a16f95da911dc27eaf2317ac266983aad71735 Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Wed, 3 Jun 2020 15:43:37 +0100 Subject: [PATCH] autu populated login page --- .../server/src/api/controllers/application.js | 26 +++++--- .../appDirectoryTemplate/package.json | 2 +- .../appDirectoryTemplate/pages/main/page.json | 2 +- .../pages/unauthenticated/page.json | 62 +++++++++++++------ 4 files changed, 64 insertions(+), 28 deletions(-) diff --git a/packages/server/src/api/controllers/application.js b/packages/server/src/api/controllers/application.js index 63422c468a..8953d5af21 100644 --- a/packages/server/src/api/controllers/application.js +++ b/packages/server/src/api/controllers/application.js @@ -5,8 +5,9 @@ const newid = require("../../db/newid") const env = require("../../environment") const instanceController = require("./instance") const { resolve, join } = require("path") -const { copy, readJSON, writeJSON, exists } = require("fs-extra") +const { copy, exists, readFile, writeFile } = require("fs-extra") const { exec } = require("child_process") +const sqrl = require("squirrelly") exports.fetch = async function(ctx) { const db = new CouchDB(ClientDb.name(env.CLIENT_ID)) @@ -82,16 +83,27 @@ const createEmptyAppPackage = async (ctx, app) => { await copy(templateFolder, newAppFolder) - const packageJsonPath = join(appsFolder, app._id, "package.json") - const packageJson = await readJSON(packageJsonPath) - - packageJson.name = npmFriendlyAppName(app.name) - - await writeJSON(packageJsonPath, packageJson) + await updateJsonFile(join(appsFolder, app._id, "package.json"), { + name: npmFriendlyAppName(app.name), + }) + await updateJsonFile( + join(appsFolder, app._id, "pages", "main", "page.json"), + app + ) + await updateJsonFile( + join(appsFolder, app._id, "pages", "unauthenticated", "page.json"), + app + ) return newAppFolder } +const updateJsonFile = async (filePath, app) => { + const json = await readFile(filePath, "utf8") + const newJson = sqrl.Render(json, app) + await writeFile(filePath, newJson, "utf8") +} + const runNpmInstall = async newAppFolder => { return new Promise((resolve, reject) => { const cmd = `cd ${newAppFolder} && npm install` diff --git a/packages/server/src/utilities/appDirectoryTemplate/package.json b/packages/server/src/utilities/appDirectoryTemplate/package.json index f49e35d23f..e67d5e0c17 100644 --- a/packages/server/src/utilities/appDirectoryTemplate/package.json +++ b/packages/server/src/utilities/appDirectoryTemplate/package.json @@ -1,5 +1,5 @@ { - "name": "name", + "name": "{{ name }}", "version": "1.0.0", "description": "", "author": "", diff --git a/packages/server/src/utilities/appDirectoryTemplate/pages/main/page.json b/packages/server/src/utilities/appDirectoryTemplate/pages/main/page.json index dbb9e3d441..1ae407774e 100644 --- a/packages/server/src/utilities/appDirectoryTemplate/pages/main/page.json +++ b/packages/server/src/utilities/appDirectoryTemplate/pages/main/page.json @@ -1,5 +1,5 @@ { - "title": "Test App", + "title": "{{ name }}", "favicon": "./_shared/favicon.png", "stylesheets": [], "componentLibraries": ["@budibase/standard-components", "@budibase/materialdesign-components"], diff --git a/packages/server/src/utilities/appDirectoryTemplate/pages/unauthenticated/page.json b/packages/server/src/utilities/appDirectoryTemplate/pages/unauthenticated/page.json index bfcd9d55f9..6ff1bfcd98 100644 --- a/packages/server/src/utilities/appDirectoryTemplate/pages/unauthenticated/page.json +++ b/packages/server/src/utilities/appDirectoryTemplate/pages/unauthenticated/page.json @@ -1,21 +1,45 @@ { - "title": "Test App", - "favicon": "./_shared/favicon.png", - "stylesheets": [], - "componentLibraries": ["@budibase/standard-components", "@budibase/materialdesign-components"], - "props" : { - "_component": "@budibase/standard-components/container", - "_children": [], - "_id": 1, - "type": "div", - "_styles": { - "active": {}, - "hover": {}, - "normal": {}, - "selected": {} - }, - "_code": "" - }, - "_css": "", - "uiFunctions": "" + "componentLibraries": [ + "@budibase/standard-components", + "@budibase/materialdesign-components" + ], + "title": "{{ name }}", + "favicon": "./_shared/favicon.png", + "stylesheets": [], + "props": { + "_component": "@budibase/standard-components/container", + "_children": [ + { + "_id": "686c252d-dbf2-4e28-9078-414ba4719759", + "_component": "@budibase/standard-components/login", + "_styles": { + "normal": {}, + "hover": {}, + "active": {}, + "selected": {} + }, + "_code": "", + "loginRedirect": "", + "usernameLabel": "Username", + "passwordLabel": "Password", + "loginButtonLabel": "Login", + "buttonClass": "", + "inputClass": "", + "_children": [], + "name": "{{ name }}", + "logo": "" + } + ], + "_id": 1, + "type": "div", + "_styles": { + "layout": {}, + "position": {} + }, + "_code": "", + "className": "", + "onLoad": [] + }, + "_css": "", + "uiFunctions": "" }