aoc-automation
Version:
Advent of Code tool to automate the repetitive parts of AoC.
99 lines (88 loc) • 2.71 kB
JavaScript
import {
saveYearReadme,
readYearReadme,
saveDayReadme,
readDayReadme,
readGlobalReadme,
saveGlobalReadme
} from "../io/readme.js";
import toFixed from "../utils/toFixed.js";
import { stripIndents } from "common-tags";
import { renderGlobalYearInfo } from "../configs/readmeMD.js";
import {
renderYearDayBadges,
renderYearResults
} from "../configs/readmeYearMD.js";
import { readConfig } from "../io/config.js";
const updateReadmes = (currentYear, currentDay) => {
const config = readConfig();
const yearConfig = config.years.find((y) => y.year == Number(currentYear));
updateGlobalReadme(yearConfig);
updateYearReadme(yearConfig);
updateDayReadme(yearConfig, currentDay);
};
const updateGlobalReadme = (config) => {
const globalInfo = renderGlobalYearInfo(config);
const readme = readGlobalReadme().replace(
/<!--SOLUTIONS-->(.|\n|\r)+<!--\/SOLUTIONS-->/,
`<!--SOLUTIONS-->
${(globalInfo == null ? void 0 : globalInfo.badges) ?? ""}
<!--/SOLUTIONS-->`
).replace(
/<!--RESULTS-->(.|\n|\r)+<!--\/RESULTS-->/,
`<!--RESULTS-->
${(globalInfo == null ? void 0 : globalInfo.results) ?? ""}
<!--/RESULTS-->`
);
saveGlobalReadme(readme);
};
const updateYearReadme = (config) => {
const badges = renderYearDayBadges(config);
const results = renderYearResults(config);
const readme = readYearReadme(config.year).replace(
/<!--SOLUTIONS-->(.|\n|\r)+<!--\/SOLUTIONS-->/,
`<!--SOLUTIONS-->
${badges}
<!--/SOLUTIONS-->`
).replace(
/<!--RESULTS-->(.|\n|\r)+<!--\/RESULTS-->/,
`<!--RESULTS-->
${results}
<!--/RESULTS-->`
);
saveYearReadme(config.year, readme);
};
const updateDayReadme = (config, currentDay) => {
config.days.forEach((d, index) => {
if ((currentDay == void 0 || currentDay - 1 == index) && (d.part1.solved || d.part2.solved)) {
const part1 = d.part1;
const part2 = d.part2;
let timeBoth = 0;
if (part1.solved) {
timeBoth += part1.time ?? 0;
}
if (part2.solved) {
timeBoth += part2.time ?? 0;
}
const dayResults = stripIndents`
\`\`\`
Time part 1: ${part1.time !== null && part1.solved ? toFixed(part1.time) + "ms" : "-"}
Time part 2: ${part2.time !== null && part2.solved ? toFixed(part2.time) + "ms" : "-"}
Both parts: ${timeBoth !== 0 ? toFixed(timeBoth) + "ms" : "-"}
\`\`\`
`;
const dayReadme = readDayReadme(config.year, index + 1).replace(
/## Results(.|\n|\r)+## Notes/,
`## Results
${dayResults}
## Notes`
);
saveDayReadme(config.year, index + 1, dayReadme);
}
});
};
var updateReadMe_default = updateReadmes;
export {
updateReadMe_default as default,
updateReadmes
};