@roots/bud
Version:
Configurable, extensible build tools for modern single and multi-page web applications
92 lines (89 loc) • 3.93 kB
JavaScript
import { __decorate } from "tslib";
import { jsx as _jsx, jsxs as _jsxs } from "@roots/bud-support/jsx-runtime";
/* eslint-disable react/no-unescaped-entities */
import BudCommand from '@roots/bud/cli/commands';
import { LabelBox } from '@roots/bud/cli/components/LabelBox';
import { Extension } from '@roots/bud-framework/extension';
import chalk from '@roots/bud-support/chalk';
import { Command } from '@roots/bud-support/clipanion';
import { bind } from '@roots/bud-support/decorators/bind';
import { Box } from '@roots/bud-support/ink';
import DisplayConfigFiles from '../config/displayConfigFiles.js';
import DisplayEnv from '../env/displayEnv.js';
import { BuildInfo } from './buildInfo.js';
import { Children } from './children.js';
import { Extensions } from './extensions.js';
import { Node } from './node.js';
import { Paths } from './paths.js';
import { Platform } from './platform.js';
import { Server } from './server.js';
import { Validate } from './validate.js';
import { criticalPackages, getPackageResults, Versions } from './versions.js';
/**
* bud doctor command
*/
export default class DoctorCommand extends BudCommand {
/**
* {@link BudCommand.paths}
*/
static paths = [[`doctor`]];
/**
* {@link BudCommand.usage}
*/
static usage = Command.Usage({
category: `debug`,
description: `Check project for common errors`,
details: `\
The \`bud doctor\` command will:
1. validate the \`production\` configuration with \`webpack\`
2. check bud.js related \`dependencies\` and \`devDependencies\` are the version bud.js expects.`,
examples: [
[`Check project for common configuration issues`, `$0 doctor`],
],
});
error;
/**
* Error handler override
*/
async catch(error) {
this.error = error;
}
/**
* Silent flag override
*/
silent = true;
/**
* Execute command
*/
async execute() {
const enabledExtensions = [];
const disabledExtensions = [];
const timer = this.makeTimer();
await this.makeBud();
await this.bud?.build.make().catch(this.catch);
Object.entries(this.bud?.extensions.repository).map(([name, extension]) => {
if (`isEnabled` in extension && extension.isEnabled()) {
return enabledExtensions.push([name, extension]);
}
if (extension instanceof Extension) {
return disabledExtensions.push([name, extension]);
}
if (!(`label` in extension)) {
name = `${name} ${chalk.yellow(`* consider giving this extension a \`label\` to make it easier to identify`)}`;
}
enabledExtensions.push([name, extension]);
});
const packages = await Promise.all(criticalPackages.map(getPackageResults.bind(this.bud)));
this.renderStatic(_jsxs(Box, { flexDirection: "column", gap: 1, marginY: 1, children: [_jsx(BuildInfo, { error: this.error, name: this.bud?.label ?? `bud.js`, time: timer() }), _jsx(Node, {}), _jsx(Platform, {}), _jsx(LabelBox, { flexDirection: "row", label: "Mode", value: this.bud?.mode }), _jsx(Versions, { packages: packages }), _jsx(Paths, { path: this.bud?.path }), _jsx(Children, { compilers: this.bud?.children }), _jsx(DisplayConfigFiles, { bud: this.bud }), _jsx(DisplayEnv, { bud: this.bud }), _jsx(Extensions, { extensions: enabledExtensions, label: "Enabled extensions" }), _jsx(Extensions, { extensions: disabledExtensions, label: "Disabled extensions" }), _jsx(Server, { bud: this.bud }), _jsx(Validate, { config: this.bud?.build.config })] }));
}
makeTimer = () => {
const start = process.hrtime();
return () => {
const end = process.hrtime(start);
return (end[0] + end[1] / 1e9).toFixed(2);
};
};
}
__decorate([
bind
], DoctorCommand.prototype, "catch", null);