UNPKG

@softwareventures/maintain-project

Version:

Automatically create and maintain TypeScript projects with standard settings for Software Ventures Limited

21 lines 1.15 kB
import { resolve } from "path"; import { mapFn } from "@softwareventures/array"; import { combineAsyncResults, mapFailureFn, success } from "../result/result.js"; import { yarn } from "../yarn/yarn.js"; import { readProjectScript } from "../npm/read-script.js"; import { isPrettierProject } from "./is-prettier-project.js"; export async function prettierFixFiles(project, relativePaths) { return Promise.resolve(relativePaths) .then(mapFn(async (path) => yarn(project, "prettier", "--write", path).then(mapFailureFn(() => ({ type: "prettier-fix-failed", path: resolve(project.path, path) }))))) .then(combineAsyncResults); } export async function prettierFixFilesIfAvailable(project, relativePaths) { return canYarnRunPrettier(project).then(async (available) => available ? prettierFixFiles(project, relativePaths) : success()); } async function canYarnRunPrettier(project) { return Promise.all([isPrettierProject(project), readProjectScript(project, "prettier")]).then(([hasDependency, script]) => hasDependency && (script == null || script.trim() === "prettier")); } //# sourceMappingURL=fix.js.map