[ci] format

This commit is contained in:
natemoo-re 2022-03-09 23:38:46 +00:00 committed by GitHub Actions
parent e8d4e56803
commit 2acfef741f
7 changed files with 48 additions and 40 deletions

View file

@ -19,30 +19,36 @@ type CLICommand = 'help' | 'version' | 'dev' | 'build' | 'preview' | 'reload' |
/** Display --help flag */ /** Display --help flag */
function printHelp() { function printHelp() {
linebreak() linebreak();
headline('astro', 'Futuristic web development tool.'); headline('astro', 'Futuristic web development tool.');
linebreak() linebreak();
title('Commands'); title('Commands');
table([ table(
['dev', 'Run Astro in development mode.'], [
['build', 'Build a pre-compiled production-ready site.'], ['dev', 'Run Astro in development mode.'],
['preview', 'Preview your build locally before deploying.'], ['build', 'Build a pre-compiled production-ready site.'],
['check', 'Check your project for errors.'], ['preview', 'Preview your build locally before deploying.'],
['--version', 'Show the version number and exit.'], ['check', 'Check your project for errors.'],
['--help', 'Show this help message.'], ['--version', 'Show the version number and exit.'],
], { padding: 28, prefix: ' astro ' }); ['--help', 'Show this help message.'],
linebreak() ],
{ padding: 28, prefix: ' astro ' }
);
linebreak();
title('Flags'); title('Flags');
table([ table(
['--config <path>', 'Specify the path to the Astro config file.'], [
['--project-root <path>', 'Specify the path to the project root folder.'], ['--config <path>', 'Specify the path to the Astro config file.'],
['--no-sitemap', 'Disable sitemap generation (build only).'], ['--project-root <path>', 'Specify the path to the project root folder.'],
['--legacy-build', 'Use the build strategy prior to 0.24.0'], ['--no-sitemap', 'Disable sitemap generation (build only).'],
['--experimental-ssr', 'Enable SSR compilation.'], ['--legacy-build', 'Use the build strategy prior to 0.24.0'],
['--drafts', 'Include markdown draft pages in the build.'], ['--experimental-ssr', 'Enable SSR compilation.'],
['--verbose', 'Enable verbose logging'], ['--drafts', 'Include markdown draft pages in the build.'],
['--silent', 'Disable logging'], ['--verbose', 'Enable verbose logging'],
], { padding: 28, prefix: ' ' }); ['--silent', 'Disable logging'],
],
{ padding: 28, prefix: ' ' }
);
// Logging utils // Logging utils
function linebreak() { function linebreak() {
@ -55,22 +61,22 @@ function printHelp() {
function title(label: string) { function title(label: string) {
console.log(` ${colors.bgWhite(colors.black(` ${label} `))}`); console.log(` ${colors.bgWhite(colors.black(` ${label} `))}`);
} }
function table(rows: [string, string][], opts: { padding: number, prefix: string }) { function table(rows: [string, string][], opts: { padding: number; prefix: string }) {
const split = rows.some(row => { const split = rows.some((row) => {
const message = `${opts.prefix}${' '.repeat(opts.padding)}${row[1]}`; const message = `${opts.prefix}${' '.repeat(opts.padding)}${row[1]}`;
return message.length > process.stdout.columns; return message.length > process.stdout.columns;
}) });
for (const row of rows) { for (const row of rows) {
row.forEach((col, i) => { row.forEach((col, i) => {
if (i === 0) { 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 { } else {
if (split) { if (split) {
process.stdout.write('\n '); process.stdout.write('\n ');
} }
process.stdout.write(colors.dim(col) + '\n') process.stdout.write(colors.dim(col) + '\n');
} }
}) });
} }
return ''; return '';
} }

View file

@ -25,7 +25,7 @@ function getLoggerLocale(): string {
const dt = new Intl.DateTimeFormat(getLoggerLocale(), { const dt = new Intl.DateTimeFormat(getLoggerLocale(), {
hour: '2-digit', hour: '2-digit',
minute: '2-digit', minute: '2-digit',
second: '2-digit' second: '2-digit',
}); });
let lastMessage: string; let lastMessage: string;
@ -74,12 +74,12 @@ export const defaultLogDestination = new Writable({
(dest as typeof process.stdout).moveCursor(0, -1); (dest as typeof process.stdout).moveCursor(0, -1);
} }
} }
message = `${message} ${yellow(`(x${lastMessageCount})`)}` message = `${message} ${yellow(`(x${lastMessageCount})`)}`;
} else { } else {
lastMessage = message; lastMessage = message;
lastMessageCount = 1; lastMessageCount = 1;
} }
dest.write(getPrefix()) dest.write(getPrefix());
dest.write(message); dest.write(message);
dest.write('\n'); dest.write('\n');

View file

@ -54,7 +54,7 @@ export function devStart({
`${dim('┃')} Network ${bold(cyan(toDisplayUrl(networkAddress)))}`, `${dim('┃')} Network ${bold(cyan(toDisplayUrl(networkAddress)))}`,
'', '',
]; ];
return messages.map(msg => ` ${msg}`).join('\n'); return messages.map((msg) => ` ${msg}`).join('\n');
} }
/** Display port in use */ /** Display port in use */

View file

@ -115,7 +115,7 @@ async function handleRequest(
} catch (_err: any) { } catch (_err: any) {
info(logging, 'serve', msg.req({ url: pathname, statusCode: 500 })); info(logging, 'serve', msg.req({ url: pathname, statusCode: 500 }));
const err = createSafeError(_err); const err = createSafeError(_err);
error(logging, 'error', msg.err(err)) error(logging, 'error', msg.err(err));
handle500Response(viteServer, origin, req, res, err); handle500Response(viteServer, origin, req, res, err);
} }
} }

View file

@ -79,7 +79,7 @@ export async function handleHotUpdate(ctx: HmrContext, config: AstroConfig, logg
invalidateCompilation(config, file); 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, '/'); const file = ctx.file.replace(config.projectRoot.pathname, '/');
if (ctx.file.endsWith('.astro')) { if (ctx.file.endsWith('.astro')) {
ctx.server.ws.send({ type: 'custom', event: 'astro:update', data: { file } }); ctx.server.ws.send({ type: 'custom', event: 'astro:update', data: { file } });

View file

@ -32,7 +32,6 @@ describe('astro cli', () => {
expect(messages[0]).to.contain('started in'); expect(messages[0]).to.contain('started in');
}); });
const hostnames = [undefined, '0.0.0.0', '127.0.0.1']; const hostnames = [undefined, '0.0.0.0', '127.0.0.1'];
hostnames.forEach((hostname) => { hostnames.forEach((hostname) => {
@ -51,10 +50,10 @@ describe('astro cli', () => {
const localURL = new URL(local); const localURL = new URL(local);
const networkURL = new URL(network); 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+! // 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(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(networkURL.hostname).to.be.equal(hostname ?? '127.0.0.1', `Expected Network URL to use passed hostname`);
}); });
}); });

View file

@ -136,7 +136,10 @@ export async function parseCliDevStart(proc) {
proc.kill(); proc.kill();
stdout = stripAnsi(stdout); 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 }; return { messages };
} }