UNPKG

@softwareventures/maintain-project

Version:

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

36 lines 2.37 kB
import { concatMapFn, filterFn, isArray, mapFn, only } from "@softwareventures/array"; import { intersects } from "semver"; import { chain } from "@softwareventures/chain"; import { mapNullFn } from "@softwareventures/nullable"; import { readProjectJson } from "../project/read-json.js"; import { allAsyncResults, bindFailureFn, failure, mapResultFn, success } from "../result/result.js"; import { readProjectYaml } from "../project/read-yaml.js"; import { nodeReleasesSupportedInDateRange } from "./releases-supported-in-date-range.js"; export async function readNodeVersions(project, today) { const currentReleases = nodeReleasesSupportedInDateRange({ start: today, end: today }); const targetVersions = readProjectJson(project, "package.json") // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access .then(mapResultFn(packageJson => packageJson?.engines?.node)) .then(mapResultFn(versions => typeof versions === "string" ? extractMajorNodeVersions(versions, today) : null)) .then(bindFailureFn(reasons => only(reasons)?.type === "file-not-found" ? success(null) : failure(reasons))) .then(mapResultFn(mapNullFn(() => nodeReleasesSupportedInDateRange({ end: today })))); const testedVersions = readProjectYaml(project, ".github/workflows/ci.yml") .then(mapResultFn(workflow => // FIXME // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access workflow?.jobs?.["build-and-test"]?.strategy?.matrix?.["node-version"])) .then(mapResultFn(versions => (typeof versions === "string" ? [versions] : versions))) .then(mapResultFn(versions => (isArray(versions) ? versions : []))) .then(mapResultFn(mapFn(String))) .then(mapResultFn(concatMapFn(version => extractMajorNodeVersions(version, today)))) .then(bindFailureFn(reasons => only(reasons)?.type === "file-not-found" ? success([]) : failure(reasons))); return allAsyncResults([targetVersions, testedVersions]).then(mapResultFn(([targetVersions, testedVersions]) => ({ targetVersions, testedVersions, currentReleases }))); } function extractMajorNodeVersions(versions, today) { return chain(nodeReleasesSupportedInDateRange({ end: today })).map(filterFn(release => intersects(`^${release}`, versions))).value; } //# sourceMappingURL=read.js.map