|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +/* |
| 4 | +usage: `make unbuilt` |
| 5 | +
|
| 6 | +This script builds only those packages that are not already built. |
| 7 | +This is for development when you need for example newly released clients to be built |
| 8 | +but do not need the actual latest build of every single client (slow). |
| 9 | +
|
| 10 | +As for why this is not a shell script, I found the combination of find with exec to be too slow. |
| 11 | + */ |
| 12 | + |
| 13 | +/** |
| 14 | + * For reference, this is the equivalent shell command. |
| 15 | + * @type {string} |
| 16 | + */ |
| 17 | +void `find ./clients/client-*/ -type d -maxdepth 0 -exec test -d "{}/dist-types" \\; -exec sh -c "cd {} && yarn build" \\;`; |
| 18 | + |
| 19 | +const path = require("node:path"); |
| 20 | +const fs = require("node:fs"); |
| 21 | +const { spawnProcess } = require("./utils/spawn-process"); |
| 22 | + |
| 23 | +const root = path.join(__dirname, ".."); |
| 24 | + |
| 25 | +const packageFolders = [ |
| 26 | + ...fs.readdirSync(path.join(root, "lib"), { withFileTypes: true }), |
| 27 | + ...fs.readdirSync(path.join(root, "clients"), { withFileTypes: true }), |
| 28 | + ...fs.readdirSync(path.join(root, "packages"), { withFileTypes: true }), |
| 29 | + ...fs.readdirSync(path.join(root, "private"), { withFileTypes: true }), |
| 30 | +]; |
| 31 | + |
| 32 | +(async () => { |
| 33 | + for (const pkgFolder of packageFolders) { |
| 34 | + const isPackage = fs.existsSync(path.join(pkgFolder.path, pkgFolder.name, "package.json")); |
| 35 | + if (isPackage) { |
| 36 | + const cwd = path.join(pkgFolder.path, pkgFolder.name); |
| 37 | + const isBuilt = fs.existsSync(path.join(cwd, "dist-types")); |
| 38 | + const hasArtifacts = fs.existsSync(path.join(cwd, "tsconfig.json")); |
| 39 | + |
| 40 | + if (!isBuilt && hasArtifacts) { |
| 41 | + console.log("Building", cwd); |
| 42 | + await spawnProcess("yarn", ["build"], { |
| 43 | + cwd, |
| 44 | + }); |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | + console.log("Done."); |
| 49 | +})(); |
0 commit comments