Allow serving old versions locally
This commit is contained in:
parent
06670ba549
commit
d73643f0b3
|
@ -2,11 +2,12 @@ import { InvalidFileExtensions } from "@budibase/shared-core"
|
||||||
import AppComponent from "./templates/BudibaseApp.svelte"
|
import AppComponent from "./templates/BudibaseApp.svelte"
|
||||||
import { join } from "../../../utilities/centralPath"
|
import { join } from "../../../utilities/centralPath"
|
||||||
import * as uuid from "uuid"
|
import * as uuid from "uuid"
|
||||||
import { devClientVersion, ObjectStoreBuckets } from "../../../constants"
|
import { ObjectStoreBuckets } from "../../../constants"
|
||||||
import { processString } from "@budibase/string-templates"
|
import { processString } from "@budibase/string-templates"
|
||||||
import {
|
import {
|
||||||
loadHandlebarsFile,
|
loadHandlebarsFile,
|
||||||
NODE_MODULES_PATH,
|
NODE_MODULES_PATH,
|
||||||
|
shouldServeLocally,
|
||||||
TOP_LEVEL_PATH,
|
TOP_LEVEL_PATH,
|
||||||
} from "../../../utilities/fileSystem"
|
} from "../../../utilities/fileSystem"
|
||||||
import env from "../../../environment"
|
import env from "../../../environment"
|
||||||
|
@ -257,25 +258,29 @@ export const serveBuilderPreview = async function (ctx: Ctx) {
|
||||||
export const serveClientLibrary = async function (ctx: Ctx) {
|
export const serveClientLibrary = async function (ctx: Ctx) {
|
||||||
const version = ctx.request.query.version
|
const version = ctx.request.query.version
|
||||||
|
|
||||||
|
if (Array.isArray(version)) {
|
||||||
|
ctx.throw(400)
|
||||||
|
}
|
||||||
|
|
||||||
const appId = context.getAppId() || (ctx.request.query.appId as string)
|
const appId = context.getAppId() || (ctx.request.query.appId as string)
|
||||||
let rootPath = join(NODE_MODULES_PATH, "@budibase", "client", "dist")
|
let rootPath = join(NODE_MODULES_PATH, "@budibase", "client", "dist")
|
||||||
if (!appId) {
|
if (!appId) {
|
||||||
ctx.throw(400, "No app ID provided - cannot fetch client library.")
|
ctx.throw(400, "No app ID provided - cannot fetch client library.")
|
||||||
}
|
}
|
||||||
if (env.isProd() || (env.isDev() && version !== devClientVersion)) {
|
|
||||||
|
const serverLocally = shouldServeLocally(version || "")
|
||||||
|
if (!serverLocally) {
|
||||||
ctx.body = await objectStore.getReadStream(
|
ctx.body = await objectStore.getReadStream(
|
||||||
ObjectStoreBuckets.APPS,
|
ObjectStoreBuckets.APPS,
|
||||||
objectStore.clientLibraryPath(appId!)
|
objectStore.clientLibraryPath(appId!)
|
||||||
)
|
)
|
||||||
ctx.set("Content-Type", "application/javascript")
|
ctx.set("Content-Type", "application/javascript")
|
||||||
} else if (env.isDev() && version === devClientVersion) {
|
} else {
|
||||||
// incase running from TS directly
|
// incase running from TS directly
|
||||||
const tsPath = join(require.resolve("@budibase/client"), "..")
|
const tsPath = join(require.resolve("@budibase/client"), "..")
|
||||||
return send(ctx, "budibase-client.js", {
|
return send(ctx, "budibase-client.js", {
|
||||||
root: !fs.existsSync(rootPath) ? tsPath : rootPath,
|
root: !fs.existsSync(rootPath) ? tsPath : rootPath,
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
ctx.throw(500, "Unable to retrieve client library.")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -152,8 +152,6 @@ export enum AutomationErrors {
|
||||||
FAILURE_CONDITION = "FAILURE_CONDITION_MET",
|
FAILURE_CONDITION = "FAILURE_CONDITION_MET",
|
||||||
}
|
}
|
||||||
|
|
||||||
export const devClientVersion = "0.0.0"
|
|
||||||
|
|
||||||
// pass through the list from the auth/core lib
|
// pass through the list from the auth/core lib
|
||||||
export const ObjectStoreBuckets = objectStore.ObjectStoreBuckets
|
export const ObjectStoreBuckets = objectStore.ObjectStoreBuckets
|
||||||
export const MAX_AUTOMATION_RECURRING_ERRORS = 5
|
export const MAX_AUTOMATION_RECURRING_ERRORS = 5
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { budibaseTempDir } from "../budibaseDir"
|
import { budibaseTempDir } from "../budibaseDir"
|
||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
import { join } from "path"
|
import { join } from "path"
|
||||||
import { ObjectStoreBuckets, devClientVersion } from "../../constants"
|
import { ObjectStoreBuckets } from "../../constants"
|
||||||
import { updateClientLibrary } from "./clientLibrary"
|
import { shouldServeLocally, updateClientLibrary } from "./clientLibrary"
|
||||||
import env from "../../environment"
|
import env from "../../environment"
|
||||||
import { objectStore, context } from "@budibase/backend-core"
|
import { objectStore, context } from "@budibase/backend-core"
|
||||||
import { TOP_LEVEL_PATH } from "./filesystem"
|
import { TOP_LEVEL_PATH } from "./filesystem"
|
||||||
|
@ -40,7 +40,7 @@ export const getComponentLibraryManifest = async (library: string) => {
|
||||||
const db = context.getAppDB()
|
const db = context.getAppDB()
|
||||||
const app = await db.get<App>(DocumentType.APP_METADATA)
|
const app = await db.get<App>(DocumentType.APP_METADATA)
|
||||||
|
|
||||||
if (app.version === devClientVersion || env.isTest()) {
|
if (shouldServeLocally(app.version) || env.isTest()) {
|
||||||
const paths = [
|
const paths = [
|
||||||
join(TOP_LEVEL_PATH, "packages/client", filename),
|
join(TOP_LEVEL_PATH, "packages/client", filename),
|
||||||
join(process.cwd(), "client", filename),
|
join(process.cwd(), "client", filename),
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import semver from "semver"
|
||||||
import path, { join } from "path"
|
import path, { join } from "path"
|
||||||
import { ObjectStoreBuckets } from "../../constants"
|
import { ObjectStoreBuckets } from "../../constants"
|
||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
|
@ -183,3 +184,19 @@ export async function revertClientLibrary(appId: string) {
|
||||||
|
|
||||||
return JSON.parse(await manifestSrc)
|
return JSON.parse(await manifestSrc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function shouldServeLocally(version: string) {
|
||||||
|
if (env.isProd() || !env.isDev()) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version === "0.0.0") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsedSemver = semver.parse(version)
|
||||||
|
if (parsedSemver?.build?.[0] === "local") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue