| 1 | import { copyFile, readdir } from "node:fs/promises"; |
| 2 | import path from "node:path"; |
| 3 | |
| 4 | const root = path.resolve(import.meta.dir, ".."); |
| 5 | const packagesDirectory = path.join(root, "packages"); |
| 6 | const thirdPartyPackages: Array<string> = [ |
| 7 | "alchemy", |
| 8 | "frontend-frameworks", |
| 9 | "cloudflare-runtime", |
| 10 | "node-utils", |
| 11 | ]; |
| 12 | const readmePackages: Array<string> = ["alchemy"]; |
| 13 | |
| 14 | const packageNames = await readdir(packagesDirectory, { |
| 15 | withFileTypes: true, |
| 16 | }).then((entries) => |
| 17 | entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name), |
| 18 | ); |
| 19 | |
| 20 | const requestedPackage = process.argv[2]; |
| 21 | const targets = requestedPackage ? [requestedPackage] : packageNames; |
| 22 | |
| 23 | for (const packageName of targets) { |
| 24 | if (!packageNames.includes(packageName)) { |
| 25 | throw new Error(`Unknown package: ${packageName}`); |
| 26 | } |
| 27 | |
| 28 | const packageDirectory = path.join(packagesDirectory, packageName); |
| 29 | await copyFile( |
| 30 | path.join(root, "LICENSE"), |
| 31 | path.join(packageDirectory, "LICENSE"), |
| 32 | ); |
| 33 | await copyFile( |
| 34 | path.join(root, "NOTICE"), |
| 35 | path.join(packageDirectory, "NOTICE"), |
| 36 | ); |
| 37 | |
| 38 | if (thirdPartyPackages.includes(packageName)) { |
| 39 | await copyFile( |
| 40 | path.join(root, "THIRD_PARTY_LICENSES.md"), |
| 41 | path.join(packageDirectory, "THIRD_PARTY_LICENSES.md"), |
| 42 | ); |
| 43 | } |
| 44 | |
| 45 | if (readmePackages.includes(packageName)) { |
| 46 | await copyFile( |
| 47 | path.join(root, "README.md"), |
| 48 | path.join(packageDirectory, "README.md"), |
| 49 | ); |
| 50 | } |
| 51 | } |