Improvement to CLI logging output for plugins --dev command - make it more obvious what next steps are.
This commit is contained in:
parent
04dac2e445
commit
0f64f6b6fb
|
@ -21,3 +21,5 @@ exports.AnalyticsEvents = {
|
|||
}
|
||||
|
||||
exports.POSTHOG_TOKEN = "phc_yGOn4i7jWKaCTapdGR6lfA4AvmuEQ2ijn5zAVSFYPlS"
|
||||
|
||||
exports.GENERATED_USER_EMAIL = "admin@admin.com"
|
||||
|
|
|
@ -1,17 +1,22 @@
|
|||
const { success } = require("../utils")
|
||||
const { updateDockerComposeService } = require("./utils")
|
||||
const randomString = require("randomstring")
|
||||
const { GENERATED_USER_EMAIL } = require("../constants")
|
||||
|
||||
exports.generateUser = async () => {
|
||||
const email = "admin@admin.com"
|
||||
const password = randomString.generate({ length: 6 })
|
||||
exports.generateUser = async (password, silent) => {
|
||||
const email = GENERATED_USER_EMAIL
|
||||
if (!password) {
|
||||
password = randomString.generate({ length: 6 })
|
||||
}
|
||||
updateDockerComposeService(service => {
|
||||
service.environment["BB_ADMIN_USER_EMAIL"] = email
|
||||
service.environment["BB_ADMIN_USER_PASSWORD"] = password
|
||||
})
|
||||
console.log(
|
||||
success(
|
||||
`User admin credentials configured, access with email: ${email} - password: ${password}`
|
||||
if (!silent) {
|
||||
console.log(
|
||||
success(
|
||||
`User admin credentials configured, access with email: ${email} - password: ${password}`
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ async function getInitConfig(type, isQuick, port) {
|
|||
}
|
||||
|
||||
exports.init = async opts => {
|
||||
let type, isSingle, watchDir, genUser, port
|
||||
let type, isSingle, watchDir, genUser, port, silent
|
||||
if (typeof opts === "string") {
|
||||
type = opts
|
||||
} else {
|
||||
|
@ -42,6 +42,7 @@ exports.init = async opts => {
|
|||
watchDir = opts["watchPluginDir"]
|
||||
genUser = opts["genUser"]
|
||||
port = opts["port"]
|
||||
silent = opts["silent"]
|
||||
}
|
||||
const isQuick = type === InitTypes.QUICK || type === InitTypes.DIGITAL_OCEAN
|
||||
await checkDockerConfigured()
|
||||
|
@ -60,14 +61,15 @@ exports.init = async opts => {
|
|||
const config = await getInitConfig(type, isQuick, port)
|
||||
if (!isSingle) {
|
||||
await downloadFiles()
|
||||
await makeFiles.makeEnv(config)
|
||||
await makeFiles.makeEnv(config, silent)
|
||||
} else {
|
||||
await makeFiles.makeSingleCompose(config)
|
||||
await makeFiles.makeSingleCompose(config, silent)
|
||||
}
|
||||
if (watchDir) {
|
||||
await watchPlugins(watchDir)
|
||||
await watchPlugins(watchDir, silent)
|
||||
}
|
||||
if (genUser) {
|
||||
await generateUser()
|
||||
const inputPassword = typeof genUser === "string" ? genUser : null
|
||||
await generateUser(inputPassword, silent)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ module.exports.QUICK_CONFIG = {
|
|||
port: 10000,
|
||||
}
|
||||
|
||||
async function make(path, contentsFn, inputs = {}) {
|
||||
async function make(path, contentsFn, inputs = {}, silent) {
|
||||
const port =
|
||||
inputs.port ||
|
||||
(await number(
|
||||
|
@ -98,19 +98,21 @@ async function make(path, contentsFn, inputs = {}) {
|
|||
))
|
||||
const fileContents = contentsFn(port)
|
||||
fs.writeFileSync(path, fileContents)
|
||||
console.log(
|
||||
success(
|
||||
`Configuration has been written successfully - please check ${path} for more details.`
|
||||
if (!silent) {
|
||||
console.log(
|
||||
success(
|
||||
`Configuration has been written successfully - please check ${path} for more details.`
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.makeEnv = async (inputs = {}) => {
|
||||
return make(ENV_PATH, getEnv, inputs)
|
||||
module.exports.makeEnv = async (inputs = {}, silent) => {
|
||||
return make(ENV_PATH, getEnv, inputs, silent)
|
||||
}
|
||||
|
||||
module.exports.makeSingleCompose = async (inputs = {}) => {
|
||||
return make(COMPOSE_PATH, getSingleCompose, inputs)
|
||||
module.exports.makeSingleCompose = async (inputs = {}, silent) => {
|
||||
return make(COMPOSE_PATH, getSingleCompose, inputs, silent)
|
||||
}
|
||||
|
||||
module.exports.getEnvProperty = property => {
|
||||
|
|
|
@ -3,7 +3,7 @@ const fs = require("fs")
|
|||
const { error, success } = require("../utils")
|
||||
const { updateDockerComposeService } = require("./utils")
|
||||
|
||||
exports.watchPlugins = async pluginPath => {
|
||||
exports.watchPlugins = async (pluginPath, silent) => {
|
||||
const PLUGIN_PATH = "/plugins"
|
||||
// get absolute path
|
||||
pluginPath = resolve(pluginPath)
|
||||
|
@ -28,7 +28,9 @@ exports.watchPlugins = async pluginPath => {
|
|||
}
|
||||
service.volumes.push(`${pluginPath}:${PLUGIN_PATH}`)
|
||||
})
|
||||
console.log(
|
||||
success(`Docker compose configured to watch directory: ${pluginPath}`)
|
||||
)
|
||||
if (!silent) {
|
||||
console.log(
|
||||
success(`Docker compose configured to watch directory: ${pluginPath}`)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ const { join } = require("path")
|
|||
const { success, error, info, moveDirectory } = require("../utils")
|
||||
const { captureEvent } = require("../events")
|
||||
const fp = require("find-free-port")
|
||||
const { GENERATED_USER_EMAIL } = require("../constants")
|
||||
const { init: hostingInit } = require("../hosting/init")
|
||||
const { start: hostingStart } = require("../hosting/start")
|
||||
|
||||
|
@ -147,14 +148,24 @@ async function watch() {
|
|||
async function dev() {
|
||||
const pluginDir = await questions.string("Directory to watch", "./")
|
||||
const [port] = await fp(10000)
|
||||
const password = "admin"
|
||||
await hostingInit({
|
||||
init: InitTypes.QUICK,
|
||||
single: true,
|
||||
watchPluginDir: pluginDir,
|
||||
genUser: true,
|
||||
genUser: password,
|
||||
port,
|
||||
silent: true,
|
||||
})
|
||||
await hostingStart()
|
||||
console.log(success(`Configuration has been written to docker-compose.yaml`))
|
||||
console.log(
|
||||
success("Development environment started successfully - connect at: ") +
|
||||
info(`http://localhost:${port}`)
|
||||
)
|
||||
console.log(success("Use the following credentials to login:"))
|
||||
console.log(success("Email: ") + info(GENERATED_USER_EMAIL))
|
||||
console.log(success("Password: ") + info(password))
|
||||
}
|
||||
|
||||
const command = new Command(`${CommandWords.PLUGIN}`)
|
||||
|
|
Loading…
Reference in New Issue