feat(cli): Add optional build step to release flow and auto-format npmextra config when registries change

This commit is contained in:
2025-12-14 10:51:16 +00:00
parent ccdca55c9a
commit 7348567a62
6 changed files with 97 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ import * as plugins from './mod.plugins.js';
import { Project } from '../classes.project.js';
import { FormatContext } from './classes.formatcontext.js';
import { FormatPlanner } from './classes.formatplanner.js';
import { BaseFormatter } from './classes.baseformatter.js';
import { logger, setVerboseMode } from '../gitzone.logging.js';
// Import wrapper classes for formatters
@@ -195,3 +196,44 @@ export const handleCleanBackups = async (): Promise<void> => {
'Backup cleaning has been disabled - backup system removed',
);
};
/**
* Run a single formatter by name (for use by other modules)
*/
export const runFormatter = async (
formatterName: string,
options: { silent?: boolean } = {}
): Promise<void> => {
const project = await Project.fromCwd();
const context = new FormatContext();
// Map formatter names to classes
const formatterMap: Record<string, new (ctx: FormatContext, proj: Project) => BaseFormatter> = {
cleanup: CleanupFormatter,
npmextra: NpmextraFormatter,
license: LicenseFormatter,
packagejson: PackageJsonFormatter,
templates: TemplatesFormatter,
gitignore: GitignoreFormatter,
tsconfig: TsconfigFormatter,
prettier: PrettierFormatter,
readme: ReadmeFormatter,
copy: CopyFormatter,
};
const FormatterClass = formatterMap[formatterName];
if (!FormatterClass) {
throw new Error(`Unknown formatter: ${formatterName}`);
}
const formatter = new FormatterClass(context, project);
const changes = await formatter.analyze();
for (const change of changes) {
await formatter.applyChange(change);
}
if (!options.silent) {
logger.log('success', `Formatter '${formatterName}' completed`);
}
};