From 67bc39d7912b33b8d45778e322bdf7a0c21fb138 Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Mon, 14 Oct 2024 13:32:58 +0200 Subject: [PATCH] chore(create): Clean up outputs, improve outro --- packages/create/src/create-vendure-app.ts | 40 ++++++++++++++++------- packages/create/src/helpers.ts | 20 ++++++++---- 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/packages/create/src/create-vendure-app.ts b/packages/create/src/create-vendure-app.ts index 661ad5c056..ac49889e08 100644 --- a/packages/create/src/create-vendure-app.ts +++ b/packages/create/src/create-vendure-app.ts @@ -238,9 +238,8 @@ export async function createVendureApp( } scaffoldSpinner.stop(`Generated app scaffold`); - cleanUpDockerResources(name); - if (mode === 'quick' && dbType === 'postgres') { + cleanUpDockerResources(name); await startPostgresDatabase(root); } @@ -297,6 +296,7 @@ export async function createVendureApp( // eslint-disable-next-line @typescript-eslint/no-var-requires require(path.join(root, 'node_modules/ts-node')).register(); + let superAdminCredentials: { identifier: string; password: string } | undefined; try { const { populate } = await import(path.join(root, 'node_modules/@vendure/core/cli/populate')); const { bootstrap, DefaultLogger, LogLevel, JobQueueService, ConfigModule } = await import( @@ -304,7 +304,7 @@ export async function createVendureApp( ); const { config } = await import(configFile); const assetsDir = path.join(__dirname, '../assets'); - + superAdminCredentials = config.authOptions.superadminCredentials; const initialDataPath = path.join(assetsDir, 'initial-data.json'); const vendureLogLevel = logLevel === 'info' || logLevel === 'silent' @@ -389,7 +389,7 @@ export async function createVendureApp( // process.stdin.resume(); process.on('SIGINT', function () { - displayOutro(root, name); + displayOutro(root, name, superAdminCredentials); quickStartProcess?.kill('SIGINT'); process.exit(0); }); @@ -412,7 +412,7 @@ export async function createVendureApp( } } else { clearTimeout(timer); - displayOutro(root, name); + displayOutro(root, name, superAdminCredentials); process.exit(0); } } catch (e: any) { @@ -422,19 +422,35 @@ export async function createVendureApp( } } -function displayOutro(root: string, name: string) { +function displayOutro( + root: string, + name: string, + superAdminCredentials?: { identifier: string; password: string }, +) { const startCommand = 'npm run dev'; const nextSteps = [ - `${pc.green('Success!')} Your new Vendure server was created!`, - `\n`, - pc.italic(root), - `\n`, - `You can run it again with:`, + `Your new Vendure server was created!`, + pc.gray(root), `\n`, + `Next, run:`, pc.gray('$ ') + pc.blue(pc.bold(`cd ${name}`)), pc.gray('$ ') + pc.blue(pc.bold(`${startCommand}`)), + `\n`, + `This will start the server in development mode.`, + `To access the Admin UI, open your browser and navigate to:`, + `\n`, + pc.green(`http://localhost:3000/admin`), + `\n`, + `Use the following credentials to log in:`, + `Username: ${pc.green(superAdminCredentials?.identifier ?? 'superadmin')}`, + `Password: ${pc.green(superAdminCredentials?.password ?? 'superadmin')}`, + '\n', + '➡️ Docs: https://docs.vendure.io', + '➡️ Discord community: https://vendure.io/community', + '➡️ Star us on GitHub:', + ' https://github.com/vendure-ecommerce/vendure', ]; - note(nextSteps.join('\n')); + note(nextSteps.join('\n'), pc.green('Setup complete!')); outro(`Happy hacking!`); } diff --git a/packages/create/src/helpers.ts b/packages/create/src/helpers.ts index c952e44252..74956db2f5 100644 --- a/packages/create/src/helpers.ts +++ b/packages/create/src/helpers.ts @@ -375,14 +375,14 @@ export async function isDockerAvailable(): Promise<{ result: 'not-found' | 'not- try { if (currentPlatform === 'win32') { // https://stackoverflow.com/a/44182489/772859 - execSync('"C:\\Program Files\\Docker\\Docker\\Docker Desktop.exe"'); + execSync('"C:\\Program Files\\Docker\\Docker\\Docker Desktop.exe"', { stdio: 'ignore' }); } else if (currentPlatform === 'darwin') { - execSync('open -a Docker'); + execSync('open -a Docker', { stdio: 'ignore' }); } else { - execSync('systemctl start docker'); + execSync('systemctl start docker', { stdio: 'ignore' }); } } catch (e: any) { - dockerSpinner.message('Could not start Docker.'); + dockerSpinner.stop('Could not start Docker.'); log(e.message, { level: 'verbose' }); return { result: 'not-running' }; } @@ -518,9 +518,15 @@ export function checkCancel(value: T | symbol): value is T { export function cleanUpDockerResources(name: string) { try { - execSync(`docker stop $(docker ps -a -q --filter "label=io.vendure.create.name=${name}")`); - execSync(`docker rm $(docker ps -a -q --filter "label=io.vendure.create.name=${name}")`); - execSync(`docker volume rm $(docker volume ls --filter "label=io.vendure.create.name=${name}" -q)`); + execSync(`docker stop $(docker ps -a -q --filter "label=io.vendure.create.name=${name}")`, { + stdio: 'ignore', + }); + execSync(`docker rm $(docker ps -a -q --filter "label=io.vendure.create.name=${name}")`, { + stdio: 'ignore', + }); + execSync(`docker volume rm $(docker volume ls --filter "label=io.vendure.create.name=${name}" -q)`, { + stdio: 'ignore', + }); } catch (e) { log(pc.yellow(`Could not clean up Docker resources`), { level: 'verbose' }); }