@trayai/tray-sync-cli 0.0.1

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 (297) hide show
  1. package/LICENSE.md +182 -0
  2. package/README.md +167 -0
  3. package/dist/api/errors.js +29 -0
  4. package/dist/api/trayClient.js +69 -0
  5. package/dist/cli.js +32 -0
  6. package/dist/commands/auth.js +103 -0
  7. package/dist/commands/env.js +534 -0
  8. package/dist/commands/init.js +115 -0
  9. package/dist/commands/project.js +175 -0
  10. package/dist/commands/promote.js +289 -0
  11. package/dist/commands/pull.js +379 -0
  12. package/dist/commands/status.js +126 -0
  13. package/dist/config/credentials.js +10 -0
  14. package/dist/config/environments.js +10 -0
  15. package/dist/config/io.js +36 -0
  16. package/dist/config/mappings.js +9 -0
  17. package/dist/config/paths.js +33 -0
  18. package/dist/config/projectConfig.js +16 -0
  19. package/dist/config/pullProgress.js +9 -0
  20. package/dist/config/state.js +9 -0
  21. package/dist/config/trayYaml.js +9 -0
  22. package/dist/config/types.js +21 -0
  23. package/dist/config/yaml.js +22 -0
  24. package/dist/lib/authDiscovery.js +76 -0
  25. package/dist/lib/checksum.js +5 -0
  26. package/dist/lib/exportStructure.js +23 -0
  27. package/dist/lib/outputFormat.js +12 -0
  28. package/dist/lib/pathContainment.js +37 -0
  29. package/dist/lib/promoteExecute.js +8 -0
  30. package/dist/lib/promoteReconstruct.js +35 -0
  31. package/dist/lib/promoteReport.js +44 -0
  32. package/dist/lib/promoteTarget.js +129 -0
  33. package/dist/lib/region.js +26 -0
  34. package/dist/lib/regionDisplay.js +11 -0
  35. package/dist/lib/regionParsing.js +12 -0
  36. package/dist/lib/scriptExtraction.js +46 -0
  37. package/dist/lib/slug.js +14 -0
  38. package/dist/lib/tokenResolution.js +19 -0
  39. package/dist/lib/uuid.js +5 -0
  40. package/dist/views/env/env.js +89 -0
  41. package/dist/views/env/shared.js +7 -0
  42. package/dist/views/init/init.js +17 -0
  43. package/dist/views/project/project.js +35 -0
  44. package/dist/views/project/shared.js +4 -0
  45. package/dist/views/promote/promote.js +44 -0
  46. package/dist/views/promote/shared.js +4 -0
  47. package/dist/views/pull/pull.js +31 -0
  48. package/dist/views/pull/shared.js +4 -0
  49. package/dist/views/shared.js +8 -0
  50. package/dist/views/status/shared.js +20 -0
  51. package/dist/views/status/status.js +23 -0
  52. package/node_modules/commander/LICENSE +22 -0
  53. package/node_modules/commander/Readme.md +1172 -0
  54. package/node_modules/commander/index.js +21 -0
  55. package/node_modules/commander/lib/argument.js +147 -0
  56. package/node_modules/commander/lib/command.js +2790 -0
  57. package/node_modules/commander/lib/error.js +36 -0
  58. package/node_modules/commander/lib/help.js +731 -0
  59. package/node_modules/commander/lib/option.js +377 -0
  60. package/node_modules/commander/lib/suggestSimilar.js +99 -0
  61. package/node_modules/commander/package-support.json +19 -0
  62. package/node_modules/commander/package.json +64 -0
  63. package/node_modules/commander/typings/index.d.ts +1113 -0
  64. package/node_modules/yaml/LICENSE +13 -0
  65. package/node_modules/yaml/README.md +172 -0
  66. package/node_modules/yaml/bin.mjs +11 -0
  67. package/node_modules/yaml/browser/dist/compose/compose-collection.js +88 -0
  68. package/node_modules/yaml/browser/dist/compose/compose-doc.js +43 -0
  69. package/node_modules/yaml/browser/dist/compose/compose-node.js +109 -0
  70. package/node_modules/yaml/browser/dist/compose/compose-scalar.js +86 -0
  71. package/node_modules/yaml/browser/dist/compose/composer.js +219 -0
  72. package/node_modules/yaml/browser/dist/compose/resolve-block-map.js +115 -0
  73. package/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +198 -0
  74. package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +49 -0
  75. package/node_modules/yaml/browser/dist/compose/resolve-end.js +37 -0
  76. package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +207 -0
  77. package/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +225 -0
  78. package/node_modules/yaml/browser/dist/compose/resolve-props.js +146 -0
  79. package/node_modules/yaml/browser/dist/compose/util-contains-newline.js +34 -0
  80. package/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +26 -0
  81. package/node_modules/yaml/browser/dist/compose/util-flow-indent-check.js +15 -0
  82. package/node_modules/yaml/browser/dist/compose/util-map-includes.js +13 -0
  83. package/node_modules/yaml/browser/dist/doc/Document.js +335 -0
  84. package/node_modules/yaml/browser/dist/doc/anchors.js +71 -0
  85. package/node_modules/yaml/browser/dist/doc/applyReviver.js +55 -0
  86. package/node_modules/yaml/browser/dist/doc/createNode.js +88 -0
  87. package/node_modules/yaml/browser/dist/doc/directives.js +176 -0
  88. package/node_modules/yaml/browser/dist/errors.js +57 -0
  89. package/node_modules/yaml/browser/dist/index.js +17 -0
  90. package/node_modules/yaml/browser/dist/log.js +11 -0
  91. package/node_modules/yaml/browser/dist/nodes/Alias.js +116 -0
  92. package/node_modules/yaml/browser/dist/nodes/Collection.js +147 -0
  93. package/node_modules/yaml/browser/dist/nodes/Node.js +38 -0
  94. package/node_modules/yaml/browser/dist/nodes/Pair.js +36 -0
  95. package/node_modules/yaml/browser/dist/nodes/Scalar.js +24 -0
  96. package/node_modules/yaml/browser/dist/nodes/YAMLMap.js +144 -0
  97. package/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +113 -0
  98. package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +63 -0
  99. package/node_modules/yaml/browser/dist/nodes/identity.js +36 -0
  100. package/node_modules/yaml/browser/dist/nodes/toJS.js +37 -0
  101. package/node_modules/yaml/browser/dist/parse/cst-scalar.js +214 -0
  102. package/node_modules/yaml/browser/dist/parse/cst-stringify.js +61 -0
  103. package/node_modules/yaml/browser/dist/parse/cst-visit.js +97 -0
  104. package/node_modules/yaml/browser/dist/parse/cst.js +98 -0
  105. package/node_modules/yaml/browser/dist/parse/lexer.js +721 -0
  106. package/node_modules/yaml/browser/dist/parse/line-counter.js +39 -0
  107. package/node_modules/yaml/browser/dist/parse/parser.js +975 -0
  108. package/node_modules/yaml/browser/dist/public-api.js +102 -0
  109. package/node_modules/yaml/browser/dist/schema/Schema.js +37 -0
  110. package/node_modules/yaml/browser/dist/schema/common/map.js +17 -0
  111. package/node_modules/yaml/browser/dist/schema/common/null.js +15 -0
  112. package/node_modules/yaml/browser/dist/schema/common/seq.js +17 -0
  113. package/node_modules/yaml/browser/dist/schema/common/string.js +14 -0
  114. package/node_modules/yaml/browser/dist/schema/core/bool.js +19 -0
  115. package/node_modules/yaml/browser/dist/schema/core/float.js +43 -0
  116. package/node_modules/yaml/browser/dist/schema/core/int.js +38 -0
  117. package/node_modules/yaml/browser/dist/schema/core/schema.js +23 -0
  118. package/node_modules/yaml/browser/dist/schema/json/schema.js +62 -0
  119. package/node_modules/yaml/browser/dist/schema/tags.js +96 -0
  120. package/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js +58 -0
  121. package/node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js +26 -0
  122. package/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +46 -0
  123. package/node_modules/yaml/browser/dist/schema/yaml-1.1/int.js +71 -0
  124. package/node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js +67 -0
  125. package/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +74 -0
  126. package/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +78 -0
  127. package/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js +39 -0
  128. package/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +93 -0
  129. package/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
  130. package/node_modules/yaml/browser/dist/stringify/foldFlowLines.js +146 -0
  131. package/node_modules/yaml/browser/dist/stringify/stringify.js +129 -0
  132. package/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +153 -0
  133. package/node_modules/yaml/browser/dist/stringify/stringifyComment.js +20 -0
  134. package/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +85 -0
  135. package/node_modules/yaml/browser/dist/stringify/stringifyNumber.js +25 -0
  136. package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +150 -0
  137. package/node_modules/yaml/browser/dist/stringify/stringifyString.js +336 -0
  138. package/node_modules/yaml/browser/dist/util.js +11 -0
  139. package/node_modules/yaml/browser/dist/visit.js +233 -0
  140. package/node_modules/yaml/browser/index.js +5 -0
  141. package/node_modules/yaml/browser/package.json +3 -0
  142. package/node_modules/yaml/dist/cli.d.ts +8 -0
  143. package/node_modules/yaml/dist/cli.mjs +201 -0
  144. package/node_modules/yaml/dist/compose/compose-collection.d.ts +11 -0
  145. package/node_modules/yaml/dist/compose/compose-collection.js +90 -0
  146. package/node_modules/yaml/dist/compose/compose-doc.d.ts +7 -0
  147. package/node_modules/yaml/dist/compose/compose-doc.js +45 -0
  148. package/node_modules/yaml/dist/compose/compose-node.d.ts +29 -0
  149. package/node_modules/yaml/dist/compose/compose-node.js +112 -0
  150. package/node_modules/yaml/dist/compose/compose-scalar.d.ts +5 -0
  151. package/node_modules/yaml/dist/compose/compose-scalar.js +88 -0
  152. package/node_modules/yaml/dist/compose/composer.d.ts +63 -0
  153. package/node_modules/yaml/dist/compose/composer.js +224 -0
  154. package/node_modules/yaml/dist/compose/resolve-block-map.d.ts +6 -0
  155. package/node_modules/yaml/dist/compose/resolve-block-map.js +117 -0
  156. package/node_modules/yaml/dist/compose/resolve-block-scalar.d.ts +11 -0
  157. package/node_modules/yaml/dist/compose/resolve-block-scalar.js +200 -0
  158. package/node_modules/yaml/dist/compose/resolve-block-seq.d.ts +6 -0
  159. package/node_modules/yaml/dist/compose/resolve-block-seq.js +51 -0
  160. package/node_modules/yaml/dist/compose/resolve-end.d.ts +6 -0
  161. package/node_modules/yaml/dist/compose/resolve-end.js +39 -0
  162. package/node_modules/yaml/dist/compose/resolve-flow-collection.d.ts +7 -0
  163. package/node_modules/yaml/dist/compose/resolve-flow-collection.js +209 -0
  164. package/node_modules/yaml/dist/compose/resolve-flow-scalar.d.ts +10 -0
  165. package/node_modules/yaml/dist/compose/resolve-flow-scalar.js +227 -0
  166. package/node_modules/yaml/dist/compose/resolve-props.d.ts +23 -0
  167. package/node_modules/yaml/dist/compose/resolve-props.js +148 -0
  168. package/node_modules/yaml/dist/compose/util-contains-newline.d.ts +2 -0
  169. package/node_modules/yaml/dist/compose/util-contains-newline.js +36 -0
  170. package/node_modules/yaml/dist/compose/util-empty-scalar-position.d.ts +2 -0
  171. package/node_modules/yaml/dist/compose/util-empty-scalar-position.js +28 -0
  172. package/node_modules/yaml/dist/compose/util-flow-indent-check.d.ts +3 -0
  173. package/node_modules/yaml/dist/compose/util-flow-indent-check.js +17 -0
  174. package/node_modules/yaml/dist/compose/util-map-includes.d.ts +4 -0
  175. package/node_modules/yaml/dist/compose/util-map-includes.js +15 -0
  176. package/node_modules/yaml/dist/doc/Document.d.ts +141 -0
  177. package/node_modules/yaml/dist/doc/Document.js +337 -0
  178. package/node_modules/yaml/dist/doc/anchors.d.ts +24 -0
  179. package/node_modules/yaml/dist/doc/anchors.js +76 -0
  180. package/node_modules/yaml/dist/doc/applyReviver.d.ts +9 -0
  181. package/node_modules/yaml/dist/doc/applyReviver.js +57 -0
  182. package/node_modules/yaml/dist/doc/createNode.d.ts +17 -0
  183. package/node_modules/yaml/dist/doc/createNode.js +90 -0
  184. package/node_modules/yaml/dist/doc/directives.d.ts +49 -0
  185. package/node_modules/yaml/dist/doc/directives.js +178 -0
  186. package/node_modules/yaml/dist/errors.d.ts +21 -0
  187. package/node_modules/yaml/dist/errors.js +62 -0
  188. package/node_modules/yaml/dist/index.d.ts +25 -0
  189. package/node_modules/yaml/dist/index.js +50 -0
  190. package/node_modules/yaml/dist/log.d.ts +3 -0
  191. package/node_modules/yaml/dist/log.js +19 -0
  192. package/node_modules/yaml/dist/nodes/Alias.d.ts +29 -0
  193. package/node_modules/yaml/dist/nodes/Alias.js +118 -0
  194. package/node_modules/yaml/dist/nodes/Collection.d.ts +73 -0
  195. package/node_modules/yaml/dist/nodes/Collection.js +151 -0
  196. package/node_modules/yaml/dist/nodes/Node.d.ts +53 -0
  197. package/node_modules/yaml/dist/nodes/Node.js +40 -0
  198. package/node_modules/yaml/dist/nodes/Pair.d.ts +22 -0
  199. package/node_modules/yaml/dist/nodes/Pair.js +39 -0
  200. package/node_modules/yaml/dist/nodes/Scalar.d.ts +47 -0
  201. package/node_modules/yaml/dist/nodes/Scalar.js +27 -0
  202. package/node_modules/yaml/dist/nodes/YAMLMap.d.ts +53 -0
  203. package/node_modules/yaml/dist/nodes/YAMLMap.js +147 -0
  204. package/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +60 -0
  205. package/node_modules/yaml/dist/nodes/YAMLSeq.js +115 -0
  206. package/node_modules/yaml/dist/nodes/addPairToJSMap.d.ts +4 -0
  207. package/node_modules/yaml/dist/nodes/addPairToJSMap.js +65 -0
  208. package/node_modules/yaml/dist/nodes/identity.d.ts +23 -0
  209. package/node_modules/yaml/dist/nodes/identity.js +53 -0
  210. package/node_modules/yaml/dist/nodes/toJS.d.ts +29 -0
  211. package/node_modules/yaml/dist/nodes/toJS.js +39 -0
  212. package/node_modules/yaml/dist/options.d.ts +350 -0
  213. package/node_modules/yaml/dist/parse/cst-scalar.d.ts +64 -0
  214. package/node_modules/yaml/dist/parse/cst-scalar.js +218 -0
  215. package/node_modules/yaml/dist/parse/cst-stringify.d.ts +8 -0
  216. package/node_modules/yaml/dist/parse/cst-stringify.js +63 -0
  217. package/node_modules/yaml/dist/parse/cst-visit.d.ts +39 -0
  218. package/node_modules/yaml/dist/parse/cst-visit.js +99 -0
  219. package/node_modules/yaml/dist/parse/cst.d.ts +109 -0
  220. package/node_modules/yaml/dist/parse/cst.js +112 -0
  221. package/node_modules/yaml/dist/parse/lexer.d.ts +87 -0
  222. package/node_modules/yaml/dist/parse/lexer.js +723 -0
  223. package/node_modules/yaml/dist/parse/line-counter.d.ts +22 -0
  224. package/node_modules/yaml/dist/parse/line-counter.js +41 -0
  225. package/node_modules/yaml/dist/parse/parser.d.ts +84 -0
  226. package/node_modules/yaml/dist/parse/parser.js +980 -0
  227. package/node_modules/yaml/dist/public-api.d.ts +44 -0
  228. package/node_modules/yaml/dist/public-api.js +107 -0
  229. package/node_modules/yaml/dist/schema/Schema.d.ts +17 -0
  230. package/node_modules/yaml/dist/schema/Schema.js +39 -0
  231. package/node_modules/yaml/dist/schema/common/map.d.ts +2 -0
  232. package/node_modules/yaml/dist/schema/common/map.js +19 -0
  233. package/node_modules/yaml/dist/schema/common/null.d.ts +4 -0
  234. package/node_modules/yaml/dist/schema/common/null.js +17 -0
  235. package/node_modules/yaml/dist/schema/common/seq.d.ts +2 -0
  236. package/node_modules/yaml/dist/schema/common/seq.js +19 -0
  237. package/node_modules/yaml/dist/schema/common/string.d.ts +2 -0
  238. package/node_modules/yaml/dist/schema/common/string.js +16 -0
  239. package/node_modules/yaml/dist/schema/core/bool.d.ts +4 -0
  240. package/node_modules/yaml/dist/schema/core/bool.js +21 -0
  241. package/node_modules/yaml/dist/schema/core/float.d.ts +4 -0
  242. package/node_modules/yaml/dist/schema/core/float.js +47 -0
  243. package/node_modules/yaml/dist/schema/core/int.d.ts +4 -0
  244. package/node_modules/yaml/dist/schema/core/int.js +42 -0
  245. package/node_modules/yaml/dist/schema/core/schema.d.ts +1 -0
  246. package/node_modules/yaml/dist/schema/core/schema.js +25 -0
  247. package/node_modules/yaml/dist/schema/json/schema.d.ts +2 -0
  248. package/node_modules/yaml/dist/schema/json/schema.js +64 -0
  249. package/node_modules/yaml/dist/schema/json-schema.d.ts +69 -0
  250. package/node_modules/yaml/dist/schema/tags.d.ts +48 -0
  251. package/node_modules/yaml/dist/schema/tags.js +99 -0
  252. package/node_modules/yaml/dist/schema/types.d.ts +92 -0
  253. package/node_modules/yaml/dist/schema/yaml-1.1/binary.d.ts +2 -0
  254. package/node_modules/yaml/dist/schema/yaml-1.1/binary.js +70 -0
  255. package/node_modules/yaml/dist/schema/yaml-1.1/bool.d.ts +7 -0
  256. package/node_modules/yaml/dist/schema/yaml-1.1/bool.js +29 -0
  257. package/node_modules/yaml/dist/schema/yaml-1.1/float.d.ts +4 -0
  258. package/node_modules/yaml/dist/schema/yaml-1.1/float.js +50 -0
  259. package/node_modules/yaml/dist/schema/yaml-1.1/int.d.ts +5 -0
  260. package/node_modules/yaml/dist/schema/yaml-1.1/int.js +76 -0
  261. package/node_modules/yaml/dist/schema/yaml-1.1/merge.d.ts +9 -0
  262. package/node_modules/yaml/dist/schema/yaml-1.1/merge.js +71 -0
  263. package/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +22 -0
  264. package/node_modules/yaml/dist/schema/yaml-1.1/omap.js +77 -0
  265. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.d.ts +10 -0
  266. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +82 -0
  267. package/node_modules/yaml/dist/schema/yaml-1.1/schema.d.ts +1 -0
  268. package/node_modules/yaml/dist/schema/yaml-1.1/schema.js +41 -0
  269. package/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +28 -0
  270. package/node_modules/yaml/dist/schema/yaml-1.1/set.js +96 -0
  271. package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
  272. package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js +105 -0
  273. package/node_modules/yaml/dist/stringify/foldFlowLines.d.ts +34 -0
  274. package/node_modules/yaml/dist/stringify/foldFlowLines.js +151 -0
  275. package/node_modules/yaml/dist/stringify/stringify.d.ts +21 -0
  276. package/node_modules/yaml/dist/stringify/stringify.js +132 -0
  277. package/node_modules/yaml/dist/stringify/stringifyCollection.d.ts +17 -0
  278. package/node_modules/yaml/dist/stringify/stringifyCollection.js +155 -0
  279. package/node_modules/yaml/dist/stringify/stringifyComment.d.ts +10 -0
  280. package/node_modules/yaml/dist/stringify/stringifyComment.js +24 -0
  281. package/node_modules/yaml/dist/stringify/stringifyDocument.d.ts +4 -0
  282. package/node_modules/yaml/dist/stringify/stringifyDocument.js +87 -0
  283. package/node_modules/yaml/dist/stringify/stringifyNumber.d.ts +2 -0
  284. package/node_modules/yaml/dist/stringify/stringifyNumber.js +27 -0
  285. package/node_modules/yaml/dist/stringify/stringifyPair.d.ts +3 -0
  286. package/node_modules/yaml/dist/stringify/stringifyPair.js +152 -0
  287. package/node_modules/yaml/dist/stringify/stringifyString.d.ts +9 -0
  288. package/node_modules/yaml/dist/stringify/stringifyString.js +338 -0
  289. package/node_modules/yaml/dist/test-events.d.ts +4 -0
  290. package/node_modules/yaml/dist/test-events.js +134 -0
  291. package/node_modules/yaml/dist/util.d.ts +16 -0
  292. package/node_modules/yaml/dist/util.js +28 -0
  293. package/node_modules/yaml/dist/visit.d.ts +102 -0
  294. package/node_modules/yaml/dist/visit.js +236 -0
  295. package/node_modules/yaml/package.json +97 -0
  296. package/node_modules/yaml/util.js +2 -0
  297. package/package.json +42 -0
@@ -0,0 +1,175 @@
1
+ import path from "node:path";
2
+ import { readdir as fsReaddir, rm as fsRm } from "node:fs/promises";
3
+ import { Command, InvalidArgumentError } from "commander";
4
+ import { createTrayClientForRegion } from "../api/trayClient.js";
5
+ import { readCredentials } from "../config/credentials.js";
6
+ import { readProjectState } from "../config/state.js";
7
+ import { readTrayYaml, writeTrayYaml } from "../config/trayYaml.js";
8
+ import { Scopes } from "../config/types.js";
9
+ import { resolveToken } from "../lib/tokenResolution.js";
10
+ import { isUuid } from "../lib/uuid.js";
11
+ import { OutputFormats, parseFormat } from "../lib/outputFormat.js";
12
+ import { printAddedProject, printAlreadyTracked, printLastPulled, printNoProjectsTracked, printNotPulledLocally, printNotTracked, printRemovedProject, printTrayYamlNotFound, printValidationSkippedOrFailed, printValidationSucceeded, printWorkspaceScopeDenied, } from "../views/project/project.js";
13
+ import { printProjectListJson } from "../views/project/shared.js";
14
+ function findProjectDir(existingDirs, projectId) {
15
+ return existingDirs.find((name) => name.split("--")[0] === projectId);
16
+ }
17
+ async function requireTrayYaml(deps) {
18
+ const trayYaml = await readTrayYaml(deps.cwd);
19
+ if (!trayYaml) {
20
+ printTrayYamlNotFound(deps.stderr);
21
+ return null;
22
+ }
23
+ return trayYaml;
24
+ }
25
+ function refuseIfWorkspaceScope(trayYaml, stderr) {
26
+ if (trayYaml.scope !== Scopes.WORKSPACE)
27
+ return false;
28
+ printWorkspaceScopeDenied(stderr);
29
+ return true;
30
+ }
31
+ async function listProjectDirs(readdir, projectsRoot) {
32
+ try {
33
+ return await readdir(projectsRoot);
34
+ }
35
+ catch {
36
+ return [];
37
+ }
38
+ }
39
+ export async function runProjectAdd(deps, options) {
40
+ const { cwd, env, createClient, stdout, stderr } = deps;
41
+ const trayYaml = await requireTrayYaml(deps);
42
+ if (!trayYaml)
43
+ return 1;
44
+ if (refuseIfWorkspaceScope(trayYaml, stderr))
45
+ return 1;
46
+ if (trayYaml.projects.includes(options.projectId)) {
47
+ printAlreadyTracked(stdout, options.projectId);
48
+ return 0;
49
+ }
50
+ const credentials = await readCredentials(env);
51
+ try {
52
+ const token = resolveToken({
53
+ tokenFlag: options.token,
54
+ credentials,
55
+ workspaceId: trayYaml.workspace_id,
56
+ env,
57
+ });
58
+ const client = createClient(trayYaml.region, token);
59
+ await client.request("GET", `/v2/projects/${options.projectId}`);
60
+ printValidationSucceeded(stdout, options.projectId);
61
+ }
62
+ catch (err) {
63
+ printValidationSkippedOrFailed(stdout, err.message);
64
+ }
65
+ const projects = [...trayYaml.projects, options.projectId].sort();
66
+ await writeTrayYaml({ ...trayYaml, projects }, cwd);
67
+ printAddedProject(stdout, options.projectId);
68
+ return 0;
69
+ }
70
+ export async function runProjectRemove(deps, options) {
71
+ const { cwd, readdir, rm, stdout, stderr } = deps;
72
+ const trayYaml = await requireTrayYaml(deps);
73
+ if (!trayYaml)
74
+ return 1;
75
+ if (refuseIfWorkspaceScope(trayYaml, stderr))
76
+ return 1;
77
+ if (!trayYaml.projects.includes(options.projectId)) {
78
+ printNotTracked(stdout, options.projectId);
79
+ return 0;
80
+ }
81
+ const projects = trayYaml.projects.filter((id) => id !== options.projectId);
82
+ await writeTrayYaml({ ...trayYaml, projects }, cwd);
83
+ const projectsRoot = path.join(cwd, "projects");
84
+ const existingDirs = await listProjectDirs(readdir, projectsRoot);
85
+ const dirName = findProjectDir(existingDirs, options.projectId);
86
+ if (dirName) {
87
+ await rm(path.join(projectsRoot, dirName));
88
+ }
89
+ printRemovedProject(stdout, options.projectId, Boolean(dirName));
90
+ return 0;
91
+ }
92
+ export async function runProjectList(deps, options) {
93
+ const { cwd, readdir, stdout } = deps;
94
+ const trayYaml = await requireTrayYaml(deps);
95
+ if (!trayYaml)
96
+ return 1;
97
+ const projectsRoot = path.join(cwd, "projects");
98
+ const existingDirs = await listProjectDirs(readdir, projectsRoot);
99
+ if (options.format === OutputFormats.JSON) {
100
+ const rows = [];
101
+ for (const projectId of trayYaml.projects) {
102
+ const dirName = findProjectDir(existingDirs, projectId);
103
+ if (!dirName) {
104
+ rows.push({ project_id: projectId, dir_name: null, last_sync: null });
105
+ continue;
106
+ }
107
+ const state = await readProjectState(path.join(projectsRoot, dirName));
108
+ rows.push({ project_id: projectId, dir_name: dirName, last_sync: state?.last_sync ?? null });
109
+ }
110
+ printProjectListJson(stdout, rows);
111
+ return 0;
112
+ }
113
+ if (trayYaml.projects.length === 0) {
114
+ printNoProjectsTracked(stdout);
115
+ return 0;
116
+ }
117
+ for (const projectId of trayYaml.projects) {
118
+ const dirName = findProjectDir(existingDirs, projectId);
119
+ if (!dirName) {
120
+ printNotPulledLocally(stdout, projectId);
121
+ continue;
122
+ }
123
+ const state = await readProjectState(path.join(projectsRoot, dirName));
124
+ const lastSync = state?.last_sync ?? "never";
125
+ printLastPulled(stdout, dirName, lastSync);
126
+ }
127
+ return 0;
128
+ }
129
+ function parseUuid(value, flagName) {
130
+ if (!isUuid(value)) {
131
+ throw new InvalidArgumentError(`${flagName} must be a UUID`);
132
+ }
133
+ return value;
134
+ }
135
+ function realDeps() {
136
+ return {
137
+ cwd: process.cwd(),
138
+ env: process.env,
139
+ createClient: (region, token) => createTrayClientForRegion(region, token),
140
+ readdir: (dir) => fsReaddir(dir),
141
+ rm: (dir) => fsRm(dir, { recursive: true, force: true }),
142
+ stdout: (line) => console.log(line),
143
+ stderr: (line) => console.error(line),
144
+ };
145
+ }
146
+ export const projectCommand = new Command("project").description("Manage tray.yaml.projects (project scope only for add/remove)");
147
+ projectCommand
148
+ .command("add")
149
+ .description("Track a project (project scope only)")
150
+ .argument("<project-id>", "Tray project UUID", (value) => parseUuid(value, "project-id"))
151
+ .option("-t, --token <token>", "Tray API token, for best-effort validation")
152
+ .action(async (projectId, opts) => {
153
+ const exitCode = await runProjectAdd(realDeps(), {
154
+ projectId,
155
+ token: opts.token,
156
+ });
157
+ process.exitCode = exitCode;
158
+ });
159
+ projectCommand
160
+ .command("remove")
161
+ .description("Untrack a project and delete its local directory (project scope only)")
162
+ .argument("<project-id>", "Tray project UUID", (value) => parseUuid(value, "project-id"))
163
+ .action(async (projectId) => {
164
+ const exitCode = await runProjectRemove(realDeps(), { projectId });
165
+ process.exitCode = exitCode;
166
+ });
167
+ projectCommand
168
+ .command("list")
169
+ .description("List managed projects with directory names and last-pulled timestamps")
170
+ .option("--format <format>", "human or json", parseFormat, OutputFormats.HUMAN)
171
+ .action(async (opts) => {
172
+ const exitCode = await runProjectList(realDeps(), { format: opts.format });
173
+ process.exitCode = exitCode;
174
+ });
175
+ //# sourceMappingURL=project.js.map
@@ -0,0 +1,289 @@
1
+ import path from "node:path";
2
+ import { readdir as fsReaddir, readFile as fsReadFile, rm as fsRm } from "node:fs/promises";
3
+ import { Command, InvalidArgumentError } from "commander";
4
+ import { createTrayClientForRegion } from "../api/trayClient.js";
5
+ import { readCredentials } from "../config/credentials.js";
6
+ import { readEnvironments } from "../config/environments.js";
7
+ import { readProjectMappings } from "../config/mappings.js";
8
+ import { promoteProgressPath } from "../config/paths.js";
9
+ import { readJson, writeJson } from "../config/io.js";
10
+ import { readProjectState } from "../config/state.js";
11
+ import { readTrayYaml } from "../config/trayYaml.js";
12
+ import { resolveContainedSafe } from "../lib/pathContainment.js";
13
+ import { entityDisplayName } from "../lib/exportStructure.js";
14
+ import { importProject, previewImport } from "../lib/promoteExecute.js";
15
+ import { printProjectImportImpact, toProjectImportImpact, } from "../lib/promoteReport.js";
16
+ import { isFullyResolved, resolveProjectRequirements, scaffoldUnresolvedAuthentications, } from "../lib/promoteTarget.js";
17
+ import { resolveToken } from "../lib/tokenResolution.js";
18
+ import { isUuid } from "../lib/uuid.js";
19
+ import { OutputFormats, parseFormat } from "../lib/outputFormat.js";
20
+ import { checkProjectDrift, DriftStatuses } from "./status.js";
21
+ import { printError, printInvalidAuthMappings, printLocalDrift, printMutuallyExclusiveResumeAndProject, printNoTargetProjectMapped, printProjectError, printProjectNoStateFile, printProjectNotPulledLocally, printPromoted, printTargetEnvNotFound, printTrayYamlNotFound, printUnresolvedRequirements, } from "../views/promote/promote.js";
22
+ import { printPromoteResultJson } from "../views/promote/shared.js";
23
+ function findProjectDir(existingDirs, projectId) {
24
+ return existingDirs.find((name) => name.split("--")[0] === projectId);
25
+ }
26
+ function newPromoteProgress(trayYaml, planned) {
27
+ return {
28
+ pull_id: `${trayYaml.workspace_id}-${planned.length}`,
29
+ started_at: new Date().toISOString(),
30
+ workspace_id: trayYaml.workspace_id,
31
+ region: trayYaml.region,
32
+ planned,
33
+ completed: [],
34
+ failed: [],
35
+ };
36
+ }
37
+ export async function runPromote(deps, options) {
38
+ const { cwd, env, createClient, readdir, readFile, readdirRecursive, rm, stdout, stderr } = deps;
39
+ const asJson = options.format === OutputFormats.JSON;
40
+ const promoted = [];
41
+ function fail(error) {
42
+ if (asJson) {
43
+ printPromoteResultJson(stdout, { dry_run: Boolean(options.dryRun), promoted, error });
44
+ }
45
+ return 1;
46
+ }
47
+ if (options.resume && options.projectIds && options.projectIds.length > 0) {
48
+ if (asJson)
49
+ return fail({ reason: "mutually_exclusive_resume_and_project" });
50
+ printMutuallyExclusiveResumeAndProject(stderr);
51
+ return 1;
52
+ }
53
+ const trayYaml = await readTrayYaml(cwd);
54
+ if (!trayYaml) {
55
+ if (asJson)
56
+ return fail({ reason: "tray_yaml_not_found" });
57
+ printTrayYamlNotFound(stderr);
58
+ return 1;
59
+ }
60
+ const environments = await readEnvironments(cwd);
61
+ const targetEnv = environments.environments[options.to];
62
+ if (!targetEnv) {
63
+ if (asJson)
64
+ return fail({ reason: "target_env_not_found", env_name: options.to });
65
+ printTargetEnvNotFound(stderr, options.to);
66
+ return 1;
67
+ }
68
+ const credentials = await readCredentials(env);
69
+ let targetToken;
70
+ try {
71
+ targetToken = resolveToken({
72
+ tokenFlag: options.token,
73
+ credentials,
74
+ workspaceId: targetEnv.workspace_id,
75
+ envName: options.to,
76
+ env,
77
+ });
78
+ }
79
+ catch (err) {
80
+ if (asJson)
81
+ return fail({ reason: "token_resolution_failed", message: err.message });
82
+ printError(stderr, err.message);
83
+ return 1;
84
+ }
85
+ const targetClient = createClient(targetEnv.region, targetToken);
86
+ const targeted = options.projectIds !== undefined && options.projectIds.length > 0;
87
+ let plannedIds = targeted ? options.projectIds : trayYaml.projects;
88
+ let progress;
89
+ if (!options.dryRun) {
90
+ if (options.resume) {
91
+ progress = await readJson(promoteProgressPath(cwd));
92
+ if (progress) {
93
+ plannedIds = progress.planned;
94
+ }
95
+ else {
96
+ progress = newPromoteProgress(trayYaml, plannedIds);
97
+ await writeJson(promoteProgressPath(cwd), progress);
98
+ }
99
+ }
100
+ else {
101
+ progress = newPromoteProgress(trayYaml, plannedIds);
102
+ await writeJson(promoteProgressPath(cwd), progress);
103
+ }
104
+ }
105
+ const alreadyCompleted = new Set(progress?.completed ?? []);
106
+ const projectsRoot = path.join(cwd, "projects");
107
+ let existingDirs;
108
+ try {
109
+ existingDirs = await readdir(projectsRoot);
110
+ }
111
+ catch {
112
+ existingDirs = [];
113
+ }
114
+ for (const projectId of plannedIds) {
115
+ if (alreadyCompleted.has(projectId)) {
116
+ continue;
117
+ }
118
+ const dirName = findProjectDir(existingDirs, projectId);
119
+ if (!dirName) {
120
+ if (asJson)
121
+ return fail({ reason: "project_not_pulled_locally", project_id: projectId });
122
+ printProjectNotPulledLocally(stderr, projectId);
123
+ return 1;
124
+ }
125
+ const projectDirPath = await resolveContainedSafe(projectsRoot, dirName);
126
+ const drift = await checkProjectDrift({ readdirRecursive, readFile }, projectId, projectDirPath);
127
+ if (drift.never_pulled) {
128
+ if (asJson)
129
+ return fail({ reason: "project_no_state_file", project_id: projectId });
130
+ printProjectNoStateFile(stderr, projectId);
131
+ return 1;
132
+ }
133
+ const dirty = drift.drift.filter((d) => d.status !== DriftStatuses.CLEAN);
134
+ if (dirty.length > 0) {
135
+ if (asJson) {
136
+ return fail({ reason: "local_drift", project_id: projectId, dir_name: dirName, drift: dirty });
137
+ }
138
+ printLocalDrift(stderr, projectId, dirName, dirty);
139
+ return 1;
140
+ }
141
+ const state = (await readProjectState(projectDirPath));
142
+ const projectJsonPath = await resolveContainedSafe(projectDirPath, "project.json");
143
+ const project = await readJson(projectJsonPath);
144
+ const sourceProjectName = project ? entityDisplayName(project) : projectId;
145
+ let knownTargetProjectId = (await readProjectMappings(projectDirPath))
146
+ ?.environments[options.to]?.target_project_id;
147
+ try {
148
+ const resolution = await resolveProjectRequirements(targetClient, { readFile }, {
149
+ projectDirPath,
150
+ envName: options.to,
151
+ targetWorkspaceId: targetEnv.workspace_id,
152
+ sourceProjectName,
153
+ state,
154
+ autoCreateProjects: Boolean(options.autoCreateProjects) && !options.dryRun,
155
+ });
156
+ if (resolution.status === "no_target_project_mapped") {
157
+ if (asJson) {
158
+ return fail({
159
+ reason: "no_target_project_mapped",
160
+ project_id: projectId,
161
+ source_project_name: sourceProjectName,
162
+ env_name: options.to,
163
+ mappings_path: resolution.mappingsPath,
164
+ });
165
+ }
166
+ printNoTargetProjectMapped(stderr, sourceProjectName, projectId, options.to, resolution.mappingsPath);
167
+ return 1;
168
+ }
169
+ if (resolution.status === "invalid_auth_mappings") {
170
+ if (asJson) {
171
+ return fail({
172
+ reason: "invalid_auth_mappings",
173
+ project_id: projectId,
174
+ source_project_name: sourceProjectName,
175
+ invalid_auth_mappings: resolution.invalidAuthMappings,
176
+ });
177
+ }
178
+ printInvalidAuthMappings(stderr, projectId, sourceProjectName, resolution.invalidAuthMappings);
179
+ return 1;
180
+ }
181
+ const { targetProjectId, payload, unresolved } = resolution;
182
+ knownTargetProjectId = targetProjectId;
183
+ if (!isFullyResolved(unresolved)) {
184
+ await scaffoldUnresolvedAuthentications(projectDirPath, options.to, unresolved);
185
+ if (asJson) {
186
+ return fail({
187
+ reason: "unresolved_requirements",
188
+ project_id: projectId,
189
+ source_project_name: sourceProjectName,
190
+ env_name: options.to,
191
+ unresolved_authentications: unresolved.unresolvedAuthentications,
192
+ has_new_config_keys: unresolved.hasNewConfigKeys,
193
+ });
194
+ }
195
+ printUnresolvedRequirements(stderr, projectId, sourceProjectName, options.to, unresolved);
196
+ return 1;
197
+ }
198
+ const preview = await previewImport(targetClient, targetProjectId, payload);
199
+ const impact = toProjectImportImpact(sourceProjectName, projectId, preview.projectImpact);
200
+ if (asJson) {
201
+ promoted.push(impact);
202
+ }
203
+ else {
204
+ printProjectImportImpact(stdout, impact);
205
+ }
206
+ if (options.dryRun) {
207
+ continue;
208
+ }
209
+ await importProject(targetClient, targetProjectId, payload);
210
+ if (!asJson) {
211
+ printPromoted(stdout, projectId, sourceProjectName, options.to);
212
+ }
213
+ }
214
+ catch (err) {
215
+ if (asJson) {
216
+ return fail({
217
+ reason: "project_error",
218
+ project_id: projectId,
219
+ source_project_name: sourceProjectName,
220
+ message: err.message,
221
+ target_project_id: knownTargetProjectId,
222
+ });
223
+ }
224
+ printProjectError(stderr, projectId, sourceProjectName, err.message, knownTargetProjectId);
225
+ return 1;
226
+ }
227
+ if (progress) {
228
+ progress = { ...progress, completed: [...progress.completed, projectId] };
229
+ await writeJson(promoteProgressPath(cwd), progress);
230
+ }
231
+ }
232
+ if (progress) {
233
+ await rm(promoteProgressPath(cwd)).catch(() => { });
234
+ }
235
+ if (asJson) {
236
+ printPromoteResultJson(stdout, { dry_run: Boolean(options.dryRun), promoted });
237
+ }
238
+ return 0;
239
+ }
240
+ function parseUuid(value, previous) {
241
+ if (!isUuid(value)) {
242
+ throw new InvalidArgumentError("--project must be a UUID");
243
+ }
244
+ return [...(previous ?? []), value];
245
+ }
246
+ export const promoteCommand = new Command("promote")
247
+ .description("Reconstruct local projects and import them into a target Tray environment")
248
+ .requiredOption("--to <env>", "target environment name (see `tray env list`)")
249
+ .option("-p, --project <id...>", "promote only these project IDs", parseUuid)
250
+ .option("--resume", "resume a previously interrupted promote")
251
+ .option("--dry-run", "report what would change without creating projects or importing")
252
+ .option("--auto-create-projects", "create the target project when no mapping exists yet")
253
+ .option("-t, --token <token>", "Tray API token (used for both source and target)")
254
+ .option("--format <format>", "human or json", parseFormat, OutputFormats.HUMAN)
255
+ .action(async (opts) => {
256
+ const cwd = process.cwd();
257
+ const exitCode = await runPromote({
258
+ cwd,
259
+ env: process.env,
260
+ createClient: (region, token) => createTrayClientForRegion(region, token),
261
+ readdir: (dir) => fsReaddir(dir),
262
+ readFile: (filePath) => fsReadFile(filePath, "utf8"),
263
+ readdirRecursive: (dir) => readdirRecursiveReal(dir),
264
+ rm: (filePath) => fsRm(filePath, { force: true }),
265
+ stdout: (line) => console.log(line),
266
+ stderr: (line) => console.error(line),
267
+ }, {
268
+ to: opts.to,
269
+ token: opts.token,
270
+ projectIds: opts.project,
271
+ resume: Boolean(opts.resume),
272
+ dryRun: Boolean(opts.dryRun),
273
+ autoCreateProjects: Boolean(opts.autoCreateProjects),
274
+ format: opts.format,
275
+ });
276
+ process.exitCode = exitCode;
277
+ });
278
+ async function readdirRecursiveReal(dirPath) {
279
+ try {
280
+ const entries = await fsReaddir(dirPath, { recursive: true, withFileTypes: true });
281
+ return entries
282
+ .filter((entry) => entry.isFile())
283
+ .map((entry) => path.relative(dirPath, path.join(entry.parentPath, entry.name)));
284
+ }
285
+ catch {
286
+ return [];
287
+ }
288
+ }
289
+ //# sourceMappingURL=promote.js.map