0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

[ci] format

This commit is contained in:
natemoo-re 2023-08-31 17:37:00 +00:00 committed by astrobot-houston
parent b21038c193
commit d7579f36d7

View file

@ -1,12 +1,12 @@
/* eslint-disable no-console */ /* eslint-disable no-console */
import type yargs from 'yargs-parser';
import * as colors from 'kleur/colors'; import * as colors from 'kleur/colors';
import { execSync } from 'node:child_process';
import { arch, platform } from 'node:os'; import { arch, platform } from 'node:os';
import prompts from 'prompts'; import prompts from 'prompts';
import type yargs from 'yargs-parser';
import { resolveConfig } from '../../core/config/index.js'; import { resolveConfig } from '../../core/config/index.js';
import { ASTRO_VERSION } from '../../core/constants.js'; import { ASTRO_VERSION } from '../../core/constants.js';
import { flagsToAstroInlineConfig } from '../flags.js'; import { flagsToAstroInlineConfig } from '../flags.js';
import { execSync } from 'node:child_process';
interface InfoOptions { interface InfoOptions {
flags: yargs.Arguments; flags: yargs.Arguments;
@ -18,13 +18,13 @@ export async function printInfo({ flags }: InfoOptions) {
['Node', process.version], ['Node', process.version],
['System', getSystem()], ['System', getSystem()],
['Package Manager', getPackageManager()], ['Package Manager', getPackageManager()],
] ];
const inlineConfig = flagsToAstroInlineConfig(flags); const inlineConfig = flagsToAstroInlineConfig(flags);
try { try {
const { userConfig } = await resolveConfig(inlineConfig, 'info'); const { userConfig } = await resolveConfig(inlineConfig, 'info');
rows.push(['Output', userConfig.output ?? 'static']) rows.push(['Output', userConfig.output ?? 'static']);
rows.push(['Adapter', userConfig.adapter?.name ?? 'none']) rows.push(['Adapter', userConfig.adapter?.name ?? 'none']);
const integrations = (userConfig?.integrations ?? []) const integrations = (userConfig?.integrations ?? [])
.filter(Boolean) .filter(Boolean)
.flat() .flat()
@ -52,13 +52,18 @@ async function copyToClipboard(text: string) {
name: 'shouldCopy', name: 'shouldCopy',
message: 'Copy to clipboard?', message: 'Copy to clipboard?',
initial: true, initial: true,
}) });
if (!shouldCopy) return; if (!shouldCopy) return;
const command = system === 'darwin' ? 'pbcopy' : 'clip'; const command = system === 'darwin' ? 'pbcopy' : 'clip';
try { try {
execSync(`echo ${JSON.stringify(text.trim())} | ${command}`, { encoding: 'utf8', stdio: 'ignore' }); execSync(`echo ${JSON.stringify(text.trim())} | ${command}`, {
encoding: 'utf8',
stdio: 'ignore',
});
} catch (e) { } catch (e) {
console.error(colors.red(`\nSorry, something went wrong!`) + ` Please copy the text above manually.`); console.error(
colors.red(`\nSorry, something went wrong!`) + ` Please copy the text above manually.`
);
} }
} }
@ -66,7 +71,7 @@ const PLATFORM_TO_OS: Partial<Record<ReturnType<typeof platform>, string>> = {
darwin: 'macOS', darwin: 'macOS',
win32: 'Windows', win32: 'Windows',
linux: 'Linux', linux: 'Linux',
} };
function getSystem() { function getSystem() {
const system = PLATFORM_TO_OS[platform()] ?? platform(); const system = PLATFORM_TO_OS[platform()] ?? platform();
@ -75,7 +80,7 @@ function getSystem() {
function getPackageManager() { function getPackageManager() {
if (!process.env.npm_config_user_agent) { if (!process.env.npm_config_user_agent) {
return 'unknown' return 'unknown';
} }
const specifier = process.env.npm_config_user_agent.split(' ')[0]; const specifier = process.env.npm_config_user_agent.split(' ')[0];
const name = specifier.substring(0, specifier.lastIndexOf('/')); const name = specifier.substring(0, specifier.lastIndexOf('/'));
@ -91,7 +96,7 @@ function printRow(label: string, value: string | string[]) {
if (rest.length > 0) { if (rest.length > 0) {
for (const entry of rest) { for (const entry of rest) {
plaintext += `\n${' '.repeat(MAX_PADDING)}${entry}`; plaintext += `\n${' '.repeat(MAX_PADDING)}${entry}`;
richtext += `\n${' '.repeat(MAX_PADDING)}${colors.green(entry)}` richtext += `\n${' '.repeat(MAX_PADDING)}${colors.green(entry)}`;
} }
} }
plaintext += '\n'; plaintext += '\n';