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.POSTHOG_TOKEN = "phc_yGOn4i7jWKaCTapdGR6lfA4AvmuEQ2ijn5zAVSFYPlS"
|
||||||
|
|
||||||
|
exports.GENERATED_USER_EMAIL = "admin@admin.com"
|
||||||
|
|
|
@ -1,17 +1,22 @@
|
||||||
const { success } = require("../utils")
|
const { success } = require("../utils")
|
||||||
const { updateDockerComposeService } = require("./utils")
|
const { updateDockerComposeService } = require("./utils")
|
||||||
const randomString = require("randomstring")
|
const randomString = require("randomstring")
|
||||||
|
const { GENERATED_USER_EMAIL } = require("../constants")
|
||||||
|
|
||||||
exports.generateUser = async () => {
|
exports.generateUser = async (password, silent) => {
|
||||||
const email = "admin@admin.com"
|
const email = GENERATED_USER_EMAIL
|
||||||
const password = randomString.generate({ length: 6 })
|
if (!password) {
|
||||||
|
password = randomString.generate({ length: 6 })
|
||||||
|
}
|
||||||
updateDockerComposeService(service => {
|
updateDockerComposeService(service => {
|
||||||
service.environment["BB_ADMIN_USER_EMAIL"] = email
|
service.environment["BB_ADMIN_USER_EMAIL"] = email
|
||||||
service.environment["BB_ADMIN_USER_PASSWORD"] = password
|
service.environment["BB_ADMIN_USER_PASSWORD"] = password
|
||||||
})
|
})
|
||||||
console.log(
|
if (!silent) {
|
||||||
success(
|
console.log(
|
||||||
`User admin credentials configured, access with email: ${email} - password: ${password}`
|
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 => {
|
exports.init = async opts => {
|
||||||
let type, isSingle, watchDir, genUser, port
|
let type, isSingle, watchDir, genUser, port, silent
|
||||||
if (typeof opts === "string") {
|
if (typeof opts === "string") {
|
||||||
type = opts
|
type = opts
|
||||||
} else {
|
} else {
|
||||||
|
@ -42,6 +42,7 @@ exports.init = async opts => {
|
||||||
watchDir = opts["watchPluginDir"]
|
watchDir = opts["watchPluginDir"]
|
||||||
genUser = opts["genUser"]
|
genUser = opts["genUser"]
|
||||||
port = opts["port"]
|
port = opts["port"]
|
||||||
|
silent = opts["silent"]
|
||||||
}
|
}
|
||||||
const isQuick = type === InitTypes.QUICK || type === InitTypes.DIGITAL_OCEAN
|
const isQuick = type === InitTypes.QUICK || type === InitTypes.DIGITAL_OCEAN
|
||||||
await checkDockerConfigured()
|
await checkDockerConfigured()
|
||||||
|
@ -60,14 +61,15 @@ exports.init = async opts => {
|
||||||
const config = await getInitConfig(type, isQuick, port)
|
const config = await getInitConfig(type, isQuick, port)
|
||||||
if (!isSingle) {
|
if (!isSingle) {
|
||||||
await downloadFiles()
|
await downloadFiles()
|
||||||
await makeFiles.makeEnv(config)
|
await makeFiles.makeEnv(config, silent)
|
||||||
} else {
|
} else {
|
||||||
await makeFiles.makeSingleCompose(config)
|
await makeFiles.makeSingleCompose(config, silent)
|
||||||
}
|
}
|
||||||
if (watchDir) {
|
if (watchDir) {
|
||||||
await watchPlugins(watchDir)
|
await watchPlugins(watchDir, silent)
|
||||||
}
|
}
|
||||||
if (genUser) {
|
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,
|
port: 10000,
|
||||||
}
|
}
|
||||||
|
|
||||||
async function make(path, contentsFn, inputs = {}) {
|
async function make(path, contentsFn, inputs = {}, silent) {
|
||||||
const port =
|
const port =
|
||||||
inputs.port ||
|
inputs.port ||
|
||||||
(await number(
|
(await number(
|
||||||
|
@ -98,19 +98,21 @@ async function make(path, contentsFn, inputs = {}) {
|
||||||
))
|
))
|
||||||
const fileContents = contentsFn(port)
|
const fileContents = contentsFn(port)
|
||||||
fs.writeFileSync(path, fileContents)
|
fs.writeFileSync(path, fileContents)
|
||||||
console.log(
|
if (!silent) {
|
||||||
success(
|
console.log(
|
||||||
`Configuration has been written successfully - please check ${path} for more details.`
|
success(
|
||||||
|
`Configuration has been written successfully - please check ${path} for more details.`
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.makeEnv = async (inputs = {}) => {
|
module.exports.makeEnv = async (inputs = {}, silent) => {
|
||||||
return make(ENV_PATH, getEnv, inputs)
|
return make(ENV_PATH, getEnv, inputs, silent)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.makeSingleCompose = async (inputs = {}) => {
|
module.exports.makeSingleCompose = async (inputs = {}, silent) => {
|
||||||
return make(COMPOSE_PATH, getSingleCompose, inputs)
|
return make(COMPOSE_PATH, getSingleCompose, inputs, silent)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.getEnvProperty = property => {
|
module.exports.getEnvProperty = property => {
|
||||||
|
|
|
@ -3,7 +3,7 @@ const fs = require("fs")
|
||||||
const { error, success } = require("../utils")
|
const { error, success } = require("../utils")
|
||||||
const { updateDockerComposeService } = require("./utils")
|
const { updateDockerComposeService } = require("./utils")
|
||||||
|
|
||||||
exports.watchPlugins = async pluginPath => {
|
exports.watchPlugins = async (pluginPath, silent) => {
|
||||||
const PLUGIN_PATH = "/plugins"
|
const PLUGIN_PATH = "/plugins"
|
||||||
// get absolute path
|
// get absolute path
|
||||||
pluginPath = resolve(pluginPath)
|
pluginPath = resolve(pluginPath)
|
||||||
|
@ -28,7 +28,9 @@ exports.watchPlugins = async pluginPath => {
|
||||||
}
|
}
|
||||||
service.volumes.push(`${pluginPath}:${PLUGIN_PATH}`)
|
service.volumes.push(`${pluginPath}:${PLUGIN_PATH}`)
|
||||||
})
|
})
|
||||||
console.log(
|
if (!silent) {
|
||||||
success(`Docker compose configured to watch directory: ${pluginPath}`)
|
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 { success, error, info, moveDirectory } = require("../utils")
|
||||||
const { captureEvent } = require("../events")
|
const { captureEvent } = require("../events")
|
||||||
const fp = require("find-free-port")
|
const fp = require("find-free-port")
|
||||||
|
const { GENERATED_USER_EMAIL } = require("../constants")
|
||||||
const { init: hostingInit } = require("../hosting/init")
|
const { init: hostingInit } = require("../hosting/init")
|
||||||
const { start: hostingStart } = require("../hosting/start")
|
const { start: hostingStart } = require("../hosting/start")
|
||||||
|
|
||||||
|
@ -147,14 +148,24 @@ async function watch() {
|
||||||
async function dev() {
|
async function dev() {
|
||||||
const pluginDir = await questions.string("Directory to watch", "./")
|
const pluginDir = await questions.string("Directory to watch", "./")
|
||||||
const [port] = await fp(10000)
|
const [port] = await fp(10000)
|
||||||
|
const password = "admin"
|
||||||
await hostingInit({
|
await hostingInit({
|
||||||
init: InitTypes.QUICK,
|
init: InitTypes.QUICK,
|
||||||
single: true,
|
single: true,
|
||||||
watchPluginDir: pluginDir,
|
watchPluginDir: pluginDir,
|
||||||
genUser: true,
|
genUser: password,
|
||||||
port,
|
port,
|
||||||
|
silent: true,
|
||||||
})
|
})
|
||||||
await hostingStart()
|
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}`)
|
const command = new Command(`${CommandWords.PLUGIN}`)
|
||||||
|
|
Loading…
Reference in New Issue