@vaharoni/devops 1.0.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (342) hide show
  1. package/README.md +51 -0
  2. package/dist/app-support/crypto/index.d.ts +15 -0
  3. package/dist/app-support/crypto/index.d.ts.map +1 -0
  4. package/dist/app-support/crypto/index.js +30 -0
  5. package/dist/app-support/crypto/internal-token.d.ts +20 -0
  6. package/dist/app-support/crypto/internal-token.d.ts.map +1 -0
  7. package/dist/app-support/crypto/internal-token.js +42 -0
  8. package/dist/app-support/crypto/internal-token.spec.d.ts +2 -0
  9. package/dist/app-support/crypto/internal-token.spec.d.ts.map +1 -0
  10. package/dist/app-support/crypto/internal-token.spec.js +45 -0
  11. package/dist/app-support/crypto/secret.d.ts +3 -0
  12. package/dist/app-support/crypto/secret.d.ts.map +1 -0
  13. package/dist/app-support/crypto/secret.js +12 -0
  14. package/dist/app-support/crypto/secret.spec.d.ts +2 -0
  15. package/dist/app-support/crypto/secret.spec.d.ts.map +1 -0
  16. package/dist/app-support/crypto/secret.spec.js +15 -0
  17. package/dist/app-support/discovery/dev-discovery-loader.d.ts +2 -0
  18. package/dist/app-support/discovery/dev-discovery-loader.d.ts.map +1 -0
  19. package/dist/app-support/discovery/dev-discovery-loader.js +30 -0
  20. package/dist/app-support/discovery/service-endpoint.d.ts +2 -0
  21. package/dist/app-support/discovery/service-endpoint.d.ts.map +1 -0
  22. package/dist/app-support/discovery/service-endpoint.js +10 -0
  23. package/dist/cli/affected.d.ts +11 -0
  24. package/dist/cli/affected.d.ts.map +1 -0
  25. package/dist/cli/affected.js +103 -0
  26. package/dist/cli/common.d.ts +89 -0
  27. package/dist/cli/common.d.ts.map +1 -0
  28. package/dist/cli/common.js +236 -0
  29. package/dist/cli/common.spec.d.ts +2 -0
  30. package/dist/cli/common.spec.d.ts.map +1 -0
  31. package/dist/cli/common.spec.js +64 -0
  32. package/dist/cli/console.d.ts +11 -0
  33. package/dist/cli/console.d.ts.map +1 -0
  34. package/dist/cli/console.js +35 -0
  35. package/dist/cli/constant.d.ts +11 -0
  36. package/dist/cli/constant.d.ts.map +1 -0
  37. package/dist/cli/constant.js +22 -0
  38. package/dist/cli/db.d.ts +11 -0
  39. package/dist/cli/db.d.ts.map +1 -0
  40. package/dist/cli/db.js +119 -0
  41. package/dist/cli/dml.d.ts +11 -0
  42. package/dist/cli/dml.d.ts.map +1 -0
  43. package/dist/cli/dml.js +116 -0
  44. package/dist/cli/env.d.ts +11 -0
  45. package/dist/cli/env.d.ts.map +1 -0
  46. package/dist/cli/env.js +67 -0
  47. package/dist/cli/exec.d.ts +11 -0
  48. package/dist/cli/exec.d.ts.map +1 -0
  49. package/dist/cli/exec.js +50 -0
  50. package/dist/cli/image.d.ts +11 -0
  51. package/dist/cli/image.d.ts.map +1 -0
  52. package/dist/cli/image.js +140 -0
  53. package/dist/cli/init.d.ts +11 -0
  54. package/dist/cli/init.d.ts.map +1 -0
  55. package/dist/cli/init.js +66 -0
  56. package/dist/cli/internal-curl.d.ts +11 -0
  57. package/dist/cli/internal-curl.d.ts.map +1 -0
  58. package/dist/cli/internal-curl.js +43 -0
  59. package/dist/cli/job.d.ts +11 -0
  60. package/dist/cli/job.d.ts.map +1 -0
  61. package/dist/cli/job.js +67 -0
  62. package/dist/cli/jwt.d.ts +11 -0
  63. package/dist/cli/jwt.d.ts.map +1 -0
  64. package/dist/cli/jwt.js +27 -0
  65. package/dist/cli/namespace.d.ts +11 -0
  66. package/dist/cli/namespace.d.ts.map +1 -0
  67. package/dist/cli/namespace.js +70 -0
  68. package/dist/cli/prep-build.d.ts +11 -0
  69. package/dist/cli/prep-build.d.ts.map +1 -0
  70. package/dist/cli/prep-build.js +82 -0
  71. package/dist/cli/prisma.d.ts +11 -0
  72. package/dist/cli/prisma.d.ts.map +1 -0
  73. package/dist/cli/prisma.js +25 -0
  74. package/dist/cli/redis.d.ts +11 -0
  75. package/dist/cli/redis.d.ts.map +1 -0
  76. package/dist/cli/redis.js +76 -0
  77. package/dist/cli/registry.d.ts +11 -0
  78. package/dist/cli/registry.d.ts.map +1 -0
  79. package/dist/cli/registry.js +58 -0
  80. package/dist/cli/run-many.d.ts +11 -0
  81. package/dist/cli/run-many.d.ts.map +1 -0
  82. package/dist/cli/run-many.js +50 -0
  83. package/dist/cli/run.d.ts +11 -0
  84. package/dist/cli/run.d.ts.map +1 -0
  85. package/dist/cli/run.js +37 -0
  86. package/dist/cli/template.d.ts +11 -0
  87. package/dist/cli/template.d.ts.map +1 -0
  88. package/dist/cli/template.js +123 -0
  89. package/dist/cli/test.d.ts +11 -0
  90. package/dist/cli/test.d.ts.map +1 -0
  91. package/dist/cli/test.js +28 -0
  92. package/dist/devops.d.ts +3 -0
  93. package/dist/devops.d.ts.map +1 -0
  94. package/dist/devops.js +103 -0
  95. package/dist/index.d.ts +4 -0
  96. package/dist/index.d.ts.map +1 -0
  97. package/dist/index.js +3 -0
  98. package/dist/libs/affected-entities.d.ts +15 -0
  99. package/dist/libs/affected-entities.d.ts.map +1 -0
  100. package/dist/libs/affected-entities.js +52 -0
  101. package/dist/libs/config.d.ts +6 -0
  102. package/dist/libs/config.d.ts.map +1 -0
  103. package/dist/libs/config.js +98 -0
  104. package/dist/libs/dependencies.d.ts +19 -0
  105. package/dist/libs/dependencies.d.ts.map +1 -0
  106. package/dist/libs/dependencies.js +62 -0
  107. package/dist/libs/dependencies.spec.d.ts +2 -0
  108. package/dist/libs/dependencies.spec.d.ts.map +1 -0
  109. package/dist/libs/dependencies.spec.js +21 -0
  110. package/dist/libs/digital-ocean/container-reg.d.ts +6 -0
  111. package/dist/libs/digital-ocean/container-reg.d.ts.map +1 -0
  112. package/dist/libs/digital-ocean/container-reg.js +69 -0
  113. package/dist/libs/discovery/dependencies.d.ts +19 -0
  114. package/dist/libs/discovery/dependencies.d.ts.map +1 -0
  115. package/dist/libs/discovery/dependencies.js +62 -0
  116. package/dist/libs/discovery/dependencies.spec.d.ts +2 -0
  117. package/dist/libs/discovery/dependencies.spec.d.ts.map +1 -0
  118. package/dist/libs/discovery/dependencies.spec.js +21 -0
  119. package/dist/libs/discovery/images.d.ts +5 -0
  120. package/dist/libs/discovery/images.d.ts.map +1 -0
  121. package/dist/libs/discovery/images.js +45 -0
  122. package/dist/libs/discovery/index.d.ts +5 -0
  123. package/dist/libs/discovery/index.d.ts.map +1 -0
  124. package/dist/libs/discovery/index.js +55 -0
  125. package/dist/libs/discovery/package-json-processor.d.ts +3 -0
  126. package/dist/libs/discovery/package-json-processor.d.ts.map +1 -0
  127. package/dist/libs/discovery/package-json-processor.js +34 -0
  128. package/dist/libs/discovery/process-common.d.ts +25 -0
  129. package/dist/libs/discovery/process-common.d.ts.map +1 -0
  130. package/dist/libs/discovery/process-common.js +40 -0
  131. package/dist/libs/discovery/process-package-json.d.ts +3 -0
  132. package/dist/libs/discovery/process-package-json.d.ts.map +1 -0
  133. package/dist/libs/discovery/process-package-json.js +34 -0
  134. package/dist/libs/discovery/process-pyproject-toml.d.ts +3 -0
  135. package/dist/libs/discovery/process-pyproject-toml.d.ts.map +1 -0
  136. package/dist/libs/discovery/process-pyproject-toml.js +36 -0
  137. package/dist/libs/discovery/pyproject-toml-processor.d.ts +3 -0
  138. package/dist/libs/discovery/pyproject-toml-processor.d.ts.map +1 -0
  139. package/dist/libs/discovery/pyproject-toml-processor.js +39 -0
  140. package/dist/libs/git-helpers.d.ts +8 -0
  141. package/dist/libs/git-helpers.d.ts.map +1 -0
  142. package/dist/libs/git-helpers.js +20 -0
  143. package/dist/libs/hetzner/reg-secret.d.ts +3 -0
  144. package/dist/libs/hetzner/reg-secret.d.ts.map +1 -0
  145. package/dist/libs/hetzner/reg-secret.js +39 -0
  146. package/dist/libs/k8s-constants.d.ts +12 -0
  147. package/dist/libs/k8s-constants.d.ts.map +1 -0
  148. package/dist/libs/k8s-constants.js +66 -0
  149. package/dist/libs/k8s-db.d.ts +18 -0
  150. package/dist/libs/k8s-db.d.ts.map +1 -0
  151. package/dist/libs/k8s-db.js +73 -0
  152. package/dist/libs/k8s-generate.d.ts +17 -0
  153. package/dist/libs/k8s-generate.d.ts.map +1 -0
  154. package/dist/libs/k8s-generate.js +179 -0
  155. package/dist/libs/k8s-helpers.d.ts +11 -0
  156. package/dist/libs/k8s-helpers.d.ts.map +1 -0
  157. package/dist/libs/k8s-helpers.js +42 -0
  158. package/dist/libs/k8s-image-config.d.ts +8 -0
  159. package/dist/libs/k8s-image-config.d.ts.map +1 -0
  160. package/dist/libs/k8s-image-config.js +113 -0
  161. package/dist/libs/k8s-job-waiter.d.ts +8 -0
  162. package/dist/libs/k8s-job-waiter.d.ts.map +1 -0
  163. package/dist/libs/k8s-job-waiter.js +84 -0
  164. package/dist/libs/k8s-namespace.d.ts +7 -0
  165. package/dist/libs/k8s-namespace.d.ts.map +1 -0
  166. package/dist/libs/k8s-namespace.js +27 -0
  167. package/dist/libs/k8s-redis.d.ts +6 -0
  168. package/dist/libs/k8s-redis.d.ts.map +1 -0
  169. package/dist/libs/k8s-redis.js +31 -0
  170. package/dist/libs/k8s-secrets-manager.d.ts +5 -0
  171. package/dist/libs/k8s-secrets-manager.d.ts.map +1 -0
  172. package/dist/libs/k8s-secrets-manager.js +61 -0
  173. package/dist/libs/validate-env.d.ts +56 -0
  174. package/dist/libs/validate-env.d.ts.map +1 -0
  175. package/dist/libs/validate-env.js +214 -0
  176. package/dist/libs/validate-env.spec.d.ts +2 -0
  177. package/dist/libs/validate-env.spec.d.ts.map +1 -0
  178. package/dist/libs/validate-env.spec.js +168 -0
  179. package/dist/libs/workspace-discovery.d.ts +2 -0
  180. package/dist/libs/workspace-discovery.d.ts.map +1 -0
  181. package/dist/libs/workspace-discovery.js +75 -0
  182. package/dist/test.d.ts +2 -0
  183. package/dist/test.d.ts.map +1 -0
  184. package/dist/test.js +1 -0
  185. package/dist/types/index.d.ts +925 -0
  186. package/dist/types/index.d.ts.map +1 -0
  187. package/dist/types/index.js +79 -0
  188. package/package.json +55 -0
  189. package/src/app-support/crypto/index.ts +31 -0
  190. package/src/app-support/crypto/internal-token.spec.ts +53 -0
  191. package/src/app-support/crypto/internal-token.ts +82 -0
  192. package/src/app-support/crypto/secret.spec.ts +18 -0
  193. package/src/app-support/crypto/secret.ts +13 -0
  194. package/src/app-support/discovery/dev-discovery-loader.ts +35 -0
  195. package/src/app-support/discovery/service-endpoint.ts +12 -0
  196. package/src/cli/affected.ts +116 -0
  197. package/src/cli/common.spec.ts +78 -0
  198. package/src/cli/common.ts +323 -0
  199. package/src/cli/console.ts +46 -0
  200. package/src/cli/constant.ts +25 -0
  201. package/src/cli/db.ts +133 -0
  202. package/src/cli/dml.ts +126 -0
  203. package/src/cli/env.ts +87 -0
  204. package/src/cli/exec.sh +21 -0
  205. package/src/cli/exec.ts +57 -0
  206. package/src/cli/image.ts +197 -0
  207. package/src/cli/init.ts +75 -0
  208. package/src/cli/internal-curl.ts +48 -0
  209. package/src/cli/job.ts +80 -0
  210. package/src/cli/jwt.ts +32 -0
  211. package/src/cli/namespace.ts +78 -0
  212. package/src/cli/prep-build.ts +96 -0
  213. package/src/cli/prisma.ts +33 -0
  214. package/src/cli/redis.ts +83 -0
  215. package/src/cli/registry.ts +76 -0
  216. package/src/cli/run-many.ts +61 -0
  217. package/src/cli/run.ts +46 -0
  218. package/src/cli/template.ts +169 -0
  219. package/src/cli/test.ts +30 -0
  220. package/src/devops.ts +119 -0
  221. package/src/index.ts +3 -0
  222. package/src/libs/affected-entities.ts +71 -0
  223. package/src/libs/config.ts +117 -0
  224. package/src/libs/digital-ocean/container-reg.ts +81 -0
  225. package/src/libs/discovery/dependencies.spec.ts +25 -0
  226. package/src/libs/discovery/dependencies.ts +73 -0
  227. package/src/libs/discovery/images.ts +57 -0
  228. package/src/libs/discovery/index.ts +60 -0
  229. package/src/libs/discovery/process-common.ts +55 -0
  230. package/src/libs/discovery/process-package-json.ts +47 -0
  231. package/src/libs/discovery/process-pyproject-toml.ts +43 -0
  232. package/src/libs/git-helpers.ts +32 -0
  233. package/src/libs/hetzner/reg-secret.ts +54 -0
  234. package/src/libs/k8s-constants.ts +83 -0
  235. package/src/libs/k8s-db.ts +83 -0
  236. package/src/libs/k8s-generate.ts +211 -0
  237. package/src/libs/k8s-helpers.ts +59 -0
  238. package/src/libs/k8s-image-config.ts +165 -0
  239. package/src/libs/k8s-job-waiter.ts +124 -0
  240. package/src/libs/k8s-namespace.ts +41 -0
  241. package/src/libs/k8s-redis.ts +31 -0
  242. package/src/libs/k8s-secrets-manager.ts +79 -0
  243. package/src/libs/validate-env.spec.ts +223 -0
  244. package/src/libs/validate-env.ts +266 -0
  245. package/src/target-templates/.devops/config/constants.yaml +17 -0
  246. package/src/target-templates/.devops/config/images.yaml +88 -0
  247. package/src/target-templates/.devops/docker-images/common/docker-common.sh +23 -0
  248. package/src/target-templates/.devops/docker-images/node-services/node-exec.sh +8 -0
  249. package/src/target-templates/.devops/docker-images/node-services/node-run.sh +8 -0
  250. package/src/target-templates/.devops/docker-images/node-services.Dockerfile +34 -0
  251. package/src/target-templates/.devops/docker-images/python-services/python-exec.sh +8 -0
  252. package/src/target-templates/.devops/docker-images/python-services/python-run.sh +8 -0
  253. package/src/target-templates/.devops/docker-images/python-services.Dockerfile +29 -0
  254. package/src/target-templates/.devops/env.example.yaml +23 -0
  255. package/src/target-templates/.devops/infra/hetzner/abandoned/harbor-values.yaml +30 -0
  256. package/src/target-templates/.devops/infra/hetzner/abandoned/hcloud-config.yaml +134 -0
  257. package/src/target-templates/.devops/infra/hetzner/cert-manager.yaml +25 -0
  258. package/src/target-templates/.devops/infra/hetzner/harbor-cert.yaml +13 -0
  259. package/src/target-templates/.devops/infra/hetzner/harbor-values.yaml +76 -0
  260. package/src/target-templates/.devops/infra/hetzner/hcloud-config.yaml +113 -0
  261. package/src/target-templates/.devops/infra/hetzner/ingress-nginx-annotations.yaml +49 -0
  262. package/src/target-templates/.devops/infra/hetzner/ingress-nginx-configmap.yaml +8 -0
  263. package/src/target-templates/.devops/infra/hetzner/retain-storage-class.yaml +8 -0
  264. package/src/target-templates/.devops/infra/monitoring-ingress.yaml +62 -0
  265. package/src/target-templates/.devops/infra/stackgres-ui-ingress.yaml +35 -0
  266. package/src/target-templates/.devops/infra/test.yaml +60 -0
  267. package/src/target-templates/.devops/manifests/_index.yaml +21 -0
  268. package/src/target-templates/.devops/manifests/cron-jobs.yaml.hb +55 -0
  269. package/src/target-templates/.devops/manifests/db-migrate-job.yaml.hb +42 -0
  270. package/src/target-templates/.devops/manifests/deployment-debug.yaml.hb +44 -0
  271. package/src/target-templates/.devops/manifests/deployment-process.yaml.hb +47 -0
  272. package/src/target-templates/.devops/manifests/deployment-web.yaml.hb +53 -0
  273. package/src/target-templates/.devops/manifests/ingress.yaml.hb +21 -0
  274. package/src/target-templates/.devops/manifests/prefect.yaml.hb +62 -0
  275. package/src/target-templates/.devops/manifests/service.yaml.hb +15 -0
  276. package/src/target-templates/.devops/milvus/production/milvus-values.yaml +2 -0
  277. package/src/target-templates/.devops/milvus/staging/milvus-values.yaml +2 -0
  278. package/src/target-templates/.devops/postgres/DailyOperatorRestart.yaml +54 -0
  279. package/src/target-templates/.devops/postgres/production/cluster/PodDisruptionBudget.yaml +27 -0
  280. package/src/target-templates/.devops/postgres/production/cluster/SGCluster.yaml +47 -0
  281. package/src/target-templates/.devops/postgres/production/cluster/StackGres-alerts.yaml +191 -0
  282. package/src/target-templates/.devops/postgres/production/configurations/06-SGDistributedLogs.yaml +11 -0
  283. package/src/target-templates/.devops/postgres/production/configurations/07-SGObjectStorage.yaml +18 -0
  284. package/src/target-templates/.devops/postgres/production/configurations/08-SGScript.yaml +12 -0
  285. package/src/target-templates/.devops/postgres/staging/cluster/SGCluster.yaml +42 -0
  286. package/src/target-templates/.devops/postgres/staging/configurations/07-SGObjectStorage.yaml +18 -0
  287. package/src/target-templates/.devops/postgres/staging/configurations/08-SGScript.yaml +12 -0
  288. package/src/target-templates/.devops/prefect/production/prefect-values.yaml +14 -0
  289. package/src/target-templates/.devops/prefect/staging/prefect-values.yaml +14 -0
  290. package/src/target-templates/.devops/redis/production/redis-values.yaml +20 -0
  291. package/src/target-templates/.devops/redis/staging/redis-values.yaml +8 -0
  292. package/src/target-templates/.envrc +5 -0
  293. package/src/target-templates/.github/actions/build-image@v1/action.yaml +86 -0
  294. package/src/target-templates/.github/actions/connect-to-digital-ocean@v1/action.yaml +29 -0
  295. package/src/target-templates/.github/actions/connect-to-hetzner@v1/action.yaml +31 -0
  296. package/src/target-templates/.github/actions/connect-to-infra@v1/action.yaml +46 -0
  297. package/src/target-templates/.github/actions/db-migrate@v1/action.yaml +23 -0
  298. package/src/target-templates/.github/actions/deploy-image@v1/action.yaml +33 -0
  299. package/src/target-templates/.github/actions/setup-prereq@v1/action.yaml +29 -0
  300. package/src/target-templates/.github/workflows/k8s-build.yaml +84 -0
  301. package/src/target-templates/applications/example-data-pipeline/pyproject.toml +14 -0
  302. package/src/target-templates/applications/example-data-pipeline/src/example_data_pipeline/main.py +38 -0
  303. package/src/target-templates/applications/example-node/index.ts +30 -0
  304. package/src/target-templates/applications/example-node/package.json +26 -0
  305. package/src/target-templates/applications/example-node/tsconfig.json +3 -0
  306. package/src/target-templates/applications/example-python/pyproject.toml +20 -0
  307. package/src/target-templates/applications/example-python/src/example_python/__init__.py +0 -0
  308. package/src/target-templates/applications/example-python/src/example_python/main.py +13 -0
  309. package/src/target-templates/applications/example-python/src/example_python/scripts.py +17 -0
  310. package/src/target-templates/applications/example-python/tests/__init__.py +0 -0
  311. package/src/target-templates/applications/jobs/README.md +68 -0
  312. package/src/target-templates/applications/jobs/index.ts +1 -0
  313. package/src/target-templates/applications/jobs/package.json +30 -0
  314. package/src/target-templates/applications/jobs/tsconfig.json +3 -0
  315. package/src/target-templates/config/.env.development +1 -0
  316. package/src/target-templates/config/.env.global +4 -0
  317. package/src/target-templates/config/.env.test +1 -0
  318. package/src/target-templates/db/db/__init__.py +0 -0
  319. package/src/target-templates/db/db/db_client_test.py +46 -0
  320. package/src/target-templates/db/db-client-test.ts +140 -0
  321. package/src/target-templates/db/db-client.ts +19 -0
  322. package/src/target-templates/db/env.yaml +4 -0
  323. package/src/target-templates/db/package.json +17 -0
  324. package/src/target-templates/db/prisma/schema.prisma +24 -0
  325. package/src/target-templates/db/prisma-setup-vitest.ts +27 -0
  326. package/src/target-templates/db/pyproject.toml +14 -0
  327. package/src/target-templates/db/tsconfig.json +3 -0
  328. package/src/target-templates/devops +3 -0
  329. package/src/target-templates/devopspy +3 -0
  330. package/src/target-templates/dml/package.json +7 -0
  331. package/src/target-templates/dml/tsconfig.json +3 -0
  332. package/src/target-templates/libs/example-node-lib/bun.lock +27 -0
  333. package/src/target-templates/libs/example-node-lib/index.ts +3 -0
  334. package/src/target-templates/libs/example-node-lib/package.json +12 -0
  335. package/src/target-templates/libs/example-node-lib/tsconfig.json +3 -0
  336. package/src/target-templates/libs/example-python-lib/pyproject.toml +11 -0
  337. package/src/target-templates/libs/example-python-lib/src/example_python_lib/__init__.py +2 -0
  338. package/src/target-templates/pyproject.toml +19 -0
  339. package/src/target-templates/tmp/.gitkeep +0 -0
  340. package/src/target-templates/tsconfig.json +27 -0
  341. package/src/test.ts +0 -0
  342. package/src/types/index.ts +173 -0
package/src/devops.ts ADDED
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env bun
2
+ // This file behaves as a façade for various devops scripts
3
+ import { CLICommandParser, printUsageAndExit } from "./cli/common";
4
+ import affected from "./cli/affected";
5
+ import constant from "./cli/constant";
6
+ import console from "./cli/console";
7
+ import db from "./cli/db";
8
+ import dml from "./cli/dml";
9
+ import registry from "./cli/registry";
10
+ import env from "./cli/env";
11
+ import exec from "./cli/exec";
12
+ import prepBuild from "./cli/prep-build";
13
+ import prisma from "./cli/prisma";
14
+ import run from "./cli/run";
15
+ import runMany from "./cli/run-many";
16
+ import test from "./cli/test";
17
+ import init from "./cli/init";
18
+ import redis from "./cli/redis";
19
+ import internalCurl from "./cli/internal-curl";
20
+ import jwt from "./cli/jwt";
21
+ import namespace from "./cli/namespace";
22
+ import image from "./cli/image";
23
+ import template from "./cli/template";
24
+ import job from "./cli/job";
25
+
26
+ const [_node, _scriptPath, ...commandArgs] = process.argv;
27
+
28
+ const allImports = [
29
+ // day-to-day
30
+ init,
31
+ run,
32
+ runMany,
33
+ exec,
34
+ env,
35
+ prisma,
36
+ dml,
37
+ db,
38
+ redis,
39
+ console,
40
+ test,
41
+ //= Infra
42
+ namespace,
43
+ image,
44
+ template,
45
+ job,
46
+ //= Deployment
47
+ prepBuild,
48
+ affected,
49
+ constant,
50
+ registry,
51
+ internalCurl,
52
+ jwt
53
+ ];
54
+
55
+ const commands: {
56
+ [key: string]: {
57
+ oneLiner: string;
58
+ keyExamples: string;
59
+ run: CallableFunction;
60
+ key: string;
61
+ };
62
+ } = {};
63
+ allImports.forEach((imported) => {
64
+ Object.entries(imported).forEach(([key, object]) => {
65
+ const { oneLiner, keyExamples, run } = object;
66
+ commands[key] = { oneLiner, keyExamples, run, key };
67
+ });
68
+ });
69
+
70
+ const keyLength = Math.max(...Object.keys(commands).map((x) => x.length)) + 10;
71
+ const newLine = "\n ";
72
+
73
+ const GENERAL_USAGE = `
74
+ Devops utilities for the monorepo.
75
+
76
+ USAGE
77
+ devops <command> <args> <env-options>
78
+
79
+ CHOOSING ENV with <env-options>
80
+ By default, all commands run under the env specified in MONOREPO_ENV env variable, or development if it does not exist.
81
+ The test command is an exception: its environment is forced to test.
82
+ When running in development, the env files config/.env.development and config/.env.global are injected, where the
83
+ former overrides the latter.
84
+
85
+ To override the environment in which a command is executed in, use --env <some-env>. This overrides the MONOREPO_ENV variable.
86
+ You can use it anywhere in the command, i.e. the following are equivalent:
87
+ $ devops --env staging run project:task
88
+ $ devops run project:task --env staging
89
+
90
+ Supported environments: development, staging, test, and production.
91
+
92
+ Certain commands like run, exec, and prisma ensure that the env variables exist and correspond to env.yaml files in the repo.
93
+ To skip this check, use --skip-env-check.
94
+
95
+
96
+ COMMANDS
97
+ ${Object.values(commands)
98
+ .map((cmd) =>
99
+ [cmd.key, " ".repeat(keyLength - cmd.key.length), cmd.oneLiner].join("")
100
+ )
101
+ .join(newLine)}
102
+ `;
103
+
104
+ // EXAMPLES
105
+ // ${Object.values(commands)
106
+ // .map((cmd) =>
107
+ // cmd.keyExamples
108
+ // .split("\n")
109
+ // .map((x) => x.trim())
110
+ // .filter(Boolean)
111
+ // .join(newLine)
112
+ // )
113
+ // .join(newLine)}
114
+
115
+ const commandObj = new CLICommandParser(commandArgs,);
116
+ const chosenCommand = commands[commandObj.command];
117
+ if (!chosenCommand) printUsageAndExit(GENERAL_USAGE);
118
+
119
+ chosenCommand.run(commandObj);
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./types/index";
2
+ export * from "./app-support/discovery/service-endpoint";
3
+ export * from "./app-support/crypto";
@@ -0,0 +1,71 @@
1
+ import { getImageNames } from "./config";
2
+ import { getWorkspace } from "./discovery";
3
+ import { getImageDescendentData, getWorkspaceImages } from "./discovery/images";
4
+ import { commitExists, isAffected } from "./git-helpers";
5
+ import { getImageVersion } from "./k8s-image-config";
6
+
7
+ type AffectedOpts = {
8
+ baseSha?: string;
9
+ headSha?: string;
10
+ fromLiveVersion?: boolean;
11
+ monorepoEnv?: string;
12
+ };
13
+
14
+ export function isImageAffected(image: string, opts: AffectedOpts = {}) {
15
+ const headSha = opts.headSha ?? "HEAD";
16
+ let baseSha;
17
+ if (opts.fromLiveVersion) {
18
+ if (!opts.monorepoEnv) {
19
+ throw new Error("monorepoEnv is required when fromLiveVersion is true");
20
+ }
21
+ baseSha = getImageVersion(opts.monorepoEnv, image);
22
+ if (!baseSha) return true;
23
+ }
24
+ baseSha ??= opts.baseSha ?? "HEAD^";
25
+ const descendentData = getImageDescendentData(image);
26
+ if (!commitExists(baseSha) || !commitExists(headSha)) return true;
27
+
28
+ for (const { rootPath } of descendentData) {
29
+ if (isAffected(rootPath, { baseSha, headSha, skipCheck: true })) {
30
+ return true;
31
+ }
32
+ }
33
+ return false;
34
+ }
35
+
36
+ export function findImagesAffected(opts: AffectedOpts = {}) {
37
+ return getImageNames().filter((imageName) =>
38
+ isImageAffected(imageName, opts)
39
+ );
40
+ }
41
+
42
+ export function isWorkspaceAffected(
43
+ workspaceName: string,
44
+ opts: { baseSha?: string; headSha?: string } = {}
45
+ ) {
46
+ const data = getWorkspace(workspaceName);
47
+ return isAffected(data.rootPath, opts);
48
+ }
49
+
50
+ export function findImagesWithAffectedWorkspace(
51
+ workspaceName: string,
52
+ opts: AffectedOpts = {}
53
+ ) {
54
+ const res = []
55
+ const headSha = opts.headSha ?? "HEAD";
56
+ const defaultBaseSha = opts.baseSha ?? "HEAD^";
57
+ const rootPath = getWorkspace(workspaceName).rootPath;
58
+ if (opts.fromLiveVersion && !opts.monorepoEnv) {
59
+ throw new Error("monorepoEnv is required when fromLiveVersion is true");
60
+ }
61
+ for (const imageName of getWorkspaceImages(workspaceName)) {
62
+ const baseSha = opts.fromLiveVersion
63
+ ? getImageVersion(opts.monorepoEnv!, imageName)
64
+ : defaultBaseSha;
65
+
66
+ if (isAffected(rootPath, { baseSha, headSha })) {
67
+ res.push(imageName);
68
+ }
69
+ }
70
+ return res;
71
+ }
@@ -0,0 +1,117 @@
1
+ import { readFileSync } from "fs";
2
+ import yaml from "yaml";
3
+ import path from "path";
4
+ import { getWorkspace } from "./discovery";
5
+ import { constFileSchema, imageFileSchema, type ConstFileSchema, type ImageFileSchema, type SingleImageSchema, type SingleTemplateSchema } from "../types";
6
+
7
+ const constantsFilePath = path.join(process.cwd(), ".devops/config/constants.yaml");
8
+ const imagesFilePath = path.join(process.cwd(), ".devops/config/images.yaml");
9
+
10
+ // We want these to be lazy loaded so that calling devops in a context that does not need the config files won't fail
11
+ export const { getConst } = processConstFile();
12
+ export const { getImageData, getImageNames, getTemplateData } = processImagesFile();
13
+
14
+ // Process config/constants.yaml
15
+
16
+ function processConstFile() {
17
+ let constants: { valid: boolean, data?: ConstFileSchema };
18
+ function constFileData() {
19
+ if (constants) return constants;
20
+ try {
21
+ const constantsYaml = readFileSync(constantsFilePath, "utf8");
22
+ constants = yaml.parse(constantsYaml);
23
+ } catch (e) {
24
+ // This is only a warning - the file may not exist, which is fine if getConst is called with ignoreIfInvalid
25
+ console.warn("Warning: cannot read .devops/config/constants.yaml");
26
+ return { valid: false };
27
+ }
28
+ const parseRes = constFileSchema.safeParse(constants);
29
+ if (parseRes.error) {
30
+ // This is an error - if the file exists, it must be valid
31
+ console.error(`Error parsing config/constants.yaml: ${parseRes.error.toString()}`);
32
+ process.exit(1);
33
+ }
34
+ constants = { valid: true, data: parseRes.data };
35
+ return constants;
36
+ }
37
+
38
+ function getConst<T extends keyof ConstFileSchema>(key: T, opts: { ignoreIfInvalid?: boolean } = {}): ConstFileSchema[T] | undefined {
39
+ const { valid, data } = constFileData();
40
+ if (!valid && !opts.ignoreIfInvalid) {
41
+ console.error(".devops/config/constants.yaml is invalid");
42
+ process.exit(1);
43
+ }
44
+ const value = data?.[key];
45
+ if (!value && !opts.ignoreIfInvalid) {
46
+ console.error(`Missing constant in .devops/config/constants.yaml: ${key}`);
47
+ process.exit(1);
48
+ }
49
+ return value;
50
+ }
51
+
52
+ return { getConst };
53
+ }
54
+
55
+ // Process config/images.yaml
56
+
57
+ function processImagesFile() {
58
+ let images: ImageFileSchema;
59
+ function imagesFileData() {
60
+ if (images) return images;
61
+ try {
62
+ const imagesYaml = readFileSync(imagesFilePath, "utf8");
63
+ images = yaml.parse(imagesYaml);
64
+ } catch (e) {
65
+ console.error("Error reading .devops/config/images.yaml");
66
+ process.exit(1);
67
+ }
68
+ const parseRes = imageFileSchema.safeParse(images);
69
+ if (parseRes.error) {
70
+ console.error(
71
+ `Error parsing config/images.yaml: ${parseRes.error.toString()}`
72
+ );
73
+ process.exit(1);
74
+ }
75
+ return images;
76
+ }
77
+
78
+ function getImageData(imageName: string): SingleImageSchema {
79
+ const imageData = imagesFileData()['images'][imageName];
80
+ if (!imageData) {
81
+ console.error(
82
+ `Image ${imageName} not found in .devops/config/images.yaml`
83
+ );
84
+ process.exit(1);
85
+ }
86
+
87
+ imageData.applications.forEach((project: string) => {
88
+ const data = getWorkspace(project);
89
+ if (!data) {
90
+ console.error(
91
+ `Project ${project} not found for image ${imageName} in .devops/config/images.yaml`
92
+ );
93
+ process.exit(1);
94
+ }
95
+ });
96
+
97
+ return imageData;
98
+ }
99
+
100
+ function getTemplateData(templateName: string): SingleTemplateSchema {
101
+ const templateData = imagesFileData()['templates'][templateName];
102
+ if (!templateData) {
103
+ console.error(
104
+ `Template ${templateName} not found in .devops/config/images.yaml`
105
+ );
106
+ process.exit(1);
107
+ }
108
+
109
+ return templateData;
110
+ }
111
+
112
+ function getImageNames() {
113
+ return Object.keys(imagesFileData()["images"]);
114
+ }
115
+
116
+ return { getImageData, getImageNames, getTemplateData };
117
+ }
@@ -0,0 +1,81 @@
1
+ import { CommandExecutor } from "../../cli/common";
2
+ import { z } from "zod";
3
+ import { getConst } from "../config";
4
+
5
+ const repoTagMetadataSchema = z.object({
6
+ // What we rely on
7
+ tag: z.string().optional(),
8
+ updated_at: z.string(),
9
+ manifest_digest: z.string(),
10
+ // Other fields that existed in the output
11
+ // registry_name: z.string().optional(),
12
+ // repository: z.string().optional(),
13
+ // compressed_size_bytes: z.number().optional(),
14
+ // size_bytes: z.number().optional(),
15
+ });
16
+ const repoTagMetadataSchemaOutput = z.array(repoTagMetadataSchema);
17
+
18
+ type RepoTagMetadata = z.infer<typeof repoTagMetadataSchema>;
19
+
20
+ /** The metadata is returned in descending order (most recent first) */
21
+ function getRepoTagMetadata(repoName: string): RepoTagMetadata[] {
22
+ // Get the metadata for the tags in the repository
23
+ const cmd = `doctl registry repository list-tags ${repoName} -o json`;
24
+ const res = new CommandExecutor(cmd, { quiet: true }).exec();
25
+ if (!res) return [];
26
+ try {
27
+ const parsed = JSON.parse(res);
28
+ const parseRes = repoTagMetadataSchemaOutput.safeParse(parsed);
29
+ if (parseRes.error) {
30
+ console.error(
31
+ `Error schema-parsing output from "${cmd}": ${parseRes.error.toString()}`
32
+ );
33
+ console.error(">>> Command output");
34
+ console.error(res);
35
+ process.exit(1);
36
+ }
37
+ return parseRes.data
38
+ .filter((data) => data.tag)
39
+ .sort(
40
+ (a, b) =>
41
+ new Date(b.updated_at).getTime() - new Date(a.updated_at).getTime()
42
+ );
43
+ } catch (e) {
44
+ console.error(`Error JSON-parsing output from "${cmd}": ${res}`);
45
+ process.exit(1);
46
+ }
47
+ }
48
+
49
+ function deleteRepoTag(repoName: string, tag: string) {
50
+ const cmd = `doctl registry repository delete-tag ${repoName} ${tag} --force`;
51
+ new CommandExecutor(cmd).exec();
52
+ }
53
+
54
+ function stargGarbageCollection(registryName: string) {
55
+ const cmd = `doctl registry garbage-collection start --include-untagged-manifests ${registryName} --force`;
56
+ new CommandExecutor(cmd).exec();
57
+ }
58
+
59
+ export function prune(
60
+ /** To keep the image-related constants simple, this accepts the full URL including the prefix registry.digitalocean.com */
61
+ registryFullName: string,
62
+ /** The name of the repository inside the registry */
63
+ repoName: string
64
+ ) {
65
+ const infra = getConst("infra");
66
+ if (infra !== "digitalocean") {
67
+ console.warn(
68
+ "Pruning is only supported for the DigitalOcean container registry"
69
+ );
70
+ return;
71
+ }
72
+ const tags = getRepoTagMetadata(repoName);
73
+ const versionsToKeep = Number(getConst("image-versions-to-keep"));
74
+ if (!tags.length || tags.length <= versionsToKeep) return;
75
+ const tagsToDelete = tags.slice(versionsToKeep);
76
+ tagsToDelete.forEach((tag) => {
77
+ deleteRepoTag(repoName, tag.tag!);
78
+ });
79
+ const registryName = registryFullName.split("/").slice(-1)[0];
80
+ stargGarbageCollection(registryName);
81
+ }
@@ -0,0 +1,25 @@
1
+
2
+ import { describe, it, expect } from 'vitest';
3
+ import { WorkspaceDependencies } from './dependencies';
4
+
5
+ describe('createDependencyResolver', () => {
6
+ const projects = {
7
+ '@local/a': { language: "node" as const, rootPath: 'applications/a', name: '@local/a', dependencyNames: ['@local/b', '@local/d', 'external1'] },
8
+ '@local/b': { language: "node" as const, rootPath: 'applications/b', name: '@local/b', dependencyNames: ['@local/c', 'external2'] },
9
+ '@local/c': { language: "node" as const, rootPath: 'applications/c', name: '@local/c', dependencyNames: [ 'external3' ] },
10
+ '@local/d': { language: "node" as const, rootPath: 'applications/d', name: '@local/d', dependencyNames: [] },
11
+ '@local/e': { language: "node" as const, rootPath: 'applications/e', name: '@local/e', dependencyNames: ['@local/f'] },
12
+ '@local/f': { language: "node" as const, rootPath: 'applications/f', name: '@local/f', dependencyNames: ['@local/e'] }
13
+ };
14
+
15
+ it('should return dependents of a given project', () => {
16
+ const resolver = new WorkspaceDependencies(() => projects);
17
+
18
+ expect(resolver.getDependents('@local/a')).toEqual(['@local/a', '@local/b', '@local/c', '@local/d']);
19
+ expect(resolver.getDependents('@local/b')).toEqual(['@local/b', '@local/c']);
20
+ expect(resolver.getDependents('@local/c')).toEqual(['@local/c']);
21
+ expect(resolver.getDependents('@local/d')).toEqual(['@local/d']);
22
+ expect(resolver.getDependents('@local/e')).toEqual(['@local/e', '@local/f']);
23
+ expect(resolver.getDependents('@local/f')).toEqual(['@local/f', '@local/e']);
24
+ });
25
+ });
@@ -0,0 +1,73 @@
1
+ import chalk from "chalk";
2
+ import type { PackageData } from "../../types";
3
+
4
+ export class WorkspaceDependencies {
5
+ dependencies: Record<string, DependencyNode> = {};
6
+ loaded = false;
7
+ workspaces: Record<string, PackageData> = {};
8
+
9
+ constructor(public getAllProjects: () => Record<string, PackageData>) {}
10
+
11
+ _getOrCreate(name: string) {
12
+ let node = this.dependencies[name];
13
+ if (!node) {
14
+ node = new DependencyNode(name);
15
+ this.dependencies[name] = node;
16
+ }
17
+ return node;
18
+ }
19
+
20
+ _buildTree() {
21
+ this.workspaces = this.getAllProjects();
22
+ this.loaded = true;
23
+ for (const workspace of Object.keys(this.workspaces)) {
24
+ const node = this._getOrCreate(workspace);
25
+ const data = this.workspaces[workspace];
26
+ for (const dep of data.dependencyNames ?? []) {
27
+ if (this.workspaces[dep]) {
28
+ node.dependsOn.add(dep);
29
+ }
30
+ }
31
+ }
32
+ }
33
+
34
+ getDependents(workspaceName: string) {
35
+ if (!this.loaded) {
36
+ this._buildTree();
37
+ }
38
+ const node = this.dependencies[workspaceName];
39
+ if (!node) {
40
+ console.error(chalk.red(`\nWorkspace ${workspaceName} not found\n`));
41
+ process.exit(1);
42
+ }
43
+ return node.flattenDependents(this.dependencies);
44
+ }
45
+ }
46
+
47
+ class DependencyNode {
48
+ name: string;
49
+ dependsOn: Set<string>;
50
+
51
+ constructor(name: string) {
52
+ this.name = name;
53
+ this.dependsOn = new Set();
54
+ }
55
+
56
+ flattenDependents(
57
+ allDependencies: Record<string, DependencyNode>,
58
+ visited?: Set<string>
59
+ ) {
60
+ visited ??= new Set();
61
+ visited.add(this.name);
62
+ const notVisitedDependents: string[] = [];
63
+ for (const dep of this.dependsOn) {
64
+ if (!visited.has(dep)) {
65
+ const node = allDependencies[dep];
66
+ notVisitedDependents.push(
67
+ ...node.flattenDependents(allDependencies, visited)
68
+ );
69
+ }
70
+ }
71
+ return [this.name, ...notVisitedDependents];
72
+ }
73
+ }
@@ -0,0 +1,57 @@
1
+ import { getWorkspace, workspaceDirectoryForLanguage } from ".";
2
+ import type { PackageData } from "../../types";
3
+ import { getImageData, getImageNames } from "../config";
4
+ import { WorkspaceDependencies } from "./dependencies";
5
+
6
+ // = From images to workspaces
7
+
8
+ const _imageDescendents: Record<string, PackageData[]> = {};
9
+ let _imageDescendentsLoaded = false;
10
+
11
+ function imageDescendents() {
12
+ if (!_imageDescendentsLoaded) {
13
+ for (const imageName of getImageNames()) {
14
+ const descendents = new Set<string>();
15
+ const imageData = getImageData(imageName);
16
+ const workspaces = workspaceDirectoryForLanguage(imageData.language);
17
+ const dependencyResolver = new WorkspaceDependencies(() => workspaces)
18
+ imageData.applications.forEach((workspace) => {
19
+ dependencyResolver.getDependents(workspace).forEach((name) => descendents.add(name));
20
+ });
21
+ _imageDescendents[imageName] = Array.from(descendents).map(name => workspaces[name]);
22
+ }
23
+ _imageDescendentsLoaded = true;
24
+ }
25
+ return _imageDescendents;
26
+ }
27
+
28
+ /** The dependent workspaces are specified in config/images.yaml */
29
+ export function getImageDescendentData(imageName: string) {
30
+ return (
31
+ imageDescendents()[imageName] ?? []
32
+ );
33
+ }
34
+
35
+ // = From workspace to images
36
+
37
+ const _workspaceImages: Record<string, string[]> = {};
38
+ let _workspaceImagesLoaded = false;
39
+
40
+ function workspaceImages() {
41
+ if (!_workspaceImagesLoaded) {
42
+ for (const [imageName, descendents] of Object.entries(imageDescendents())) {
43
+ for (const packageData of descendents) {
44
+ _workspaceImages[packageData.name] ??= [];
45
+ _workspaceImages[packageData.name].push(imageName);
46
+ }
47
+ }
48
+ _workspaceImagesLoaded = true;
49
+ }
50
+ return _workspaceImages;
51
+ }
52
+
53
+
54
+ export function getWorkspaceImages(workspaceName: string) {
55
+ const _verifyPresence = getWorkspace(workspaceName);
56
+ return workspaceImages()[workspaceName] ?? [];
57
+ }
@@ -0,0 +1,60 @@
1
+ import chalk from "chalk";
2
+ import { nodeWorkspaces } from "./process-package-json";
3
+ import { pythonWorkspaces } from "./process-pyproject-toml";
4
+ import type { SupportedLanguages, WorkspaceIndex } from "../../types";
5
+
6
+ const _workspaces: WorkspaceIndex = {};
7
+ let _workspacesLoaded = false;
8
+
9
+ export function workspaces() {
10
+ if (_workspacesLoaded) return _workspaces;
11
+ const nodeWorkspacesData = nodeWorkspaces();
12
+ const pythonWorkspacesData = pythonWorkspaces();
13
+
14
+ Object.values(nodeWorkspacesData).forEach(data => {
15
+ _workspaces[data.name] = {
16
+ rootPath: data.rootPath,
17
+ packageDataEntries: [data]
18
+ };
19
+ })
20
+
21
+ Object.values(pythonWorkspacesData).forEach(data => {
22
+ const existing = _workspaces[data.name];
23
+ if (existing) {
24
+ if (existing.rootPath !== data.rootPath) {
25
+ // prettier-ignore
26
+ console.error(chalk.red(`\nWorkspace ${data.name} has conflicting root paths:\n\t${existing.rootPath}\n\t${data.rootPath}\n`));
27
+ process.exit(1);
28
+ }
29
+ } else {
30
+ _workspaces[data.name] = {
31
+ rootPath: data.rootPath,
32
+ packageDataEntries: []
33
+ };
34
+ }
35
+ _workspaces[data.name].packageDataEntries.push(data);
36
+ })
37
+ _workspacesLoaded = true;
38
+ return _workspaces;
39
+ }
40
+
41
+ export function workspaceDirectoryForLanguage(language: SupportedLanguages) {
42
+ switch (language) {
43
+ case "node":
44
+ return nodeWorkspaces();
45
+ case "python":
46
+ return pythonWorkspaces();
47
+ default:
48
+ throw new Error(`Unsupported language: ${language}`);
49
+ }
50
+ }
51
+
52
+ export function getWorkspace(workspaceName: string) {
53
+ const workspace = workspaces()[workspaceName];
54
+ if (!workspace) {
55
+ console.error(chalk.red(`\nWorkspace ${workspaceName} not found\n`));
56
+ // The gha relies on the 13 exit code for "not found"
57
+ process.exit(13);
58
+ }
59
+ return workspace;
60
+ }
@@ -0,0 +1,55 @@
1
+ import type { ZodSchema } from "zod";
2
+ import type { PackageData, SupportedLanguages } from "../../types";
3
+ import fs from "fs";
4
+ import path from "path"
5
+
6
+ export const IGNORED_PATHS = ["node_modules/", "venv/"];
7
+
8
+ type PackageDataProcessorConfig<T> = {
9
+ language: SupportedLanguages;
10
+ pathList: string[];
11
+ zodSchema: ZodSchema<T>;
12
+ fileParser: (fileStringData: string) => unknown;
13
+ nameExtractor: (data: T) => string;
14
+ }
15
+
16
+ export class PackageDataProcessor<T> {
17
+ workspaceNames: Set<string> = new Set();
18
+ loadedFiles: Record<string, { name: string, data: T }> = {};
19
+ language: SupportedLanguages;
20
+ nameExtractor: (data: T) => string;
21
+
22
+ constructor(config: PackageDataProcessorConfig<T>) {
23
+ this.language = config.language;
24
+ this.nameExtractor = config.nameExtractor;
25
+ this._runFirstPass(config.pathList, config.zodSchema, config.fileParser);
26
+ }
27
+
28
+ _runFirstPass(pathList: string[], zodSchema: ZodSchema<T>, fileParser: (fileStringData: string) => unknown) {
29
+ pathList.forEach((packageFilePath) => {
30
+ if (IGNORED_PATHS.find(path => packageFilePath.includes(path))) return;
31
+ const unsafeData = fileParser(fs.readFileSync(packageFilePath, "utf8"));
32
+ const parsedRes = zodSchema.safeParse(unsafeData);
33
+ if (parsedRes.error) {
34
+ console.error(`Error parsing ${packageFilePath}: ${parsedRes.error}`);
35
+ process.exit(1);
36
+ }
37
+ const rootDir = path.dirname(packageFilePath);
38
+ const name = this.nameExtractor(parsedRes.data)
39
+ this.workspaceNames.add(name);
40
+ this.loadedFiles[rootDir] = { name, data: parsedRes.data };
41
+ });
42
+ }
43
+
44
+ // Should be used by the iterator sent to convert in order to filter out dependencies that are not workspaces
45
+ filterDependencies(dependencyNames: string[]) {
46
+ return dependencyNames.filter((name) => this.workspaceNames.has(name));
47
+ }
48
+
49
+ convert(iterator: (data: T) => Omit<PackageData, 'rootPath' | 'language' | 'name'>): PackageData[] {
50
+ return Object.entries(this.loadedFiles).map(([rootPath, { name, data }]) => {
51
+ const res = iterator(data);
52
+ return { rootPath, language: this.language, name, ...res };
53
+ })
54
+ }
55
+ }