Merge branch 'master' into fix-dev-setup
This commit is contained in:
commit
947ffa326f
|
@ -12,19 +12,17 @@ const { exec } = require("child_process")
|
||||||
|
|
||||||
module.exports = opts => {
|
module.exports = opts => {
|
||||||
run(opts)
|
run(opts)
|
||||||
console.log(chalk.green(`Budibase app ${opts.name} created!`))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const run = async opts => {
|
const run = async opts => {
|
||||||
console.log(opts)
|
|
||||||
try {
|
try {
|
||||||
opts.dir = xPlatHomeDir(opts.dir)
|
opts.dir = xPlatHomeDir(opts.dir)
|
||||||
console.log(resolve(opts.dir))
|
|
||||||
const bbconfig = dotenv.config({ path: resolve(opts.dir, ".env") })
|
const bbconfig = dotenv.config({ path: resolve(opts.dir, ".env") })
|
||||||
console.log(bbconfig)
|
console.log(bbconfig)
|
||||||
await createAppInstance(opts)
|
await createAppInstance(opts)
|
||||||
await createEmptyAppPackage(opts)
|
await createEmptyAppPackage(opts)
|
||||||
exec(`cd ${join(opts.dir, opts.applicationId)} && npm install`)
|
exec(`cd ${join(opts.dir, opts.applicationId)} && npm install`)
|
||||||
|
console.log(chalk.green(`Budibase app ${opts.name} created!`))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(chalk.red("Error creating new app", error))
|
console.error(chalk.red("Error creating new app", error))
|
||||||
}
|
}
|
||||||
|
@ -41,6 +39,7 @@ const createAppInstance = async opts => {
|
||||||
|
|
||||||
await createApplication(createAppCtx)
|
await createApplication(createAppCtx)
|
||||||
opts.applicationId = createAppCtx.body.id
|
opts.applicationId = createAppCtx.body.id
|
||||||
|
console.log(chalk.green(`Application Created: ${createAppCtx.body.id}`))
|
||||||
await createInstance({
|
await createInstance({
|
||||||
params: {
|
params: {
|
||||||
clientId: process.env.CLIENT_ID,
|
clientId: process.env.CLIENT_ID,
|
||||||
|
@ -50,6 +49,7 @@ const createAppInstance = async opts => {
|
||||||
body: { name: `dev-${process.env.CLIENT_ID}` },
|
body: { name: `dev-${process.env.CLIENT_ID}` },
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
console.log(chalk.green(`Default Instance Created`))
|
||||||
}
|
}
|
||||||
|
|
||||||
const createEmptyAppPackage = async opts => {
|
const createEmptyAppPackage = async opts => {
|
||||||
|
|
|
@ -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}..`)
|
||||||
|
|
|
@ -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")
|
||||||
|
|
||||||
exports.fetchAppComponentDefinitions = async function(ctx) {
|
exports.fetchAppComponentDefinitions = async function(ctx) {
|
||||||
const db = new CouchDB(`client-${ctx.params.clientId}`)
|
const db = new CouchDB(`client-${ctx.params.clientId}`)
|
||||||
|
@ -9,14 +12,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 (ctx.isDev) {
|
if (ctx.isDev) {
|
||||||
appDirectory = "/tmp/.budibase"
|
appDirectory = budibaseTempDir()
|
||||||
}
|
}
|
||||||
|
|
||||||
const componentJson = require(join(
|
const componentJson = require(join(
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
const CouchDB = require("../../db")
|
const CouchDB = require("../../db")
|
||||||
|
const uuid = require("uuid")
|
||||||
|
|
||||||
exports.create = async function(ctx) {
|
exports.create = async function(ctx) {
|
||||||
const instanceName = ctx.request.body.name
|
const instanceName = ctx.request.body.name
|
||||||
|
const instanceId = `app_${ctx.params.applicationId.substring(6)}_inst_${uuid.v4()}`
|
||||||
const { clientId, applicationId } = ctx.params
|
const { clientId, applicationId } = ctx.params
|
||||||
const db = new CouchDB(instanceName)
|
const db = new CouchDB(instanceId)
|
||||||
await db.put({
|
await db.put({
|
||||||
_id: "_design/database",
|
_id: "_design/database",
|
||||||
metadata: {
|
metadata: {
|
||||||
|
@ -31,7 +32,7 @@ exports.create = async function(ctx) {
|
||||||
const clientDatabaseId = `client-${clientId}`
|
const clientDatabaseId = `client-${clientId}`
|
||||||
const clientDb = new CouchDB(clientDatabaseId)
|
const clientDb = new CouchDB(clientDatabaseId)
|
||||||
const budibaseApp = await clientDb.get(applicationId)
|
const budibaseApp = await clientDb.get(applicationId)
|
||||||
const instance = { id: instanceName, name: instanceName }
|
const instance = { id: instanceId, name: instanceName }
|
||||||
budibaseApp.instances.push(instance)
|
budibaseApp.instances.push(instance)
|
||||||
await clientDb.put(budibaseApp)
|
await clientDb.put(budibaseApp)
|
||||||
|
|
||||||
|
|
|
@ -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"
|
||||||
)
|
)
|
||||||
|
|
|
@ -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"
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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 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 })
|
||||||
|
|
Loading…
Reference in New Issue