@sap/cds-dk 4.8.2 → 4.9.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 (83) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/bin/activate.js +8 -7
  3. package/bin/bind.js +12 -12
  4. package/bin/build/all.js +3 -5
  5. package/bin/build/index.js +1 -1
  6. package/bin/cds.js +1 -1
  7. package/bin/deploy/index.js +7 -1
  8. package/bin/deploy/to-hana.js +5 -4
  9. package/bin/deploy/to-sqlite.js +2 -1
  10. package/bin/extend.js +5 -5
  11. package/bin/help.js +1 -0
  12. package/bin/import.js +45 -31
  13. package/bin/login.js +5 -6
  14. package/bin/logout.js +2 -2
  15. package/bin/parse.js +19 -0
  16. package/lib/bind/bindingUtil.js +41 -49
  17. package/lib/bind/cfKeyProvider.js +9 -17
  18. package/lib/bind/userCdsrcJsonStorageProvider.js +1 -0
  19. package/lib/client/activate.js +3 -2
  20. package/lib/client/extend.js +5 -6
  21. package/lib/client/helper/fs_helper.js +8 -8
  22. package/lib/client/settings_manager.js +12 -9
  23. package/lib/compile/openapi/csdl2openapi.js +213 -165
  24. package/lib/compile/openapi/index.js +1 -2
  25. package/lib/compile/to-xsuaa.js +1 -1
  26. package/lib/import/index.js +22 -15
  27. package/lib/import/message.js +3 -1
  28. package/lib/import/utils/MetadataConverter.js +1 -1
  29. package/lib/import/v2parser.js +112 -56
  30. package/lib/import/v4parser.js +149 -98
  31. package/lib/init/constants.js +6 -2
  32. package/lib/init/index.js +3 -2
  33. package/lib/init/template/_merging/existences.js +80 -4
  34. package/lib/init/template/approuter/files/cds.cdsrc.json +7 -0
  35. package/lib/init/template/approuter/files/cds.cdsrc.json.hbs +9 -0
  36. package/lib/init/template/approuter/files/cds.package.json +9 -0
  37. package/lib/init/template/approuter/files/cds.package.json.hbs +11 -0
  38. package/lib/init/template/approuter/files/index.html +1 -0
  39. package/lib/init/template/approuter/files/mta.yaml.hbs +35 -21
  40. package/lib/init/template/approuter/files/package.json +3 -0
  41. package/lib/init/template/approuter/files/xs-app.json.hbs +19 -0
  42. package/lib/init/template/approuter/index.js +47 -18
  43. package/lib/init/template/auditlog/index.js +5 -5
  44. package/lib/init/template/hana/files/java/cdsrc.json.hbs +7 -0
  45. package/lib/init/template/hana/files/java/{package.json → db/package.json} +0 -0
  46. package/lib/init/template/hana/files/java/profile.cdsrc.json.hbs +12 -0
  47. package/lib/init/template/hana/files/mta.yaml.hbs +10 -17
  48. package/lib/init/template/hana/files/nodejs/cds.package.json.hbs +9 -0
  49. package/lib/init/template/hana/files/nodejs/cds.profile.package.json.hbs +14 -0
  50. package/lib/init/template/hana/files/nodejs/dependencies.package.json +1 -1
  51. package/lib/init/template/hana/index.js +60 -86
  52. package/lib/init/template/java/index.js +5 -2
  53. package/lib/init/template/kibana-logging/files/cds.package.json +7 -0
  54. package/lib/init/template/kibana-logging/files/cds.profile.package.json.hbs +9 -0
  55. package/lib/init/template/kibana-logging/files/mta.yaml.hbs +13 -0
  56. package/lib/init/template/kibana-logging/index.js +64 -0
  57. package/lib/init/template/mta/files/mta.yaml.hbs +3 -8
  58. package/lib/init/template/mta/index.js +8 -2
  59. package/lib/init/template/mtx/files/cds.package.json +0 -12
  60. package/lib/init/template/mtx/files/cds.package.json.hbs +14 -0
  61. package/lib/init/template/mtx/files/java/.cdsrc.json +17 -0
  62. package/lib/init/template/mtx/files/java/package.json +43 -0
  63. package/lib/init/template/mtx/files/java/server.js +30 -0
  64. package/lib/init/template/mtx/files/mta.yaml.hbs +6 -6
  65. package/lib/init/template/mtx/index.js +41 -22
  66. package/lib/init/template/templateBase.js +4 -1
  67. package/lib/init/template/xsuaa/files/cds.cdsrc.json +7 -0
  68. package/lib/init/template/xsuaa/files/cds.cdsrc.json.hbs +9 -0
  69. package/lib/init/template/xsuaa/files/cds.package.json +1 -1
  70. package/lib/init/template/xsuaa/files/cds.package.json.hbs +11 -0
  71. package/lib/init/template/xsuaa/files/mta.yaml.hbs +2 -2
  72. package/lib/init/template/xsuaa/index.js +43 -27
  73. package/lib/init/types.d.ts +43 -19
  74. package/lib/init/util/fsUtil.js +15 -4
  75. package/lib/init/util/projectReader.js +21 -18
  76. package/lib/init/util/templateUtil.js +78 -28
  77. package/lib/util/exec.js +2 -2
  78. package/lib/watch/livereload-server.js +3 -0
  79. package/lib/watch/node-watch.js +8 -1
  80. package/npm-shrinkwrap.json +170 -148
  81. package/package.json +3 -3
  82. package/lib/init/template/approuter/files/xs-app.json +0 -8
  83. package/lib/init/template/nodejs/files/.vscode/settings.json +0 -7
@@ -0,0 +1 @@
1
+ Hello World
@@ -2,42 +2,56 @@
2
2
  modules:
3
3
  - name: {{cap.appName}}-srv
4
4
  type: {{cap.pLanguage}}
5
+ {{#cap.isJava}}
6
+ {{#cap.isMultitenant}}
7
+ properties:
8
+ CDS_MULTITENANCY_APPUI_TENANTSEPARATOR: "-"
9
+ {{/cap.isMultitenant}}
10
+ {{/cap.isJava}}
5
11
  requires:
6
- - name: {{cap.appName}}-uaa
12
+ - name: {{cap.appName}}-auth
13
+ {{#cap.isJava}}
14
+ - name: app-api
15
+ properties:
16
+ CDS_MULTITENANCY_APPUI_URL: ~{url}
17
+ {{/cap.isJava}}
7
18
 
8
19
  - name: {{cap.appName}}
9
20
  type: approuter.nodejs
10
- path: {{& ui.appPath}} # from cds.env.folders. Consider also cds.env.build.target --> gen/app
21
+ path: {{& ui.appPath}} # from cds.env.folders. Consider also cds.env.build.target -> gen/app
11
22
  parameters:
12
23
  keep-existing-routes: true
13
24
  disk-quota: 256M
14
25
  memory: 256M
15
- # hosts: # additional tenant specific hostnames (only for Canary)
16
- ## the developer will do this via an extension descriptor:
17
- # - <paas-subdomain >${tenant-delimiter}${host}
18
- # - <saas-subdomain1>${tenant-delimiter}${host}
19
- # - ...
20
26
  {{#cap.isMultitenant}}
21
27
  properties:
22
28
  TENANT_HOST_PATTERN: "^(.*)-${default-uri}"
23
29
  {{/cap.isMultitenant}}
24
30
  requires:
25
- - name: srv-api
26
- group: destinations
27
- properties:
28
- name: srv-api # this is a name which must be used in xs-app.json as well
29
- url: ~{srv-url}
30
- forwardAuthToken: true
31
- {{#cap.isMultitenant}}
32
- - name: mtx-api # in here always, but really used only if mtx client is used (our recommendation is that they contact cds-mtx via the approuter)
33
- group: destinations
34
- properties:
35
- name: mtx-api # this is a name which must be used in xs-app.json as well
36
- url: ~{mtx-url}
37
- {{/cap.isMultitenant}}
31
+ - name: srv-api
32
+ group: destinations
33
+ properties:
34
+ name: srv-api # must be used in xs-app.json as well
35
+ url: ~{srv-url}
36
+ forwardAuthToken: true
37
+ {{#cap.isMultitenant}}
38
+ {{#cap.isNodejs}}
39
+ - name: mtx-api
40
+ group: destinations
41
+ properties:
42
+ name: mtx-api # must be used in xs-app.json as well
43
+ url: ~{mtx-url}
44
+ {{/cap.isNodejs}}
45
+ {{/cap.isMultitenant}}
46
+ {{#cap.isJava}}
47
+ provides:
48
+ - name: app-api
49
+ properties:
50
+ url: ${default-url}
51
+ {{/cap.isJava}}
38
52
 
39
53
  resources:
40
- - name: {{cap.appName}}-uaa{{#cap.isMultitenant}}-mt{{/cap.isMultitenant}}
54
+ - name: {{cap.appName}}-auth
41
55
  type: org.cloudfoundry.managed-service
42
56
  parameters:
43
57
  service: xsuaa
@@ -3,6 +3,9 @@
3
3
  "dependencies": {
4
4
  "@sap/approuter": "^10"
5
5
  },
6
+ "engines": {
7
+ "node": "^16"
8
+ },
6
9
  "scripts": {
7
10
  "start": "node node_modules/@sap/approuter/approuter.js"
8
11
  }
@@ -0,0 +1,19 @@
1
+ {
2
+ "authenticationMethod": "route",
3
+ "routes": [
4
+ {
5
+ "source": "^/app/(.*)$",
6
+ "target": "$1",
7
+ "localDir": ".",
8
+ "authenticationType": "xsuaa",
9
+ "cacheControl": "no-cache, no-store, must-revalidate"
10
+ },
11
+ {
12
+ "source": "^/(.*)$",
13
+ "target": "$1",
14
+ "destination": "srv-api",
15
+ "authenticationType": "xsuaa",
16
+ "csrfProtection": true
17
+ }
18
+ ]
19
+ }
@@ -1,9 +1,13 @@
1
+ const fs = require('fs');
2
+ const { join } = require('path');
1
3
  const TemplateBase = require('../templateBase');
2
4
  const ProjectReader = require('../../util/projectReader');
3
- const { fse } = require('@sap/cds-foss');
4
- const path = require('path');
5
- const { OPTION_XSUAA } = require('../../constants');
6
- const { srvNode, srvJava, approuter, xsuaa } = require('../_merging/existences');
5
+ const { OPTION_XSUAA, PROJECT_TYPE } = require('../../constants');
6
+ const {
7
+ srvNode, srvJava, approuter, // Modules
8
+ xsuaa, // BTP Services
9
+ requiredMtxAPI, requiredJavaApprouterAPI, providedJavaApprouterAPI // APIs
10
+ } = require('../_merging/existences');
7
11
 
8
12
  module.exports = class ApprouterTemplate extends TemplateBase {
9
13
  constructor(projectPath, generator) {
@@ -17,26 +21,30 @@ module.exports = class ApprouterTemplate extends TemplateBase {
17
21
 
18
22
  async runMTAMerging() {
19
23
  const projectDescriptor = await this.projectReader.read(this.options);
20
- const mtaYAMLPath = path.join(this.projectPath, 'mta.yaml');
21
- if (!fse.existsSync(mtaYAMLPath)) return;
22
- const srv = projectDescriptor.cap.isNodejs ? srvNode : srvJava
24
+ const mtaYAMLPath = join(this.projectPath, 'mta.yaml');
25
+ if (!fs.existsSync(mtaYAMLPath)) return;
26
+ const { isNodejs, isJava, isMultitenant } = projectDescriptor.cap
27
+ const srv = isNodejs ? srvNode : srvJava
28
+ const apis = isJava ? [requiredJavaApprouterAPI, providedJavaApprouterAPI] : []
29
+ if (isNodejs && isMultitenant) apis.push(requiredMtxAPI)
30
+ const existences = [srv, approuter, xsuaa, ...apis]
23
31
  await this.templateUtil.mergeYAML(
24
32
  mtaYAMLPath,
25
33
  `${__dirname}/files/mta.yaml.hbs`,
26
34
  projectDescriptor,
27
35
  {
28
- existences: [srv, approuter, xsuaa],
36
+ existences,
29
37
  relationships: [{
30
- in: srv.ref,
38
+ in: srv,
31
39
  inKeyPath: ["requires"],
32
40
  into: "name",
33
- existences: [xsuaa.ref],
41
+ existences: [xsuaa],
34
42
  existenceKeyPath: ["name"],
35
43
  }, {
36
- in: approuter.ref,
44
+ in: approuter,
37
45
  inKeyPath: ["requires"],
38
46
  into: "name",
39
- existences: [xsuaa.ref],
47
+ existences: [xsuaa],
40
48
  existenceKeyPath: ["name"],
41
49
  }],
42
50
  }
@@ -45,22 +53,43 @@ module.exports = class ApprouterTemplate extends TemplateBase {
45
53
 
46
54
  async run() {
47
55
  const projectDescriptor = await this.projectReader.read(this.options);
48
- const appPath = path.join(this.projectPath, projectDescriptor.ui.appPath)
56
+ const appPath = join(this.projectPath, projectDescriptor.ui.appPath || 'app');
57
+ const appPackageJSONPath = join(appPath, 'package.json');
49
58
 
50
- await this.templateUtil.mergeJSON(
51
- `${appPath}/package.json`,
52
- `${__dirname}/files/package.json`
53
- );
59
+ await this.templateUtil.mergeJSON(appPackageJSONPath, join(__dirname, 'files', 'package.json'));
60
+ await this.templateUtil.sortDependencies(appPackageJSONPath);
54
61
 
55
62
  await this.templateUtil.mergeJSON(
56
63
  `${appPath}/xs-app.json`,
57
- `${__dirname}/files/xs-app.json`
64
+ `${__dirname}/files/xs-app.json.hbs`,
65
+ projectDescriptor
58
66
  );
59
67
 
60
68
  await this.templateUtil.mergeJSON(
61
69
  `${appPath}/default-env.json`,
62
70
  `${__dirname}/files/default-env.json`
63
71
  );
72
+
73
+ // await this.fsUtil.copy(join(__dirname, 'files', 'index.html'), join(appPath, 'index.html'));
74
+
75
+ const projectType = await this.getProjectType();
76
+ switch (projectType) {
77
+ case PROJECT_TYPE.java: {
78
+ const cdsrcJSONPath = join(this.projectPath, '.cdsrc.json')
79
+ const cdsTemplateFile = projectDescriptor.cap.for ? 'cds.cdsrc.json.hbs' : 'cds.cdsrc.json'
80
+ const cdsPackageJSONPath = join(__dirname, 'files', cdsTemplateFile)
81
+ await this.templateUtil.mergeJSON(cdsrcJSONPath, cdsPackageJSONPath, projectDescriptor)
82
+ break
83
+ }
84
+ case PROJECT_TYPE.nodejs: {
85
+ const packageJSONPath = join(this.projectPath, 'package.json')
86
+ const cdsTemplateFile = projectDescriptor.cap.for ? 'cds.package.json.hbs' : 'cds.package.json'
87
+ const cdsPackageJSONPath = join(__dirname, 'files', cdsTemplateFile)
88
+ await this.templateUtil.mergeJSON(packageJSONPath, cdsPackageJSONPath, projectDescriptor)
89
+ break
90
+ }
91
+ }
92
+
64
93
  await this.runMTAMerging()
65
94
  }
66
95
  }
@@ -1,7 +1,7 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
1
3
  const TemplateBase = require('../templateBase');
2
4
  const ProjectReader = require('../../util/projectReader');
3
- const { fse } = require('@sap/cds-foss');
4
- const path = require('path');
5
5
  const { srvNode, srvJava, auditlog } = require('../_merging/existences');
6
6
 
7
7
  module.exports = class AuditlogTemplate extends TemplateBase {
@@ -13,7 +13,7 @@ module.exports = class AuditlogTemplate extends TemplateBase {
13
13
  async runMTAMerging() {
14
14
  const projectDescriptor = await this.projectReader.read(this.options);
15
15
  const mtaYAMLPath = path.join(this.projectPath, 'mta.yaml');
16
- if (!fse.existsSync(mtaYAMLPath)) return;
16
+ if (!fs.existsSync(mtaYAMLPath)) return;
17
17
  const srv = projectDescriptor.cap.isNodejs ? srvNode : srvJava
18
18
  await this.templateUtil.mergeYAML(
19
19
  mtaYAMLPath,
@@ -22,10 +22,10 @@ module.exports = class AuditlogTemplate extends TemplateBase {
22
22
  {
23
23
  existences: [srv, auditlog],
24
24
  relationships: [{
25
- in: srv.ref,
25
+ in: srv,
26
26
  inKeyPath: ["requires"],
27
27
  into: "name",
28
- existences: [auditlog.ref],
28
+ existences: [auditlog],
29
29
  existenceKeyPath: ["name"],
30
30
  }],
31
31
  }
@@ -0,0 +1,7 @@
1
+ {
2
+ "requires": {
3
+ "db": {
4
+ "kind": { "#overwrite": "{{#cap.isMultitenant}}hana-mt{{/cap.isMultitenant}}{{^cap.isMultitenant}}hana-cloud{{/cap.isMultitenant}}" }
5
+ }
6
+ }
7
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "requires": {
3
+ "[{{cap.for}}]": {
4
+ "db": {
5
+ "kind": { "#overwrite": "{{#cap.isMultitenant}}hana-mt{{/cap.isMultitenant}}{{^cap.isMultitenant}}hana-cloud{{/cap.isMultitenant}}" }
6
+ }
7
+ },
8
+ "db": {
9
+ "kind": "sql"
10
+ }
11
+ }
12
+ }
@@ -15,28 +15,21 @@ modules:
15
15
  - name: {{cap.appName}}-db
16
16
  {{/cap.isMultitenant}}
17
17
 
18
- {{#cap.hasRequires}}
19
18
  resources:
20
- {{#cap.requires}}
21
- {{#resource.isHana}}
22
19
  - name: {{cap.appName}}-db
23
- {{#resource.isPlainHana}}
20
+ {{^cap.isMultitenant}}
24
21
  type: com.sap.xs.hdi-container
25
22
  parameters:
26
- service: {{resource.service}} # or 'hanatrial' on trial landscapes
27
- {{/resource.isPlainHana}}
28
- {{#resource.isManagedHana}} {{! enable automatic switching to 'hanatrial' on trial accounts}}
23
+ service: hana # or 'hanatrial' on trial landscapes
24
+ service-plan: hdi-shared
25
+ {{/cap.isMultitenant}}
26
+ {{#cap.isMultitenant}} {{! enable automatic switching to 'hanatrial' on trial accounts}}
29
27
  type: org.cloudfoundry.managed-service
30
28
  parameters:
31
- service: {{resource.service}}
32
- {{/resource.isManagedHana}}
33
- service-plan: {{resource.vcap.plan}}
34
- {{#resource.vcap.name}}
35
- service-name: {{resource.vcap.name}}
36
- {{/resource.vcap.name}}
29
+ service: service-manager
30
+ service-plan: container
31
+ {{/cap.isMultitenant}}
32
+ {{#cap.isJava}}
37
33
  properties:
38
34
  hdi-service-name: ${service-name}
39
- {{/resource.isHana}}
40
-
41
- {{/cap.requires}}
42
- {{/cap.hasRequires}}
35
+ {{/cap.isJava}}
@@ -0,0 +1,9 @@
1
+ {
2
+ "cds": {
3
+ "requires": {
4
+ "db": {
5
+ "kind": { "#overwrite": "{{#cap.isMultitenant}}hana-mt{{/cap.isMultitenant}}{{^cap.isMultitenant}}hana-cloud{{/cap.isMultitenant}}" }
6
+ }
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "cds": {
3
+ "requires": {
4
+ "[{{cap.for}}]": {
5
+ "db": {
6
+ "kind": { "#overwrite": "{{#cap.isMultitenant}}hana-mt{{/cap.isMultitenant}}{{^cap.isMultitenant}}hana-cloud{{/cap.isMultitenant}}" }
7
+ }
8
+ },
9
+ "db": {
10
+ "kind": "sql"
11
+ }
12
+ }
13
+ }
14
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "dependencies": {
3
- "hdb": "^0.18.3"
3
+ "hdb": "^0.19.0"
4
4
  }
5
5
  }
@@ -1,7 +1,6 @@
1
+ const fs = require('fs');
1
2
  const path = require('path');
2
3
 
3
- const { fse } = require('@sap/cds-foss');
4
-
5
4
  const commandUtil = require('../../util/commandUtil');
6
5
  const mvnArchetypes = require('../../util/mvnArchetypeUtil');
7
6
  const term = require('../../../util/term');
@@ -9,7 +8,7 @@ const ProjectReader = require('../../util/projectReader');
9
8
 
10
9
  const TemplateBase = require('../templateBase');
11
10
 
12
- const { PROJECT_TYPE, OPTION_JAVA, KIND_SQL, URLS, KIND_HANA } = require('../../constants');
11
+ const { PROJECT_TYPE, OPTION_JAVA, URLS, KIND_HANA } = require('../../constants');
13
12
  const { nullLogger } = require('../../util/logger');
14
13
  const { srvNode, srvJava, hdbDeployer, serviceManager, hdiContainer } = require('../_merging/existences');
15
14
 
@@ -30,17 +29,43 @@ module.exports = class HanaTemplate extends TemplateBase {
30
29
  }
31
30
  }
32
31
 
32
+ async checkEnabled() {
33
+ const { lt } = require('semver')
34
+ const cds = require('@sap/cds/lib')
35
+ if (lt(cds.version, '5.9.0')) {
36
+ cds.error('The added configuration requires @sap/cds 5.9.0 or higher. Please update @sap/cds to the latest version and run \x1b[1mcds add hana\x1b[0m again.')
37
+ }
38
+ return true
39
+ }
40
+
33
41
  async runMTAMerging() {
34
42
  const projectDescriptor = await this.projectReader.read(this.options);
35
43
 
36
44
  const mtaYAMLPath = path.join(this.projectPath, 'mta.yaml');
37
- if (!fse.existsSync(mtaYAMLPath)) {
38
- console.warn(`There is no MTA file in your project. Run \`cds add mta\` to add an MTA file or create the HANA services yourself.`)
39
- return;
40
- }
45
+
46
+ if (!fs.existsSync(mtaYAMLPath)) return
47
+
41
48
  const srv = projectDescriptor.cap.isNodejs ? srvNode : srvJava
42
49
  const deployer = projectDescriptor.cap.isMultitenant ? null : hdbDeployer
43
50
  const db = projectDescriptor.cap.isMultitenant ? serviceManager : hdiContainer
51
+ const deletions = projectDescriptor.cap.isMultitenant ? [{
52
+ existence: hdbDeployer,
53
+ relationships: [{
54
+ allWithinKeyPath: ["modules"],
55
+ inKeyPath: ["requires"],
56
+ into: "name",
57
+ existenceKeyPath: ["name"],
58
+ }]
59
+ }, {
60
+ existence: hdiContainer,
61
+ relationships: [{
62
+ allWithinKeyPath: ["modules"],
63
+ inKeyPath: ["requires"],
64
+ into: "name",
65
+ existenceKeyPath: ["name"],
66
+ }]
67
+ }] : []
68
+
44
69
  await this.templateUtil.mergeYAML(
45
70
  mtaYAMLPath,
46
71
  `${__dirname}/files/mta.yaml.hbs`,
@@ -48,20 +73,21 @@ module.exports = class HanaTemplate extends TemplateBase {
48
73
  {
49
74
  existences: [srv, deployer, db],
50
75
  relationships: [{
51
- in: srv.ref,
76
+ in: srv,
52
77
  inKeyPath: ["requires"],
53
78
  into: "name",
54
- existences: [db.ref],
79
+ existences: [db],
55
80
  existenceKeyPath: ["name"],
56
81
  },
57
82
  !projectDescriptor.cap.isMultitenant && projectDescriptor.cap.isNodejs ?
58
- {
59
- in: deployer.ref,
60
- inKeyPath: ["requires"],
61
- into: "name",
62
- existences: [db.ref],
63
- existenceKeyPath: ["name"],
64
- } : null],
83
+ {
84
+ in: deployer,
85
+ inKeyPath: ["requires"],
86
+ into: "name",
87
+ existences: [db],
88
+ existenceKeyPath: ["name"],
89
+ } : null],
90
+ deletions
65
91
  }
66
92
  );
67
93
  }
@@ -80,14 +106,14 @@ module.exports = class HanaTemplate extends TemplateBase {
80
106
  const projectType = await this.getProjectType();
81
107
  switch (projectType) {
82
108
  case PROJECT_TYPE.java: {
83
- await this.templateUtil.copyFiles('java', path.join(this.projectPath, env.folders.db), {}, this.options.force);
109
+ await this.templateUtil.copyFiles(path.join('java', 'db'), path.join(this.projectPath, env.folders.db), {}, this.options.force);
84
110
  await this._updatePomXml();
85
111
  const cdsrcJsonPath = path.join(this.projectPath, '.cdsrc.json');
86
112
  await this._updateCdsrcJson(cdsrcJsonPath, env.folders.db, env);
87
113
  break;
88
114
  }
89
115
  case PROJECT_TYPE.nodejs:
90
- await this._updatePackageJson(path.join(this.projectPath, 'package.json'), env.folders.db, env);
116
+ await this._updatePackageJson(path.join(this.projectPath, 'package.json'));
91
117
  break;
92
118
 
93
119
  default: break;
@@ -112,81 +138,29 @@ module.exports = class HanaTemplate extends TemplateBase {
112
138
  }
113
139
  }
114
140
 
115
- async _updatePackageJson(packageJsonPath, modelName, env) { //NOSONAR
116
- modelName = path.basename(modelName);
141
+ async _updatePackageJson(packageJsonPath) {
142
+ const projectDescriptor = await this.projectReader.read(this.options);
143
+ const dependenciesTemplatePath = path.join(__dirname, 'files', 'nodejs', 'dependencies.package.json');
144
+ await this.templateUtil.mergeJSON(packageJsonPath, dependenciesTemplatePath);
117
145
 
118
- if (!await this.fsUtil.pathExists(packageJsonPath)) {
119
- throw new Error(`package.json not found in project. ${packageJsonPath}`);
120
- }
146
+ const cdsTemplateFile = projectDescriptor.cap.for ? 'cds.profile.package.json.hbs' : 'cds.package.json.hbs';
147
+ const cdsTemplatePath = path.join(__dirname, 'files', 'nodejs', cdsTemplateFile);
148
+ await this.templateUtil.mergeJSON(packageJsonPath, cdsTemplatePath, projectDescriptor);
121
149
 
122
- let changed;
123
150
  const packageJson = await this.fsUtil.readJSON(packageJsonPath);
124
-
125
- this.logger.isDebug && this.logger.debug(`_updatePackageJson before: ${JSON.stringify(packageJson, null, 2)}`);
126
-
127
- if (!packageJson.dependencies || !packageJson.dependencies.hdb) {
128
- packageJson.dependencies = packageJson.dependencies || {};
129
- packageJson.dependencies.hdb = '^0.18.3';
130
- changed = true;
131
- }
132
- if (packageJson.dependencies && packageJson.dependencies['@sap/hana-client']) {
133
- delete packageJson.dependencies['@sap/hana-client']
134
- changed = true
135
- }
136
-
137
- if (!this._isUsingHana(modelName, env)) {
138
- packageJson.cds = packageJson.cds || {};
139
- packageJson.cds.requires = packageJson.cds.requires || {};
140
- packageJson.cds.requires[modelName] = packageJson.cds.requires[modelName] || {};
141
- packageJson.cds.requires[modelName].kind = KIND_SQL;
142
- changed = true;
143
- }
144
-
145
- if (!packageJson.cds || !packageJson.cds.hana || !packageJson.cds.hana['deploy-format']) {
146
- packageJson.cds = packageJson.cds || {};
147
- packageJson.cds.hana = packageJson.cds.hana || {}
148
- packageJson.cds.hana['deploy-format'] = 'hdbtable'
149
- changed = true;
150
- }
151
-
152
- if (changed) {
151
+ if (packageJson.dependencies['@sap/hana-client']) {
152
+ delete packageJson.dependencies['@sap/hana-client'];
153
153
  await this.fsUtil.writeJSON(packageJsonPath, packageJson);
154
- this.logger.isDebug && this.logger.debug(`_updatePackageJson written: ${JSON.stringify(packageJson, null, 2)}`);
155
154
  }
156
155
  }
157
156
 
158
- async _updateCdsrcJson(cdsrcJsonPath, modelName, env) {
159
- modelName = path.basename(modelName);
160
-
161
- let changed;
162
- let cdsrcJson = {}
163
- try {
164
- cdsrcJson = await this.fsUtil.readJSON(cdsrcJsonPath);
165
- } catch (err) {
166
- //
167
- }
168
-
169
- this.logger.isDebug && this.logger.debug(`_updateCdsrcJson before: ${JSON.stringify(cdsrcJson, null, 2)}`);
170
-
171
- if (!this._isUsingHana(modelName, env)) {
172
- cdsrcJson.requires = cdsrcJson.requires || {};
173
- cdsrcJson.requires[modelName] = cdsrcJson.requires[modelName] || {};
174
- cdsrcJson.requires[modelName].kind = KIND_SQL;
175
- changed = true
176
- }
177
- if (!cdsrcJson.hana || !cdsrcJson.hana['deploy-format']) {
178
- cdsrcJson.hana = cdsrcJson.hana || {}
179
- cdsrcJson.hana['deploy-format'] = 'hdbtable'
180
- changed = true
181
- }
182
-
183
- if (changed) {
184
- await this.fsUtil.writeJSON(cdsrcJsonPath, cdsrcJson);
185
- this.logger.isDebug && this.logger.debug(`_updateCdsrcJson written: ${JSON.stringify(cdsrcJson, null, 2)}`);
157
+ async _updateCdsrcJson(cdsrcJsonPath) {
158
+ const projectDescriptor = await this.projectReader.read(this.options);
159
+ const cdsTemplateFile = projectDescriptor.cap.for ? 'profile.cdsrc.json.hbs' : 'cdsrc.json.hbs';
160
+ const cdsTemplatePath = path.join(__dirname, 'files', 'java', cdsTemplateFile);
161
+ if (!fs.existsSync(cdsrcJsonPath)) {
162
+ this.fsUtil.writeJSON(cdsrcJsonPath, {})
186
163
  }
187
- }
188
-
189
- _isUsingHana(db, env) {
190
- return [`kind`, `dialect`, `use`].map(p => env.get(`requires.${db}.${p}`)).includes(KIND_HANA)
164
+ await this.templateUtil.mergeJSON(cdsrcJsonPath, cdsTemplatePath, projectDescriptor);
191
165
  }
192
166
  }
@@ -1,3 +1,4 @@
1
+ const fs = require('fs').promises;
1
2
  const os = require('os');
2
3
  const path = require('path');
3
4
 
@@ -9,7 +10,7 @@ const mvnArchetypeUtil = require('../../util/mvnArchetypeUtil');
9
10
  const term = require('../../../util/term');
10
11
 
11
12
  const TemplateBase = require('../templateBase');
12
- const { COMMAND_ADD, URLS, OPTION_JAVA, OPTION_NODEJS } = require('../../constants');
13
+ const { COMMAND_ADD, URLS, OPTION_JAVA, OPTION_NODEJS, MAVEN_ARCHETYPE_VERSION } = require('../../constants');
13
14
  const { nullLogger } = require('../../util/logger');
14
15
 
15
16
 
@@ -31,9 +32,11 @@ module.exports = class JavaTemplate extends TemplateBase {
31
32
  }
32
33
 
33
34
  async run() {
35
+ this.logger.log(`Using Maven archetype version ${MAVEN_ARCHETYPE_VERSION}`);
36
+
34
37
  const mvnCmdArgs = mvnArchetypeUtil.getGenerateCmdArgs(this.projectName, this.options, this.logger);
35
38
 
36
- const tempFolder = await fse.mkdtemp(path.join(os.tmpdir(), `${this.projectName}_`));
39
+ const tempFolder = await fs.mkdtemp(path.join(os.tmpdir(), `${this.projectName}_`));
37
40
  try {
38
41
  await commandUtil.spawnCommand('mvn', mvnCmdArgs.cmdLine, {
39
42
  cwd: tempFolder
@@ -0,0 +1,7 @@
1
+ {
2
+ "cds": {
3
+ "features": {
4
+ "kibana_formatter": true
5
+ }
6
+ }
7
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "cds": {
3
+ "features": {
4
+ "[{{cap.for}}]": {
5
+ "kibana_formatter": true
6
+ }
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,13 @@
1
+ ---
2
+ modules:
3
+ - name: {{cap.appName}}-srv
4
+ type: {{cap.pLanguage}}
5
+ requires:
6
+ - name: {{cap.appName}}-cf-logging
7
+
8
+ resources:
9
+ - name: {{cap.appName}}-cf-logging
10
+ type: org.cloudfoundry.managed-service
11
+ parameters:
12
+ service: application-logs
13
+ service-plan: lite