bugfix: early require of environment.js
This commit is contained in:
parent
eabcb48bba
commit
49ff6201af
|
@ -3,10 +3,8 @@ const { exists, readFile, writeFile, ensureDir } = require("fs-extra")
|
|||
const chalk = require("chalk")
|
||||
const { serverFileName, xPlatHomeDir } = require("../../common")
|
||||
const { join } = require("path")
|
||||
const { create } = require("@budibase/server/src/db/clientDb")
|
||||
const Sqrl = require("squirrelly")
|
||||
const uuid = require("uuid")
|
||||
const CouchDB = require("@budibase/server/src/db/client")
|
||||
|
||||
module.exports = opts => {
|
||||
run(opts)
|
||||
|
@ -57,6 +55,9 @@ const prompts = async opts => {
|
|||
|
||||
const createClientDatabase = async opts => {
|
||||
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()
|
||||
|
||||
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 => {
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
const { xPlatHomeDir } = require("../../common")
|
||||
const dotenv = require("dotenv")
|
||||
const createInstance = require("@budibase/server/src/api/controllers/instance")
|
||||
.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 { copy, readJSON, writeJSON, exists } = require("fs-extra")
|
||||
const { resolve, join } = require("path")
|
||||
const chalk = require("chalk")
|
||||
const { exec } = require("child_process")
|
||||
|
@ -37,10 +32,18 @@ const createAppInstance = async opts => {
|
|||
body: {},
|
||||
}
|
||||
|
||||
await createApplication(createAppCtx)
|
||||
opts.applicationId = createAppCtx.body.id
|
||||
console.log(chalk.green(`Application Created: ${createAppCtx.body.id}`))
|
||||
await createInstance({
|
||||
// this cannot be a top level require as it will cause
|
||||
// the environment module to be loaded prematurely
|
||||
const appController = require("@budibase/server/src/api/controllers/application")
|
||||
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: {
|
||||
clientId: process.env.CLIENT_ID,
|
||||
applicationId: opts.applicationId,
|
||||
|
@ -49,6 +52,7 @@ const createAppInstance = async opts => {
|
|||
body: { name: `dev-${process.env.CLIENT_ID}` },
|
||||
},
|
||||
})
|
||||
|
||||
console.log(chalk.green(`Default Instance Created`))
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,12 @@ module.exports = ({ dir }) => {
|
|||
dir = xPlatHomeDir(dir)
|
||||
process.env.BUDIBASE_DIR = resolve(dir)
|
||||
require("dotenv").config({ path: resolve(dir, ".env") })
|
||||
require("@budibase/server/src/app")().then(() => {
|
||||
console.log(`Budibase Builder running on port ${process.env.PORT}..`)
|
||||
console.log("dotenv loaded")
|
||||
|
||||
// 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