Merge branch 'master' into fix-dev-setup
This commit is contained in:
commit
4c62f8181e
|
@ -12,19 +12,17 @@ const { exec } = require("child_process")
|
|||
|
||||
module.exports = opts => {
|
||||
run(opts)
|
||||
console.log(chalk.green(`Budibase app ${opts.name} created!`))
|
||||
}
|
||||
|
||||
const run = async opts => {
|
||||
console.log(opts)
|
||||
try {
|
||||
opts.dir = xPlatHomeDir(opts.dir)
|
||||
console.log(resolve(opts.dir))
|
||||
const bbconfig = dotenv.config({ path: resolve(opts.dir, ".env") })
|
||||
console.log(bbconfig)
|
||||
await createAppInstance(opts)
|
||||
await createEmptyAppPackage(opts)
|
||||
exec(`cd ${join(opts.dir, opts.applicationId)} && npm install`)
|
||||
console.log(chalk.green(`Budibase app ${opts.name} created!`))
|
||||
} catch (error) {
|
||||
console.error(chalk.red("Error creating new app", error))
|
||||
}
|
||||
|
@ -41,6 +39,7 @@ const createAppInstance = async opts => {
|
|||
|
||||
await createApplication(createAppCtx)
|
||||
opts.applicationId = createAppCtx.body.id
|
||||
console.log(chalk.green(`Application Created: ${createAppCtx.body.id}`))
|
||||
await createInstance({
|
||||
params: {
|
||||
clientId: process.env.CLIENT_ID,
|
||||
|
@ -50,6 +49,7 @@ const createAppInstance = async opts => {
|
|||
body: { name: `dev-${process.env.CLIENT_ID}` },
|
||||
},
|
||||
})
|
||||
console.log(chalk.green(`Default Instance Created`))
|
||||
}
|
||||
|
||||
const createEmptyAppPackage = async opts => {
|
||||
|
|
|
@ -3,6 +3,7 @@ const { resolve } = require("path")
|
|||
|
||||
module.exports = ({ dir }) => {
|
||||
dir = xPlatHomeDir(dir)
|
||||
process.env.BUDIBASE_DIR = resolve(dir)
|
||||
require("dotenv").config({ path: resolve(dir, ".env") })
|
||||
require("@budibase/server/src/app")
|
||||
console.log(`Budibase Builder running on port ${process.env.PORT}..`)
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
const CouchDB = require("../../db")
|
||||
const { homedir } = require("os")
|
||||
const { resolve, join } = require("path")
|
||||
const {
|
||||
budibaseTempDir,
|
||||
budibaseAppsDir,
|
||||
} = require("../../utilities/budibaseDir")
|
||||
|
||||
exports.fetchAppComponentDefinitions = async function(ctx) {
|
||||
const db = new CouchDB(`client-${ctx.params.clientId}`)
|
||||
|
@ -9,14 +12,13 @@ exports.fetchAppComponentDefinitions = async function(ctx) {
|
|||
const componentDefinitions = app.componentLibraries.reduce(
|
||||
(acc, componentLibrary) => {
|
||||
let appDirectory = resolve(
|
||||
homedir(),
|
||||
".budibase",
|
||||
budibaseAppsDir(),
|
||||
ctx.params.appId,
|
||||
"node_modules"
|
||||
)
|
||||
|
||||
if (ctx.isDev) {
|
||||
appDirectory = "/tmp/.budibase"
|
||||
appDirectory = budibaseTempDir()
|
||||
}
|
||||
|
||||
const componentJson = require(join(
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
const CouchDB = require("../../db")
|
||||
const uuid = require("uuid")
|
||||
|
||||
exports.create = async function(ctx) {
|
||||
const instanceName = ctx.request.body.name
|
||||
|
||||
const instanceId = `app_${ctx.params.applicationId.substring(6)}_inst_${uuid.v4()}`
|
||||
const { clientId, applicationId } = ctx.params
|
||||
const db = new CouchDB(instanceName)
|
||||
const db = new CouchDB(instanceId)
|
||||
await db.put({
|
||||
_id: "_design/database",
|
||||
metadata: {
|
||||
|
@ -31,7 +32,7 @@ exports.create = async function(ctx) {
|
|||
const clientDatabaseId = `client-${clientId}`
|
||||
const clientDb = new CouchDB(clientDatabaseId)
|
||||
const budibaseApp = await clientDb.get(applicationId)
|
||||
const instance = { id: instanceName, name: instanceName }
|
||||
const instance = { id: instanceId, name: instanceName }
|
||||
budibaseApp.instances.push(instance)
|
||||
await clientDb.put(budibaseApp)
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
const send = require("koa-send")
|
||||
const { resolve, join } = require("path")
|
||||
const { homedir } = require("os")
|
||||
const {
|
||||
budibaseAppsDir,
|
||||
budibaseTempDir,
|
||||
} = require("../../utilities/budibaseDir")
|
||||
|
||||
exports.serveBuilder = async function(ctx) {
|
||||
let builderPath = resolve(process.cwd(), "builder")
|
||||
|
@ -12,8 +15,7 @@ exports.serveApp = async function(ctx) {
|
|||
// TODO: update homedir stuff to wherever budi is run
|
||||
// default to homedir
|
||||
const appPath = resolve(
|
||||
homedir(),
|
||||
".budibase",
|
||||
budibaseAppsDir(),
|
||||
ctx.params.appId,
|
||||
"public",
|
||||
ctx.isAuthenticated ? "main" : "unauthenticated"
|
||||
|
@ -26,8 +28,7 @@ exports.serveComponentLibrary = async function(ctx) {
|
|||
// TODO: update homedir stuff to wherever budi is run
|
||||
// default to homedir
|
||||
let componentLibraryPath = resolve(
|
||||
homedir(),
|
||||
".budibase",
|
||||
budibaseAppsDir(),
|
||||
ctx.params.appId,
|
||||
"node_modules",
|
||||
decodeURI(ctx.query.library),
|
||||
|
@ -36,8 +37,7 @@ exports.serveComponentLibrary = async function(ctx) {
|
|||
|
||||
if (ctx.isDev) {
|
||||
componentLibraryPath = join(
|
||||
"/tmp",
|
||||
".budibase",
|
||||
budibaseTempDir(),
|
||||
decodeURI(ctx.query.library),
|
||||
"dist"
|
||||
)
|
||||
|
|
|
@ -2,8 +2,7 @@ const Router = require("@koa/router")
|
|||
const authenticated = require("../middleware/authenticated")
|
||||
const compress = require("koa-compress")
|
||||
const zlib = require("zlib")
|
||||
const { resolve } = require("path")
|
||||
const { homedir } = require("os")
|
||||
const { budibaseAppsDir } = require("../utilities/budibaseDir")
|
||||
const {
|
||||
authRoutes,
|
||||
pageRoutes,
|
||||
|
@ -34,7 +33,7 @@ router
|
|||
)
|
||||
.use(async (ctx, next) => {
|
||||
ctx.config = {
|
||||
latestPackagesFolder: resolve(homedir(), ".budibase"),
|
||||
latestPackagesFolder: budibaseAppsDir(),
|
||||
jwtSecret: process.env.JWT_SECRET,
|
||||
}
|
||||
ctx.isDev = process.env.NODE_ENV !== "production"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const Router = require("@koa/router")
|
||||
const controller = require("../controllers/static")
|
||||
const { budibaseTempDir } = require("../../utilities/budibaseDir")
|
||||
|
||||
const router = Router()
|
||||
|
||||
|
@ -9,7 +10,7 @@ router
|
|||
|
||||
// Serving the client library from your local dir in dev
|
||||
if (ctx.isDev && ctx.file.startsWith("budibase-client")) {
|
||||
ctx.devPath = "/tmp/.budibase"
|
||||
ctx.devPath = budibaseTempDir()
|
||||
}
|
||||
|
||||
await next()
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
const PouchDB = require("pouchdb")
|
||||
const allDbs = require("pouchdb-all-dbs")
|
||||
const os = require("os")
|
||||
const path = require("path")
|
||||
const { budibaseAppsDir } = require("../utilities/budibaseDir")
|
||||
|
||||
const BUDIBASE_DIR = path.join(os.homedir(), ".budibase")
|
||||
|
||||
const COUCH_DB_URL = process.env.COUCH_DB_URL || `leveldb://${BUDIBASE_DIR}/`
|
||||
const COUCH_DB_URL = process.env.COUCH_DB_URL || `leveldb://${budibaseAppsDir()}/`
|
||||
|
||||
const Pouch = PouchDB.defaults({
|
||||
prefix: COUCH_DB_URL,
|
||||
|
|
|
@ -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}`)
|
||||
})
|
|
@ -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")
|
||||
}
|
|
@ -10,8 +10,10 @@
|
|||
const fs = require("fs")
|
||||
const { resolve } = require("path")
|
||||
const rimraf = require("rimraf");
|
||||
|
||||
const devDir = "/tmp/.budibase"
|
||||
const {
|
||||
budibaseTempDir,
|
||||
} = require("../packages/server/src/utilities/budibaseDir")
|
||||
const devDir = budibaseTempDir()
|
||||
|
||||
rimraf.sync(devDir);
|
||||
fs.mkdirSync(`${devDir}/@budibase`, { recursive: true })
|
||||
|
|
Loading…
Reference in New Issue