@decohere/scaffold 0.0.1-dev.126 → 0.0.1-dev.18

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 (264) hide show
  1. package/package.json +9 -19
  2. package/src/add-api.action.ts +25 -0
  3. package/src/add-api.command.ts +31 -0
  4. package/src/add.command.ts +20 -0
  5. package/src/add.module.ts +11 -0
  6. package/src/cli.ts +4 -0
  7. package/src/create.command.ts +20 -0
  8. package/src/create.module.ts +11 -0
  9. package/src/domain/prompt.ts +50 -0
  10. package/{types/src/index.d.ts → src/index.ts} +0 -4
  11. package/src/models/compose.model.ts +205 -0
  12. package/src/models/config-yaml.model.ts +83 -0
  13. package/src/models/const.ts +20 -0
  14. package/src/models/dev-container.model.ts +136 -0
  15. package/src/models/docker-image.model.ts +343 -0
  16. package/src/models/env-file.model.ts +45 -0
  17. package/src/models/gitignore.model.ts +35 -0
  18. package/src/models/launch-json.model.ts +60 -0
  19. package/src/models/package-json.model.ts +169 -0
  20. package/src/models/project.model.ts +141 -0
  21. package/{types/src/models/source-file.d.ts → src/models/source-file.ts} +6 -4
  22. package/src/models/tsconfig.model.ts +29 -0
  23. package/src/models/vitest-config.model.ts +26 -0
  24. package/src/models/vscode-settings.model.ts +24 -0
  25. package/src/program.ts +63 -0
  26. package/{types/src/resolve-target-dir.d.ts → src/resolve-target-dir.ts} +4 -1
  27. package/src/services/scaffold.service.ts +89 -0
  28. package/src/version.ts +56 -0
  29. package/src/webapi/api-name.ts +73 -0
  30. package/src/webapi/cli-options.ts +56 -0
  31. package/{types/src/webapi/const.d.ts → src/webapi/const.ts} +21 -9
  32. package/src/webapi/create-api.ts +275 -0
  33. package/src/webapi/devcontainer/host-scripts.ts +35 -0
  34. package/src/webapi/features/auth.feature.ts +454 -0
  35. package/src/webapi/features/auth0-cli.ts +421 -0
  36. package/src/webapi/features/biome-format.ts +34 -0
  37. package/src/webapi/features/database.feature.ts +522 -0
  38. package/src/webapi/features/finalize.feature.ts +112 -0
  39. package/src/webapi/features/postman.feature.ts +287 -0
  40. package/src/webapi/models/api-package-json.model.ts +60 -0
  41. package/src/webapi/models/auth-config.model.ts +36 -0
  42. package/src/webapi/models/controller-source-file.model.ts +232 -0
  43. package/{es6/src/webapi/models/github-ci.model.js → src/webapi/models/github-ci.model.ts} +29 -27
  44. package/src/webapi/models/main-source-file.model.ts +208 -0
  45. package/src/webapi/models/production-dockerfile.model.ts +162 -0
  46. package/src/webapi/models/sample-files.model.ts +45 -0
  47. package/src/webapi/models/webapi-image.model.ts +21 -0
  48. package/src/webapi/postman/hello-openapi.ts +92 -0
  49. package/src/webapi/postman/local-view.ts +195 -0
  50. package/src/webapi/postman/openapi-to-postman.ts +208 -0
  51. package/src/webapi/workspace-readme.ts +192 -0
  52. package/src/webapi.action.ts +22 -0
  53. package/src/webapi.command.ts +41 -0
  54. package/tests/auth-postman.wiring.spec.ts +263 -0
  55. package/tests/auth0-cli.spec.ts +232 -0
  56. package/tests/biome-format.spec.ts +49 -0
  57. package/tests/cli.integration.spec.ts +658 -0
  58. package/tests/compose.model.spec.ts +51 -0
  59. package/tests/container-image.model.spec.ts +162 -0
  60. package/tests/dev-container.model.spec.ts +29 -0
  61. package/tests/devcontainer-base-image.spec.ts +32 -0
  62. package/tests/hello-di-inject.scaffold.spec.ts +18 -0
  63. package/tests/hello-route.contract.spec.ts +94 -0
  64. package/tests/package-json.order.spec.ts +59 -0
  65. package/tests/postman-from-openapi.spec.ts +197 -0
  66. package/tests/seed-devcontainer-templates.ts +40 -0
  67. package/tests/webapi/devcontainer/codebase-rag-mcp.spec.ts +96 -0
  68. package/LICENSE +0 -15
  69. package/commonjs/src/add-api.action.js +0 -37
  70. package/commonjs/src/add-api.command.js +0 -39
  71. package/commonjs/src/add.command.js +0 -22
  72. package/commonjs/src/add.module.js +0 -24
  73. package/commonjs/src/auth0-configure.action.js +0 -28
  74. package/commonjs/src/auth0-configure.command.js +0 -24
  75. package/commonjs/src/auth0-login.action.js +0 -28
  76. package/commonjs/src/auth0-login.command.js +0 -23
  77. package/commonjs/src/auth0.command.js +0 -22
  78. package/commonjs/src/auth0.module.js +0 -28
  79. package/commonjs/src/cli.js +0 -8
  80. package/commonjs/src/create.command.js +0 -22
  81. package/commonjs/src/create.module.js +0 -24
  82. package/commonjs/src/domain/prompt.js +0 -62
  83. package/commonjs/src/index.js +0 -48
  84. package/commonjs/src/models/compose.model.js +0 -258
  85. package/commonjs/src/models/config-yaml.model.js +0 -86
  86. package/commonjs/src/models/const.js +0 -30
  87. package/commonjs/src/models/dev-container.model.js +0 -172
  88. package/commonjs/src/models/docker-image.model.js +0 -277
  89. package/commonjs/src/models/env-file.model.js +0 -48
  90. package/commonjs/src/models/gitignore.model.js +0 -48
  91. package/commonjs/src/models/launch-json.model.js +0 -70
  92. package/commonjs/src/models/package-json.model.js +0 -156
  93. package/commonjs/src/models/project.model.js +0 -132
  94. package/commonjs/src/models/source-file.js +0 -4
  95. package/commonjs/src/models/tsconfig.model.js +0 -32
  96. package/commonjs/src/models/vitest-config.model.js +0 -33
  97. package/commonjs/src/models/vscode-settings.model.js +0 -29
  98. package/commonjs/src/program.js +0 -64
  99. package/commonjs/src/resolve-target-dir.js +0 -17
  100. package/commonjs/src/services/scaffold.service.js +0 -60
  101. package/commonjs/src/version.js +0 -55
  102. package/commonjs/src/webapi/api-name.js +0 -93
  103. package/commonjs/src/webapi/auth0-commands.js +0 -250
  104. package/commonjs/src/webapi/authorize-scopes.js +0 -79
  105. package/commonjs/src/webapi/cli-options.js +0 -99
  106. package/commonjs/src/webapi/const.js +0 -54
  107. package/commonjs/src/webapi/create-api.js +0 -265
  108. package/commonjs/src/webapi/devcontainer/codebase-rag-mcp.js +0 -164
  109. package/commonjs/src/webapi/devcontainer/codebase-rag-mcp.ts +0 -182
  110. package/commonjs/src/webapi/devcontainer/host-scripts.js +0 -50
  111. package/commonjs/src/webapi/devcontainer/templates/codebase-rag.env.example +0 -3
  112. package/commonjs/src/webapi/devcontainer/templates/initialize.sh +0 -169
  113. package/commonjs/src/webapi/devcontainer/templates/post-create.sh +0 -35
  114. package/commonjs/src/webapi/devcontainer/templates/post-start.sh +0 -65
  115. package/commonjs/src/webapi/devcontainer/templates/tty-prompt.sh +0 -38
  116. package/commonjs/src/webapi/features/auth.feature.js +0 -408
  117. package/commonjs/src/webapi/features/auth0-cli.js +0 -472
  118. package/commonjs/src/webapi/features/biome-format.js +0 -47
  119. package/commonjs/src/webapi/features/database.feature.js +0 -433
  120. package/commonjs/src/webapi/features/finalize.feature.js +0 -93
  121. package/commonjs/src/webapi/features/postman.feature.js +0 -322
  122. package/commonjs/src/webapi/models/api-package-json.model.js +0 -58
  123. package/commonjs/src/webapi/models/auth-config.model.js +0 -24
  124. package/commonjs/src/webapi/models/controller-source-file.model.js +0 -190
  125. package/commonjs/src/webapi/models/github-ci.model.js +0 -193
  126. package/commonjs/src/webapi/models/main-source-file.model.js +0 -165
  127. package/commonjs/src/webapi/models/production-dockerfile.model.js +0 -75
  128. package/commonjs/src/webapi/models/sample-files.model.js +0 -58
  129. package/commonjs/src/webapi/models/webapi-image.model.js +0 -25
  130. package/commonjs/src/webapi/postman/hello-openapi.js +0 -173
  131. package/commonjs/src/webapi/postman/local-view.js +0 -182
  132. package/commonjs/src/webapi/postman/openapi-to-postman.js +0 -238
  133. package/commonjs/src/webapi/workspace-readme.js +0 -109
  134. package/commonjs/src/webapi.action.js +0 -28
  135. package/commonjs/src/webapi.command.js +0 -43
  136. package/es6/src/add-api.action.js +0 -27
  137. package/es6/src/add-api.command.js +0 -29
  138. package/es6/src/add.command.js +0 -12
  139. package/es6/src/add.module.js +0 -14
  140. package/es6/src/auth0-configure.action.js +0 -18
  141. package/es6/src/auth0-configure.command.js +0 -14
  142. package/es6/src/auth0-login.action.js +0 -18
  143. package/es6/src/auth0-login.command.js +0 -13
  144. package/es6/src/auth0.command.js +0 -12
  145. package/es6/src/auth0.module.js +0 -18
  146. package/es6/src/cli.js +0 -4
  147. package/es6/src/create.command.js +0 -12
  148. package/es6/src/create.module.js +0 -14
  149. package/es6/src/domain/prompt.js +0 -41
  150. package/es6/src/index.js +0 -9
  151. package/es6/src/models/compose.model.js +0 -254
  152. package/es6/src/models/config-yaml.model.js +0 -74
  153. package/es6/src/models/const.js +0 -20
  154. package/es6/src/models/dev-container.model.js +0 -162
  155. package/es6/src/models/docker-image.model.js +0 -235
  156. package/es6/src/models/env-file.model.js +0 -44
  157. package/es6/src/models/gitignore.model.js +0 -38
  158. package/es6/src/models/launch-json.model.js +0 -60
  159. package/es6/src/models/package-json.model.js +0 -141
  160. package/es6/src/models/project.model.js +0 -117
  161. package/es6/src/models/source-file.js +0 -1
  162. package/es6/src/models/tsconfig.model.js +0 -22
  163. package/es6/src/models/vitest-config.model.js +0 -23
  164. package/es6/src/models/vscode-settings.model.js +0 -19
  165. package/es6/src/program.js +0 -50
  166. package/es6/src/resolve-target-dir.js +0 -7
  167. package/es6/src/services/scaffold.service.js +0 -50
  168. package/es6/src/version.js +0 -34
  169. package/es6/src/webapi/api-name.js +0 -57
  170. package/es6/src/webapi/auth0-commands.js +0 -185
  171. package/es6/src/webapi/authorize-scopes.js +0 -55
  172. package/es6/src/webapi/cli-options.js +0 -34
  173. package/es6/src/webapi/const.js +0 -21
  174. package/es6/src/webapi/create-api.js +0 -245
  175. package/es6/src/webapi/devcontainer/codebase-rag-mcp.js +0 -154
  176. package/es6/src/webapi/devcontainer/codebase-rag-mcp.ts +0 -182
  177. package/es6/src/webapi/devcontainer/host-scripts.js +0 -29
  178. package/es6/src/webapi/devcontainer/templates/codebase-rag.env.example +0 -3
  179. package/es6/src/webapi/devcontainer/templates/initialize.sh +0 -169
  180. package/es6/src/webapi/devcontainer/templates/post-create.sh +0 -35
  181. package/es6/src/webapi/devcontainer/templates/post-start.sh +0 -65
  182. package/es6/src/webapi/devcontainer/templates/tty-prompt.sh +0 -38
  183. package/es6/src/webapi/features/auth.feature.js +0 -357
  184. package/es6/src/webapi/features/auth0-cli.js +0 -406
  185. package/es6/src/webapi/features/biome-format.js +0 -40
  186. package/es6/src/webapi/features/database.feature.js +0 -423
  187. package/es6/src/webapi/features/finalize.feature.js +0 -83
  188. package/es6/src/webapi/features/postman.feature.js +0 -256
  189. package/es6/src/webapi/models/api-package-json.model.js +0 -53
  190. package/es6/src/webapi/models/auth-config.model.js +0 -20
  191. package/es6/src/webapi/models/controller-source-file.model.js +0 -181
  192. package/es6/src/webapi/models/main-source-file.model.js +0 -161
  193. package/es6/src/webapi/models/production-dockerfile.model.js +0 -66
  194. package/es6/src/webapi/models/sample-files.model.js +0 -40
  195. package/es6/src/webapi/models/webapi-image.model.js +0 -18
  196. package/es6/src/webapi/postman/hello-openapi.js +0 -166
  197. package/es6/src/webapi/postman/local-view.js +0 -167
  198. package/es6/src/webapi/postman/openapi-to-postman.js +0 -179
  199. package/es6/src/webapi/workspace-readme.js +0 -88
  200. package/es6/src/webapi.action.js +0 -18
  201. package/es6/src/webapi.command.js +0 -33
  202. package/types/src/add-api.action.d.ts +0 -13
  203. package/types/src/add-api.command.d.ts +0 -7
  204. package/types/src/add.command.d.ts +0 -6
  205. package/types/src/add.module.d.ts +0 -14
  206. package/types/src/auth0-configure.action.d.ts +0 -7
  207. package/types/src/auth0-configure.command.d.ts +0 -6
  208. package/types/src/auth0-login.action.d.ts +0 -4
  209. package/types/src/auth0-login.command.d.ts +0 -6
  210. package/types/src/auth0.command.d.ts +0 -6
  211. package/types/src/auth0.module.d.ts +0 -18
  212. package/types/src/cli.d.ts +0 -2
  213. package/types/src/create.command.d.ts +0 -6
  214. package/types/src/create.module.d.ts +0 -14
  215. package/types/src/domain/prompt.d.ts +0 -4
  216. package/types/src/models/compose.model.d.ts +0 -73
  217. package/types/src/models/config-yaml.model.d.ts +0 -27
  218. package/types/src/models/const.d.ts +0 -20
  219. package/types/src/models/dev-container.model.d.ts +0 -49
  220. package/types/src/models/docker-image.model.d.ts +0 -90
  221. package/types/src/models/env-file.model.d.ts +0 -16
  222. package/types/src/models/gitignore.model.d.ts +0 -9
  223. package/types/src/models/launch-json.model.d.ts +0 -7
  224. package/types/src/models/package-json.model.d.ts +0 -36
  225. package/types/src/models/project.model.d.ts +0 -60
  226. package/types/src/models/tsconfig.model.d.ts +0 -5
  227. package/types/src/models/vitest-config.model.d.ts +0 -5
  228. package/types/src/models/vscode-settings.model.d.ts +0 -7
  229. package/types/src/program.d.ts +0 -8
  230. package/types/src/services/scaffold.service.d.ts +0 -22
  231. package/types/src/version.d.ts +0 -6
  232. package/types/src/webapi/api-name.d.ts +0 -14
  233. package/types/src/webapi/auth0-commands.d.ts +0 -11
  234. package/types/src/webapi/authorize-scopes.d.ts +0 -7
  235. package/types/src/webapi/cli-options.d.ts +0 -6
  236. package/types/src/webapi/create-api.d.ts +0 -15
  237. package/types/src/webapi/devcontainer/codebase-rag-mcp.d.ts +0 -32
  238. package/types/src/webapi/devcontainer/codebase-rag-mcp.ts +0 -182
  239. package/types/src/webapi/devcontainer/host-scripts.d.ts +0 -7
  240. package/types/src/webapi/devcontainer/templates/codebase-rag.env.example +0 -3
  241. package/types/src/webapi/devcontainer/templates/initialize.sh +0 -169
  242. package/types/src/webapi/devcontainer/templates/post-create.sh +0 -35
  243. package/types/src/webapi/devcontainer/templates/post-start.sh +0 -65
  244. package/types/src/webapi/devcontainer/templates/tty-prompt.sh +0 -38
  245. package/types/src/webapi/features/auth.feature.d.ts +0 -10
  246. package/types/src/webapi/features/auth0-cli.d.ts +0 -84
  247. package/types/src/webapi/features/biome-format.d.ts +0 -5
  248. package/types/src/webapi/features/database.feature.d.ts +0 -7
  249. package/types/src/webapi/features/finalize.feature.d.ts +0 -2
  250. package/types/src/webapi/features/postman.feature.d.ts +0 -16
  251. package/types/src/webapi/models/api-package-json.model.d.ts +0 -18
  252. package/types/src/webapi/models/auth-config.model.d.ts +0 -26
  253. package/types/src/webapi/models/controller-source-file.model.d.ts +0 -46
  254. package/types/src/webapi/models/github-ci.model.d.ts +0 -9
  255. package/types/src/webapi/models/main-source-file.model.d.ts +0 -54
  256. package/types/src/webapi/models/production-dockerfile.model.d.ts +0 -18
  257. package/types/src/webapi/models/sample-files.model.d.ts +0 -7
  258. package/types/src/webapi/models/webapi-image.model.d.ts +0 -12
  259. package/types/src/webapi/postman/hello-openapi.d.ts +0 -19
  260. package/types/src/webapi/postman/local-view.d.ts +0 -17
  261. package/types/src/webapi/postman/openapi-to-postman.d.ts +0 -62
  262. package/types/src/webapi/workspace-readme.d.ts +0 -18
  263. package/types/src/webapi.action.d.ts +0 -14
  264. package/types/src/webapi.command.d.ts +0 -11
@@ -1,258 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "DockerCompose", {
6
- enumerable: true,
7
- get: function() {
8
- return DockerCompose;
9
- }
10
- });
11
- const _nodefs = require("node:fs");
12
- const _yaml = require("yaml");
13
- const _const = require("./const.js");
14
- class DockerCompose {
15
- key = _const.WELL_KNOWN_FILES.DOCKER_COMPOSE;
16
- _projectName;
17
- _headerComments = [];
18
- _services = new Map();
19
- _volumes = new Set();
20
- _networks = new Map();
21
- _envFiles = [];
22
- _existing;
23
- /** Load an existing compose file so `decohere add api` can merge into it. */ static fromFile(absolutePath) {
24
- const compose = new DockerCompose();
25
- compose._existing = (0, _yaml.parseDocument)((0, _nodefs.readFileSync)(absolutePath, "utf8"));
26
- return compose;
27
- }
28
- /** True when the service is defined (in the loaded file or added since). */ hasService(name) {
29
- return this._services.has(name) || this._existing?.hasIn([
30
- "services",
31
- name
32
- ]) === true;
33
- }
34
- /** Compose project name (`name:` top-level) — isolates containers/volumes. */ setProjectName(name) {
35
- this._projectName = name;
36
- return this;
37
- }
38
- /** File-level `#` comments rendered above `name:` / `services:`. */ addHeaderComment(...lines) {
39
- this._headerComments.push(...lines);
40
- return this;
41
- }
42
- addService(name, config) {
43
- this._services.set(name, config);
44
- return this;
45
- }
46
- files() {
47
- return [
48
- {
49
- filePath: ".devcontainer/docker-compose.yml",
50
- content: this.getContent()
51
- }
52
- ];
53
- }
54
- addVolume(name) {
55
- this._volumes.add(name);
56
- return this;
57
- }
58
- addNetwork(key, network) {
59
- this._networks.set(key, network);
60
- return this;
61
- }
62
- /** Append an env_file path to an existing service. */ addEnvFile(serviceName, filePath) {
63
- // A service already in the loaded file wins over an `addService` of the same name.
64
- const svc = this._existing?.hasIn([
65
- "services",
66
- serviceName
67
- ]) ? undefined : this._services.get(serviceName);
68
- if (svc) svc.env_file = [
69
- ...svc.env_file ?? [],
70
- filePath
71
- ];
72
- else this._envFiles.push([
73
- serviceName,
74
- filePath
75
- ]);
76
- return this;
77
- }
78
- getContent() {
79
- if (this._existing) return this.mergeIntoExisting(this._existing);
80
- const lines = [];
81
- for (const comment of this._headerComments){
82
- lines.push(comment.startsWith("#") ? comment : `# ${comment}`);
83
- }
84
- if (this._headerComments.length > 0) {
85
- lines.push("");
86
- }
87
- if (this._projectName) {
88
- lines.push(`name: ${this._projectName}`, "");
89
- }
90
- lines.push("services:");
91
- for (const [name, svc] of this._services){
92
- lines.push(` ${name}:`);
93
- if (svc.build) lines.push(` build: ${svc.build}`);
94
- if (svc.image) lines.push(` image: ${svc.image}`);
95
- if (svc.container_name) lines.push(` container_name: ${svc.container_name}`);
96
- if (svc.command) lines.push(` command: ${svc.command}`);
97
- if (svc.user) lines.push(` user: "${svc.user}"`);
98
- if (svc.restart) lines.push(` restart: ${svc.restart}`);
99
- if (svc.profiles && svc.profiles.length > 0) {
100
- lines.push(" profiles:");
101
- for (const p of svc.profiles)lines.push(` - ${p}`);
102
- }
103
- if (svc.env_file && svc.env_file.length > 0) {
104
- lines.push(" env_file:");
105
- for (const f of svc.env_file)lines.push(` - ${f}`);
106
- }
107
- if (svc.environment && Object.keys(svc.environment).length > 0) {
108
- lines.push(" environment:");
109
- for (const [k, v] of Object.entries(svc.environment)){
110
- lines.push(` ${k}: ${v}`);
111
- }
112
- }
113
- if (svc.ports && svc.ports.length > 0) {
114
- lines.push(" ports:");
115
- for (const p of svc.ports)lines.push(` - "${p}"`);
116
- }
117
- if (svc.volumes && svc.volumes.length > 0) {
118
- lines.push(" volumes:");
119
- for (const v of svc.volumes)lines.push(` - ${v}`);
120
- }
121
- if (svc.networks && svc.networks.length > 0) {
122
- const onlyStrings = svc.networks.every((n)=>typeof n === "string");
123
- if (onlyStrings) {
124
- lines.push(" networks:");
125
- for (const n of svc.networks)lines.push(` - ${n}`);
126
- } else {
127
- lines.push(" networks:");
128
- for (const n of svc.networks){
129
- if (typeof n === "string") {
130
- lines.push(` ${n}:`);
131
- } else {
132
- for (const [netKey, cfg] of Object.entries(n)){
133
- lines.push(` ${netKey}:`);
134
- if (cfg.aliases && cfg.aliases.length > 0) {
135
- lines.push(" aliases:");
136
- for (const a of cfg.aliases)lines.push(` - ${a}`);
137
- }
138
- }
139
- }
140
- }
141
- }
142
- }
143
- if (svc.depends_on && svc.depends_on.length > 0) {
144
- lines.push(" depends_on:");
145
- for (const d of svc.depends_on)lines.push(` - ${d}`);
146
- }
147
- if (svc.healthcheck) {
148
- const hc = svc.healthcheck;
149
- lines.push(" healthcheck:");
150
- lines.push(` test: ${JSON.stringify(hc.test)}`);
151
- if (hc.interval) lines.push(` interval: ${hc.interval}`);
152
- if (hc.timeout) lines.push(` timeout: ${hc.timeout}`);
153
- if (hc.retries != null) lines.push(` retries: ${hc.retries}`);
154
- }
155
- }
156
- if (this._networks.size > 0) {
157
- lines.push("");
158
- lines.push("networks:");
159
- for (const [key, net] of this._networks){
160
- lines.push(` ${key}:`);
161
- lines.push(` name: ${net.name}`);
162
- if (net.external) lines.push(" external: true");
163
- }
164
- }
165
- if (this._volumes.size > 0) {
166
- lines.push("");
167
- lines.push("volumes:");
168
- for (const v of this._volumes)lines.push(` ${v}:`);
169
- }
170
- return `${lines.join("\n")}\n`;
171
- }
172
- mergeIntoExisting(doc) {
173
- if (!(0, _yaml.isMap)(doc.contents)) throw new Error("docker-compose.yml is not a YAML mapping");
174
- for (const line of this._headerComments){
175
- const text = line.replace(/^#\s?/, "");
176
- const before = doc.commentBefore ?? "";
177
- if (!before.includes(text)) doc.commentBefore = before ? `${before}\n ${text}` : ` ${text}`;
178
- }
179
- for (const [name, svc] of this._services){
180
- if (!doc.hasIn([
181
- "services",
182
- name
183
- ])) doc.setIn([
184
- "services",
185
- name
186
- ], doc.createNode(toComposeYaml(svc)));
187
- }
188
- for (const [service, path] of this._envFiles){
189
- if (!doc.hasIn([
190
- "services",
191
- service
192
- ])) continue;
193
- const envFiles = doc.getIn([
194
- "services",
195
- service,
196
- "env_file"
197
- ]);
198
- if ((0, _yaml.isSeq)(envFiles)) {
199
- if (!envFiles.items.some((item)=>String(item) === path)) envFiles.add(path);
200
- } else if (envFiles == null) {
201
- doc.setIn([
202
- "services",
203
- service,
204
- "env_file"
205
- ], doc.createNode([
206
- path
207
- ]));
208
- } else if (String(envFiles) !== path) {
209
- doc.setIn([
210
- "services",
211
- service,
212
- "env_file"
213
- ], doc.createNode([
214
- String(envFiles),
215
- path
216
- ]));
217
- }
218
- }
219
- for (const [key, network] of this._networks){
220
- if (!doc.hasIn([
221
- "networks",
222
- key
223
- ])) doc.setIn([
224
- "networks",
225
- key
226
- ], doc.createNode(network));
227
- }
228
- for (const volume of this._volumes){
229
- if (!doc.hasIn([
230
- "volumes",
231
- volume
232
- ])) doc.setIn([
233
- "volumes",
234
- volume
235
- ], null);
236
- }
237
- return doc.toString({
238
- lineWidth: 0
239
- });
240
- }
241
- }
242
- /** Plain compose YAML shape for a service (networks with aliases become a map). */ function toComposeYaml(svc) {
243
- const { networks, ...rest } = svc;
244
- if (!networks || networks.length === 0) return rest;
245
- if (networks.every((n)=>typeof n === "string")) return {
246
- ...rest,
247
- networks
248
- };
249
- const networkMap = {};
250
- for (const network of networks){
251
- if (typeof network === "string") networkMap[network] = null;
252
- else Object.assign(networkMap, network);
253
- }
254
- return {
255
- ...rest,
256
- networks: networkMap
257
- };
258
- }
@@ -1,86 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: Object.getOwnPropertyDescriptor(all, name).get
9
- });
10
- }
11
- _export(exports, {
12
- get ConfigYaml () {
13
- return ConfigYaml;
14
- },
15
- get injectYamlDataSource () {
16
- return injectYamlDataSource;
17
- }
18
- });
19
- const _nodefs = require("node:fs");
20
- class ConfigYaml {
21
- key;
22
- filePath;
23
- _sections = [];
24
- constructor(key, filePath, baseContent){
25
- this.key = key;
26
- this.filePath = filePath;
27
- this._sections.push(baseContent);
28
- }
29
- addSection(yaml) {
30
- this._sections.push(yaml);
31
- return this;
32
- }
33
- /** True when a datasource with this `name:` already appears in the file. */ hasDataSource(name) {
34
- return this._sections.join("\n").includes(`name: ${name}\n`);
35
- }
36
- hasDataSources() {
37
- return this._sections.join("\n").includes("dataSources:");
38
- }
39
- /**
40
- * Insert a `dataSources` list item. Used by `webapi add` so we do not write a
41
- * second top-level `database:` key (YAML last-key-wins).
42
- */ appendDataSource(item) {
43
- const current = this._sections.join("\n");
44
- this._sections.length = 0;
45
- this._sections.push(injectYamlDataSource(current, item));
46
- return this;
47
- }
48
- static fromFile(key, relativePath, absolutePath) {
49
- const content = (0, _nodefs.readFileSync)(absolutePath, "utf8");
50
- return new ConfigYaml(key, relativePath, content);
51
- }
52
- files() {
53
- return [
54
- {
55
- filePath: this.filePath,
56
- content: this._sections.join("\n")
57
- }
58
- ];
59
- }
60
- }
61
- function injectYamlDataSource(yaml, item) {
62
- const block = item.replace(/\n$/, "");
63
- if (!yaml.includes("dataSources:")) {
64
- const prefix = yaml.trimEnd();
65
- const section = `database:\n dataSources:\n${block}\n`;
66
- return prefix.length > 0 ? `${prefix}\n\n${section}` : section;
67
- }
68
- const lines = yaml.split("\n");
69
- const dsIndex = lines.findIndex((line)=>/^\s*dataSources:\s*$/.test(line));
70
- if (dsIndex < 0) {
71
- return `${yaml.trimEnd()}\n\ndatabase:\n dataSources:\n${block}\n`;
72
- }
73
- let insertAt = lines.length;
74
- for(let i = dsIndex + 1; i < lines.length; i++){
75
- if (/^[A-Za-z]/.test(lines[i] ?? "")) {
76
- insertAt = i;
77
- break;
78
- }
79
- }
80
- const insertLines = block.split("\n");
81
- if (insertAt < lines.length && lines[insertAt - 1] !== "") {
82
- insertLines.push("");
83
- }
84
- lines.splice(insertAt, 0, ...insertLines);
85
- return lines.join("\n");
86
- }
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "WELL_KNOWN_FILES", {
6
- enumerable: true,
7
- get: function() {
8
- return WELL_KNOWN_FILES;
9
- }
10
- });
11
- const WELL_KNOWN_FILES = {
12
- VSCODE_SETTINGS: "VSCODE_SETTINGS",
13
- LAUNCH_JSON: "LAUNCH_JSON",
14
- DOCKER_COMPOSE: "DOCKER_COMPOSE",
15
- DEVCONTAINER_JSON: "DEVCONTAINER_JSON",
16
- DOCKERFILE: "DOCKERFILE",
17
- PRODUCTION_DOCKERFILE: "PRODUCTION_DOCKERFILE",
18
- GITHUB_CI: "GITHUB_CI",
19
- PACKAGE_JSON: "PACKAGE_JSON",
20
- API_PACKAGE_JSON: "API_PACKAGE_JSON",
21
- TSCONFIG: "TSCONFIG",
22
- VITEST_CONFIG: "VITEST_CONFIG",
23
- MAIN_TS: "MAIN_TS",
24
- CONTROLLER_TS: "CONTROLLER_TS",
25
- CONFIG_YAML: "CONFIG_YAML",
26
- CONFIG_DEV_YAML: "CONFIG_DEV_YAML",
27
- GITIGNORE: "GITIGNORE",
28
- AUTH_CONFIG: "AUTH_CONFIG",
29
- ENV_FILE: "ENV_FILE"
30
- };
@@ -1,172 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "DevContainer", {
6
- enumerable: true,
7
- get: function() {
8
- return DevContainer;
9
- }
10
- });
11
- const _nodefs = require("node:fs");
12
- const _const = require("./const.js");
13
- class DevContainer {
14
- key = _const.WELL_KNOWN_FILES.DEVCONTAINER_JSON;
15
- _extensions = [];
16
- _ports = [];
17
- _portAttributes = new Map();
18
- _mounts;
19
- _workspaceFolder = "/workspace";
20
- _postCreateCommand;
21
- _updateContentCommand;
22
- _postStartCommand;
23
- _initializeCommand;
24
- _remoteUser = "node";
25
- _useCompose = false;
26
- _existing;
27
- /**
28
- * Load an existing devcontainer.json so `decohere add api` can merge into it.
29
- * Only extensions, forwarded ports and port attributes are merged; everything else is kept.
30
- */ static fromFile(absolutePath) {
31
- const devContainer = new DevContainer();
32
- try {
33
- devContainer._existing = JSON.parse((0, _nodefs.readFileSync)(absolutePath, "utf8"));
34
- } catch (error) {
35
- throw new Error(`Can't update ${absolutePath}: it isn't plain JSON (${error.message}). Remove any comments or trailing commas and try again.`);
36
- }
37
- return devContainer;
38
- }
39
- constructor(){
40
- this._mounts = [
41
- this.bindMount(this._workspaceFolder)
42
- ];
43
- }
44
- /** In-container path Cursor/VS Code opens (Agents window uses the basename). */ setWorkspaceFolder(folder) {
45
- this._workspaceFolder = folder;
46
- this._mounts = [
47
- this.bindMount(folder)
48
- ];
49
- return this;
50
- }
51
- bindMount(target) {
52
- return `source=..,target=${target},type=bind,consistency=cached`;
53
- }
54
- addExtension(...ids) {
55
- this._extensions.push(...ids);
56
- return this;
57
- }
58
- forwardPort(...ports) {
59
- this._ports.push(...ports);
60
- return this;
61
- }
62
- setPortAttributes(port, attrs) {
63
- this._portAttributes.set(port, attrs);
64
- return this;
65
- }
66
- setPostCreateCommand(cmd) {
67
- this._postCreateCommand = cmd;
68
- return this;
69
- }
70
- setUpdateContentCommand(cmd) {
71
- this._updateContentCommand = cmd;
72
- return this;
73
- }
74
- setPostStartCommand(cmd) {
75
- this._postStartCommand = cmd;
76
- return this;
77
- }
78
- setInitializeCommand(cmd) {
79
- this._initializeCommand = cmd;
80
- return this;
81
- }
82
- setRemoteUser(user) {
83
- this._remoteUser = user;
84
- return this;
85
- }
86
- useCompose() {
87
- this._useCompose = true;
88
- return this;
89
- }
90
- files() {
91
- const config = this._existing ? this.mergeIntoExisting(this._existing) : this.build();
92
- return [
93
- {
94
- filePath: ".devcontainer/devcontainer.json",
95
- content: JSON.stringify(config, null, 2)
96
- }
97
- ];
98
- }
99
- mergeIntoExisting(existing) {
100
- const config = structuredClone(existing);
101
- if (this._extensions.length > 0) {
102
- const customizations = objectAt(config, "customizations");
103
- const vscode = objectAt(customizations, "vscode");
104
- vscode.extensions = union(vscode.extensions, this._extensions);
105
- }
106
- if (this._ports.length > 0) {
107
- config.forwardPorts = union(config.forwardPorts, this._ports);
108
- }
109
- if (this._portAttributes.size > 0) {
110
- const attributes = objectAt(config, "portsAttributes");
111
- for (const [port, attrs] of this._portAttributes){
112
- attributes[String(port)] ??= attrs;
113
- }
114
- }
115
- return config;
116
- }
117
- build() {
118
- const config = {};
119
- if (this._useCompose) {
120
- config.dockerComposeFile = "docker-compose.yml";
121
- config.service = "devcontainer";
122
- config.workspaceFolder = this._workspaceFolder;
123
- }
124
- if (this._initializeCommand) {
125
- config.initializeCommand = this._initializeCommand;
126
- }
127
- if (this._mounts) {
128
- config.mounts = this._mounts;
129
- }
130
- if (this._extensions.length > 0) {
131
- config.customizations = {
132
- vscode: {
133
- extensions: this._extensions
134
- }
135
- };
136
- }
137
- if (this._ports.length > 0) {
138
- config.forwardPorts = this._ports;
139
- }
140
- if (this._portAttributes.size > 0) {
141
- const portsAttributes = {};
142
- for (const [port, attrs] of this._portAttributes){
143
- portsAttributes[String(port)] = attrs;
144
- }
145
- config.portsAttributes = portsAttributes;
146
- }
147
- if (this._postCreateCommand) {
148
- config.postCreateCommand = this._postCreateCommand;
149
- }
150
- if (this._updateContentCommand) {
151
- config.updateContentCommand = this._updateContentCommand;
152
- }
153
- if (this._postStartCommand) {
154
- config.postStartCommand = this._postStartCommand;
155
- }
156
- if (this._remoteUser) {
157
- config.remoteUser = this._remoteUser;
158
- }
159
- return config;
160
- }
161
- }
162
- /** The object at `parent[key]`, created when missing. */ function objectAt(parent, key) {
163
- parent[key] ??= {};
164
- return parent[key];
165
- }
166
- function union(existing, additions) {
167
- const items = Array.isArray(existing) ? [
168
- ...existing
169
- ] : [];
170
- for (const item of additions)if (!items.includes(item)) items.push(item);
171
- return items;
172
- }