bugfix: early require of environment.js
This commit is contained in:
parent
fc9657f00d
commit
42d19efeba
|
@ -3,10 +3,8 @@ const { exists, readFile, writeFile, ensureDir } = require("fs-extra")
|
||||||
const chalk = require("chalk")
|
const chalk = require("chalk")
|
||||||
const { serverFileName, xPlatHomeDir } = require("../../common")
|
const { serverFileName, xPlatHomeDir } = require("../../common")
|
||||||
const { join } = require("path")
|
const { join } = require("path")
|
||||||
const { create } = require("@budibase/server/src/db/clientDb")
|
|
||||||
const Sqrl = require("squirrelly")
|
const Sqrl = require("squirrelly")
|
||||||
const uuid = require("uuid")
|
const uuid = require("uuid")
|
||||||
const CouchDB = require("@budibase/server/src/db/client")
|
|
||||||
|
|
||||||
module.exports = opts => {
|
module.exports = opts => {
|
||||||
run(opts)
|
run(opts)
|
||||||
|
@ -57,6 +55,9 @@ const prompts = async opts => {
|
||||||
|
|
||||||
const createClientDatabase = async opts => {
|
const createClientDatabase = async opts => {
|
||||||
if (opts.clientId === "new") {
|
if (opts.clientId === "new") {
|
||||||
|
// cannot be a top level require as it
|
||||||
|
// will cause environment module to be loaded prematurely
|
||||||
|
const CouchDB = require("@budibase/server/src/db/client")
|
||||||
const existing = await CouchDB.allDbs()
|
const existing = await CouchDB.allDbs()
|
||||||
|
|
||||||
let i = 0
|
let i = 0
|
||||||
|
@ -68,7 +69,10 @@ const createClientDatabase = async opts => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await create(opts.clientId)
|
// cannot be a top level require as it
|
||||||
|
// will cause environment module to be loaded prematurely
|
||||||
|
const clientDb = require("@budibase/server/src/db/clientDb")
|
||||||
|
await clientDb.create(opts.clientId)
|
||||||
}
|
}
|
||||||
|
|
||||||
const createDevEnvFile = async opts => {
|
const createDevEnvFile = async opts => {
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
const { xPlatHomeDir } = require("../../common")
|
const { xPlatHomeDir } = require("../../common")
|
||||||
const dotenv = require("dotenv")
|
const dotenv = require("dotenv")
|
||||||
const createInstance = require("@budibase/server/src/api/controllers/instance")
|
const { copy, readJSON, writeJSON, exists } = require("fs-extra")
|
||||||
.create
|
|
||||||
const createApplication = require("@budibase/server/src/api/controllers/application")
|
|
||||||
.create
|
|
||||||
const buildPage = require("@budibase/server/src/utilities/builder/buildPage")
|
|
||||||
const { copy, readJSON, writeJSON, remove, exists } = require("fs-extra")
|
|
||||||
const { resolve, join } = require("path")
|
const { resolve, join } = require("path")
|
||||||
const chalk = require("chalk")
|
const chalk = require("chalk")
|
||||||
const { exec } = require("child_process")
|
const { exec } = require("child_process")
|
||||||
|
@ -37,10 +32,18 @@ const createAppInstance = async opts => {
|
||||||
body: {},
|
body: {},
|
||||||
}
|
}
|
||||||
|
|
||||||
await createApplication(createAppCtx)
|
// this cannot be a top level require as it will cause
|
||||||
opts.applicationId = createAppCtx.body.id
|
// the environment module to be loaded prematurely
|
||||||
console.log(chalk.green(`Application Created: ${createAppCtx.body.id}`))
|
const appController = require("@budibase/server/src/api/controllers/application")
|
||||||
await createInstance({
|
await appController.create(createAppCtx)
|
||||||
|
|
||||||
|
opts.applicationId = createAppCtx.body._id
|
||||||
|
console.log(chalk.green(`Application Created: ${createAppCtx.body._id}`))
|
||||||
|
|
||||||
|
// this cannot be a top level require as it will cause
|
||||||
|
// the environment module to be loaded prematurely
|
||||||
|
const instanceController = require("@budibase/server/src/api/controllers/instance")
|
||||||
|
await instanceController.create({
|
||||||
params: {
|
params: {
|
||||||
clientId: process.env.CLIENT_ID,
|
clientId: process.env.CLIENT_ID,
|
||||||
applicationId: opts.applicationId,
|
applicationId: opts.applicationId,
|
||||||
|
@ -49,6 +52,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`))
|
console.log(chalk.green(`Default Instance Created`))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,12 @@ module.exports = ({ dir }) => {
|
||||||
dir = xPlatHomeDir(dir)
|
dir = xPlatHomeDir(dir)
|
||||||
process.env.BUDIBASE_DIR = resolve(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")().then(() => {
|
console.log("dotenv loaded")
|
||||||
console.log(`Budibase Builder running on port ${process.env.PORT}..`)
|
|
||||||
|
// dont make this a variable or top level require
|
||||||
|
// ti will cause environment module to be loaded prematurely
|
||||||
|
require("@budibase/server/src/app")().then(server => {
|
||||||
|
server.on("close", () => console.log("Server Closed"))
|
||||||
|
console.log(`Budibase running on ${JSON.stringify(server.address())}`)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue