diff --git a/packages/cli/src/constants.js b/packages/cli/src/constants.js index aa49523d4e..6b0265ffd2 100644 --- a/packages/cli/src/constants.js +++ b/packages/cli/src/constants.js @@ -21,3 +21,5 @@ exports.AnalyticsEvents = { } exports.POSTHOG_TOKEN = "phc_yGOn4i7jWKaCTapdGR6lfA4AvmuEQ2ijn5zAVSFYPlS" + +exports.GENERATED_USER_EMAIL = "admin@admin.com" diff --git a/packages/cli/src/hosting/genUser.js b/packages/cli/src/hosting/genUser.js index b6e078c8bd..7ee11179af 100644 --- a/packages/cli/src/hosting/genUser.js +++ b/packages/cli/src/hosting/genUser.js @@ -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}` + ) ) - ) + } } diff --git a/packages/cli/src/hosting/init.js b/packages/cli/src/hosting/init.js index 37dfe9b4db..88063f1732 100644 --- a/packages/cli/src/hosting/init.js +++ b/packages/cli/src/hosting/init.js @@ -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) } } diff --git a/packages/cli/src/hosting/makeFiles.js b/packages/cli/src/hosting/makeFiles.js index 0723d5e03d..abb0736858 100644 --- a/packages/cli/src/hosting/makeFiles.js +++ b/packages/cli/src/hosting/makeFiles.js @@ -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 => { diff --git a/packages/cli/src/hosting/watch.js b/packages/cli/src/hosting/watch.js index fb51aa9ad8..56f1c8e201 100644 --- a/packages/cli/src/hosting/watch.js +++ b/packages/cli/src/hosting/watch.js @@ -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}`) + ) + } } diff --git a/packages/cli/src/plugins/index.js b/packages/cli/src/plugins/index.js index 1057ca9aaa..873be10612 100644 --- a/packages/cli/src/plugins/index.js +++ b/packages/cli/src/plugins/index.js @@ -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}`)