Created
September 3, 2020 14:40
-
-
Save DanielMSchmidt/a1a5e3f753a52e13f53efeac42579461 to your computer and use it in GitHub Desktop.
Generates renovate config to fix @types and package running out of sync
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
// Generates renovate config to fix @types and package running out of sync | |
// See https://github.com/renovatebot/renovate/issues/4893 | |
const path = require("path"); | |
const fs = require("fs"); | |
// This script lies under scripts/update-renovate.js, therefore the .. | |
const renovatePath = path.resolve(__dirname, "../renovate.json"); | |
const renovateConfig = require(renovatePath); | |
// packages relative to root | |
const packages = [ | |
".", | |
"backend", | |
"frontend" | |
]; | |
const detypify = (typedName) => | |
typedName.replace("@types/", "").replace("__", "/"); | |
renovateConfig.packageRules = packages | |
.map((p) => path.resolve(__dirname, "..", p, "package.json")) | |
.map((path) => require(path)) | |
.map((package) => | |
Object.keys(package.dependencies || {}).concat( | |
...Object.keys(package.devDependencies || {}) | |
) | |
) | |
.reduce((acc, cur) => [...acc, ...cur], []) | |
.filter((value, index, self) => self.indexOf(value) === index) | |
.filter((dep) => dep.includes("@types/")) | |
.map((typesPackage) => ({ | |
packagePatterns: [typesPackage, detypify(typesPackage)], | |
groupName: detypify(typesPackage), | |
})); | |
fs.writeFileSync( | |
renovatePath, | |
JSON.stringify(renovateConfig, null, 2), | |
"utf-8" | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment