Skip to content

Instantly share code, notes, and snippets.

@DanielMSchmidt
Created September 3, 2020 14:40
Show Gist options
  • Save DanielMSchmidt/a1a5e3f753a52e13f53efeac42579461 to your computer and use it in GitHub Desktop.
Save DanielMSchmidt/a1a5e3f753a52e13f53efeac42579461 to your computer and use it in GitHub Desktop.
Generates renovate config to fix @types and package running out of sync
#!/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