[ci] format
This commit is contained in:
parent
e8d4e56803
commit
2acfef741f
7 changed files with 48 additions and 40 deletions
|
@ -19,21 +19,25 @@ 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.'],
|
['dev', 'Run Astro in development mode.'],
|
||||||
['build', 'Build a pre-compiled production-ready site.'],
|
['build', 'Build a pre-compiled production-ready site.'],
|
||||||
['preview', 'Preview your build locally before deploying.'],
|
['preview', 'Preview your build locally before deploying.'],
|
||||||
['check', 'Check your project for errors.'],
|
['check', 'Check your project for errors.'],
|
||||||
['--version', 'Show the version number and exit.'],
|
['--version', 'Show the version number and exit.'],
|
||||||
['--help', 'Show this help message.'],
|
['--help', 'Show this help message.'],
|
||||||
], { padding: 28, prefix: ' astro ' });
|
],
|
||||||
linebreak()
|
{ padding: 28, prefix: ' astro ' }
|
||||||
|
);
|
||||||
|
linebreak();
|
||||||
title('Flags');
|
title('Flags');
|
||||||
table([
|
table(
|
||||||
|
[
|
||||||
['--config <path>', 'Specify the path to the Astro config file.'],
|
['--config <path>', 'Specify the path to the Astro config file.'],
|
||||||
['--project-root <path>', 'Specify the path to the project root folder.'],
|
['--project-root <path>', 'Specify the path to the project root folder.'],
|
||||||
['--no-sitemap', 'Disable sitemap generation (build only).'],
|
['--no-sitemap', 'Disable sitemap generation (build only).'],
|
||||||
|
@ -42,7 +46,9 @@ function printHelp() {
|
||||||
['--drafts', 'Include markdown draft pages in the build.'],
|
['--drafts', 'Include markdown draft pages in the build.'],
|
||||||
['--verbose', 'Enable verbose logging'],
|
['--verbose', 'Enable verbose logging'],
|
||||||
['--silent', 'Disable logging'],
|
['--silent', 'Disable logging'],
|
||||||
], { padding: 28, prefix: ' ' });
|
],
|
||||||
|
{ 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 '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -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');
|
||||||
|
|
||||||
|
|
|
@ -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 */
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 } });
|
||||||
|
|
|
@ -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`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue