import { resolve } from 'node:path'; import { readSettings, normalizePath } from "../utils/pageContext.js"; import { validatePathSettings } from "../pathOperations/validatePathSettings.js"; import { logData } from "../utils/logData.js"; import { createPrefixLog } from "../utils/prefixLog.js"; import { createLoggedFs } from "../utils/createLoggedFs.js"; /** * Display local settings.json and validation issues. */ export const settings = async (ctx, options) => { const json = ctx.json; const fix = options?.fix ?? false; const cmdLog = createPrefixLog(ctx.cliName, 'settings'); const fs = createLoggedFs(cmdLog, ctx.cwd); const data = await readSettings('.', fs); if (!data) { const message = 'No settings.json found in the current directory'; if (json) { logData({ error: 'not_found', message }, true); process.exitCode = 1; return; } throw new Error(message); } const rootCtx = { reference: 'main', path: data.path, normalizedPath: normalizePath(data.path), serverUrl: '', auth: '', settings: data, dir: '.', absoluteDir: resolve(ctx.cwd), log: cmdLog, prompt: ctx.prompt, forbiddenPaths: [], }; const violations = await validatePathSettings(rootCtx); if (violations.length === 0) { logData({ valid: true }, json); return; } if (fix) { let fixedCount = 0; const unfixed = []; for (const v of violations) { if (v.apply) { await v.apply(); fixedCount++; } else { unfixed.push(v); } } logData({ fixed: `${fixedCount}/${violations.length}`, valid: unfixed.length === 0, violations: unfixed }, json); if (unfixed.length > 0) { process.exitCode = 1; } return; } if (json) { logData({ valid: false, violations }, true); } else { logData({ violations }); } process.exitCode = 1; }; //# sourceMappingURL=settings.js.map