@sap/cds-dk 4.9.7 → 6.0.3

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 (145) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/bin/activate.js +4 -4
  3. package/bin/add.js +11 -5
  4. package/bin/bind.js +16 -28
  5. package/bin/build/all.js +2 -2
  6. package/bin/build/index.js +12 -19
  7. package/bin/cds.js +22 -19
  8. package/bin/compile/index.js +12 -3
  9. package/bin/deploy/index.js +15 -9
  10. package/bin/deploy/to-hana.js +4 -4
  11. package/bin/deploy/to-sqlite.js +1 -1
  12. package/bin/env.js +13 -4
  13. package/bin/eval.js +1 -1
  14. package/bin/fix-redirects.js +1 -1
  15. package/bin/import.js +44 -179
  16. package/bin/repl.js +1 -1
  17. package/bin/watch.js +10 -15
  18. package/lib/bind/BindingManager.js +87 -0
  19. package/lib/bind/bindingResolver.js +15 -87
  20. package/lib/bind/bindingUtil.js +18 -11
  21. package/lib/bind/cfKeyProvider.js +58 -29
  22. package/lib/bind/kubernetesCredentialsProvider.js +44 -21
  23. package/lib/bind/userCdsrcJsonStorageProvider.js +12 -18
  24. package/lib/cds.js +13 -0
  25. package/lib/client/base_command.js +3 -2
  26. package/lib/client/extend.js +6 -7
  27. package/lib/client/helper/fs_helper.js +7 -8
  28. package/lib/client/settings_manager.js +14 -10
  29. package/lib/compile/index.js +9 -10
  30. package/lib/compile/openapi/csdl2openapi.js +151 -43
  31. package/lib/compile/openapi/index.js +2 -2
  32. package/lib/compile/to-xsuaa.js +3 -2
  33. package/lib/import/common.js +342 -27
  34. package/lib/import/importapi.js +81 -13
  35. package/lib/import/message.js +4 -4
  36. package/lib/import/odata/index.js +141 -0
  37. package/lib/import/{utils → odata/metadataconverter}/MetadataConverter.js +2 -2
  38. package/lib/import/{utils → odata/metadataconverter}/MetadataConverterFactory.js +1 -1
  39. package/lib/import/{utils → odata/util}/MultiMap.js +0 -0
  40. package/lib/import/{v2parser.js → odata/v2parser.js} +405 -468
  41. package/lib/import/{v4parser.js → odata/v4parser.js} +311 -322
  42. package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Aggregation.V1.json +0 -0
  43. package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Authorization.V1.json +0 -0
  44. package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Capabilities.V1.json +0 -0
  45. package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Core.V1.json +0 -0
  46. package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Measures.V1.json +0 -0
  47. package/lib/import/{vocabularies → odata/vocabularies}/Org.OData.Validation.V1.json +0 -0
  48. package/lib/import/openapi/importOpenAPI.js +521 -0
  49. package/lib/import/openapi/index.js +19 -0
  50. package/lib/import/openapi/utilities.js +38 -0
  51. package/lib/index.js +1 -1
  52. package/lib/init/constants.js +7 -2
  53. package/lib/init/index.js +10 -3
  54. package/lib/init/template/_merging/existences.js +79 -19
  55. package/lib/init/template/approuter/files/mta.yaml.hbs +25 -11
  56. package/lib/init/template/approuter/files/package.json +1 -1
  57. package/lib/init/template/approuter/files/xs-app.json.hbs +7 -0
  58. package/lib/init/template/approuter/index.js +61 -54
  59. package/lib/init/template/auditlog/index.js +2 -2
  60. package/lib/init/template/data/index.js +2 -2
  61. package/lib/init/template/hana/files/mta.yaml.hbs +17 -17
  62. package/lib/init/template/hana/index.js +8 -4
  63. package/lib/init/template/helm/index.js +39 -0
  64. package/lib/init/template/helm/update/index.js +28 -0
  65. package/lib/init/template/java/index.js +7 -9
  66. package/lib/init/template/kibana-logging/index.js +5 -6
  67. package/lib/init/template/lint/index.js +1 -1
  68. package/lib/init/template/mta/index.js +4 -4
  69. package/lib/init/template/mtx/files/java/package.json +9 -9
  70. package/lib/init/template/mtx/files/mta.yaml.hbs +0 -7
  71. package/lib/init/template/mtx/files/xs-security.json.hbs +11 -20
  72. package/lib/init/template/mtx/index.js +50 -57
  73. package/lib/init/template/nodejs/files/package.json.hbs +2 -2
  74. package/lib/init/template/notebook/index.js +2 -0
  75. package/lib/init/template/templateBase.js +8 -6
  76. package/lib/init/template/xsuaa/index.js +9 -5
  77. package/lib/init/util/fsUtil.js +25 -10
  78. package/lib/init/util/logger.js +1 -1
  79. package/lib/init/util/mvnArchetypeUtil.js +4 -10
  80. package/lib/init/util/projectReader.js +17 -9
  81. package/lib/init/util/templateUtil.js +30 -34
  82. package/lib/k8s/ChartAdder.js +65 -0
  83. package/lib/k8s/ChartBuilder.js +186 -0
  84. package/lib/k8s/Context.js +71 -0
  85. package/lib/k8s/ImageUtil.js +21 -0
  86. package/lib/k8s/Model.d.ts +53 -0
  87. package/lib/k8s/auditlog/index.js +29 -0
  88. package/lib/k8s/auditlog/templates/auditlog.yaml +1 -0
  89. package/lib/k8s/buildModel.js +70 -0
  90. package/lib/k8s/connectivity/index.js +80 -0
  91. package/lib/k8s/connectivity/templates/connectivity-binding.yaml +9 -0
  92. package/lib/k8s/connectivity/templates/connectivity-proxy-info.yaml +20 -0
  93. package/lib/k8s/connectivity/templates/connectivity.yaml +1 -0
  94. package/lib/k8s/deployment/index.js +81 -0
  95. package/lib/k8s/deployment/subchart/Chart.yaml +6 -0
  96. package/lib/k8s/deployment/subchart/templates/_helpers.tpl +156 -0
  97. package/lib/k8s/deployment/subchart/templates/api-rule.yaml +24 -0
  98. package/lib/k8s/deployment/subchart/templates/deployment.yaml +110 -0
  99. package/lib/k8s/deployment/subchart/templates/network-policy.yaml +16 -0
  100. package/lib/k8s/deployment/subchart/templates/pod-disruption-budget.yaml +11 -0
  101. package/lib/k8s/deployment/subchart/templates/secret.yaml +10 -0
  102. package/lib/k8s/deployment/subchart/templates/service-binding.yaml +27 -0
  103. package/lib/k8s/deployment/subchart/templates/service.yaml +11 -0
  104. package/lib/k8s/deployment/subchart/values-lint.yaml +8 -0
  105. package/lib/k8s/deployment/subchart/values.schema.json +449 -0
  106. package/lib/k8s/deployment/subchart/values.yaml +76 -0
  107. package/lib/k8s/deployment/subchart-override/templates/_web_application_helpers.tpl +81 -0
  108. package/lib/k8s/destinations/index.js +40 -0
  109. package/lib/k8s/destinations/lib.js +16 -0
  110. package/lib/k8s/destinations/templates/destinations.yaml +1 -0
  111. package/lib/k8s/docker/push.js +8 -0
  112. package/lib/k8s/event-mesh/index.js +53 -0
  113. package/lib/k8s/event-mesh/lib.js +9 -0
  114. package/lib/k8s/event-mesh/templates/event-mesh.yaml +1 -0
  115. package/lib/k8s/hana-deployer/index.js +38 -0
  116. package/lib/k8s/hana-deployer/templates/hana-deployer-job.yaml +41 -0
  117. package/lib/k8s/helm/Release.js +80 -0
  118. package/lib/k8s/html5-apps-deployer/index.js +43 -0
  119. package/lib/k8s/html5-apps-deployer/templates/_html5_deployment_helpers.tpl +16 -0
  120. package/lib/k8s/html5-apps-deployer/templates/html5-apps-deployer-job.yaml +53 -0
  121. package/lib/k8s/html5-apps-repo-host/index.js +26 -0
  122. package/lib/k8s/html5-apps-repo-host/lib.js +16 -0
  123. package/lib/k8s/html5-apps-repo-host/templates/html5-apps-repo-host.yaml +1 -0
  124. package/lib/k8s/index.js +153 -0
  125. package/lib/k8s/modules.js +36 -0
  126. package/lib/k8s/multitenancy/index.js +24 -0
  127. package/lib/k8s/multitenancy/lib.js +25 -0
  128. package/lib/k8s/multitenancy/templates/saas-registry.yaml +19 -0
  129. package/lib/k8s/readProject.js +14 -0
  130. package/lib/k8s/resources/helm/chart/templates/NOTES.txt +11 -0
  131. package/lib/k8s/resources/helm/chart/templates/_deployment_helpers.tpl +221 -0
  132. package/lib/k8s/resources/helm/chart/templates/_helpers.tpl +167 -0
  133. package/lib/k8s/resources/helm/chart/templates/_sapcp_helpers.tpl +103 -0
  134. package/lib/k8s/util.js +186 -0
  135. package/lib/k8s/wrapFeature.js +55 -0
  136. package/lib/k8s/xsuaa/index.js +64 -0
  137. package/lib/k8s/xsuaa/lib.js +17 -0
  138. package/lib/k8s/xsuaa/templates/xsuaa.yaml +1 -0
  139. package/lib/lint/generators.js +1 -1
  140. package/lib/util/exec.js +1 -1
  141. package/lib/util/write.js +1 -1
  142. package/lib/watch/node-watch.js +43 -14
  143. package/npm-shrinkwrap.json +923 -2705
  144. package/package.json +5 -5
  145. package/lib/import/index.js +0 -235
package/CHANGELOG.md CHANGED
@@ -6,6 +6,83 @@ This project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
7
  The format is based on [Keep a Changelog](http://keepachangelog.com/).
8
8
 
9
+ ## Version 6.0.3 - 2022-07-14
10
+
11
+ ### Changed
12
+
13
+ - `cds init` uses latest Maven Java archetype version 1.26.0 for creating Java projects.
14
+ - `cds init` now creates Node.js projects with version 6 of `@sap/cds`
15
+
16
+ ### Fixed
17
+
18
+ - `--vcap-file` parameter of `cds deploy` is available again (removed in 6.0.0)
19
+ - `cds add helm:connectivity`: `connectivity.configMapName` was not used for the `connectivity-proxy-info`.
20
+ - `cds add helm:connectivity`: Environment variables added for connectivity service for Java.
21
+ - `cds add helm`: Generation of `xs-security.json` file works on Windows now (`cds compile srv -2 xsuaa` command failed).
22
+
23
+
24
+ ## Version 6.0.2 - 2022-07-06
25
+
26
+ ### Changed
27
+
28
+ - Use `@sap/cds` 6.0.2
29
+
30
+ ## Version 6.0.1 - 2022-07-05
31
+
32
+ ### Changed
33
+
34
+ - Deprecated the `--for <filterPattern>` parameter of `cds add data` in favor of the new `--data:for`. The former is still supported, but will eventually be removed, as it collides with the general `--for <profile>` parameter of `cds add`.
35
+
36
+ ### Fixed
37
+
38
+ - `cds bind` api endpoint regex for cli now ignores trailing version info in url
39
+
40
+ ## Version 6.0.0 - 2022-07-01
41
+
42
+ ### Added
43
+
44
+ - `cds import` now supports importing external openapi specification file into CSN.
45
+ - `cds import` now supports the `--from` option to specify the protocol for importing an external file.
46
+ - `cds import` can be programmatically accessed using APIs `cds.import()`, `cds.import.from.edmx()` and `cds.import.from.openapi()`.
47
+ - `cds compile --to openapi` allows describing custom headers and custom query options.
48
+ - `cds import` now supports `HasStream="true"` for both OData V4 and V2.
49
+ - `cds compile --to openapi` now adds properties with `@mandatory` to the required field.
50
+ - Added a link to VS Code CAP Notebooks documentation to `cds init --add notebooks` and `cds add notebooks`.
51
+
52
+ ### Changed
53
+
54
+ - `cds import` now uses `@odata.Type` and `@odata.Precision` for edm to cds type mapping.
55
+ - `cds compile --to openapi` now has better description for `$expand` query option.
56
+ - The original package `sqlite3` is now used again in its latest version.
57
+ - `cds import` now deprecated `cds.DecimalFloat` type.
58
+ - `cds import` now allows OData version 4.01 edmx files and supports `Scale="floating"`.
59
+ - `cds import` now adds `@odata.Type` annotation for `Edm.Byte` and `Edm.SByte`.
60
+ - `cds import` now has improved tests to check `--as`option with `force` flag file overwriting.
61
+ - `cds init` uses latest Maven Java archetype version 1.25.0 for creating Java projects.
62
+ - `cds import` now imports edmx file without any entities containing only unbounded action/function.
63
+ - `cds import` API now supports includeNamespaces option.
64
+ - `cds compile --to openapi` now adds `format`, `multipleOf`, `maximum` and `minimum` to anyOf.
65
+ - `cds import` will now mark an association as a composition when `OnDelete Action="Cascade"` is present.
66
+ - `cds import` has deprecated `--into` option.
67
+ - `cds bind` reads Cloud Foundry file `config.json` to get org and space information.
68
+ - `cds deploy` now stores connection information without credentials by default in `.cdsrc-private.json`.
69
+ - `cds deploy` has a new option `--store-credentials` to enforce the former behavior of storing credentials in `default-env.json`.
70
+ - If a `@sap/cds` is installed locally in a project, it must be version 4 or higher for CLI commands to run.
71
+ - `cds import` now doesn't trim the bound action/function name in the csn if the format of the name is A_B.
72
+ - `@sap/cds` version 6 is now required in new projects added by `cds init` and `cds add`.
73
+
74
+ ### Fixed
75
+
76
+ - `cds compile --to openapi` fixes annotations on bound action overloads.
77
+ - `cds add cf-manifest` now uses the correct `application` plan for the `xsuaa` service
78
+ - A combination of `cds add approuter`, `cds add mtx`, and `cds add mta` will now use a safer approach to determine the subscription URL.
79
+ - `cds init` and `cds add` output the feature names correctly in case the names contain a dash
80
+ - `cds compile --to openapi` fix for type error when entity/action is not specified in the service definition.
81
+ - `cds import` API fix for race condition issue.
82
+ - `cds somecdsfile --profile ...` (without the `compile` command) no longer ignores the given profile
83
+ - `cds watch` got more robust against unlucky timing and no longer runs into port conflicts
84
+
85
+
9
86
  ## Version 4.9.7 - 2022-06-08
10
87
 
11
88
  ### Changed
package/bin/activate.js CHANGED
@@ -9,7 +9,7 @@ module.exports = Object.assign(activate, {
9
9
 
10
10
  Activate an extension project.
11
11
  By default, the current working directory is used as project directory.
12
-
12
+
13
13
  To facilitate running this multiple times against the same app, refer to the *cds login* command.
14
14
 
15
15
 
@@ -25,14 +25,14 @@ module.exports = Object.assign(activate, {
25
25
 
26
26
  *-p* | *--passcode* <passcode>
27
27
 
28
- Tenant-specific passcode for authentication.
28
+ Tenant-specific passcode for authentication.
29
29
  Also see cds login --help or https://cap.cloud.sap/docs/guides/extensibility/#save-an-authentication-token-for-a-simplified-workflow
30
30
 
31
31
  *-u* | *--username* <name>
32
32
 
33
33
  Deprecated. Use the passcode parameter.
34
34
 
35
- *-c* | *--clientid* <clientid>
35
+ *-c* | *--clientid* <clientid>
36
36
 
37
37
  Client ID for authentication. This will override the default Client ID from environment.
38
38
 
@@ -49,7 +49,7 @@ module.exports = Object.assign(activate, {
49
49
 
50
50
  async function activate ([projectFolder], options = {}) {
51
51
  const injection = {
52
- cds: require('@sap/cds/lib')
52
+ cds: require('../lib/cds')
53
53
  }
54
54
 
55
55
  Object.assign(options, { projectFolder })
package/bin/add.js CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  module.exports = Object.assign(add, {
3
- options: ['--for', '--out'],
3
+ options: ['--for', '--out', '--data:for'],
4
4
  shortcuts: ['-4', '-o'],
5
5
  flags: ['--force', '--verbose'],
6
6
  help: `
@@ -15,7 +15,13 @@ module.exports = Object.assign(add, {
15
15
 
16
16
  *hana* - adds configuration for SAP HANA deployment
17
17
 
18
- *mta* - adds an _mta.yaml_ file for MTA based SAP Business Technology Platform deployment
18
+ *xsuaa* - adds configuration for authentication via XSUAA
19
+
20
+ *mtx* - adds configuration for multitenancy and extensibility
21
+
22
+ *approuter* - adds configuration for the Cloud Foundry approuter
23
+
24
+ *mta* - adds an _mta.yaml_ file for MTA-based SAP Business Technology Platform deployment
19
25
 
20
26
  *cf-manifest* - adds _manifest.yml_ and _services-manifest.yml_ files for Cloud Foundry native deployment
21
27
 
@@ -34,9 +40,9 @@ module.exports = Object.assign(add, {
34
40
 
35
41
  # OPTIONS
36
42
 
37
- *-4* | *--for* <entity name or prefix>
43
+ *--data:for* <entity name or prefix>
38
44
 
39
- Filters entity names with the given string. If it contains meta characters like
45
+ Adds data content for entities matching the given pattern. If it contains meta characters like
40
46
  '^' or '*', it is treated like a regular expression, otherwise as a prefix.
41
47
 
42
48
  *-o* | *--out* <target folder>
@@ -51,7 +57,7 @@ module.exports = Object.assign(add, {
51
57
  # EXAMPLES
52
58
 
53
59
  *cds add* hana,mta,pipeline
54
- *cds add* mta
60
+ *cds add* mtx --for production
55
61
  *cds add* cf-manifest
56
62
  *cds add* data --for my.namspace.MyEntity
57
63
 
package/bin/bind.js CHANGED
@@ -46,31 +46,28 @@ module.exports = Object.assign(cds_bind, {
46
46
  `
47
47
  });
48
48
 
49
- const cds = require('@sap/cds/lib');
49
+ const cds = require('../lib/cds');
50
50
  const LOG = cds.log('bind');
51
51
  // required for spinner
52
52
  LOG.isDebug = LOG._debug;
53
53
  LOG.isTTY = process.stdout.isTTY;
54
+ const resolveBinding = require('../lib/bind/bindingResolver').resolver(LOG);
54
55
 
55
56
  const { highlight, bold, info } = require('../lib/util/term');
56
57
 
57
58
  const Spinner = require('../lib/init/util/spinner');
58
- const resolveBinding = require('../lib/bind/bindingResolver').resolver(LOG);
59
59
  const { determineKinds, getRequiresNameFromKind, execAndExit, checkIsJavaProject, throwError, platformText, bindingText } = require('../lib/bind/bindingUtil');
60
60
 
61
- const VCAP_LABEL_PLACEHOLDER = '<replace with service label>';
62
-
63
61
  async function cds_bind(args, options, logger = LOG) {
62
+
64
63
  options.profile = parseProfile(options.profile);
65
64
  setProfile(options.profile);
66
65
 
67
66
  if (options.exec) {
68
- cds_bind_exec(args, options)
67
+ await cds_bind_exec(args, options)
69
68
  return;
70
69
  }
71
70
 
72
- const env = cds.env.for('cds', process.cwd());
73
-
74
71
  if (!options.to) {
75
72
  throw new Error(`use option --to or -2 to specify the target instance, e.g. cds bind --to myInstance:myService`);
76
73
  }
@@ -138,25 +135,16 @@ async function cds_bind(args, options, logger = LOG) {
138
135
  resolvedService.name = getRequiresNameFromKind(resolvedService.binding.instance, resolvedService.kind);
139
136
  }
140
137
 
141
- if (!resolvedService.name) {
142
- if (isJavaProject) {
143
- const { binding } = resolvedService;
144
- // Generate a custom service entry for Java projects w/o the need to specify a name manually
145
- resolvedService.name = `custom-service:${binding.instance || binding.secret}`
146
- } else {
147
- throw new Error(`Unknown CDS service name for service "${resolvedService._target}". Please specify as argument for "cds bind".`)
148
- }
149
- }
150
-
151
138
  const { kind, name, binding } = resolvedService;
152
139
  const kindText = kind && `with kind ${highlight(kind)}`;
153
- const nameText = !isJavaProject && highlight(name);
140
+ const nameText = !isJavaProject && name && highlight(name);
154
141
 
155
142
  logger.log(['Binding', nameText, 'to', platformText(binding), bindingText(binding, highlight), kindText].filter(t => t).join(' '));
156
143
 
157
- if (isJavaProject && !hasVcapLabel(binding) && !hasVcapLabel(env.requires[resolvedService.name]) && !(kind && hasVcapLabel(env.requires[kind]))) {
158
- resolvedService.vcap = { label: VCAP_LABEL_PLACEHOLDER };
159
- logger.log(`${info('INFO:')} Please add a "vcap.label" property to the binding for consumption in CAP Java projects`);
144
+ if (!resolvedService.name) {
145
+ const { binding } = resolvedService;
146
+ // Generate a custom service entry for Java projects w/o the need to specify a name manually
147
+ resolvedService.name = `custom-service:${binding.instance || binding.secret}`
160
148
  }
161
149
  }
162
150
 
@@ -173,15 +161,15 @@ async function cds_bind(args, options, logger = LOG) {
173
161
  }
174
162
 
175
163
  async function cds_bind_exec(command) { // eslint-disable-lint
176
- const cds = require('@sap/cds/lib');
164
+ const cds = require('../lib/cds');
177
165
  const env = cds.env.for('cds', process.cwd());
178
- env._emulate_vcap_services();
179
- await require('../lib/bind/bindingResolver').applyTo({ env, output: 'info' });
180
- execAndExit(...command);
181
- }
182
166
 
183
- function hasVcapLabel(service) {
184
- return service && service.vcap && service.vcap.label && service.vcap.label != VCAP_LABEL_PLACEHOLDER;
167
+ const BindingManager = require('../lib/bind/BindingManager')
168
+ const bindingManager = new BindingManager({ env, output: 'info' })
169
+ const bindingEnv = await bindingManager.bindingEnv()
170
+ const processEnv = Object.assign(process.env, bindingEnv)
171
+
172
+ execAndExit({ env: processEnv }, ...command);
185
173
  }
186
174
 
187
175
  function runCmd({ profile }, isJavaProject) {
package/bin/build/all.js CHANGED
@@ -48,7 +48,7 @@ module.exports = Object.assign(build, {
48
48
  `
49
49
  })
50
50
 
51
- function build([project], options = {}, /* for unit tests only: */ _env = null) {
51
+ function build([project], options = {}) {
52
52
  options.project = options.project || project
53
53
  // switch-off error logging as CLI is logging any exceptions by default
54
54
  // otherwise errors are logged twice
@@ -66,7 +66,7 @@ function build([project], options = {}, /* for unit tests only: */ _env = null)
66
66
  }
67
67
 
68
68
  try {
69
- return require('@sap/cds').build.build(options, _env)
69
+ return require('../../lib/cds').build(options)
70
70
  } catch (error) {
71
71
  return Promise.reject(error.message)
72
72
  }
@@ -4,7 +4,7 @@ module.exports = Object.assign(build, {
4
4
  help: `
5
5
  # SYNOPSIS
6
6
 
7
- *cds build* [<options>]
7
+ *cds build* [<project>] [<options>]
8
8
 
9
9
  Builds all modules in the current project by compiling contained CDS sources.
10
10
  The modules are folders in the project root directory. All well known modules (db, srv, app)
@@ -12,28 +12,22 @@ module.exports = Object.assign(build, {
12
12
 
13
13
  # OPTIONS
14
14
 
15
- *-4* | *--for* hana | java-cf | node-cf | mtx
15
+ *-4 | --for* hana | java | nodejs | mtx
16
16
 
17
17
  Name of the build task that is applied to the source folder, either explicitly configured in
18
18
  the build task list or generated out of the project setup
19
19
  For example, the "hana" build task will create SAP HANA artefacts.
20
20
  The module folder can be defined using option "--src", a default is used otherwise.
21
21
 
22
- *--use* <qualified node module name>
22
+ *-s | --src* <folder>
23
23
 
24
- Fully qualified name of the build task that is applied to the source folder.
25
- For example, "@sap/cds/build/hana" represents the fully qualified name of the "hana" build task.
26
- The module folder can be defined using option "--src", a default is used otherwise.
27
-
28
- *-s* | *--src* <folder>
29
-
30
- The module folder to build using the build task defined by option "--for" or "--use".
24
+ The module folder to build using the build task defined by option "--for".
31
25
  This option is only supported when building an individual module of the project.
32
26
  The folder is resolved based on "<project>/<cds.env.build.target>".
33
27
  A default is used based on the type of the build task, for example, the folder "db" is used for a
34
- "hana" build task, "srv" for "node-cf" or "java-cf" build task.
28
+ "hana" build task, "srv" for "nodejs" or "java" build task.
35
29
 
36
- *-o* | *--dest* <folder>
30
+ *-o | --dest* <folder>
37
31
 
38
32
  Output folder of the build task. The type of build task is defined by option "--for".
39
33
  The folder is resolved based on "<project>/<cds.env.build.target>".
@@ -56,12 +50,11 @@ module.exports = Object.assign(build, {
56
50
  Builds the project using the "production" profile - same when NODE_ENV environment variable is set to "production".
57
51
  E.g. HANA deployment artefacts will be created if "sql" has been set as database kind in cds configuration.
58
52
 
59
- *-in* | *--project* <folder> deprecated
53
+ *-in | --project* [<project>]
60
54
 
61
- Use the specified folder as the project root.
62
- Default - current working directory.
55
+ Runs _cds build_ for the specified project, default is current working directory.
63
56
 
64
- *-c* | *--clean* deprecated
57
+ *-c | --clean* deprecated
65
58
 
66
59
  Incremental builds are not supported.
67
60
  Build output folders are always cleaned before build.
@@ -73,17 +66,17 @@ module.exports = Object.assign(build, {
73
66
  *cds* build --production
74
67
  *cds* build --log-level info
75
68
  *cds* build --for hana
76
- *cds* build --for java-cf --dest ../srv/target --opts model=[db/model,srv,schema]
69
+ *cds* build --for java --dest ../srv/target --opts model=[db/model,srv,schema]
77
70
  `})
78
71
 
79
72
  /**
80
73
  * Redirect to modular build system.
81
74
  */
82
- function build(project, options = {}, config = null) {
75
+ function build(project, options = {}) {
83
76
  if (options.dry) {
84
77
  // eslint-disable-next-line no-console
85
78
  console.warn("[cds] - CLI option 'dry' is no longer supported.\n")
86
79
  delete options.dry
87
80
  }
88
- return require('./all')(project, options, config)
81
+ return require('./all')(project, options)
89
82
  }
package/bin/cds.js CHANGED
@@ -34,9 +34,9 @@ const cli = { //NOSONAR
34
34
  if (cmd in this.Shortcuts) cmd = process.argv[2] = this.Shortcuts[cmd]
35
35
  if (argv.some(a => this.Shortcuts[a]==='help')) return this.help (cmd)
36
36
 
37
- const cds_cli = require (_local('@sap/cds/bin/cds')) // this triggers loading of sap/cds lib
38
- DEBUG && DEBUG (`[cds] - @sap/cds ${global.cds.version} loaded: ${global.cds.home}`)
37
+ const cds_cli = require (_local('@sap/cds/bin/cds'))
39
38
  if (cmd !== 'repl' && process.env.NODE_ENV !== 'test') cds_cli.errorHandlers()
39
+ DEBUG && DEBUG (`[cds] - @sap/cds ${require('../lib/cds').version} loaded: ${require('../lib/cds').home}`)
40
40
 
41
41
  const task = this.load (cmd, /*else*/ (f)=> argv.unshift(cmd) && _defaultCompile (argv,f))
42
42
  if (task) {
@@ -67,17 +67,28 @@ const cli = { //NOSONAR
67
67
 
68
68
  const DEBUG = /\b(cli)\b/.test (process.env.DEBUG) && console.error
69
69
 
70
- function _local (id) {
71
- return require.resolve (id, {paths:[process.cwd(), __dirname]})
70
+ function _local (id, _else) {
71
+ try { return require.resolve (id, {paths:[process.cwd(), __dirname]}) }
72
+ catch(e) {
73
+ if (_else) return _else(e)
74
+ else throw e
75
+ }
72
76
  }
73
77
 
74
78
  function _defaultCompile (argv, _force) {
75
79
  // Try all arguments if one resolves to a model. If yes, we assume 'compile' is intended.
76
- const model = _force || require (_local('@sap/cds')).resolve(argv)
80
+ const model = _force || _is_model(argv)
77
81
  if (model) return _require ('./compile')
78
82
  DEBUG && DEBUG (`[cds] - Command is not a model to compile: ${argv}`)
79
83
  }
80
84
 
85
+ function _is_model (argv) {
86
+ // IMPORTANT: have a separate env here, so that the normal one is not initialized before `cds_cli.args` above
87
+ const env = require (_local('@sap/cds/lib/env/cds-env', ()=>_local('@sap/cds/lib/env'))).for('cds')
88
+ const cds = require (_local('@sap/cds'))
89
+ return !!cds.resolve(argv,{env,cache:{}})
90
+ }
91
+
81
92
  function _dieForUnknownCommand(cmd) {
82
93
  const term = require('../lib/util/term');
83
94
  const fuzzySearch = _require('./util/fuzzySearch');
@@ -92,19 +103,20 @@ function _dieForUnknownCommand(cmd) {
92
103
  bestMatchText = '';
93
104
  break;
94
105
  case 1:
95
- bestMatchText = `A similar command is \n\n ${term.bold("cds " + bestMatches[0])}`;
106
+ bestMatchText = `A similar command is \n\n ${term.bold("cds " + bestMatches[0])}`;
96
107
  break;
97
108
  default:
98
- bestMatchText = `Similar commands are \n\n ${term.bold("cds " + bestMatches.join('\n cds '))}`;
109
+ bestMatchText = `Similar commands are \n\n ${term.bold("cds " + bestMatches.join('\n cds '))}`;
99
110
  }
100
111
 
101
112
  const msg = `
102
113
  Unknown command '${term.bold(cmd)}'. ${bestMatchText}
103
114
 
104
115
  Haven't found the proper command yet? Here are all supported commands:
105
- ${term.bold(commands.join(', '))}
106
116
 
107
- You can use ${term.bold("cds help {command}")} to get more information on the command.
117
+ ${term.bold(commands.join('\n '))}
118
+
119
+ You can use ${term.bold("cds help [command]")} to get more information on the command.
108
120
  `
109
121
  console.error(msg)
110
122
 
@@ -117,17 +129,8 @@ function _require (id,o) {
117
129
  return require (resolved)
118
130
  }
119
131
 
120
- function _minVersion (id, minVersion) {
121
- const { version } = require (_local (id+'/package.json'))
122
- return version.split('.')[0] >= minVersion
123
- }
132
+ module.exports = Object.assign ((..._) => cli.exec(..._), cli)
124
133
 
125
- if (_minVersion ('@sap/cds', 4)) {
126
- module.exports = Object.assign ((..._) => cli.exec(..._), cli)
127
- }
128
- else { // TODO compat to cds 3 remove after a while.
129
- module.exports = require (_local('@sap/cds/bin/cds'))
130
- }
131
134
  if (!module.parent) module.exports()
132
135
 
133
136
  /* eslint no-console:off */
@@ -120,7 +120,7 @@ module.exports = Object.assign ( compile, {
120
120
  function compile_all (root='.') {
121
121
 
122
122
  const {exec} = require ('child_process')
123
- const cds = require ('@sap/cds')
123
+ const cds = require('../../lib/compile') // get the enhanced cds w/ additional compile processors
124
124
 
125
125
  exec(`find ${root} -name *.cds ! -path '*/node_modules/*'`, (_,stdout)=>{
126
126
  const all = stdout.split('\n').slice(0,-1)
@@ -142,7 +142,7 @@ function compile (models, options={}) {
142
142
  if (options.all) return compile_all (models[0])
143
143
 
144
144
  const { inspect } = require('util')
145
- const cds = require ('../../lib/compile')
145
+ const cds = require('../../lib/compile') // get the enhanced cds w/ additional compile processors
146
146
 
147
147
  let model, src, _suffix; //> be filled in below
148
148
  if (!options.as && !/,/.test(options.to)) options.as = 'str'
@@ -202,7 +202,7 @@ function compile (models, options={}) {
202
202
  }))
203
203
 
204
204
  // add processor for logging compiler messages and errors
205
- const log = this.log || require('@sap/cds/bin/utils/log')
205
+ const log = this.log || _log
206
206
  chain = chain.then ((results)=>{
207
207
  if (messages.length) log (messages, options)
208
208
  return results
@@ -272,4 +272,13 @@ function compile (models, options={}) {
272
272
  }[x] || '.'+x) }
273
273
 
274
274
  }
275
+
276
+ function _log (messages, options) {
277
+ const cds = require('../../lib/cds')
278
+ const { sortMessagesSeverityAware, deduplicateMessages } = cds.compiler
279
+ deduplicateMessages(messages)
280
+ messages = sortMessagesSeverityAware (messages)
281
+ cds.utils._log (messages, options)
282
+ }
283
+
275
284
  /* eslint no-console:0 */
@@ -1,5 +1,6 @@
1
1
  module.exports = Object.assign(deploy, {
2
- options: ['--to', '--tunnel-address', '--vcap-file'], flags: [ '--no-save', '--auto-undeploy', '--dry', '--with-mocks', '--bind' ],
2
+ options: ['--to', '--tunnel-address', '--vcap-file'],
3
+ flags: [ '--no-save', '--auto-undeploy', '--dry', '--with-mocks', '--store-credentials', '--bind' ],
3
4
  shortcuts: ['-2'],
4
5
  help: `
5
6
  # SYNOPSIS
@@ -47,23 +48,28 @@ module.exports = Object.assign(deploy, {
47
48
  creating new credentials. File must be in *default-env.json* format, with a root
48
49
  node *VCAP_SERVICES*.
49
50
 
50
- *--bind* (beta feature, only in combination with *--to hana*)
51
+ *--store-credentials* (only in combination with *--to hana*)
52
+
53
+ Stores credentials in *default-env.json file*. This is the former default behavior
54
+ which has been replaced by creating and storing connection information in file
55
+ *.cdsrc-private.json*.
51
56
 
52
- Use *cds bind* to connect the created service after deployment.
53
- This will no longer create default-env.json files. Instead, cds bind is used to
54
- create and store connection information in file *.cdsrc-private.json*.
55
57
 
56
58
  # EXAMPLES
57
59
  cds deploy --to sqlite:db
60
+ cds deploy --to hana
58
61
  cds deploy --to hana:myService --auto-undeploy
59
- cds deploy --to hana --vcap-file ./secret/default-env.json
60
62
 
61
63
  `})
62
64
 
63
- const cds = require('@sap/cds/lib')
65
+ const cds = require('../../lib/cds')
64
66
 
65
67
  async function deploy (_model, options) { // NOSONAR
66
68
 
69
+ if (options.bind) {
70
+ console.log (`Option '--bind' is now active by default and can therefore be omitted.`)
71
+ }
72
+
67
73
  if (_model && _model.length === 0) _model = undefined // empty array (no model args) means default models
68
74
  const { 'to':url, 'no-save':no_save = cds.env.deploy.no_save } = options
69
75
  if (!options.mocked) { options.mocked = options['with-mocks'] }
@@ -90,7 +96,7 @@ async function deploy (_model, options) { // NOSONAR
90
96
  await deployer.deploy (_model, _db, options)
91
97
  if (options.dry) return
92
98
  if (kind === 'hana') return // REVISIT: the hana deployer is a bit special
93
- if (url && !no_save) await updata_package_json (_kind, _model, _db)
99
+ if (url && !no_save) await update_package_json (_kind, _model, _db)
94
100
  } catch (e) {
95
101
  if (e.code === 'MODEL_NOT_FOUND') {
96
102
  if (!_model) throw new Error ('No .cds models found, please specify one as an argument')
@@ -100,7 +106,7 @@ async function deploy (_model, options) { // NOSONAR
100
106
  }
101
107
 
102
108
 
103
- async function updata_package_json (kind, model, database) {
109
+ async function update_package_json (kind, model, database) {
104
110
  const { fs, path, isfile } = cds.utils
105
111
  const { readFile, writeFile } = fs.promises
106
112
  const package_json = path.resolve ('package.json'), exists = isfile (package_json)
@@ -1,10 +1,10 @@
1
1
  const { join } = require('path');
2
2
 
3
3
  exports.deploy = (_model, _db, options) => {
4
- // locate deployer relative to already located sap/cds -> local cds takes precedence
5
- const cdsHome = require('@sap/cds').home;
4
+ // locate deployer relative to sap/cds
5
+ const cdsHome = require('../../lib/cds').home;
6
6
  const deployer = require(join(cdsHome, 'bin/deploy/to-hana'));
7
7
 
8
- const bind = require('../bind');
9
- return deployer.deploy(_model, _db, options, options.bind ? bind : null);
8
+ const bind = !options['store-credentials'] ? require('../bind') : undefined;
9
+ return deployer.deploy(_model, _db, options, bind);
10
10
  }
@@ -1,5 +1,5 @@
1
1
  exports.deploy = function deploy_to_sqlite (_model, _db, options) {
2
- const cds = require('@sap/cds/lib')
2
+ const cds = require('../../lib/cds')
3
3
  const {to:_dbrl} = options
4
4
  const conf = cds.env.requires.db || {}
5
5
  const fts = cds.env.features.folders
package/bin/env.js CHANGED
@@ -44,22 +44,31 @@ const info = (s) => process.stdout.isTTY ? term.info (s) : s
44
44
 
45
45
  async function env ([cmd, key, value], options={}) {
46
46
 
47
- const cds = require('@sap/cds/lib')
47
+ const cds = require('../lib/cds')
48
48
  const fn = (options["process-env"] ? processEnvCommands[cmd] : commands[cmd]) || (()=>{
49
49
  this.help ('env')
50
50
  throw new Error (`Don't understand '${cmd}' here...`)
51
51
  })
52
52
 
53
- const env = options.for ? cds.env.for (options.for) : cds.env
54
- env['_home_cds-dk'] = path.resolve(__dirname, '..') // to help tools find the DK
53
+ let env = options.for ? cds.env.for(options.for) : cds.env
54
+
55
+ if (options["resolve-bindings"]) {
56
+ const BindingManager = require('../lib/bind/BindingManager')
57
+ const bindingManager = new BindingManager({env, output: "debug"})
58
+ const bindingEnv = await bindingManager.bindingEnv()
59
+ Object.assign(process.env, bindingEnv)
60
+ env = cds.env.for(options.for || 'cds') // reload env
61
+ }
55
62
 
56
- if (options["resolve-bindings"]) await require('../lib/bind/bindingResolver').applyTo({env, output: "debug"})
63
+
64
+ env['_home_cds-dk'] = path.resolve(__dirname, '..') // to help tools find the DK
57
65
 
58
66
  if (!options.for && options.mocked) await cds.service.bindings
59
67
 
60
68
  fn (env, key, value)
61
69
  }
62
70
 
71
+
63
72
  const commands = {
64
73
 
65
74
  get [undefined]() { return commands.list },
package/bin/eval.js CHANGED
@@ -21,7 +21,7 @@ module.exports = Object.assign ( run, { help: `
21
21
  function run ([code]) {
22
22
  if (!code) return console.error (`Please specify the code to execute, like\n\n cds -e "cds.compile('my-model').to.json()"\n`)
23
23
  // eslint-disable-next-line no-unused-vars
24
- const cds = require('@sap/cds/lib')
24
+ const cds = require('../lib/cds')
25
25
  if (code[0] === '.') code = 'cds' + code
26
26
  const outcome = eval(code) //NOSONAR
27
27
  console.log (outcome)
@@ -1,5 +1,5 @@
1
1
  const [arg0, arg1, _, ...args] = process.argv // eslint-disable-line no-unused-vars
2
- const files = require('@sap/cds').resolve(args.length ? args : '*')
2
+ const files = require('../lib/cds').resolve(args.length ? args : '*')
3
3
  process.argv = [ arg0, arg1, 'ria', ...files ]
4
4
 
5
5
  console.log ('[cds] - searching for ambiguous redirects in', files)