Initial commit

This commit is contained in:
Alejandro Martinez
2026-02-12 02:04:10 +01:00
commit f09af719cf
13433 changed files with 2193445 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
import type { AstroVersionProvider } from '../definitions.js';
export declare class BuildTimeAstroVersionProvider implements AstroVersionProvider {
readonly version: string;
}

View File

@@ -0,0 +1,7 @@
class BuildTimeAstroVersionProvider {
// Injected during the build through esbuild define
version = "5.17.1";
}
export {
BuildTimeAstroVersionProvider
};

View File

@@ -0,0 +1,9 @@
import type { CommandRunner, HelpDisplay } from '../definitions.js';
import type { AnyCommand } from '../domain/command.js';
export declare class CliCommandRunner implements CommandRunner {
#private;
constructor({ helpDisplay, }: {
helpDisplay: HelpDisplay;
});
run<T extends AnyCommand>(command: T, ...args: Parameters<T['run']>): ReturnType<T['run']> | undefined;
}

View File

@@ -0,0 +1,18 @@
class CliCommandRunner {
#helpDisplay;
constructor({
helpDisplay
}) {
this.#helpDisplay = helpDisplay;
}
run(command, ...args) {
if (this.#helpDisplay.shouldFire()) {
this.#helpDisplay.show(command.help);
return;
}
return command.run(...args);
}
}
export {
CliCommandRunner
};

View File

@@ -0,0 +1,15 @@
import type { Logger } from '../../core/logger/core.js';
import type { AstroVersionProvider, HelpDisplay, TextStyler } from '../definitions.js';
import type { HelpPayload } from '../domain/help-payload.js';
import type { Flags } from '../flags.js';
export declare class LoggerHelpDisplay implements HelpDisplay {
#private;
constructor({ logger, textStyler, astroVersionProvider, flags, }: {
logger: Logger;
textStyler: TextStyler;
astroVersionProvider: AstroVersionProvider;
flags: Flags;
});
shouldFire(): boolean;
show({ commandName, description, headline, tables, usage }: HelpPayload): void;
}

View File

@@ -0,0 +1,71 @@
import { formatVersion } from "../utils/format-version.js";
class LoggerHelpDisplay {
#logger;
#textStyler;
#astroVersionProvider;
// TODO: find something better
#flags;
constructor({
logger,
textStyler,
astroVersionProvider,
flags
}) {
this.#logger = logger;
this.#textStyler = textStyler;
this.#astroVersionProvider = astroVersionProvider;
this.#flags = flags;
}
shouldFire() {
return !!(this.#flags.help || this.#flags.h);
}
show({ commandName, description, headline, tables, usage }) {
const linebreak = () => "";
const title = (label) => ` ${this.#textStyler.bgWhite(this.#textStyler.black(` ${label} `))}`;
const table = (rows, { padding }) => {
const split = process.stdout.columns < 60;
let raw = "";
for (const row of rows) {
if (split) {
raw += ` ${row[0]}
`;
} else {
raw += `${`${row[0]}`.padStart(padding)}`;
}
raw += " " + this.#textStyler.dim(row[1]) + "\n";
}
return raw.slice(0, -1);
};
let message = [];
if (headline) {
message.push(
linebreak(),
`${formatVersion({ name: commandName, textStyler: this.#textStyler, astroVersionProvider: this.#astroVersionProvider })} ${headline}`
);
}
if (usage) {
message.push(
linebreak(),
` ${this.#textStyler.green(commandName)} ${this.#textStyler.bold(usage)}`
);
}
if (tables) {
let calculateTablePadding2 = function(rows) {
return rows.reduce((val, [first]) => Math.max(val, first.length), 0) + 2;
};
var calculateTablePadding = calculateTablePadding2;
const tableEntries = Object.entries(tables);
const padding = Math.max(...tableEntries.map(([, rows]) => calculateTablePadding2(rows)));
for (const [tableTitle, tableRows] of tableEntries) {
message.push(linebreak(), title(tableTitle), table(tableRows, { padding }));
}
}
if (description) {
message.push(linebreak(), `${description}`);
}
this.#logger.info("SKIP_FORMAT", message.join("\n") + "\n");
}
}
export {
LoggerHelpDisplay
};

View File

@@ -0,0 +1,9 @@
import type { TextStyler } from '../definitions.js';
export declare class PassthroughTextStyler implements TextStyler {
bgWhite(msg: string): string;
black(msg: string): string;
dim(msg: string): string;
green(msg: string): string;
bold(msg: string): string;
bgGreen(msg: string): string;
}

View File

@@ -0,0 +1,23 @@
class PassthroughTextStyler {
bgWhite(msg) {
return msg;
}
black(msg) {
return msg;
}
dim(msg) {
return msg;
}
green(msg) {
return msg;
}
bold(msg) {
return msg;
}
bgGreen(msg) {
return msg;
}
}
export {
PassthroughTextStyler
};

View File

@@ -0,0 +1,2 @@
import type { TextStyler } from '../definitions.js';
export declare const piccoloreTextStyler: TextStyler;

View File

@@ -0,0 +1,5 @@
import colors from "piccolore";
const piccoloreTextStyler = colors;
export {
piccoloreTextStyler
};

View File

@@ -0,0 +1,6 @@
import type { OperatingSystemProvider } from '../definitions.js';
export declare class ProcessOperatingSystemProvider implements OperatingSystemProvider {
#private;
readonly name: NodeJS.Platform;
readonly displayName: string;
}

View File

@@ -0,0 +1,12 @@
class ProcessOperatingSystemProvider {
#platformToOs = {
darwin: "macOS",
win32: "Windows",
linux: "Linux"
};
name = process.platform;
displayName = `${this.#platformToOs[this.name] ?? this.name} (${process.arch})`;
}
export {
ProcessOperatingSystemProvider
};

View File

@@ -0,0 +1,6 @@
import type { CommandExecutor, CommandExecutorOptions } from '../definitions.js';
export declare class TinyexecCommandExecutor implements CommandExecutor {
execute(command: string, args?: Array<string>, options?: CommandExecutorOptions): Promise<{
stdout: string;
}>;
}

View File

@@ -0,0 +1,34 @@
import { NonZeroExitError, x } from "tinyexec";
class TinyexecCommandExecutor {
async execute(command, args, options) {
const proc = x(command, args, {
throwOnError: true,
nodeOptions: {
cwd: options?.cwd,
env: options?.env,
shell: options?.shell,
stdio: options?.stdio
}
});
if (options?.input) {
proc.process?.stdin?.end(options.input);
}
return await proc.then(
(o) => o,
(e) => {
if (e instanceof NonZeroExitError) {
const fullCommand = args?.length ? `${command} ${args.map((a) => a.includes(" ") ? `"${a}"` : a).join(" ")}` : command;
const message = `The command \`${fullCommand}\` exited with code ${e.exitCode}`;
const newError = new Error(message, e.cause ? { cause: e.cause } : void 0);
newError.stderr = e.output?.stderr;
newError.stdout = e.output?.stdout;
throw newError;
}
throw e;
}
);
}
}
export {
TinyexecCommandExecutor
};