#!/usr/bin/env ts-node import * as fs from "fs/promises"; import { sync as globSync } from "glob"; import * as yaml from "js-yaml"; import * as path from "path"; /** * @returns a list of file paths for each package in the packages folder, relative to the root. * @example * ``` * ['packages/react-native-callkeep', 'packages/react-native-camera', ...] * ``` */ function getAllPackageJsonFiles(root: string): string[] { const packageJsonFiles = globSync("packages/*/package.json", { cwd: root, }); return packageJsonFiles.map((pkgJsonFilePath) => path.dirname(pkgJsonFilePath) ); } (async () => { const root = path.join(__dirname, "../"); const filePaths = getAllPackageJsonFiles(root); const config: { version: number; updates: { "package-ecosystem": string; directory: string; schedule: { interval?: string; time?: string; timezone?: string }; }[]; } = { version: 2, updates: [], }; for (const filePath of filePaths.sort()) { config.updates.push({ "package-ecosystem": "npm", directory: filePath, // Default for every package is to run at the beginning of every Expo work day. schedule: { interval: "daily", time: "09:00", // Expo is based out of California timezone: "America/Los_Angeles", }, }); } const outputFilePath = path.join(root, ".github/dependabot.yml"); const results = yaml.dump(config); console.log("Results:\n", results); console.log(""); console.log("Writing to:", outputFilePath); await fs.writeFile( outputFilePath, [ "# AUTO GENERATED:", "# This file was generated by running the following in the root directory:", "#", "# yarn update-dependabot-config", "", results, ].join("\n") ); })();