@powerhousedao/codegen 5.1.0 → 5.2.0-staging.2

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 (260) hide show
  1. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/error.esm.t +3 -3
  2. package/dist/src/codegen/.hygen/templates/powerhouse/generate-editor/index.js +1 -3
  3. package/dist/src/codegen/.hygen/templates/powerhouse/generate-subgraph/lib.esm.t +9 -0
  4. package/dist/src/codegen/__tests__/config.d.ts +1 -0
  5. package/dist/src/codegen/__tests__/config.d.ts.map +1 -1
  6. package/dist/src/codegen/__tests__/config.js +1 -0
  7. package/dist/src/codegen/__tests__/config.js.map +1 -1
  8. package/dist/src/codegen/__tests__/generate-doc-model.test.js +113 -88
  9. package/dist/src/codegen/__tests__/generate-doc-model.test.js.map +1 -1
  10. package/dist/src/codegen/__tests__/generate-drive-editor.test.js +6 -3
  11. package/dist/src/codegen/__tests__/generate-drive-editor.test.js.map +1 -1
  12. package/dist/src/codegen/__tests__/generate-editor.test.js +8 -7
  13. package/dist/src/codegen/__tests__/generate-editor.test.js.map +1 -1
  14. package/dist/src/codegen/__tests__/generate-manifest.test.js.map +1 -1
  15. package/dist/src/codegen/__tests__/generate-versioned-document-model.test.d.ts +2 -0
  16. package/dist/src/codegen/__tests__/generate-versioned-document-model.test.d.ts.map +1 -0
  17. package/dist/src/codegen/__tests__/generate-versioned-document-model.test.js +142 -0
  18. package/dist/src/codegen/__tests__/generate-versioned-document-model.test.js.map +1 -0
  19. package/dist/src/codegen/generate.d.ts +42 -6
  20. package/dist/src/codegen/generate.d.ts.map +1 -1
  21. package/dist/src/codegen/generate.js +212 -95
  22. package/dist/src/codegen/generate.js.map +1 -1
  23. package/dist/src/codegen/graphql.d.ts +20 -17
  24. package/dist/src/codegen/graphql.d.ts.map +1 -1
  25. package/dist/src/codegen/graphql.js +105 -78
  26. package/dist/src/codegen/graphql.js.map +1 -1
  27. package/dist/src/codegen/hygen.d.ts +1 -8
  28. package/dist/src/codegen/hygen.d.ts.map +1 -1
  29. package/dist/src/codegen/hygen.js +11 -68
  30. package/dist/src/codegen/hygen.js.map +1 -1
  31. package/dist/src/index.d.ts +0 -1
  32. package/dist/src/index.d.ts.map +1 -1
  33. package/dist/src/index.js +0 -1
  34. package/dist/src/index.js.map +1 -1
  35. package/dist/src/ts-morph-utils/constants.d.ts +18 -0
  36. package/dist/src/ts-morph-utils/constants.d.ts.map +1 -0
  37. package/dist/src/ts-morph-utils/constants.js +18 -0
  38. package/dist/src/ts-morph-utils/constants.js.map +1 -0
  39. package/dist/src/ts-morph-utils/file-builders/document-editor.d.ts +28 -0
  40. package/dist/src/ts-morph-utils/file-builders/document-editor.d.ts.map +1 -0
  41. package/dist/src/ts-morph-utils/file-builders/document-editor.js +305 -0
  42. package/dist/src/ts-morph-utils/file-builders/document-editor.js.map +1 -0
  43. package/dist/src/ts-morph-utils/file-builders/document-model/gen-dir.d.ts +3 -0
  44. package/dist/src/ts-morph-utils/file-builders/document-model/gen-dir.d.ts.map +1 -0
  45. package/dist/src/ts-morph-utils/file-builders/document-model/gen-dir.js +216 -0
  46. package/dist/src/ts-morph-utils/file-builders/document-model/gen-dir.js.map +1 -0
  47. package/dist/src/ts-morph-utils/file-builders/document-model/root-dir.d.ts +3 -0
  48. package/dist/src/ts-morph-utils/file-builders/document-model/root-dir.d.ts.map +1 -0
  49. package/dist/src/ts-morph-utils/file-builders/document-model/root-dir.js +55 -0
  50. package/dist/src/ts-morph-utils/file-builders/document-model/root-dir.js.map +1 -0
  51. package/dist/src/ts-morph-utils/file-builders/document-model/src-dir.d.ts +3 -0
  52. package/dist/src/ts-morph-utils/file-builders/document-model/src-dir.d.ts.map +1 -0
  53. package/dist/src/ts-morph-utils/file-builders/document-model/src-dir.js +252 -0
  54. package/dist/src/ts-morph-utils/file-builders/document-model/src-dir.js.map +1 -0
  55. package/dist/src/ts-morph-utils/file-builders/document-model/types.d.ts +32 -0
  56. package/dist/src/ts-morph-utils/file-builders/document-model/types.d.ts.map +1 -0
  57. package/dist/src/ts-morph-utils/file-builders/document-model/types.js +2 -0
  58. package/dist/src/ts-morph-utils/file-builders/document-model/types.js.map +1 -0
  59. package/dist/src/ts-morph-utils/file-builders/document-model/upgrades-dir.d.ts +31 -0
  60. package/dist/src/ts-morph-utils/file-builders/document-model/upgrades-dir.d.ts.map +1 -0
  61. package/dist/src/ts-morph-utils/file-builders/document-model/upgrades-dir.js +136 -0
  62. package/dist/src/ts-morph-utils/file-builders/document-model/upgrades-dir.js.map +1 -0
  63. package/dist/src/ts-morph-utils/file-builders/document-model.d.ts +8 -0
  64. package/dist/src/ts-morph-utils/file-builders/document-model.d.ts.map +1 -0
  65. package/dist/src/ts-morph-utils/file-builders/document-model.js +250 -0
  66. package/dist/src/ts-morph-utils/file-builders/document-model.js.map +1 -0
  67. package/dist/src/ts-morph-utils/file-builders/drive-editor.d.ts +56 -0
  68. package/dist/src/ts-morph-utils/file-builders/drive-editor.d.ts.map +1 -0
  69. package/dist/src/ts-morph-utils/file-builders/drive-editor.js +341 -0
  70. package/dist/src/ts-morph-utils/file-builders/drive-editor.js.map +1 -0
  71. package/dist/src/ts-morph-utils/file-builders/editor-common.d.ts +3 -0
  72. package/dist/src/ts-morph-utils/file-builders/editor-common.d.ts.map +1 -0
  73. package/dist/src/ts-morph-utils/file-builders/editor-common.js +15 -0
  74. package/dist/src/ts-morph-utils/file-builders/editor-common.js.map +1 -0
  75. package/dist/src/ts-morph-utils/file-builders/index-files.d.ts +18 -0
  76. package/dist/src/ts-morph-utils/file-builders/index-files.d.ts.map +1 -0
  77. package/dist/src/ts-morph-utils/file-builders/index-files.js +25 -0
  78. package/dist/src/ts-morph-utils/file-builders/index-files.js.map +1 -0
  79. package/dist/src/ts-morph-utils/file-builders/module-files.d.ts +25 -0
  80. package/dist/src/ts-morph-utils/file-builders/module-files.d.ts.map +1 -0
  81. package/dist/src/ts-morph-utils/file-builders/module-files.js +104 -0
  82. package/dist/src/ts-morph-utils/file-builders/module-files.js.map +1 -0
  83. package/dist/src/ts-morph-utils/file-builders/subgraphs.d.ts +6 -0
  84. package/dist/src/ts-morph-utils/file-builders/subgraphs.d.ts.map +1 -0
  85. package/dist/src/ts-morph-utils/file-builders/subgraphs.js +53 -0
  86. package/dist/src/ts-morph-utils/file-builders/subgraphs.js.map +1 -0
  87. package/dist/src/ts-morph-utils/file-builders/types.d.ts +13 -0
  88. package/dist/src/ts-morph-utils/file-builders/types.d.ts.map +1 -0
  89. package/dist/src/ts-morph-utils/file-builders/types.js +2 -0
  90. package/dist/src/ts-morph-utils/file-builders/types.js.map +1 -0
  91. package/dist/src/ts-morph-utils/file-utils.d.ts +28 -0
  92. package/dist/src/ts-morph-utils/file-utils.d.ts.map +1 -0
  93. package/dist/src/ts-morph-utils/file-utils.js +102 -0
  94. package/dist/src/ts-morph-utils/file-utils.js.map +1 -0
  95. package/dist/src/ts-morph-utils/name-builders/common-files.d.ts +5 -0
  96. package/dist/src/ts-morph-utils/name-builders/common-files.d.ts.map +1 -0
  97. package/dist/src/ts-morph-utils/name-builders/common-files.js +15 -0
  98. package/dist/src/ts-morph-utils/name-builders/common-files.js.map +1 -0
  99. package/dist/src/ts-morph-utils/name-builders/document-model-files.d.ts +4 -0
  100. package/dist/src/ts-morph-utils/name-builders/document-model-files.d.ts.map +1 -0
  101. package/dist/src/ts-morph-utils/name-builders/document-model-files.js +12 -0
  102. package/dist/src/ts-morph-utils/name-builders/document-model-files.js.map +1 -0
  103. package/dist/src/ts-morph-utils/name-builders/editor-files.d.ts +10 -0
  104. package/dist/src/ts-morph-utils/name-builders/editor-files.d.ts.map +1 -0
  105. package/dist/src/ts-morph-utils/name-builders/editor-files.js +37 -0
  106. package/dist/src/ts-morph-utils/name-builders/editor-files.js.map +1 -0
  107. package/dist/src/ts-morph-utils/name-builders/get-file-paths.d.ts +4 -0
  108. package/dist/src/ts-morph-utils/name-builders/get-file-paths.d.ts.map +1 -0
  109. package/dist/src/ts-morph-utils/name-builders/get-file-paths.js +21 -0
  110. package/dist/src/ts-morph-utils/name-builders/get-file-paths.js.map +1 -0
  111. package/dist/src/ts-morph-utils/name-builders/get-variable-names.d.ts +37 -0
  112. package/dist/src/ts-morph-utils/name-builders/get-variable-names.d.ts.map +1 -0
  113. package/dist/src/ts-morph-utils/name-builders/get-variable-names.js +145 -0
  114. package/dist/src/ts-morph-utils/name-builders/get-variable-names.js.map +1 -0
  115. package/dist/src/ts-morph-utils/name-builders/types.d.ts +18 -0
  116. package/dist/src/ts-morph-utils/name-builders/types.d.ts.map +1 -0
  117. package/dist/src/ts-morph-utils/name-builders/types.js +2 -0
  118. package/dist/src/ts-morph-utils/name-builders/types.js.map +1 -0
  119. package/dist/src/ts-morph-utils/name-builders/variables.d.ts +12 -0
  120. package/dist/src/ts-morph-utils/name-builders/variables.d.ts.map +1 -0
  121. package/dist/src/ts-morph-utils/name-builders/variables.js +35 -0
  122. package/dist/src/ts-morph-utils/name-builders/variables.js.map +1 -0
  123. package/dist/src/ts-morph-utils/syntax-builders.d.ts +72 -0
  124. package/dist/src/ts-morph-utils/syntax-builders.d.ts.map +1 -0
  125. package/dist/src/ts-morph-utils/syntax-builders.js +201 -0
  126. package/dist/src/ts-morph-utils/syntax-builders.js.map +1 -0
  127. package/dist/src/ts-morph-utils/syntax-getters.d.ts +11 -0
  128. package/dist/src/ts-morph-utils/syntax-getters.d.ts.map +1 -0
  129. package/dist/src/ts-morph-utils/syntax-getters.js +45 -0
  130. package/dist/src/ts-morph-utils/syntax-getters.js.map +1 -0
  131. package/dist/src/ts-morph-utils/templates/document-model/actions.d.ts +3 -0
  132. package/dist/src/ts-morph-utils/templates/document-model/actions.d.ts.map +1 -0
  133. package/dist/src/ts-morph-utils/templates/document-model/actions.js +28 -0
  134. package/dist/src/ts-morph-utils/templates/document-model/actions.js.map +1 -0
  135. package/dist/src/ts-morph-utils/templates/document-model/gen/actions.d.ts +3 -0
  136. package/dist/src/ts-morph-utils/templates/document-model/gen/actions.d.ts.map +1 -0
  137. package/dist/src/ts-morph-utils/templates/document-model/gen/actions.js +40 -0
  138. package/dist/src/ts-morph-utils/templates/document-model/gen/actions.js.map +1 -0
  139. package/dist/src/ts-morph-utils/templates/document-model/gen/creators.d.ts +3 -0
  140. package/dist/src/ts-morph-utils/templates/document-model/gen/creators.d.ts.map +1 -0
  141. package/dist/src/ts-morph-utils/templates/document-model/gen/creators.js +16 -0
  142. package/dist/src/ts-morph-utils/templates/document-model/gen/creators.js.map +1 -0
  143. package/dist/src/ts-morph-utils/templates/document-model/gen/document-schema.d.ts +3 -0
  144. package/dist/src/ts-morph-utils/templates/document-model/gen/document-schema.d.ts.map +1 -0
  145. package/dist/src/ts-morph-utils/templates/document-model/gen/document-schema.js +56 -0
  146. package/dist/src/ts-morph-utils/templates/document-model/gen/document-schema.js.map +1 -0
  147. package/dist/src/ts-morph-utils/templates/document-model/gen/document-type.d.ts +3 -0
  148. package/dist/src/ts-morph-utils/templates/document-model/gen/document-type.d.ts.map +1 -0
  149. package/dist/src/ts-morph-utils/templates/document-model/gen/document-type.js +5 -0
  150. package/dist/src/ts-morph-utils/templates/document-model/gen/document-type.js.map +1 -0
  151. package/dist/src/ts-morph-utils/templates/document-model/gen/index.d.ts +3 -0
  152. package/dist/src/ts-morph-utils/templates/document-model/gen/index.d.ts.map +1 -0
  153. package/dist/src/ts-morph-utils/templates/document-model/gen/index.js +29 -0
  154. package/dist/src/ts-morph-utils/templates/document-model/gen/index.js.map +1 -0
  155. package/dist/src/ts-morph-utils/templates/document-model/gen/modules/actions.d.ts +8 -0
  156. package/dist/src/ts-morph-utils/templates/document-model/gen/modules/actions.d.ts.map +1 -0
  157. package/dist/src/ts-morph-utils/templates/document-model/gen/modules/actions.js +39 -0
  158. package/dist/src/ts-morph-utils/templates/document-model/gen/modules/actions.js.map +1 -0
  159. package/dist/src/ts-morph-utils/templates/document-model/gen/modules/creators.d.ts +3 -0
  160. package/dist/src/ts-morph-utils/templates/document-model/gen/modules/creators.d.ts.map +1 -0
  161. package/dist/src/ts-morph-utils/templates/document-model/gen/modules/creators.js +94 -0
  162. package/dist/src/ts-morph-utils/templates/document-model/gen/modules/creators.js.map +1 -0
  163. package/dist/src/ts-morph-utils/templates/document-model/gen/modules/error.d.ts +3 -0
  164. package/dist/src/ts-morph-utils/templates/document-model/gen/modules/error.d.ts.map +1 -0
  165. package/dist/src/ts-morph-utils/templates/document-model/gen/modules/error.js +73 -0
  166. package/dist/src/ts-morph-utils/templates/document-model/gen/modules/error.js.map +1 -0
  167. package/dist/src/ts-morph-utils/templates/document-model/gen/modules/operations.d.ts +3 -0
  168. package/dist/src/ts-morph-utils/templates/document-model/gen/modules/operations.d.ts.map +1 -0
  169. package/dist/src/ts-morph-utils/templates/document-model/gen/modules/operations.js +61 -0
  170. package/dist/src/ts-morph-utils/templates/document-model/gen/modules/operations.js.map +1 -0
  171. package/dist/src/ts-morph-utils/templates/document-model/gen/ph-factories.d.ts +3 -0
  172. package/dist/src/ts-morph-utils/templates/document-model/gen/ph-factories.d.ts.map +1 -0
  173. package/dist/src/ts-morph-utils/templates/document-model/gen/ph-factories.js +93 -0
  174. package/dist/src/ts-morph-utils/templates/document-model/gen/ph-factories.js.map +1 -0
  175. package/dist/src/ts-morph-utils/templates/document-model/gen/reducer.d.ts +3 -0
  176. package/dist/src/ts-morph-utils/templates/document-model/gen/reducer.d.ts.map +1 -0
  177. package/dist/src/ts-morph-utils/templates/document-model/gen/reducer.js +106 -0
  178. package/dist/src/ts-morph-utils/templates/document-model/gen/reducer.js.map +1 -0
  179. package/dist/src/ts-morph-utils/templates/document-model/gen/schema/index.d.ts +2 -0
  180. package/dist/src/ts-morph-utils/templates/document-model/gen/schema/index.d.ts.map +1 -0
  181. package/dist/src/ts-morph-utils/templates/document-model/gen/schema/index.js +6 -0
  182. package/dist/src/ts-morph-utils/templates/document-model/gen/schema/index.js.map +1 -0
  183. package/dist/src/ts-morph-utils/templates/document-model/gen/types.d.ts +3 -0
  184. package/dist/src/ts-morph-utils/templates/document-model/gen/types.d.ts.map +1 -0
  185. package/dist/src/ts-morph-utils/templates/document-model/gen/types.js +38 -0
  186. package/dist/src/ts-morph-utils/templates/document-model/gen/types.js.map +1 -0
  187. package/dist/src/ts-morph-utils/templates/document-model/gen/utils.d.ts +3 -0
  188. package/dist/src/ts-morph-utils/templates/document-model/gen/utils.d.ts.map +1 -0
  189. package/dist/src/ts-morph-utils/templates/document-model/gen/utils.js +77 -0
  190. package/dist/src/ts-morph-utils/templates/document-model/gen/utils.js.map +1 -0
  191. package/dist/src/ts-morph-utils/templates/document-model/hooks.d.ts +3 -0
  192. package/dist/src/ts-morph-utils/templates/document-model/hooks.d.ts.map +1 -0
  193. package/dist/src/ts-morph-utils/templates/document-model/hooks.js +49 -0
  194. package/dist/src/ts-morph-utils/templates/document-model/hooks.js.map +1 -0
  195. package/dist/src/ts-morph-utils/templates/document-model/index.d.ts +2 -0
  196. package/dist/src/ts-morph-utils/templates/document-model/index.d.ts.map +1 -0
  197. package/dist/src/ts-morph-utils/templates/document-model/index.js +9 -0
  198. package/dist/src/ts-morph-utils/templates/document-model/index.js.map +1 -0
  199. package/dist/src/ts-morph-utils/templates/document-model/module.d.ts +8 -0
  200. package/dist/src/ts-morph-utils/templates/document-model/module.d.ts.map +1 -0
  201. package/dist/src/ts-morph-utils/templates/document-model/module.js +25 -0
  202. package/dist/src/ts-morph-utils/templates/document-model/module.js.map +1 -0
  203. package/dist/src/ts-morph-utils/templates/document-model/src/index.d.ts +2 -0
  204. package/dist/src/ts-morph-utils/templates/document-model/src/index.d.ts.map +1 -0
  205. package/dist/src/ts-morph-utils/templates/document-model/src/index.js +5 -0
  206. package/dist/src/ts-morph-utils/templates/document-model/src/index.js.map +1 -0
  207. package/dist/src/ts-morph-utils/templates/document-model/src/tests/document-model.test.d.ts +3 -0
  208. package/dist/src/ts-morph-utils/templates/document-model/src/tests/document-model.test.d.ts.map +1 -0
  209. package/dist/src/ts-morph-utils/templates/document-model/src/tests/document-model.test.js +121 -0
  210. package/dist/src/ts-morph-utils/templates/document-model/src/tests/document-model.test.js.map +1 -0
  211. package/dist/src/ts-morph-utils/templates/document-model/src/tests/module.test.d.ts +6 -0
  212. package/dist/src/ts-morph-utils/templates/document-model/src/tests/module.test.d.ts.map +1 -0
  213. package/dist/src/ts-morph-utils/templates/document-model/src/tests/module.test.js +87 -0
  214. package/dist/src/ts-morph-utils/templates/document-model/src/tests/module.test.js.map +1 -0
  215. package/dist/src/ts-morph-utils/templates/document-model/src/utils.d.ts +2 -0
  216. package/dist/src/ts-morph-utils/templates/document-model/src/utils.d.ts.map +1 -0
  217. package/dist/src/ts-morph-utils/templates/document-model/src/utils.js +5 -0
  218. package/dist/src/ts-morph-utils/templates/document-model/src/utils.js.map +1 -0
  219. package/dist/src/ts-morph-utils/templates/document-model/upgrades/upgrade-transition.d.ts +7 -0
  220. package/dist/src/ts-morph-utils/templates/document-model/upgrades/upgrade-transition.d.ts.map +1 -0
  221. package/dist/src/ts-morph-utils/templates/document-model/upgrades/upgrade-transition.js +22 -0
  222. package/dist/src/ts-morph-utils/templates/document-model/upgrades/upgrade-transition.js.map +1 -0
  223. package/dist/src/ts-morph-utils/templates/document-model/utils.d.ts +3 -0
  224. package/dist/src/ts-morph-utils/templates/document-model/utils.d.ts.map +1 -0
  225. package/dist/src/ts-morph-utils/templates/document-model/utils.js +11 -0
  226. package/dist/src/ts-morph-utils/templates/document-model/utils.js.map +1 -0
  227. package/dist/src/ts-morph-utils/templates/drive-editor.d.ts +5 -0
  228. package/dist/src/ts-morph-utils/templates/drive-editor.d.ts.map +1 -0
  229. package/dist/src/ts-morph-utils/templates/drive-editor.js +211 -0
  230. package/dist/src/ts-morph-utils/templates/drive-editor.js.map +1 -0
  231. package/dist/src/ts-morph-utils/templates/unsafe-utils.d.ts +8 -0
  232. package/dist/src/ts-morph-utils/templates/unsafe-utils.d.ts.map +1 -0
  233. package/dist/src/ts-morph-utils/templates/unsafe-utils.js +23 -0
  234. package/dist/src/ts-morph-utils/templates/unsafe-utils.js.map +1 -0
  235. package/dist/src/ts-morph-utils/templates/utils.d.ts +6 -0
  236. package/dist/src/ts-morph-utils/templates/utils.d.ts.map +1 -0
  237. package/dist/src/ts-morph-utils/templates/utils.js +16 -0
  238. package/dist/src/ts-morph-utils/templates/utils.js.map +1 -0
  239. package/dist/src/ts-morph-utils/ts-morph-project.d.ts +3 -0
  240. package/dist/src/ts-morph-utils/ts-morph-project.d.ts.map +1 -0
  241. package/dist/src/ts-morph-utils/ts-morph-project.js +9 -0
  242. package/dist/src/ts-morph-utils/ts-morph-project.js.map +1 -0
  243. package/dist/src/ts-morph-utils/types.d.ts +34 -0
  244. package/dist/src/ts-morph-utils/types.d.ts.map +1 -0
  245. package/dist/src/ts-morph-utils/types.js +2 -0
  246. package/dist/src/ts-morph-utils/types.js.map +1 -0
  247. package/dist/src/utils/mock.d.ts +2 -3
  248. package/dist/src/utils/mock.d.ts.map +1 -1
  249. package/dist/src/utils/mock.js +4 -4
  250. package/dist/src/utils/mock.js.map +1 -1
  251. package/dist/tsconfig.tsbuildinfo +1 -1
  252. package/package.json +20 -14
  253. package/dist/src/codegen/__tests__/generate-schemas.test.d.ts +0 -2
  254. package/dist/src/codegen/__tests__/generate-schemas.test.d.ts.map +0 -1
  255. package/dist/src/codegen/__tests__/generate-schemas.test.js +0 -143
  256. package/dist/src/codegen/__tests__/generate-schemas.test.js.map +0 -1
  257. package/dist/src/ts-morph-utils.d.ts +0 -48
  258. package/dist/src/ts-morph-utils.d.ts.map +0 -1
  259. package/dist/src/ts-morph-utils.js +0 -207
  260. package/dist/src/ts-morph-utils.js.map +0 -1
@@ -0,0 +1,250 @@
1
+ import { paramCase } from "change-case";
2
+ import { writeFileSync } from "fs";
3
+ import path from "path";
4
+ import {} from "ts-morph";
5
+ import { generateDocumentModelZodSchemas } from "../../codegen/graphql.js";
6
+ import { documentModelModulesOutputFileName, documentModelModulesVariableName, documentModelModulesVariableType, documentModelModuleTypeName, } from "../constants.js";
7
+ import { formatSourceFileWithPrettier, getOrCreateSourceFile, } from "../file-utils.js";
8
+ import { getDocumentModelFilePaths } from "../name-builders/get-file-paths.js";
9
+ import { getDocumentModelDirName, getDocumentModelVariableNames, } from "../name-builders/get-variable-names.js";
10
+ import { getInitialStates } from "../templates/unsafe-utils.js";
11
+ import { buildTsMorphProject } from "../ts-morph-project.js";
12
+ import { makeGenDirFiles } from "./document-model/gen-dir.js";
13
+ import { makeRootDirFiles } from "./document-model/root-dir.js";
14
+ import { makeSrcDirFiles } from "./document-model/src-dir.js";
15
+ import { createOrUpdateUpgradeManifestFile, createOrUpdateVersionConstantsFile, makeUpgradeFile, makeUpgradesIndexFile, } from "./document-model/upgrades-dir.js";
16
+ import { makeModulesFile } from "./module-files.js";
17
+ function ensureDirectoriesExist(project, ...pathsToEnsure) {
18
+ for (const dirPath of pathsToEnsure) {
19
+ const dir = project.getDirectory(dirPath);
20
+ if (!dir) {
21
+ project.createDirectory(dirPath);
22
+ project.saveSync();
23
+ }
24
+ }
25
+ }
26
+ function makeDocumentModelIndexFile(args) {
27
+ const { project, documentModelDirPath, latestVersion } = args;
28
+ const filePath = path.join(documentModelDirPath, "index.ts");
29
+ const { sourceFile } = getOrCreateSourceFile(project, filePath);
30
+ sourceFile.replaceWithText("");
31
+ sourceFile.addExportDeclarations([
32
+ { moduleSpecifier: `./v${latestVersion}/index.js` },
33
+ { moduleSpecifier: `./upgrades/index.js` },
34
+ ]);
35
+ formatSourceFileWithPrettier(sourceFile);
36
+ }
37
+ function writeDocumentModelStateJsonFile({ documentModelState, documentModelDirName, documentModelDirPath, }) {
38
+ const filePath = path.join(documentModelDirPath, `${documentModelDirName}.json`);
39
+ const documentModelStateJson = JSON.stringify(documentModelState, null, 2);
40
+ writeFileSync(filePath, documentModelStateJson);
41
+ }
42
+ async function generateDocumentModelForSpec({ project, projectDir, packageName, documentModelState, documentModelPackageImportPath, documentModelsDirPath, documentModelDirName, documentModelDirPath, useVersioning, version, ...documentModelVariableNames }) {
43
+ const specification = documentModelState.specifications.find((spec) => spec.version === version);
44
+ if (!specification) {
45
+ throw new Error(`Document model specifications array is misconfigured, no specification found for version: ${version}`);
46
+ }
47
+ const versionDirName = useVersioning ? `v${version}` : "";
48
+ const documentModelVersionDirName = path.join(documentModelDirName, versionDirName);
49
+ const documentModelVersionDirPath = path.join(documentModelDirPath, versionDirName);
50
+ const versionedDocumentModelPackageImportPath = path.join(documentModelPackageImportPath, versionDirName);
51
+ const fileExtension = documentModelState.extension;
52
+ const documentTypeId = documentModelState.id;
53
+ const srcDirPath = path.join(documentModelVersionDirPath, "src");
54
+ const reducersDirPath = path.join(srcDirPath, "reducers");
55
+ const testsDirPath = path.join(srcDirPath, "tests");
56
+ const genDirPath = path.join(documentModelVersionDirPath, "gen");
57
+ const schemaDirPath = path.join(genDirPath, "schema");
58
+ const { initialGlobalState, initialLocalState } = getInitialStates(specification.state);
59
+ const hasLocalSchema = specification.state.local.schema !== "";
60
+ const modules = specification.modules;
61
+ const moduleDirPaths = modules.map((module) => path.join(genDirPath, paramCase(module.name)));
62
+ ensureDirectoriesExist(project, documentModelVersionDirPath, reducersDirPath, testsDirPath, schemaDirPath, ...moduleDirPaths);
63
+ const fileMakerArgs = {
64
+ project,
65
+ projectDir,
66
+ packageName,
67
+ version,
68
+ useVersioning,
69
+ documentTypeId,
70
+ documentModelState,
71
+ initialGlobalState,
72
+ initialLocalState,
73
+ modules,
74
+ hasLocalSchema,
75
+ documentModelsDirPath,
76
+ documentModelDirPath,
77
+ documentModelDirName,
78
+ documentModelVersionDirName,
79
+ documentModelVersionDirPath,
80
+ documentModelPackageImportPath,
81
+ versionedDocumentModelPackageImportPath,
82
+ srcDirPath,
83
+ genDirPath,
84
+ testsDirPath,
85
+ schemaDirPath,
86
+ reducersDirPath,
87
+ fileExtension,
88
+ ...documentModelVariableNames,
89
+ };
90
+ await generateDocumentModelZodSchemas({
91
+ documentModelDirPath: documentModelVersionDirPath,
92
+ specification,
93
+ });
94
+ makeRootDirFiles(fileMakerArgs);
95
+ makeGenDirFiles(fileMakerArgs);
96
+ makeSrcDirFiles(fileMakerArgs);
97
+ makeDocumentModelModulesFile(fileMakerArgs);
98
+ if (!useVersioning)
99
+ return;
100
+ const previousVersionDirPath = getPreviousVersionDirPath(documentModelDirPath, version);
101
+ if (!previousVersionDirPath)
102
+ return;
103
+ persistCustomFilesFromPreviousVersion({
104
+ project,
105
+ currentVersionDirPath: documentModelVersionDirPath,
106
+ previousVersionDirPath,
107
+ });
108
+ }
109
+ export async function tsMorphGenerateDocumentModel({ projectDir, packageName, documentModelState, useVersioning, }) {
110
+ const project = buildTsMorphProject(projectDir);
111
+ const { documentModelsSourceFilesPath } = getDocumentModelFilePaths(projectDir);
112
+ project.addSourceFilesAtPaths(documentModelsSourceFilesPath);
113
+ const documentModelsDirPath = path.join(projectDir, "document-models");
114
+ const documentModelDirName = getDocumentModelDirName(documentModelState);
115
+ const documentModelDirPath = path.join(documentModelsDirPath, documentModelDirName);
116
+ const documentModelVariableNames = getDocumentModelVariableNames(documentModelState.name);
117
+ ensureDirectoriesExist(project, documentModelsDirPath, documentModelDirPath);
118
+ const upgradesDirPath = path.join(documentModelDirPath, "upgrades");
119
+ if (useVersioning) {
120
+ ensureDirectoriesExist(project, upgradesDirPath);
121
+ }
122
+ const documentModelPackageImportPath = path.join(packageName, "document-models", documentModelDirName);
123
+ const specVersions = [
124
+ ...new Set([
125
+ ...documentModelState.specifications.map((spec) => spec.version),
126
+ ]),
127
+ ].toSorted();
128
+ if (specVersions.length !== documentModelState.specifications.length) {
129
+ throw new Error("Document model specifications array is misconfigured. Length is not match with spec versions.");
130
+ }
131
+ const latestVersion = specVersions[specVersions.length - 1];
132
+ if (documentModelState.specifications[documentModelState.specifications.length - 1].version !== latestVersion) {
133
+ throw new Error("Document model has incorrect version at the latest version index");
134
+ }
135
+ writeDocumentModelStateJsonFile({
136
+ documentModelState,
137
+ documentModelDirName,
138
+ documentModelDirPath,
139
+ });
140
+ if (useVersioning) {
141
+ await Promise.all(specVersions.map(async (version) => await generateDocumentModelForSpec({
142
+ project,
143
+ version,
144
+ useVersioning: true,
145
+ packageName,
146
+ documentModelState,
147
+ projectDir,
148
+ documentModelsDirPath,
149
+ documentModelDirName,
150
+ documentModelDirPath,
151
+ documentModelPackageImportPath,
152
+ ...documentModelVariableNames,
153
+ })));
154
+ for (const version of specVersions) {
155
+ makeUpgradeFile({
156
+ version,
157
+ upgradesDirPath,
158
+ project,
159
+ documentModelPackageImportPath,
160
+ ...documentModelVariableNames,
161
+ });
162
+ }
163
+ makeDocumentModelIndexFile({
164
+ project,
165
+ documentModelDirPath,
166
+ latestVersion,
167
+ });
168
+ createOrUpdateVersionConstantsFile({
169
+ project,
170
+ specVersions,
171
+ latestVersion,
172
+ upgradesDirPath,
173
+ });
174
+ createOrUpdateUpgradeManifestFile({
175
+ project,
176
+ specVersions,
177
+ latestVersion,
178
+ upgradesDirPath,
179
+ documentModelId: documentModelState.id,
180
+ ...documentModelVariableNames,
181
+ });
182
+ makeUpgradesIndexFile({ project, upgradesDirPath, specVersions });
183
+ }
184
+ else {
185
+ await generateDocumentModelForSpec({
186
+ project,
187
+ useVersioning: false,
188
+ version: latestVersion,
189
+ packageName,
190
+ documentModelState,
191
+ projectDir,
192
+ documentModelsDirPath,
193
+ documentModelDirName,
194
+ documentModelDirPath,
195
+ documentModelPackageImportPath,
196
+ ...documentModelVariableNames,
197
+ });
198
+ }
199
+ project.saveSync();
200
+ }
201
+ export function makeDocumentModelModulesFile({ project, projectDir, }) {
202
+ const { documentModelsDirPath, documentModelsSourceFilesPath } = getDocumentModelFilePaths(projectDir);
203
+ makeModulesFile({
204
+ project,
205
+ modulesDirPath: documentModelsDirPath,
206
+ modulesSourceFilesPath: documentModelsSourceFilesPath,
207
+ outputFileName: documentModelModulesOutputFileName,
208
+ typeName: documentModelModuleTypeName,
209
+ variableName: documentModelModulesVariableName,
210
+ variableType: documentModelModulesVariableType,
211
+ });
212
+ }
213
+ function getPreviousVersionDirPath(documentModelDirPath, version) {
214
+ const previousVersion = version - 1;
215
+ if (previousVersion < 1)
216
+ return;
217
+ const previousVersionDirName = `v${previousVersion}`;
218
+ return path.join(documentModelDirPath, previousVersionDirName);
219
+ }
220
+ function persistCustomFilesFromPreviousVersion(args) {
221
+ const { project, currentVersionDirPath, previousVersionDirPath } = args;
222
+ const currentVersionDir = project.getDirectoryOrThrow(currentVersionDirPath);
223
+ const previousVersionDir = project.getDirectory(previousVersionDirPath);
224
+ if (!previousVersionDir)
225
+ return;
226
+ const currentVersionSourceFiles = currentVersionDir.getDescendantSourceFiles();
227
+ const previousVersionSourceFiles = previousVersionDir.getDescendantSourceFiles();
228
+ const currentVersionDirs = currentVersionDir.getDescendantDirectories();
229
+ const previousVersionDirs = previousVersionDir.getDescendantDirectories();
230
+ const previousVersionRelativeDirPaths = previousVersionDirs.map((d) => previousVersionDir.getRelativePathTo(d));
231
+ const currentVersionRelativeDirPaths = currentVersionDirs.map((d) => currentVersionDir.getRelativePathTo(d));
232
+ const missingDirPaths = previousVersionRelativeDirPaths.filter((p) => !currentVersionRelativeDirPaths.includes(p));
233
+ const missingDirs = previousVersionDirs.filter((f) => missingDirPaths.includes(previousVersionDir.getRelativePathTo(f)));
234
+ for (const dir of missingDirs) {
235
+ const relativePath = previousVersionDir.getRelativePathTo(dir);
236
+ const newDir = currentVersionDir.createDirectory(relativePath);
237
+ newDir.saveSync();
238
+ }
239
+ const previousVersionRelativeFilePaths = previousVersionSourceFiles.map((f) => previousVersionDir.getRelativePathTo(f));
240
+ const currentVersionRelativeFilePaths = currentVersionSourceFiles.map((f) => currentVersionDir.getRelativePathTo(f));
241
+ const missingFilePaths = previousVersionRelativeFilePaths.filter((p) => !currentVersionRelativeFilePaths.includes(p));
242
+ const missingFiles = previousVersionSourceFiles.filter((f) => missingFilePaths.includes(previousVersionDir.getRelativePathTo(f)));
243
+ for (const file of missingFiles) {
244
+ const relativePath = previousVersionDir.getRelativePathTo(file);
245
+ const fileText = file.getText();
246
+ const newFile = currentVersionDir.createSourceFile(relativePath, fileText);
247
+ newFile.saveSync();
248
+ }
249
+ }
250
+ //# sourceMappingURL=document-model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-model.js","sourceRoot":"","sources":["../../../../src/ts-morph-utils/file-builders/document-model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACnC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAgB,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,+BAA+B,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EACL,kCAAkC,EAClC,gCAAgC,EAChC,gCAAgC,EAChC,2BAA2B,GAC5B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,4BAA4B,EAC5B,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAC/E,OAAO,EACL,uBAAuB,EACvB,6BAA6B,GAC9B,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAK9D,OAAO,EACL,iCAAiC,EACjC,kCAAkC,EAClC,eAAe,EACf,qBAAqB,GACtB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,SAAS,sBAAsB,CAAC,OAAgB,EAAE,GAAG,aAAuB;IAC1E,KAAK,MAAM,OAAO,IAAI,aAAa,EAAE,CAAC;QACpC,M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F,MAAM,+BAA+B,GAAG,yBAAyB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAC1E,iBAAiB,CAAC,iBAAiB,CAAC,CAAC,CAAC,CACvC,CAAC;IAEF,MAAM,gBAAgB,GAAG,gCAAgC,CAAC,MAAM,CAC9D,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,+BAA+B,CAAC,QAAQ,CAAC,CAAC,CAAC,CACpD,CAAC;IAEF,MAAM,YAAY,GAAG,0BAA0B,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAC3D,gBAAgB,CAAC,QAAQ,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CACnE,CAAC;IAEF,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;QAChC,MAAM,YAAY,GAAG,kBAAkB,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAChE,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAChC,MAAM,OAAO,GAAG,iBAAiB,CAAC,gBAAgB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QAC3E,OAAO,CAAC,QAAQ,EAAE,CAAC;IACrB,CAAC;AACH,CAAC"}
@@ -0,0 +1,56 @@
1
+ import { type Project } from "ts-morph";
2
+ import type { CommonGenerateEditorArgs } from "./types.js";
3
+ type GenerateDriveEditorArgs = CommonGenerateEditorArgs & {
4
+ allowedDocumentModelIds: string[];
5
+ isDragAndDropEnabled: boolean;
6
+ };
7
+ export declare function tsMorphGenerateDriveEditor({ projectDir, editorDir, editorName, editorId, allowedDocumentModelIds, isDragAndDropEnabled, }: GenerateDriveEditorArgs): void;
8
+ type MakeDriveEditorComponentArgs = {
9
+ project: Project;
10
+ editorFilePath: string;
11
+ };
12
+ export declare function makeDriveEditorComponent({ project, editorFilePath, }: MakeDriveEditorComponentArgs): void;
13
+ type MakeDriveEditorConfigFileArgs = {
14
+ project: Project;
15
+ editorConfigFilePath: string;
16
+ allowedDocumentModelIds: string[];
17
+ isDragAndDropEnabled: boolean;
18
+ };
19
+ export declare function makeDriveEditorConfigFile({ project, editorConfigFilePath, allowedDocumentModelIds, isDragAndDropEnabled, }: MakeDriveEditorConfigFileArgs): void;
20
+ type MakeDriveContentsFileArgs = {
21
+ project: Project;
22
+ driveContentsFilePath: string;
23
+ };
24
+ export declare function makeDriveContentsFile({ project, driveContentsFilePath, }: MakeDriveContentsFileArgs): void;
25
+ type MakeNavigationBreadcrumbsFileArgs = {
26
+ project: Project;
27
+ editorComponentsDirPath: string;
28
+ };
29
+ export declare function makeNavigationBreadcrumbsFile({ project, editorComponentsDirPath, }: MakeNavigationBreadcrumbsFileArgs): void;
30
+ type MakeFoldersFileArgs = {
31
+ project: Project;
32
+ editorComponentsDirPath: string;
33
+ };
34
+ export declare function makeFoldersFile({ project, editorComponentsDirPath, }: MakeFoldersFileArgs): void;
35
+ type MakeFilesFileArgs = {
36
+ project: Project;
37
+ editorComponentsDirPath: string;
38
+ };
39
+ export declare function makeFilesFile({ project, editorComponentsDirPath, }: MakeFilesFileArgs): void;
40
+ type MakeFolderTreeFileArgs = {
41
+ project: Project;
42
+ editorComponentsDirPath: string;
43
+ };
44
+ export declare function makeFolderTreeFile({ project, editorComponentsDirPath, }: MakeFolderTreeFileArgs): void;
45
+ type MakeEmptyStateFileArgs = {
46
+ project: Project;
47
+ editorComponentsDirPath: string;
48
+ };
49
+ export declare function makeEmptyStateFile({ project, editorComponentsDirPath, }: MakeEmptyStateFileArgs): void;
50
+ type MakeCreateDocumentFileArgs = {
51
+ project: Project;
52
+ editorComponentsDirPath: string;
53
+ };
54
+ export declare function makeCreateDocumentFile({ project, editorComponentsDirPath, }: MakeCreateDocumentFileArgs): void;
55
+ export {};
56
+ //# sourceMappingURL=drive-editor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drive-editor.d.ts","sourceRoot":"","sources":["../../../../src/ts-morph-utils/file-builders/drive-editor.ts"],"names":[],"mappings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AAO,EAAE,OAAO,CAAC;IACjB,uBAAuB,EAAE,MAAM,CAAC;CACjC,CAAC;AACF,wBAAgB,eAAe,CAAC,EAC9B,OAAO,EACP,uBAAuB,GACxB,EAAE,mBAAmB,QA6CrB;AAED,KAAK,iBAAiB,GAAG;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,uBAAuB,EAAE,MAAM,CAAC;CACjC,CAAC;AACF,wBAAgB,aAAa,CAAC,EAC5B,OAAO,EACP,uBAAuB,GACxB,EAAE,iBAAiB,QA+CnB;AAwBD,KAAK,sBAAsB,GAAG;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,uBAAuB,EAAE,MAAM,CAAC;CACjC,CAAC;AACF,wBAAgB,kBAAkB,CAAC,EACjC,OAAO,EACP,uBAAuB,GACxB,EAAE,sBAAsB,QAaxB;AAED,KAAK,sBAAsB,GAAG;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,uBAAuB,EAAE,MAAM,CAAC;CACjC,CAAC;AACF,wBAAgB,kBAAkB,CAAC,EACjC,OAAO,EACP,uBAAuB,GACxB,EAAE,sBAAsB,QAaxB;AAED,KAAK,0BAA0B,GAAG;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,uBAAuB,EAAE,MAAM,CAAC;CACjC,CAAC;AACF,wBAAgB,sBAAsB,CAAC,EACrC,OAAO,EACP,uBAAuB,GACxB,EAAE,0BAA0B,QAa5B"}
@@ -0,0 +1,341 @@
1
+ import { tsx } from "@tmpl/core";
2
+ import path from "path";
3
+ import { VariableDeclarationKind } from "ts-morph";
4
+ import { buildNodePrinter, formatSourceFileWithPrettier, getOrCreateSourceFile, } from "../file-utils.js";
5
+ import { getDocumentModelFilePaths, getEditorFilePaths, } from "../name-builders/get-file-paths.js";
6
+ import { buildArrayLiteralWithStringElements, buildClassNameAttribute, buildFunctionCall, buildJsxElement, buildJsxSpreadAttribute, buildReturn, buildSelfClosingJsxElement, } from "../syntax-builders.js";
7
+ import { getObjectLiteral } from "../syntax-getters.js";
8
+ import { createDocumentFileTemplate, driveExplorerFileTemplate, emptyStateFileTemplate, folderTreeFileTemplate, } from "../templates/drive-editor.js";
9
+ import { buildTsMorphProject } from "../ts-morph-project.js";
10
+ import { makeEditorModuleFile } from "./document-editor.js";
11
+ import { makeEditorsModulesFile } from "./editor-common.js";
12
+ export function tsMorphGenerateDriveEditor({ projectDir, editorDir, editorName, editorId, allowedDocumentModelIds, isDragAndDropEnabled, }) {
13
+ const { documentModelsSourceFilesPath } = getDocumentModelFilePaths(projectDir);
14
+ const { editorSourceFilesPath, ...editorFilePaths } = getEditorFilePaths(projectDir, editorDir);
15
+ const project = buildTsMorphProject(projectDir);
16
+ project.addSourceFilesAtPaths(documentModelsSourceFilesPath);
17
+ project.addSourceFilesAtPaths(editorSourceFilesPath);
18
+ makeNavigationBreadcrumbsFile({
19
+ project,
20
+ ...editorFilePaths,
21
+ });
22
+ makeCreateDocumentFile({
23
+ project,
24
+ ...editorFilePaths,
25
+ });
26
+ makeEmptyStateFile({
27
+ project,
28
+ ...editorFilePaths,
29
+ });
30
+ makeFoldersFile({
31
+ project,
32
+ ...editorFilePaths,
33
+ });
34
+ makeFolderTreeFile({
35
+ project,
36
+ ...editorFilePaths,
37
+ });
38
+ makeFilesFile({
39
+ project,
40
+ ...editorFilePaths,
41
+ });
42
+ makeDriveExplorerFile({
43
+ project,
44
+ ...editorFilePaths,
45
+ });
46
+ makeDriveContentsFile({
47
+ project,
48
+ ...editorFilePaths,
49
+ });
50
+ makeDriveEditorComponent({
51
+ project,
52
+ ...editorFilePaths,
53
+ });
54
+ makeDriveEditorConfigFile({
55
+ project,
56
+ allowedDocumentModelIds,
57
+ isDragAndDropEnabled,
58
+ ...editorFilePaths,
59
+ });
60
+ makeEditorModuleFile({
61
+ project,
62
+ editorName,
63
+ editorId,
64
+ documentModelId: "powerhouse/document-drive",
65
+ ...editorFilePaths,
66
+ });
67
+ makeEditorsModulesFile(project, projectDir);
68
+ project.saveSync();
69
+ }
70
+ export function makeDriveEditorComponent({ project, editorFilePath, }) {
71
+ const { alreadyExists, sourceFile: driveEditorComponentSourceFile } = getOrCreateSourceFile(project, editorFilePath);
72
+ if (alreadyExists) {
73
+ const editorFunction = driveEditorComponentSourceFile.getFunction("Editor");
74
+ if (editorFunction) {
75
+ if (!editorFunction.isDefaultExport()) {
76
+ editorFunction.setIsDefaultExport(true);
77
+ }
78
+ return;
79
+ }
80
+ }
81
+ driveEditorComponentSourceFile.replaceWithText("");
82
+ const printNode = buildNodePrinter(driveEditorComponentSourceFile);
83
+ const importDeclarations = [
84
+ {
85
+ namedImports: ["useSetPHDriveEditorConfig"],
86
+ moduleSpecifier: "@powerhousedao/reactor-browser",
87
+ },
88
+ {
89
+ namedImports: ["EditorProps"],
90
+ moduleSpecifier: "document-model",
91
+ isTypeOnly: true,
92
+ },
93
+ {
94
+ namedImports: ["DriveExplorer"],
95
+ moduleSpecifier: "./components/DriveExplorer.js",
96
+ },
97
+ {
98
+ namedImports: ["editorConfig"],
99
+ moduleSpecifier: "./config.js",
100
+ },
101
+ ];
102
+ driveEditorComponentSourceFile.addImportDeclarations(importDeclarations);
103
+ const useSetPHDriveEditorConfigHookCall = buildFunctionCall({
104
+ functionName: "useSetPHDriveEditorConfig",
105
+ argumentsArray: ["editorConfig"],
106
+ });
107
+ const driveExplorerComponent = buildSelfClosingJsxElement("DriveExplorer", [
108
+ buildJsxSpreadAttribute("props"),
109
+ ]);
110
+ const returnStatement = buildReturn(driveExplorerComponent);
111
+ const statements = [useSetPHDriveEditorConfigHookCall, returnStatement].map(printNode);
112
+ driveEditorComponentSourceFile.addFunction({
113
+ name: "Editor",
114
+ isDefaultExport: true,
115
+ parameters: [{ name: "props", type: "EditorProps" }],
116
+ statements,
117
+ docs: ["Implement your drive explorer behavior here"],
118
+ });
119
+ formatSourceFileWithPrettier(driveEditorComponentSourceFile);
120
+ }
121
+ export function makeDriveEditorConfigFile({ project, editorConfigFilePath, allowedDocumentModelIds, isDragAndDropEnabled, }) {
122
+ const { sourceFile: driveEditorConfigSourceFile } = getOrCreateSourceFile(project, editorConfigFilePath);
123
+ driveEditorConfigSourceFile.replaceWithText("");
124
+ driveEditorConfigSourceFile.addImportDeclaration({
125
+ moduleSpecifier: "@powerhousedao/reactor-browser",
126
+ namedImports: ["PHDriveEditorConfig"],
127
+ isTypeOnly: true,
128
+ });
129
+ const printNode = buildNodePrinter(driveEditorConfigSourceFile);
130
+ const configObjectVariableStatement = driveEditorConfigSourceFile.addVariableStatement({
131
+ docs: ["Editor config for the AtlasDriveExplorer"],
132
+ declarationKind: VariableDeclarationKind.Const,
133
+ isExported: true,
134
+ declarations: [
135
+ {
136
+ name: "editorConfig",
137
+ type: "PHDriveEditorConfig",
138
+ initializer: "{}",
139
+ },
140
+ ],
141
+ });
142
+ const objectLiteral = getObjectLiteral(configObjectVariableStatement);
143
+ if (!objectLiteral) {
144
+ throw new Error("Object literal not found");
145
+ }
146
+ objectLiteral.addPropertyAssignment({
147
+ name: "isDragAndDropEnabled",
148
+ initializer: isDragAndDropEnabled ? "true" : "false",
149
+ });
150
+ objectLiteral.addPropertyAssignment({
151
+ name: "allowedDocumentTypes",
152
+ initializer: printNode(buildArrayLiteralWithStringElements(allowedDocumentModelIds)),
153
+ });
154
+ }
155
+ export function makeDriveContentsFile({ project, driveContentsFilePath, }) {
156
+ const { alreadyExists, sourceFile: driveContentsSourceFile } = getOrCreateSourceFile(project, driveContentsFilePath);
157
+ if (alreadyExists)
158
+ return;
159
+ const printNode = buildNodePrinter(driveContentsSourceFile);
160
+ const importDeclarations = [
161
+ {
162
+ namedImports: ["CreateDocument"],
163
+ moduleSpecifier: "./CreateDocument.js",
164
+ },
165
+ {
166
+ namedImports: ["EmptyState"],
167
+ moduleSpecifier: "./EmptyState.js",
168
+ },
169
+ {
170
+ namedImports: ["Files"],
171
+ moduleSpecifier: "./Files.js",
172
+ },
173
+ {
174
+ namedImports: ["Folders"],
175
+ moduleSpecifier: "./Folders.js",
176
+ },
177
+ {
178
+ namedImports: ["NavigationBreadcrumbs"],
179
+ moduleSpecifier: "./NavigationBreadcrumbs.js",
180
+ },
181
+ ];
182
+ driveContentsSourceFile.addImportDeclarations(importDeclarations);
183
+ const navigationBreadcrumbs = buildSelfClosingJsxElement("NavigationBreadcrumbs");
184
+ const folders = buildSelfClosingJsxElement("Folders");
185
+ const files = buildSelfClosingJsxElement("Files");
186
+ const emptyState = buildSelfClosingJsxElement("EmptyState");
187
+ const createDocument = buildSelfClosingJsxElement("CreateDocument");
188
+ const wrapperDiv = buildJsxElement("div", [navigationBreadcrumbs, folders, files, emptyState, createDocument], [buildClassNameAttribute("space-y-6 px-6")]);
189
+ const returnStatement = buildReturn(wrapperDiv);
190
+ const statements = [returnStatement].map(printNode);
191
+ driveContentsSourceFile.addFunction({
192
+ name: "DriveContents",
193
+ isExported: true,
194
+ docs: ["Shows the documents and folders in the selected drive"],
195
+ parameters: [],
196
+ statements,
197
+ });
198
+ formatSourceFileWithPrettier(driveContentsSourceFile);
199
+ }
200
+ export function makeNavigationBreadcrumbsFile({ project, editorComponentsDirPath, }) {
201
+ const navigationBreadcrumbsFilePath = path.join(editorComponentsDirPath, "NavigationBreadcrumbs.tsx");
202
+ const { alreadyExists, sourceFile: navigationBreadcrumbsSourceFile } = getOrCreateSourceFile(project, navigationBreadcrumbsFilePath);
203
+ if (alreadyExists)
204
+ return;
205
+ const printNode = buildNodePrinter(navigationBreadcrumbsSourceFile);
206
+ const importDeclarations = [
207
+ {
208
+ namedImports: ["Breadcrumbs"],
209
+ moduleSpecifier: "@powerhousedao/design-system/connect",
210
+ },
211
+ ];
212
+ navigationBreadcrumbsSourceFile.addImportDeclarations(importDeclarations);
213
+ const breadcrumbs = buildSelfClosingJsxElement("Breadcrumbs");
214
+ const wrapperDiv = buildJsxElement("div", [breadcrumbs], [buildClassNameAttribute("border-b border-gray-200 pb-3 space-y-3")]);
215
+ const returnStatement = buildReturn(wrapperDiv);
216
+ const statements = [returnStatement].map(printNode);
217
+ navigationBreadcrumbsSourceFile.addFunction({
218
+ name: "NavigationBreadcrumbs",
219
+ isExported: true,
220
+ docs: ["Shows the navigation breadcrumbs for the selected drive or folder"],
221
+ parameters: [],
222
+ statements,
223
+ });
224
+ formatSourceFileWithPrettier(navigationBreadcrumbsSourceFile);
225
+ }
226
+ export function makeFoldersFile({ project, editorComponentsDirPath, }) {
227
+ const foldersFilePath = path.join(editorComponentsDirPath, "Folders.tsx");
228
+ const { alreadyExists, sourceFile: foldersSourceFile } = getOrCreateSourceFile(project, foldersFilePath);
229
+ if (alreadyExists)
230
+ return;
231
+ const importDeclarations = [
232
+ {
233
+ namedImports: ["FolderItem"],
234
+ moduleSpecifier: "@powerhousedao/design-system/connect",
235
+ },
236
+ {
237
+ namedImports: ["useNodesInSelectedDriveOrFolder", "isFolderNodeKind"],
238
+ moduleSpecifier: "@powerhousedao/reactor-browser",
239
+ },
240
+ ];
241
+ foldersSourceFile.addImportDeclarations(importDeclarations);
242
+ foldersSourceFile.addFunction({
243
+ name: "Folders",
244
+ isExported: true,
245
+ docs: ["Shows the folders in the selected drive or folder"],
246
+ parameters: [],
247
+ statements: [
248
+ tsx `
249
+ const nodes = useNodesInSelectedDriveOrFolder();
250
+ const folderNodes = nodes.filter((n) => isFolderNodeKind(n));
251
+ const hasFolders = folderNodes.length > 0;
252
+ if (!hasFolders) return null;
253
+
254
+ return (
255
+ <div>
256
+ <h3 className="mb-2 text-sm font-bold text-gray-600">Folders</h3>
257
+ <div className="flex flex-wrap gap-4">
258
+ {folderNodes.map((folderNode) => (
259
+ <FolderItem key={folderNode.id} folderNode={folderNode} />
260
+ ))}
261
+ </div>
262
+ </div>
263
+ );`.raw,
264
+ ],
265
+ });
266
+ formatSourceFileWithPrettier(foldersSourceFile);
267
+ }
268
+ export function makeFilesFile({ project, editorComponentsDirPath, }) {
269
+ const filesFilePath = path.join(editorComponentsDirPath, "Files.tsx");
270
+ const { alreadyExists, sourceFile: filesSourceFile } = getOrCreateSourceFile(project, filesFilePath);
271
+ if (alreadyExists)
272
+ return;
273
+ const importDeclarations = [
274
+ {
275
+ namedImports: ["FileItem"],
276
+ moduleSpecifier: "@powerhousedao/design-system/connect",
277
+ },
278
+ {
279
+ namedImports: ["useNodesInSelectedDriveOrFolder", "isFileNodeKind"],
280
+ moduleSpecifier: "@powerhousedao/reactor-browser",
281
+ },
282
+ ];
283
+ filesSourceFile.addImportDeclarations(importDeclarations);
284
+ const statements = [
285
+ tsx `const nodes = useNodesInSelectedDriveOrFolder();`.raw,
286
+ tsx `const fileNodes = nodes.filter((n) => isFileNodeKind(n));`.raw,
287
+ tsx `const hasFiles = fileNodes.length > 0;`.raw,
288
+ tsx `if (!hasFiles) return null;`.raw,
289
+ tsx `return (
290
+ <div>
291
+ <h3 className="mb-2 text-sm font-semibold text-gray-600">Documents</h3>
292
+ <div className="flex flex-wrap gap-4">
293
+ {fileNodes.map((fileNode) => (
294
+ <FileItem key={fileNode.id} fileNode={fileNode} />
295
+ ))}
296
+ </div>
297
+ </div>
298
+ );`.raw,
299
+ ];
300
+ filesSourceFile.addFunction({
301
+ name: "Files",
302
+ isExported: true,
303
+ docs: ["Shows the files in the selected drive or folder"],
304
+ parameters: [],
305
+ statements,
306
+ });
307
+ formatSourceFileWithPrettier(filesSourceFile);
308
+ }
309
+ function makeDriveExplorerFile({ project, editorComponentsDirPath, }) {
310
+ const driveExplorerFilePath = path.join(editorComponentsDirPath, "DriveExplorer.tsx");
311
+ const { alreadyExists, sourceFile: driveExplorerSourceFile } = getOrCreateSourceFile(project, driveExplorerFilePath);
312
+ if (alreadyExists)
313
+ return;
314
+ driveExplorerSourceFile.replaceWithText(driveExplorerFileTemplate);
315
+ formatSourceFileWithPrettier(driveExplorerSourceFile);
316
+ }
317
+ export function makeFolderTreeFile({ project, editorComponentsDirPath, }) {
318
+ const folderTreeFilePath = path.join(editorComponentsDirPath, "FolderTree.tsx");
319
+ const { alreadyExists, sourceFile: folderTreeSourceFile } = getOrCreateSourceFile(project, folderTreeFilePath);
320
+ if (alreadyExists)
321
+ return;
322
+ folderTreeSourceFile.replaceWithText(folderTreeFileTemplate);
323
+ formatSourceFileWithPrettier(folderTreeSourceFile);
324
+ }
325
+ export function makeEmptyStateFile({ project, editorComponentsDirPath, }) {
326
+ const emptyStateFilePath = path.join(editorComponentsDirPath, "EmptyState.tsx");
327
+ const { alreadyExists, sourceFile: emptyStateSourceFile } = getOrCreateSourceFile(project, emptyStateFilePath);
328
+ if (alreadyExists)
329
+ return;
330
+ emptyStateSourceFile.replaceWithText(emptyStateFileTemplate);
331
+ formatSourceFileWithPrettier(emptyStateSourceFile);
332
+ }
333
+ export function makeCreateDocumentFile({ project, editorComponentsDirPath, }) {
334
+ const createDocumentFilePath = path.join(editorComponentsDirPath, "CreateDocument.tsx");
335
+ const { alreadyExists, sourceFile: createDocumentSourceFile } = getOrCreateSourceFile(project, createDocumentFilePath);
336
+ if (alreadyExists)
337
+ return;
338
+ createDocumentSourceFile.replaceWithText(createDocumentFileTemplate);
339
+ formatSourceFileWithPrettier(createDocumentSourceFile);
340
+ }
341
+ //# sourceMappingURL=drive-editor.js.map