@sap/cds-dk 7.9.4 → 8.0.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 (286) hide show
  1. package/CHANGELOG.md +2116 -0
  2. package/bin/add.js +18 -52
  3. package/bin/bind.js +2 -2
  4. package/bin/build.js +29 -4
  5. package/bin/cds.js +23 -11
  6. package/bin/compile/index.js +7 -6
  7. package/bin/completion/index.js +70 -46
  8. package/bin/completion/scripts/cds-bash.sh +4 -1
  9. package/bin/completion/scripts/cds-fish.fish +13 -0
  10. package/bin/completion/scripts/cds-ps.ps1 +2 -1
  11. package/bin/completion/scripts/cds-zsh.sh +2 -1
  12. package/bin/deploy/index.js +6 -5
  13. package/bin/deploy/to-sqlite.js +2 -2
  14. package/bin/extend.js +19 -50
  15. package/bin/help.js +2 -2
  16. package/bin/init.js +10 -77
  17. package/bin/login.js +13 -5
  18. package/bin/migrate.js +1 -1
  19. package/bin/pull.js +11 -0
  20. package/bin/repl.js +3 -0
  21. package/bin/test.js +5 -0
  22. package/bin/version.js +7 -7
  23. package/bin/watch.js +2 -11
  24. package/lib/bind/KubernetesApiAccessor.js +10 -9
  25. package/lib/build/buildTaskEngine.js +11 -7
  26. package/lib/build/buildTaskFactory.js +15 -43
  27. package/lib/build/buildTaskProviderFactory.js +16 -44
  28. package/lib/build/constants.js +3 -3
  29. package/lib/build/index.js +2 -2
  30. package/lib/build/{buildPlugin.js → plugin.js} +65 -46
  31. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/content-deployment/Chart.yaml +1 -1
  32. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/content-deployment/values.yaml +1 -1
  33. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/service-instance/Chart.yaml +1 -1
  34. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/service-instance/templates/_helpers.tpl +7 -0
  35. package/lib/build/plugins/helm/files/subcharts/service-instance/templates/servicebinding.yaml +32 -0
  36. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/service-instance/templates/serviceinstance.yaml +3 -0
  37. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/service-instance/values.schema.json +63 -0
  38. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/service-instance/values.yaml +23 -1
  39. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/Chart.yaml +1 -1
  40. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/deployment.yaml +2 -0
  41. package/lib/build/plugins/helm/files/subcharts/web-application/templates/hpa.yaml +22 -0
  42. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/pod-disruption-budget.yaml +1 -0
  43. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/values.schema.json +49 -0
  44. package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/values.yaml +8 -2
  45. package/lib/{init/template/helm/files/chart → build/plugins/helm/files}/templates/_deployment_helpers.tpl +5 -0
  46. package/lib/build/plugins/helm/files/templates/_helpers.tpl +13 -0
  47. package/lib/build/plugins/helm/index.js +81 -0
  48. package/lib/build/plugins.js +12 -15
  49. package/lib/build/provider/featureToggleBuildPlugin.js +7 -39
  50. package/lib/build/provider/hana/2migration.js +168 -124
  51. package/lib/build/provider/hana/index.js +20 -25
  52. package/lib/build/provider/hana/template/.hdiconfig-all +3 -0
  53. package/lib/build/provider/hana/template/.hdiconfig-cloud +3 -0
  54. package/lib/build/provider/hana/template/package.json +4 -3
  55. package/lib/build/provider/internalBuildPlugin.js +32 -97
  56. package/lib/build/provider/internalBuildTaskProvider.js +10 -46
  57. package/lib/build/provider/java/index.js +2 -3
  58. package/lib/build/provider/mtx/index.js +5 -4
  59. package/lib/build/provider/mtx-extension/index.js +5 -2
  60. package/lib/build/provider/mtx-sidecar/index.js +2 -2
  61. package/lib/build/util.js +83 -12
  62. package/lib/compile/to-mermaid.js +108 -0
  63. package/lib/compile/to_asyncapi.js +7 -0
  64. package/lib/compile/to_openapi.js +7 -0
  65. package/lib/deploy/to-hana/hana.js +37 -34
  66. package/lib/deploy/to-hana/hdiDeployUtil.js +8 -6
  67. package/lib/env/schemas/cds-rc.js +1 -1
  68. package/lib/import/common.js +2 -2
  69. package/lib/import/odata/metadataconverter/MetadataConverter.js +4 -4
  70. package/lib/import/odata/v2parser.js +83 -197
  71. package/lib/import/odata/v4parser.js +1 -38
  72. package/lib/import/openapi/importOpenAPI.js +164 -42
  73. package/lib/index.js +10 -12
  74. package/lib/init/bas.js +91 -0
  75. package/lib/init/constants.js +16 -10
  76. package/lib/init/index.js +74 -150
  77. package/lib/init/merge.js +12 -20
  78. package/lib/init/mvn.js +103 -150
  79. package/lib/init/plugin.js +11 -7
  80. package/lib/init/projectReader.js +53 -19
  81. package/lib/init/registries/mta.js +51 -6
  82. package/lib/init/template/application-logging/files/package.json.hbs +7 -0
  83. package/lib/init/template/application-logging/index.js +13 -1
  84. package/lib/init/template/approuter/files/containerize.yaml.hbs +10 -0
  85. package/lib/init/template/approuter/files/mta.yaml.hbs +1 -2
  86. package/lib/init/template/approuter/files/values.yaml.hbs +19 -4
  87. package/lib/init/template/approuter/files/xs-app.json.hbs +12 -3
  88. package/lib/init/template/approuter/index.js +29 -25
  89. package/lib/init/template/attachments/files/mta.yaml.hbs +14 -0
  90. package/lib/init/template/attachments/files/package.json.hbs +5 -0
  91. package/lib/init/template/attachments/files/values.yaml +7 -0
  92. package/lib/init/template/attachments/index.js +53 -0
  93. package/lib/init/template/audit-logging/files/mta.yaml.hbs +14 -0
  94. package/lib/init/template/audit-logging/files/package.json.hbs +7 -0
  95. package/lib/init/template/audit-logging/index.js +66 -0
  96. package/lib/init/template/cf-manifest/index.js +4 -0
  97. package/lib/init/template/completion/completionSetup.js +54 -33
  98. package/lib/init/template/completion/index.js +7 -1
  99. package/lib/init/template/connectivity/index.js +4 -4
  100. package/lib/init/template/containerize/files/containerize.yaml.hbs +26 -0
  101. package/lib/init/template/containerize/index.js +24 -0
  102. package/lib/init/template/data/index.js +4 -0
  103. package/lib/init/template/destination/files/mta.yaml.hbs +25 -1
  104. package/lib/init/template/destination/index.js +12 -2
  105. package/lib/init/template/enterprise-messaging/index.js +6 -3
  106. package/lib/init/template/enterprise-messaging-shared/index.js +5 -1
  107. package/lib/init/template/extensibility/files/package.json.hbs +1 -1
  108. package/lib/init/template/extensibility/files/xs-security.json.hbs +2 -8
  109. package/lib/init/template/extensibility/index.js +3 -1
  110. package/lib/init/template/file-based-messaging/index.js +4 -0
  111. package/lib/init/template/h2/index.js +4 -0
  112. package/lib/init/template/hana/files/containerize.yaml.hbs +10 -0
  113. package/lib/init/template/hana/files/db/package.json +3 -2
  114. package/lib/init/template/hana/files/package.json.hbs +4 -7
  115. package/lib/init/template/hana/files/src/.hdiconfig +3 -0
  116. package/lib/init/template/hana/files/values.yaml.hbs +1 -2
  117. package/lib/init/template/hana/index.js +15 -7
  118. package/lib/init/template/helm/files/Chart.yaml.hbs +2 -3
  119. package/lib/init/template/helm/files/values.schema.json +2173 -0
  120. package/lib/init/template/helm/files/values.yaml.hbs +11 -6
  121. package/lib/init/template/helm/index.js +77 -18
  122. package/lib/init/template/helm-unified-runtime/index.js +19 -56
  123. package/lib/init/template/html5-repo/files/app-package.json.hbs +11 -7
  124. package/lib/init/template/html5-repo/files/manifest.json +13 -0
  125. package/lib/init/template/html5-repo/files/mta.yaml.hbs +41 -8
  126. package/lib/init/template/html5-repo/files/ui5-deploy.yaml.hbs +21 -0
  127. package/lib/init/template/html5-repo/files/ui5.yaml.hbs +2 -29
  128. package/lib/init/template/html5-repo/files/values.yaml.hbs +6 -2
  129. package/lib/init/template/html5-repo/files/xs-app.json.hbs +21 -8
  130. package/lib/init/template/html5-repo/index.js +33 -30
  131. package/lib/init/template/http/index.js +36 -12
  132. package/lib/init/template/java/index.js +18 -12
  133. package/lib/init/template/kafka/index.js +4 -0
  134. package/lib/init/template/lint/index.js +7 -2
  135. package/lib/init/template/liquibase/index.js +4 -0
  136. package/lib/init/template/local-messaging/index.js +4 -0
  137. package/lib/init/template/malware-scanner/files/mta.yaml.hbs +14 -0
  138. package/lib/init/template/malware-scanner/files/package.json.hbs +17 -0
  139. package/lib/init/template/malware-scanner/files/values.yaml +7 -0
  140. package/lib/init/template/malware-scanner/index.js +47 -0
  141. package/lib/init/template/mta/files/mta.yaml.hbs +3 -3
  142. package/lib/init/template/mta/files/package.json +1 -1
  143. package/lib/init/template/mta/index.js +4 -0
  144. package/lib/init/template/mtx/index.js +4 -0
  145. package/lib/init/template/multitenancy/files/containerize.yaml.hbs +10 -0
  146. package/lib/init/template/multitenancy/files/mta.yaml.hbs +0 -1
  147. package/lib/init/template/multitenancy/files/package.json.hbs +1 -1
  148. package/lib/init/template/multitenancy/files/package.sidecar.json.hbs +6 -5
  149. package/lib/init/template/multitenancy/files/values.yaml.hbs +14 -24
  150. package/lib/init/template/multitenancy/index.js +50 -28
  151. package/lib/init/template/nodejs/files/eslint.config.mjs +2 -0
  152. package/lib/init/template/nodejs/files/package.json.hbs +2 -3
  153. package/lib/init/template/nodejs/index.js +4 -0
  154. package/lib/init/template/notifications/files/mta.yaml.hbs +2 -2
  155. package/lib/init/template/notifications/index.js +4 -0
  156. package/lib/init/template/pipeline/files/.pipeline/config.yml +1 -1
  157. package/lib/init/template/pipeline/files/Jenkinsfile +1 -1
  158. package/lib/init/template/pipeline/index.js +4 -0
  159. package/lib/init/template/portal/files/mta.yaml.hbs +52 -0
  160. package/lib/init/template/portal/files/package.json.hbs +11 -0
  161. package/lib/init/template/portal/files/package.sidecar.json +7 -0
  162. package/lib/init/template/portal/files/portal-site/CommonDataModel.json.hbs +97 -0
  163. package/lib/init/template/portal/files/portal-site/i18n/catalog.properties +1 -0
  164. package/lib/init/template/portal/files/portal-site/i18n/catalog_de.properties +1 -0
  165. package/lib/init/template/portal/files/portal-site/i18n/group.properties +1 -0
  166. package/lib/init/template/portal/files/portal-site/i18n/group_de.properties +1 -0
  167. package/lib/init/template/portal/index.js +84 -0
  168. package/lib/init/template/postgres/index.js +5 -1
  169. package/lib/init/template/redis-messaging/index.js +4 -0
  170. package/lib/init/template/sample/files/app/admin-books/webapp/i18n/i18n_de.properties +3 -0
  171. package/lib/init/template/sample/files/app/admin-books/webapp/i18n/i18n_en.properties +3 -0
  172. package/lib/init/template/sample/files/app/admin-books/webapp/manifest.json +13 -1
  173. package/lib/init/template/sample/files/app/browse/webapp/i18n/i18n.properties +2 -2
  174. package/lib/init/template/sample/files/app/browse/webapp/i18n/i18n_de.properties +3 -0
  175. package/lib/init/template/sample/files/app/browse/webapp/i18n/i18n_en.properties +4 -0
  176. package/lib/init/template/sample/files/app/browse/webapp/manifest.json +3 -3
  177. package/lib/init/template/sample/files/app/index.html +1 -1
  178. package/lib/init/template/sample/files/db/data/sap.capire.bookshop-Authors.csv +5 -5
  179. package/lib/init/template/sample/files/db/data/sap.capire.bookshop-Books.csv +6 -6
  180. package/lib/init/template/sample/files/db/data/sap.capire.bookshop-Books_texts.csv +5 -5
  181. package/lib/init/template/sample/files/db/data/sap.capire.bookshop-Genres.csv +16 -16
  182. package/lib/init/template/sample/files/nodejs/cat-service.js +2 -2
  183. package/lib/init/template/sample/files/package.json.hbs +3 -0
  184. package/lib/init/template/sample/index.js +16 -9
  185. package/lib/init/template/sqlite/index.js +4 -0
  186. package/lib/init/template/tiny-sample/files/nodejs/db/data/my.bookshop-Books.csv +3 -3
  187. package/lib/init/template/tiny-sample/files/nodejs/srv/cat-service.cds.hbs +1 -1
  188. package/lib/init/template/tiny-sample/index.js +4 -0
  189. package/lib/init/template/toggles/files/package.json.hbs +1 -1
  190. package/lib/init/template/toggles/index.js +4 -0
  191. package/lib/init/template/typer/index.js +4 -0
  192. package/lib/init/template/typescript/files/package.json +12 -0
  193. package/lib/init/template/typescript/files/tsconfig.json +13 -0
  194. package/lib/init/template/typescript/index.js +39 -0
  195. package/lib/init/template/workzone/index.js +5 -0
  196. package/lib/init/template/workzone-standard/files/manifest.json.hbs +6 -0
  197. package/lib/init/template/workzone-standard/index.js +30 -0
  198. package/lib/init/template/xsuaa/files/package.json.hbs +1 -1
  199. package/lib/init/template/xsuaa/files/values.yaml.hbs +3 -2
  200. package/lib/init/template/xsuaa/index.js +11 -7
  201. package/lib/init/validate.js +27 -0
  202. package/lib/lint/generators.js +1 -1
  203. package/lib/lint/io.js +25 -7
  204. package/lib/mtx/auth_manager.js +64 -30
  205. package/lib/mtx/download_legacy.js +2 -2
  206. package/lib/mtx/index.js +0 -4
  207. package/lib/mtx/params.js +32 -38
  208. package/lib/mtx/pull.js +151 -43
  209. package/lib/mtx/push.js +3 -3
  210. package/lib/mtx/settings_manager.js +75 -35
  211. package/lib/mtx/tenant_action.js +1 -1
  212. package/lib/mtx/util/cf.js +1 -1
  213. package/lib/mtx/util/fs.js +26 -1
  214. package/lib/mtx/util/logging.js +7 -3
  215. package/lib/util/command.js +0 -2
  216. package/lib/util/fs.js +2 -3
  217. package/lib/util/question.js +28 -0
  218. package/lib/util/term.js +5 -3
  219. package/npm-shrinkwrap.json +231 -1089
  220. package/package.json +13 -8
  221. package/bin/activate.js +0 -77
  222. package/lib/compile/asyncapi/channels.js +0 -22
  223. package/lib/compile/asyncapi/components/messageTraits/index.js +0 -89
  224. package/lib/compile/asyncapi/components/messages/index.js +0 -173
  225. package/lib/compile/asyncapi/components/schemas/annotations.js +0 -33
  226. package/lib/compile/asyncapi/components/schemas/array.js +0 -8
  227. package/lib/compile/asyncapi/components/schemas/cache.js +0 -14
  228. package/lib/compile/asyncapi/components/schemas/definition.js +0 -187
  229. package/lib/compile/asyncapi/components/schemas/enum.js +0 -16
  230. package/lib/compile/asyncapi/components/schemas/examples.js +0 -10
  231. package/lib/compile/asyncapi/components/schemas/index.js +0 -14
  232. package/lib/compile/asyncapi/components/schemas/localized.js +0 -29
  233. package/lib/compile/asyncapi/components/schemas/primitiveElement.js +0 -41
  234. package/lib/compile/asyncapi/components/schemas/ref.js +0 -45
  235. package/lib/compile/asyncapi/components/schemas/utils.js +0 -108
  236. package/lib/compile/asyncapi/index.js +0 -247
  237. package/lib/compile/asyncapi/message.js +0 -13
  238. package/lib/compile/asyncapi/utils.js +0 -27
  239. package/lib/compile/openapi/csdl2openapi.js +0 -2448
  240. package/lib/compile/openapi/index.js +0 -68
  241. package/lib/init/template/helm/files/chart/templates/NOTES.txt +0 -14
  242. package/lib/init/template/helm/files/chart/templates/_helpers.tpl +0 -28
  243. package/lib/init/template/helm/files/chart/values.root.schema.json +0 -61
  244. package/lib/init/template/helm/files/chart/values.schema.json +0 -366
  245. package/lib/init/template/helm-unified-runtime/files/Chart.yaml.hbs +0 -10
  246. package/lib/init/template/helm-unified-runtime/files/templates/_deployment_helpers.tpl +0 -90
  247. package/lib/init/template/helm-unified-runtime/files/templates/_helpers.tpl +0 -28
  248. package/lib/init/template/helm-unified-runtime/files/values.root.schema.json +0 -61
  249. package/lib/init/template/helm-unified-runtime/files/values.schema.json +0 -366
  250. package/lib/init/template/helm-unified-runtime/files/values.yaml.hbs +0 -26
  251. package/lib/init/template/helm-unified-runtime/package.json +0 -4
  252. package/lib/init/template/multitenancy/files/mtxs-configmap-java-approuter.yaml +0 -20
  253. package/lib/init/template/multitenancy/files/mtxs-configmap-java.yaml +0 -18
  254. package/lib/init/template/multitenancy/files/mtxs-configmap-nodejs-approuter.yaml +0 -12
  255. package/lib/init/template/multitenancy/files/mtxs-configmap-nodejs.yaml +0 -12
  256. package/lib/init/template/multitenancy/files/saas-registry-secret.yaml +0 -9
  257. package/lib/init/template/nodejs/files/eslint.config.js +0 -13
  258. package/lib/init/template/notebook/index.js +0 -11
  259. package/lib/init/template/samples/index.js +0 -9
  260. package/lib/mtx/activate.js +0 -238
  261. package/lib/mtx/extend.js +0 -173
  262. package/lib/util/exec.d.ts +0 -54
  263. package/lib/util/exec.js +0 -211
  264. /package/lib/{init/template/approuter/files → build/plugins/helm/files/plugins/approuter}/approuter-configmap.yaml +0 -0
  265. /package/lib/{init/template/connectivity/files → build/plugins/helm/files/plugins/connectivity}/connectivity-proxy-info.yaml +0 -0
  266. /package/lib/{init/template/html5-repo/files → build/plugins/helm/files/plugins/html5-repo}/html5-apps-deployer-configmap.yaml +0 -0
  267. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/content-deployment/templates/_helpers.tpl +0 -0
  268. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/content-deployment/templates/job.yaml +0 -0
  269. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/content-deployment/templates/secret.yaml +0 -0
  270. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/content-deployment/templates/service-account.yaml +0 -0
  271. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/content-deployment/templates/service-binding.yaml +0 -0
  272. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/content-deployment/values.schema.json +0 -0
  273. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/NOTES.txt +0 -0
  274. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/_api.tpl +0 -0
  275. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/_helpers.tpl +0 -0
  276. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/api-rule.yaml +0 -0
  277. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/network-policy.yaml +0 -0
  278. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/rbac.yaml +0 -0
  279. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/secret.yaml +0 -0
  280. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/service-account.yaml +0 -0
  281. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/service-binding.yaml +0 -0
  282. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/service.yaml +0 -0
  283. /package/lib/{init/template/helm/files → build/plugins/helm/files/subcharts}/web-application/templates/virtual-service.yaml +0 -0
  284. /package/lib/{init/template/helm-unified-runtime → build/plugins/helm}/files/templates/NOTES.txt +0 -0
  285. /package/lib/init/template/{nodejs/files → java}/.cdsrc.json +0 -0
  286. /package/lib/init/template/tiny-sample/files/nodejs/db/{data-model.cds → schema.cds} +0 -0
package/lib/init/index.js CHANGED
@@ -1,102 +1,60 @@
1
- const path = require('path');
1
+ const path = require('path')
2
+ const term = require('../util/term')
3
+ const validate = require('./validate')
2
4
 
3
- const term = require('../util/term');
5
+ const { OPTIONS, COMMAND_INIT, PROJECT_FILES } = require('./constants')
6
+ const { readdirSync } = require('fs')
7
+ const { join } = require('path')
8
+ const { NODEJS, JAVA } = OPTIONS
4
9
 
5
- const { OPTIONS, COMMAND_INIT, PROJECT_FILES, REGEX_PROJECT_NAME } = require('./constants')
6
- const {
7
- NODEJS, JAVA,
8
- HANA, APPROUTER, XSUAA, APPLICATION_LOGGING, ENTERPRISE_MESSAGING,
9
- MTA, MULTITENANCY, PIPELINE,
10
- TINY_SAMPLE, SAMPLE
11
- } = OPTIONS
12
-
13
- const cds = require('..'), { exists, readdir } = cds.utils
10
+ const cds = require('..'), { exists } = cds.utils
14
11
  const DEBUG = /\b(y|all|cli)\b/.test(process.env.DEBUG) ? console.debug : undefined
15
12
 
16
13
  module.exports = class CDSGenerator {
17
- constructor() {
18
- this.cwd = process.cwd()
19
14
 
20
- this.uiConfig = [{
21
- title: 'Project Name',
22
- description: 'Enter your project name.',
23
- default: '',
24
- target: 'projectName',
25
- validate: async (value) => {
26
- try {
27
- cds.root = path.resolve(this.cwd, value || '.');
28
-
29
- await this._validateProjectName(value);
30
- await this._validateProjectFolder(path.join(this.cwd, value), this.cwd);
31
- } catch (e) {
32
- return e
33
- }
15
+ /** @returns {string[]} */
16
+ static #findPlugins(excluded) {
17
+ // actually needs to be sync to be usable in module.exports of dk/bin/init.js
18
+ const fromDk = readdirSync(join(__dirname, 'template'))
19
+ const fromPlugins = Object.keys(Object.fromEntries(require('./add').registered))
20
+ return [...fromDk, ...fromPlugins]
21
+ .filter(plugin => !excluded?.includes(plugin))
22
+ }
34
23
 
35
- return true;
36
- },
37
- guiOptions: {
38
- hint: 'This name is restricted to certain characters. A valid project name is compatible across platforms.',
39
- mandatory: true
40
- }
41
- }, {
42
- title: 'Type',
43
- description: `Select your runtime.`,
44
- default: NODEJS,
45
- choices: [
46
- { name: 'Node.js', value: NODEJS },
47
- { name: 'Java', value: JAVA }
48
- ],
49
- multiple: false,
50
- target: 'add',
51
- guiOptions: {
52
- hint: `The preferred runtime can't be changed afterwards. To use a different runtime, create a new project.`,
53
- mandatory: true
54
- }
55
- }, {
56
- title: 'Features',
57
- description: 'Choose productive runtime capabilities for your application.',
58
- default: '',
59
- choices: [
60
- { name: 'SAP HANA Cloud', value: HANA },
61
- { name: 'SAP Application Router', value: APPROUTER },
62
- { name: 'User Authentication via XSUAA', value: XSUAA },
63
- { name: 'Application Logging', value: APPLICATION_LOGGING },
64
- { name: 'SAP BTP Event Mesh', value: ENTERPRISE_MESSAGING }
65
- ],
66
- multiple: true,
67
- target: 'add',
68
- guiOptions: {
69
- hint: `Choose any combination of features enriching the capabilities of your project. You can also add features later with ${term.bold('cds add')}`
70
- }
71
- }, {
72
- title: 'Deployment',
73
- description: 'Choose which way to deploy your project.',
74
- default: '',
75
- choices: [
76
- { name: 'Cloud Foundry: MTA Deployment', value: MTA },
77
- // { name: 'Kyma: Helm Deployment', value: HELM },
78
- { name: 'Multitenancy', value: MULTITENANCY },
79
- { name: 'CI/CD Pipeline Integration', value: PIPELINE },
80
- ],
81
- multiple: true,
82
- target: 'add',
83
- guiOptions: {
84
- hint: `Choose any combination of features enriching the capabilities of your project. You can also add features later with ${term.bold('cds add')}`
85
- }
86
- }, {
87
- title: 'Samples',
88
- description: `Add sample content to your project.`,
89
- default: '',
90
- choices: [
91
- { name: 'Minimal Sample', value: TINY_SAMPLE },
92
- { name: 'Extended Sample with UI', value: SAMPLE }
93
- ],
94
- multiple: true,
95
- target: 'add',
96
- guiOptions: {
97
- hint: 'Speed up your ramp-up phase with sample files in your project.'
98
- }
99
- }]
24
+ static help({ exclude = [] } = {}) {
25
+ const plugins = this.readPlugins(exclude)
26
+ const nameFixedLength = Math.max(...plugins.map(plugin => plugin.name.length))
27
+ return plugins
28
+ .map(({name, module}) => {
29
+ const help = module.help?.() ?? ''
30
+ return ` *${name}*${' '.repeat(nameFixedLength - name.length)} - ${help}`
31
+ })
32
+ .join('\n\n')
33
+ }
34
+
35
+ /**
36
+ * @returns {{name: string, module: import('module')}[]}
37
+ */
38
+ static readPlugins(excluded = []) {
39
+ const plugins = this.#findPlugins(excluded)
40
+ .map(plugin => ({
41
+ name: plugin,
42
+ module: cds.add.registered.get(plugin) ?? require('./template/' + plugin)
43
+ }))
44
+ const cmds = Object.values(OPTIONS)
45
+ const byPriority = (lhs, rhs) => {
46
+ const a = cmds.indexOf(lhs.name), b = cmds.indexOf(rhs.name)
47
+ if (a === -1 && b === -1) return 0
48
+ if (a === -1) return 1
49
+ if (b === -1) return -1
50
+ return a - b
51
+ }
52
+ return plugins.sort(byPriority)
53
+ }
54
+
55
+ constructor() {
56
+ this.cwd = process.cwd()
57
+ this.uiConfig = require('./bas') // Used by CAP Generator
100
58
  }
101
59
 
102
60
  /**
@@ -113,7 +71,7 @@ module.exports = class CDSGenerator {
113
71
  // `add data` can live without project metadata
114
72
  const nonProjectFacets = { completion:1, data:1 }
115
73
  const needsProject = facets.some(facet => !nonProjectFacets[facet])
116
- if (needsProject && !PROJECT_FILES.find(exists)) {
74
+ if (needsProject && !PROJECT_FILES.some(exists)) {
117
75
  throw `The current folder doesn't seem to contain a project. None of the following files found: ${PROJECT_FILES.join(', ')}.`
118
76
  }
119
77
 
@@ -124,12 +82,12 @@ module.exports = class CDSGenerator {
124
82
  /**
125
83
  * @param {string} projectName, the project name
126
84
  */
127
- async initCmd(projectName) {
85
+ async init(projectName) {
128
86
  await this.stepInit(projectName);
129
87
  await this.stepEnd();
130
88
  }
131
89
 
132
- async stepInit(projectName, options) {
90
+ async stepInit(projectName, options) { // Also used by CAP Generator
133
91
  if (options) {
134
92
  // called from CAP generator with options
135
93
  cds.cli = {
@@ -177,13 +135,18 @@ module.exports = class CDSGenerator {
177
135
  async _process(facets) {
178
136
  DEBUG?.(`Project path: ${cds.root}`);
179
137
 
180
- await this._validateOptions();
181
-
182
- const { command, options } = cds.cli
138
+ const { options, command } = cds.cli
139
+ if (command === COMMAND_INIT) {
140
+ validate.projectName(this.projectName)
141
+ validate.projectFolder(this.cwd)
142
+ }
183
143
  const plugins = command === COMMAND_INIT ? options.add : new Set(facets)
184
144
  await this._fillTemplateList(plugins)
185
145
 
186
- for (const [i, facet] of Object.entries(Array.from(plugins))) {
146
+ const cmds = Object.values(OPTIONS)
147
+ const byPriority = (a, b) => cmds.indexOf(a) - cmds.indexOf(b)
148
+ const sorted = Array.from(plugins).sort(byPriority)
149
+ for (const [i, facet] of Object.entries(sorted)) {
187
150
  if (!cds.cli.options.dry) console.log(`Adding feature '${facet}'...`);
188
151
  const template = this.templateList[i]
189
152
  await template.run();
@@ -209,16 +172,16 @@ module.exports = class CDSGenerator {
209
172
  return new Plugin(this)
210
173
  } catch (err) {
211
174
  if (err.code === 'MODULE_NOT_FOUND') {
212
- const entries = (await readdir(path.join(__dirname, 'template')))
213
- .filter(entry =>
214
- !entry.startsWith('_') &&
215
- !entry.endsWith('.js') &&
216
- entry !== 'nodejs' &&
217
- entry !== 'java'
218
- );
175
+ const entries = this.constructor.readPlugins()
219
176
  const fuzzySearch = require('../../bin/util/fuzzySearch')
220
- const [bestMatch] = fuzzySearch(plugin, entries)
221
- throw `Unknown facet '${term.bold(plugin)}'. Did you mean ${term.bold(`cds add ${bestMatch}`)}?\n\nHaven't found the proper facet yet? Here are all supported facets:\n\n ${term.bold(entries.join('\n '))}\n`
177
+ const [bestMatch] = fuzzySearch(plugin, entries.map(e => e.name))
178
+ const max = entries.reduce((max, {name}) => Math.max(max, name.length), 0)
179
+ const allFacetsText = entries.map(({name, module}) => {
180
+ const help = module.help?.() ?? ''
181
+ return `${term.bold(name) + ' '.repeat(max - name.length)} ${term.dim(help)}`
182
+ }).join('\n')
183
+ DEBUG?.(err)
184
+ throw `Unknown facet '${term.bold(plugin)}'. Did you mean ${term.bold(`cds add ${bestMatch}`)}?\n\nHaven't found the proper facet yet? Here are all supported facets:\n\n${allFacetsText}\n`
222
185
  }
223
186
  throw err
224
187
  }
@@ -226,7 +189,6 @@ module.exports = class CDSGenerator {
226
189
 
227
190
  async _fillTemplateList(plugins) {
228
191
  const templates = new Map
229
-
230
192
  for (let plugin of plugins) {
231
193
  // Compat
232
194
  if (plugin === 'helm' && cds.cli.options['internal-unified-runtime-charts']) {
@@ -245,6 +207,8 @@ module.exports = class CDSGenerator {
245
207
  templates.set(plugin, template)
246
208
  const dependencies = await template.requires()
247
209
  dependencies?.forEach(d => plugins.add(d))
210
+ } else {
211
+ throw 'cannot run plugin \'' + plugin + '\'' + (DEBUG ? 'Does not satisfy the canRun() function:\n ' + template.canRun : '')
248
212
  }
249
213
  }
250
214
  }
@@ -260,12 +224,10 @@ module.exports = class CDSGenerator {
260
224
  })
261
225
  .map((entry) => entry[1])
262
226
 
263
- // check debug to avoid lengthy computation when not in debug mode
264
227
  DEBUG?.(`Features: ${this.templateList.map(({ name }) => name).join(', ')}`);
265
228
  }
266
229
 
267
- // CAP Generator API
268
- async stepEnd() {
230
+ async stepEnd() { // Also used by CAP Generator
269
231
  for (const template of this.templateList) {
270
232
  await template.finalize();
271
233
  }
@@ -305,42 +267,4 @@ module.exports = class CDSGenerator {
305
267
  options.add.add(NODEJS);
306
268
  }
307
269
  }
308
-
309
- async _validateOptions() {
310
- const { options, command } = cds.cli
311
- if (options.force) {
312
- return;
313
- }
314
-
315
- if (command === COMMAND_INIT) {
316
- await this._validateProjectName(this.projectName);
317
- await this._validateProjectFolder(this.cwd);
318
- }
319
- }
320
-
321
- async _validateProjectName(projectName) {
322
- if (!projectName) {
323
- throw 'Specify a project name.'
324
- }
325
-
326
- // remove duplicates by using a set
327
- const invalidChars = new Set(projectName.match(REGEX_PROJECT_NAME));
328
- if (invalidChars.size > 0) {
329
- throw `Project name '${projectName}' contains at least one character ('${[...invalidChars]}') which is not supported in npm package names.
330
- Specify a different project name by replacing characters with '_' or '-', for example '${projectName.replace(REGEX_PROJECT_NAME, '_')}' or '${projectName.replace(REGEX_PROJECT_NAME, '-')}'.`
331
- }
332
- }
333
-
334
- async _validateProjectFolder(cwd) {
335
- const existingProjectFile = PROJECT_FILES.find(exists)
336
- if (existingProjectFile) {
337
- let message;
338
- if (cwd === cds.root) {
339
- message = `You seem to be working in a project which is already initialized. Use ${term.bold('cds add')} to add more features.`;
340
- } else {
341
- message = `You seem to be trying to initialize an existing project. Use a different project name instead.`;
342
- }
343
- throw `${message}\nDetails: File '${existingProjectFile}' exists in the project folder which indicates an existing project. Use ${term.bold('cds add')} to add more features.`
344
- }
345
- }
346
270
  }
package/lib/init/merge.js CHANGED
@@ -1,9 +1,10 @@
1
- const YAML = require('@sap/cds-foss').yaml
1
+ const { EOL } = require('node:os')
2
+ const { inspect } = require('node:util')
2
3
  const cds = require('../cds')
3
- const { copy, read, write, exists } = cds.utils
4
+ const { copy, read, write, exists, path, yaml: YAML } = cds.utils
4
5
  const { readYAML, writeYAML, readJSON } = require('../util/fs')
5
- const { EOL } = require('node:os')
6
6
  const { detectIndent } = require('./indent')
7
+ const { colors } = require('../util/term')
7
8
 
8
9
  function _isObject(item) {
9
10
  return item && typeof item === 'object' && !Array.isArray(item)
@@ -28,7 +29,7 @@ function _mergeObject(target, source) {
28
29
  return target ?? source
29
30
  }
30
31
 
31
- async function sort(path, key) {
32
+ module.exports.sort = async function(path, key) {
32
33
  const json = await read(path)
33
34
  json[key] = Object.fromEntries(
34
35
  Object.entries(json[key]).sort(([a],[b]) => a>b ? 1 : -1)
@@ -41,7 +42,7 @@ async function sort(path, key) {
41
42
  * @param {string | string[]} from - either path to file (string) or lines from source gitignore (string[])
42
43
  * @returns {Promise<string[]>} the lines of the updated .gitignore
43
44
  */
44
- async function mergeGitignore (into, from) {
45
+ module.exports.mergeGitignore = async function(into, from) {
45
46
  const source = typeof from === 'string' ? (await read(from)).split(EOL) : from
46
47
 
47
48
  if (typeof into === 'string' && !exists(into)) {
@@ -196,7 +197,7 @@ async function _mergeYAML(into, from, project, semantics = {}) {
196
197
  }
197
198
  } else if (YAML.isPair(node) && node.value?.items) {
198
199
  collectionStack.unshift(node.value)
199
- } else if (YAML.isScalar(node) && semantics.forceOverwrite && templateNode) {
200
+ } else if (YAML.isScalar(node) && semantics.forceOverwrite && templateNode && node.comment != 'cds.noOverwrite') {
200
201
  node.value = templateNode.value ?? templateNode.items?.[0]?.value?.value
201
202
  }
202
203
 
@@ -326,9 +327,11 @@ async function _mergeYAML(into, from, project, semantics = {}) {
326
327
  })
327
328
  .filter(item => !entryMap.get(item))
328
329
  .forEach(item => {
330
+ if (!templateEntryMap.get(item)) throw 'Error: did not find entry in template for ' + inspect(item, { colors }) + ' in ' + from
329
331
  const templateNode = templateEntryMap.get(item).node
330
332
  item.at !== undefined ? targetNode.items.splice(item.at, 0, templateNode) : targetNode.add(templateNode)
331
333
  })
334
+
332
335
  }
333
336
  },
334
337
  }, source.contents)
@@ -372,7 +375,7 @@ async function _mergeYAML(into, from, project, semantics = {}) {
372
375
  return target
373
376
  }
374
377
 
375
- async function removeFromYAML(name, keyPaths) {
378
+ module.exports.removeFromYAML = async function (name, keyPaths) {
376
379
  const yaml = await readYAML(name)
377
380
  for (const keyPath of keyPaths) {
378
381
  let node = yaml
@@ -389,7 +392,7 @@ async function removeFromYAML(name, keyPaths) {
389
392
  await writeYAML(name, yaml)
390
393
  }
391
394
 
392
- async function removeFromYAMLArray(name, keyPath, aliasToRemove) {
395
+ module.exports.removeFromYAMLArray = async function(name, keyPath, aliasToRemove) {
393
396
  const yaml = await readYAML(name)
394
397
 
395
398
  let node = yaml
@@ -414,16 +417,13 @@ async function removeFromYAMLArray(name, keyPath, aliasToRemove) {
414
417
  await writeYAML(name, yaml)
415
418
  }
416
419
 
417
-
418
- const path = require('path')
419
-
420
420
  /**
421
421
  * @param {...(string | Object | YAML.Document)} src The source to merge from.
422
422
  * @returns {{
423
423
  * into: (dst: (string | Object | YAML.Document), options?: {project?: Object, semantics?: MergingSemantics}) => Promise<any>
424
424
  * }} An object with an 'into' method to merge the sources into the specified destination.
425
425
  */
426
- const merge = (...src) => {
426
+ module.exports.merge = (...src) => {
427
427
  return {
428
428
  /**
429
429
  * Merges sources into the specified destination.
@@ -447,11 +447,3 @@ const merge = (...src) => {
447
447
  }
448
448
  }
449
449
  }
450
-
451
- module.exports = {
452
- merge,
453
- sort,
454
- mergeGitignore,
455
- removeFromYAML,
456
- removeFromYAMLArray
457
- }