Skip to content

Commit

Permalink
chore(create): Clean up outputs, improve outro
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Oct 14, 2024
1 parent ff23486 commit 67bc39d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
40 changes: 28 additions & 12 deletions packages/create/src/create-vendure-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -297,14 +296,15 @@ 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(
path.join(root, 'node_modules/@vendure/core/dist/index')
);
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'
Expand Down Expand Up @@ -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);
});
Expand All @@ -412,7 +412,7 @@ export async function createVendureApp(
}
} else {
clearTimeout(timer);
displayOutro(root, name);
displayOutro(root, name, superAdminCredentials);
process.exit(0);
}
} catch (e: any) {
Expand All @@ -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!`);
}

Expand Down
20 changes: 13 additions & 7 deletions packages/create/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' };
}
Expand Down Expand Up @@ -518,9 +518,15 @@ export function checkCancel<T>(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' });
}
Expand Down

0 comments on commit 67bc39d

Please sign in to comment.