From 2acfef741fe3d4166fa0f63d887d0ad1a02e0e92 Mon Sep 17 00:00:00 2001 From: natemoo-re Date: Wed, 9 Mar 2022 23:38:46 +0000 Subject: [PATCH] [ci] format --- packages/astro/src/cli/index.ts | 64 ++++++++++--------- packages/astro/src/core/logger.ts | 6 +- packages/astro/src/core/messages.ts | 2 +- .../src/vite-plugin-astro-server/index.ts | 2 +- packages/astro/src/vite-plugin-astro/hmr.ts | 2 +- packages/astro/test/cli.test.js | 7 +- packages/astro/test/test-utils.js | 5 +- 7 files changed, 48 insertions(+), 40 deletions(-) diff --git a/packages/astro/src/cli/index.ts b/packages/astro/src/cli/index.ts index 49c1d47ad..962586ac3 100644 --- a/packages/astro/src/cli/index.ts +++ b/packages/astro/src/cli/index.ts @@ -19,58 +19,64 @@ type CLICommand = 'help' | 'version' | 'dev' | 'build' | 'preview' | 'reload' | /** Display --help flag */ function printHelp() { - linebreak() + linebreak(); headline('astro', 'Futuristic web development tool.'); - linebreak() + linebreak(); title('Commands'); - table([ - ['dev', 'Run Astro in development mode.'], - ['build', 'Build a pre-compiled production-ready site.'], - ['preview', 'Preview your build locally before deploying.'], - ['check', 'Check your project for errors.'], - ['--version', 'Show the version number and exit.'], - ['--help', 'Show this help message.'], - ], { padding: 28, prefix: ' astro ' }); - linebreak() + table( + [ + ['dev', 'Run Astro in development mode.'], + ['build', 'Build a pre-compiled production-ready site.'], + ['preview', 'Preview your build locally before deploying.'], + ['check', 'Check your project for errors.'], + ['--version', 'Show the version number and exit.'], + ['--help', 'Show this help message.'], + ], + { padding: 28, prefix: ' astro ' } + ); + linebreak(); title('Flags'); - table([ - ['--config ', 'Specify the path to the Astro config file.'], - ['--project-root ', 'Specify the path to the project root folder.'], - ['--no-sitemap', 'Disable sitemap generation (build only).'], - ['--legacy-build', 'Use the build strategy prior to 0.24.0'], - ['--experimental-ssr', 'Enable SSR compilation.'], - ['--drafts', 'Include markdown draft pages in the build.'], - ['--verbose', 'Enable verbose logging'], - ['--silent', 'Disable logging'], - ], { padding: 28, prefix: ' ' }); + table( + [ + ['--config ', 'Specify the path to the Astro config file.'], + ['--project-root ', 'Specify the path to the project root folder.'], + ['--no-sitemap', 'Disable sitemap generation (build only).'], + ['--legacy-build', 'Use the build strategy prior to 0.24.0'], + ['--experimental-ssr', 'Enable SSR compilation.'], + ['--drafts', 'Include markdown draft pages in the build.'], + ['--verbose', 'Enable verbose logging'], + ['--silent', 'Disable logging'], + ], + { padding: 28, prefix: ' ' } + ); // Logging utils function linebreak() { console.log(); } - function headline(name: string, tagline: string) { + function headline(name: string, tagline: string) { console.log(` ${colors.bgGreen(colors.black(` ${name} `))} ${colors.green(`v${process.env.PACKAGE_VERSION ?? ''}`)} ${tagline}`); } - function title(label: string) { + function title(label: string) { console.log(` ${colors.bgWhite(colors.black(` ${label} `))}`); } - function table(rows: [string, string][], opts: { padding: number, prefix: string }) { - const split = rows.some(row => { + function table(rows: [string, string][], opts: { padding: number; prefix: string }) { + const split = rows.some((row) => { const message = `${opts.prefix}${' '.repeat(opts.padding)}${row[1]}`; return message.length > process.stdout.columns; - }) + }); for (const row of rows) { row.forEach((col, i) => { if (i === 0) { - process.stdout.write(`${opts.prefix}${colors.bold(pad(`${col}`, opts.padding - opts.prefix.length))}`) + process.stdout.write(`${opts.prefix}${colors.bold(pad(`${col}`, opts.padding - opts.prefix.length))}`); } else { if (split) { process.stdout.write('\n '); } - process.stdout.write(colors.dim(col) + '\n') + process.stdout.write(colors.dim(col) + '\n'); } - }) + }); } return ''; } diff --git a/packages/astro/src/core/logger.ts b/packages/astro/src/core/logger.ts index d6b8f5ac0..2f3620579 100644 --- a/packages/astro/src/core/logger.ts +++ b/packages/astro/src/core/logger.ts @@ -25,7 +25,7 @@ function getLoggerLocale(): string { const dt = new Intl.DateTimeFormat(getLoggerLocale(), { hour: '2-digit', minute: '2-digit', - second: '2-digit' + second: '2-digit', }); let lastMessage: string; @@ -74,12 +74,12 @@ export const defaultLogDestination = new Writable({ (dest as typeof process.stdout).moveCursor(0, -1); } } - message = `${message} ${yellow(`(x${lastMessageCount})`)}` + message = `${message} ${yellow(`(x${lastMessageCount})`)}`; } else { lastMessage = message; lastMessageCount = 1; } - dest.write(getPrefix()) + dest.write(getPrefix()); dest.write(message); dest.write('\n'); diff --git a/packages/astro/src/core/messages.ts b/packages/astro/src/core/messages.ts index 8d7c2d3ad..83b48c336 100644 --- a/packages/astro/src/core/messages.ts +++ b/packages/astro/src/core/messages.ts @@ -54,7 +54,7 @@ export function devStart({ `${dim('┃')} Network ${bold(cyan(toDisplayUrl(networkAddress)))}`, '', ]; - return messages.map(msg => ` ${msg}`).join('\n'); + return messages.map((msg) => ` ${msg}`).join('\n'); } /** Display port in use */ diff --git a/packages/astro/src/vite-plugin-astro-server/index.ts b/packages/astro/src/vite-plugin-astro-server/index.ts index 62727a213..ff6825e8f 100644 --- a/packages/astro/src/vite-plugin-astro-server/index.ts +++ b/packages/astro/src/vite-plugin-astro-server/index.ts @@ -115,7 +115,7 @@ async function handleRequest( } catch (_err: any) { info(logging, 'serve', msg.req({ url: pathname, statusCode: 500 })); const err = createSafeError(_err); - error(logging, 'error', msg.err(err)) + error(logging, 'error', msg.err(err)); handle500Response(viteServer, origin, req, res, err); } } diff --git a/packages/astro/src/vite-plugin-astro/hmr.ts b/packages/astro/src/vite-plugin-astro/hmr.ts index 0b0724bb0..7afd956b0 100644 --- a/packages/astro/src/vite-plugin-astro/hmr.ts +++ b/packages/astro/src/vite-plugin-astro/hmr.ts @@ -79,7 +79,7 @@ export async function handleHotUpdate(ctx: HmrContext, config: AstroConfig, logg invalidateCompilation(config, file); } - const mod = ctx.modules.find(m => m.file === ctx.file); + const mod = ctx.modules.find((m) => m.file === ctx.file); const file = ctx.file.replace(config.projectRoot.pathname, '/'); if (ctx.file.endsWith('.astro')) { ctx.server.ws.send({ type: 'custom', event: 'astro:update', data: { file } }); diff --git a/packages/astro/test/cli.test.js b/packages/astro/test/cli.test.js index ca735c2b9..0072727a2 100644 --- a/packages/astro/test/cli.test.js +++ b/packages/astro/test/cli.test.js @@ -32,7 +32,6 @@ describe('astro cli', () => { expect(messages[0]).to.contain('started in'); }); - const hostnames = [undefined, '0.0.0.0', '127.0.0.1']; hostnames.forEach((hostname) => { @@ -51,10 +50,10 @@ describe('astro cli', () => { const localURL = new URL(local); const networkURL = new URL(network); - expect(localURL.hostname).to.be.equal('localhost', `Expected local URL to be on localhost`) + expect(localURL.hostname).to.be.equal('localhost', `Expected local URL to be on localhost`); // Note: our tests run in parallel so this could be 3000+! - expect(Number.parseInt(localURL.port)).to.be.greaterThanOrEqual(3000, `Expected Port to be >= 3000`) - expect(networkURL.hostname).to.be.equal(hostname ?? '127.0.0.1', `Expected Network URL to use passed hostname`) + expect(Number.parseInt(localURL.port)).to.be.greaterThanOrEqual(3000, `Expected Port to be >= 3000`); + expect(networkURL.hostname).to.be.equal(hostname ?? '127.0.0.1', `Expected Network URL to use passed hostname`); }); }); diff --git a/packages/astro/test/test-utils.js b/packages/astro/test/test-utils.js index fd46e0d70..69fabacda 100644 --- a/packages/astro/test/test-utils.js +++ b/packages/astro/test/test-utils.js @@ -136,7 +136,10 @@ export async function parseCliDevStart(proc) { proc.kill(); stdout = stripAnsi(stdout); - const messages = stdout.split('\n').filter(ln => !!ln.trim()).map(ln => ln.replace(/[🚀┃]/g, '').replace(/\s+/g, ' ').trim()); + const messages = stdout + .split('\n') + .filter((ln) => !!ln.trim()) + .map((ln) => ln.replace(/[🚀┃]/g, '').replace(/\s+/g, ' ').trim()); return { messages }; }