allow bb home folder to bem anywhere

This commit is contained in:
Michael Shanks 2020-05-11 15:42:42 +01:00
parent 6fac98074d
commit a004aa5838
9 changed files with 34 additions and 32 deletions

View File

@ -3,6 +3,7 @@ const { resolve } = require("path")
module.exports = ({ dir }) => { module.exports = ({ dir }) => {
dir = xPlatHomeDir(dir) dir = xPlatHomeDir(dir)
process.env.BUDIBASE_DIR = resolve(dir)
require("dotenv").config({ path: resolve(dir, ".env") }) require("dotenv").config({ path: resolve(dir, ".env") })
require("@budibase/server/src/app") require("@budibase/server/src/app")
console.log(`Budibase Builder running on port ${process.env.PORT}..`) console.log(`Budibase Builder running on port ${process.env.PORT}..`)

View File

@ -1,6 +1,9 @@
const CouchDB = require("../../db") const CouchDB = require("../../db")
const { homedir } = require("os")
const { resolve, join } = require("path") const { resolve, join } = require("path")
const {
budibaseTempDir,
budibaseAppsDir,
} = require("../../utilities/budibaseDir")
const isDev = process.env.NODE_ENV !== "production" const isDev = process.env.NODE_ENV !== "production"
@ -11,14 +14,13 @@ exports.fetchAppComponentDefinitions = async function(ctx) {
const componentDefinitions = app.componentLibraries.reduce( const componentDefinitions = app.componentLibraries.reduce(
(acc, componentLibrary) => { (acc, componentLibrary) => {
let appDirectory = resolve( let appDirectory = resolve(
homedir(), budibaseAppsDir(),
".budibase",
ctx.params.appId, ctx.params.appId,
"node_modules" "node_modules"
) )
if (isDev) { if (isDev) {
appDirectory = "/tmp/.budibase" appDirectory = budibaseTempDir()
} }
const componentJson = require(join( const componentJson = require(join(

View File

@ -1,6 +1,9 @@
const send = require("koa-send") const send = require("koa-send")
const { resolve, join } = require("path") const { resolve, join } = require("path")
const { homedir } = require("os") const {
budibaseAppsDir,
budibaseTempDir,
} = require("../../utilities/budibaseDir")
exports.serveBuilder = async function(ctx) { exports.serveBuilder = async function(ctx) {
let builderPath = resolve(process.cwd(), "builder") let builderPath = resolve(process.cwd(), "builder")
@ -12,8 +15,7 @@ exports.serveApp = async function(ctx) {
// TODO: update homedir stuff to wherever budi is run // TODO: update homedir stuff to wherever budi is run
// default to homedir // default to homedir
const appPath = resolve( const appPath = resolve(
homedir(), budibaseAppsDir(),
".budibase",
ctx.params.appId, ctx.params.appId,
"public", "public",
ctx.isAuthenticated ? "main" : "unauthenticated" ctx.isAuthenticated ? "main" : "unauthenticated"
@ -26,8 +28,7 @@ exports.serveComponentLibrary = async function(ctx) {
// TODO: update homedir stuff to wherever budi is run // TODO: update homedir stuff to wherever budi is run
// default to homedir // default to homedir
let componentLibraryPath = resolve( let componentLibraryPath = resolve(
homedir(), budibaseAppsDir(),
".budibase",
ctx.params.appId, ctx.params.appId,
"node_modules", "node_modules",
decodeURI(ctx.query.library), decodeURI(ctx.query.library),
@ -36,8 +37,7 @@ exports.serveComponentLibrary = async function(ctx) {
if (ctx.isDev) { if (ctx.isDev) {
componentLibraryPath = join( componentLibraryPath = join(
"/tmp", budibaseTempDir(),
".budibase",
decodeURI(ctx.query.library), decodeURI(ctx.query.library),
"dist" "dist"
) )

View File

@ -2,8 +2,7 @@ const Router = require("@koa/router")
const authenticated = require("../middleware/authenticated") const authenticated = require("../middleware/authenticated")
const compress = require("koa-compress") const compress = require("koa-compress")
const zlib = require("zlib") const zlib = require("zlib")
const { resolve } = require("path") const { budibaseAppsDir } = require("../utilities/budibaseDir")
const { homedir } = require("os")
const { const {
authRoutes, authRoutes,
pageRoutes, pageRoutes,
@ -34,7 +33,7 @@ router
) )
.use(async (ctx, next) => { .use(async (ctx, next) => {
ctx.config = { ctx.config = {
latestPackagesFolder: resolve(homedir(), ".budibase"), latestPackagesFolder: budibaseAppsDir(),
jwtSecret: process.env.JWT_SECRET, jwtSecret: process.env.JWT_SECRET,
} }
ctx.isDev = process.env.NODE_ENV !== "production" ctx.isDev = process.env.NODE_ENV !== "production"

View File

@ -1,5 +1,6 @@
const Router = require("@koa/router") const Router = require("@koa/router")
const controller = require("../controllers/static") const controller = require("../controllers/static")
const { budibaseTempDir } = require("../../utilities/budibaseDir")
const router = Router() const router = Router()
@ -9,7 +10,7 @@ router
// Serving the client library from your local dir in dev // Serving the client library from your local dir in dev
if (ctx.isDev && ctx.file.startsWith("budibase-client")) { if (ctx.isDev && ctx.file.startsWith("budibase-client")) {
ctx.devPath = "/tmp/.budibase" ctx.devPath = budibaseTempDir()
} }
await next() await next()

View File

@ -1,11 +1,8 @@
const PouchDB = require("pouchdb") const PouchDB = require("pouchdb")
const allDbs = require("pouchdb-all-dbs") const allDbs = require("pouchdb-all-dbs")
const os = require("os") const { budibaseAppsDir } = require("../utilities/budibaseDir")
const path = require("path")
const BUDIBASE_DIR = path.join(os.homedir(), ".budibase") const COUCH_DB_URL = process.env.COUCH_DB_URL || `leveldb://${budibaseAppsDir()}/`
const COUCH_DB_URL = process.env.COUCH_DB_URL || `leveldb://${BUDIBASE_DIR}/`
const Pouch = PouchDB.defaults({ const Pouch = PouchDB.defaults({
prefix: COUCH_DB_URL, prefix: COUCH_DB_URL,

View File

@ -1,10 +0,0 @@
const { join } = require("path")
const { homedir } = require("os")
const path = join(homedir(), ".budibase", ".env")
require("dotenv").config({ path })
const server = require("./app")
server.on("listening", () => {
console.log(`Budibase Server listening on port ${process.env.PORT}`)
})

View File

@ -0,0 +1,10 @@
const { join } = require("path")
const { homedir, tmpdir } = require("os")
module.exports.budibaseAppsDir = function() {
return process.env.BUDIBASE_DIR || join(homedir(), ".budibase")
}
module.exports.budibaseTempDir = function() {
return join(tmpdir(), ".budibase")
}

View File

@ -10,8 +10,10 @@
const fs = require("fs") const fs = require("fs")
const { resolve } = require("path") const { resolve } = require("path")
const rimraf = require("rimraf"); const rimraf = require("rimraf");
const {
const devDir = "/tmp/.budibase" budibaseTempDir,
} = require("../packages/server/src/utilities/budibaseDir")
const devDir = budibaseTempDir()
rimraf.sync(devDir); rimraf.sync(devDir);
fs.mkdirSync(`${devDir}/@budibase`, { recursive: true }) fs.mkdirSync(`${devDir}/@budibase`, { recursive: true })