@sap/cds-dk 7.0.2 → 7.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.
- package/bin/add.js +2 -2
- package/bin/bind.js +0 -1
- package/bin/cds.js +6 -4
- package/bin/deploy/to-hana.js +1 -1
- package/bin/init.js +2 -2
- package/lib/bind/cfKeyProvider.js +1 -0
- package/lib/bind/index.js +3 -0
- package/lib/bind/userCdsrcJsonStorageProvider.js +2 -10
- package/lib/build/constants.js +16 -14
- package/lib/build/provider/mtx/resourcesTarBuilder.js +2 -6
- package/lib/build/provider/mtx-sidecar/index.js +13 -8
- package/lib/client/base_command.js +3 -6
- package/lib/compile/asyncapi/components/messages/index.js +41 -18
- package/lib/compile/asyncapi/index.js +23 -2
- package/lib/import/odata/metadataconverter/MetadataConverter.js +1 -0
- package/lib/init/constants.js +1 -1
- package/lib/init/index.js +58 -66
- package/lib/init/template/approuter/index.js +3 -4
- package/lib/init/template/auditlog/index.js +3 -4
- package/lib/init/template/cf-manifest/files/manifest.yml.hbs +15 -23
- package/lib/init/template/cf-manifest/files/services-manifest.yml.hbs +22 -17
- package/lib/init/template/cf-manifest/index.js +2 -2
- package/lib/init/template/connectivity/index.js +2 -3
- package/lib/init/template/data/index.js +5 -5
- package/lib/init/template/destination/index.js +3 -5
- package/lib/init/template/enterprise-messaging/index.js +4 -5
- package/lib/init/template/enterprise-messaging-shared/index.js +3 -4
- package/lib/init/template/extensibility/index.js +2 -3
- package/lib/init/template/file-based-messaging/index.js +2 -2
- package/lib/init/template/hana/files/mta.yaml.hbs +1 -1
- package/lib/init/template/hana/index.js +39 -63
- package/lib/init/template/helm/index.js +15 -14
- package/lib/init/template/html5-repo/index.js +3 -7
- package/lib/init/template/java/index.js +3 -3
- package/lib/init/template/kibana/index.js +3 -4
- package/lib/init/template/lint/index.js +8 -7
- package/lib/init/template/mta/index.js +3 -2
- package/lib/init/template/multitenancy/files/package.sidecar.json.hbs +1 -1
- package/lib/init/template/multitenancy/index.js +16 -37
- package/lib/init/template/nodejs/index.js +2 -3
- package/lib/init/template/pipeline/index.js +2 -2
- package/lib/init/template/redis-messaging/index.js +3 -4
- package/lib/init/template/sample/files/app/admin-books/webapp/manifest.json +1 -1
- package/lib/init/template/sample/files/app/browse/webapp/manifest.json +1 -1
- package/lib/init/template/sample/files/srv/admin-service.cds +1 -1
- package/lib/init/template/sample/files/srv/cat-service.cds +1 -1
- package/lib/init/template/sample/index.js +6 -5
- package/lib/init/template/sqlite/index.js +1 -1
- package/lib/init/template/templateBase.js +9 -19
- package/lib/init/template/tiny-sample/index.js +5 -5
- package/lib/init/template/toggles/index.js +1 -2
- package/lib/init/template/typer/files/xsconfig.json +0 -1
- package/lib/init/template/typer/index.js +1 -1
- package/lib/init/template/xsuaa/index.js +3 -4
- package/lib/init/util/indent.js +57 -0
- package/lib/init/util/merge.js +71 -15
- package/lib/init/util/mvn.js +23 -9
- package/lib/init/util/projectReader.js +52 -168
- package/lib/init/util/template.js +12 -11
- package/lib/init/util/xml.js +6 -6
- package/lib/util/pruneAxiosErrors.js +22 -0
- package/lib/watch/open.js +6 -3
- package/npm-shrinkwrap.json +11 -17
- package/package.json +1 -2
|
@@ -13,7 +13,7 @@ module.exports = class Html5RepoTemplate extends require('../templateBase') {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
async canRun() {
|
|
16
|
-
const project = await readProject(
|
|
16
|
+
const project = await readProject()
|
|
17
17
|
const { hasMta, hasHelm } = project
|
|
18
18
|
if (!hasHelm && hasMta) {
|
|
19
19
|
throw `'cds add html5-repo' is not available for Cloud Foundry yet`
|
|
@@ -26,12 +26,8 @@ module.exports = class Html5RepoTemplate extends require('../templateBase') {
|
|
|
26
26
|
return exists(join('chart', 'templates', 'html5-apps-deployer-configmap.yaml'))
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
async run() {
|
|
30
|
-
await this.runDependentMerging()
|
|
31
|
-
}
|
|
32
|
-
|
|
33
29
|
async runDependentMerging(context = {}) {
|
|
34
|
-
const { appName, hasHelm } = await readProject(
|
|
30
|
+
const { appName, hasHelm } = await readProject()
|
|
35
31
|
|
|
36
32
|
if (hasHelm) {
|
|
37
33
|
//in case facet is being added to the already exisiting charts folder
|
|
@@ -78,7 +74,7 @@ module.exports = class Html5RepoTemplate extends require('../templateBase') {
|
|
|
78
74
|
|
|
79
75
|
// copy content deployment chart if it is not present
|
|
80
76
|
const HelmTemplate = require(`../helm`);
|
|
81
|
-
const helmTemplate = new HelmTemplate(
|
|
77
|
+
const helmTemplate = new HelmTemplate(context.oldTrackingData, context.newTrackingData);
|
|
82
78
|
isIndependentCommand = isIndependentCommand | await helmTemplate.addSubChart('content-deployment');
|
|
83
79
|
|
|
84
80
|
// add dependency entry in chart.yaml
|
|
@@ -23,13 +23,13 @@ module.exports = class JavaTemplate extends require('../templateBase') {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
async run() {
|
|
26
|
-
const { cmdLine, artifactId, archetypeVersion } = await mvn.getGenerateCmdArgs(
|
|
26
|
+
const { cmdLine, artifactId, archetypeVersion } = await mvn.getGenerateCmdArgs(path.basename(cds.root))
|
|
27
27
|
console.log(`Using Maven archetype version ${archetypeVersion}`)
|
|
28
28
|
|
|
29
|
-
const temp = await fs.promises.mkdtemp(join(os.tmpdir(), `${
|
|
29
|
+
const temp = await fs.promises.mkdtemp(join(os.tmpdir(), `${path.basename(cds.root)}_`))
|
|
30
30
|
try {
|
|
31
31
|
await cmd.spawnCommand('mvn', cmdLine, { cwd: temp })
|
|
32
|
-
await copy(join(temp, artifactId),
|
|
32
|
+
await copy(join(temp, artifactId), cds.root);
|
|
33
33
|
} catch (err) {
|
|
34
34
|
if (err.code === 'ENOENT' && err.path === 'mvn') {
|
|
35
35
|
throw `Maven executable 'mvn' not found, follow ${term.info(URLS.MAVEN_INSTALL_HELP)} and install Maven on your machine.`
|
|
@@ -10,21 +10,20 @@ module.exports = class KibanaTemplate extends require('../templateBase') {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
async canRun() {
|
|
13
|
-
const { hasMta, hasHelm, isJava } = await readProject(
|
|
13
|
+
const { hasMta, hasHelm, isJava } = await readProject()
|
|
14
14
|
if (hasHelm && !hasMta) throw `'cds add kibana' is not available for Kyma yet`
|
|
15
15
|
if (isJava) throw `'cds add kibana' is not available for Java yet`
|
|
16
16
|
return true
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
async run() {
|
|
20
|
-
const project = await readProject(
|
|
20
|
+
const project = await readProject()
|
|
21
21
|
const { configFile } = project
|
|
22
22
|
await mergeJSON(configFile, join(__dirname, 'files', 'package.json.hbs'), project)
|
|
23
|
-
await this.runDependentMerging()
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
async runDependentMerging() {
|
|
27
|
-
const project = await readProject(
|
|
26
|
+
const project = await readProject()
|
|
28
27
|
const { hasMta, hasApprouter, isJava, isMultitenant, srvPath } = project
|
|
29
28
|
|
|
30
29
|
if (hasMta) {
|
|
@@ -19,8 +19,8 @@ const VSCODE_FILE_ASSOCIATIONS = {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
module.exports = class LintTemplate extends require('../templateBase') {
|
|
22
|
-
constructor(
|
|
23
|
-
super(
|
|
22
|
+
constructor() {
|
|
23
|
+
super();
|
|
24
24
|
this.customPath = path.join(cds.root, ".eslint");
|
|
25
25
|
this.docsPath = path.join(this.customPath, "docs");
|
|
26
26
|
this.rulesPath = path.join(this.customPath, "rules");
|
|
@@ -32,13 +32,14 @@ module.exports = class LintTemplate extends require('../templateBase') {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
async canRun() {
|
|
35
|
-
|
|
35
|
+
const { lint } = cds.cli.options
|
|
36
|
+
if (lint) {
|
|
36
37
|
// If custom rule example is requested, also trigger
|
|
37
38
|
// "custom" rule type of setup
|
|
38
|
-
if (
|
|
39
|
+
if (lint.has(LINT_DEV)) {
|
|
39
40
|
this.customRuleExample = true;
|
|
40
41
|
}
|
|
41
|
-
if (
|
|
42
|
+
if (lint.has(LINT_GLOBAL)) {
|
|
42
43
|
this.lintType = "global";
|
|
43
44
|
}
|
|
44
45
|
}
|
|
@@ -98,7 +99,7 @@ module.exports = class LintTemplate extends require('../templateBase') {
|
|
|
98
99
|
"names"
|
|
99
100
|
].join(" ")}`;
|
|
100
101
|
|
|
101
|
-
if (
|
|
102
|
+
if (cds.cli.options.force) {
|
|
102
103
|
LOG.info(
|
|
103
104
|
`\n\nAlmost done - installing ${this.missingNpmDependencies["names"].length} npm dependencies:\n${task}`
|
|
104
105
|
);
|
|
@@ -187,7 +188,7 @@ module.exports = class LintTemplate extends require('../templateBase') {
|
|
|
187
188
|
clearTimeout(timerID);
|
|
188
189
|
received = answer.trim().toLowerCase();
|
|
189
190
|
// If user confirms or force flag is set, install dependencies
|
|
190
|
-
if (["y", "yes"].includes(received) ||
|
|
191
|
+
if (["y", "yes"].includes(received) || cds.cli.options.force) {
|
|
191
192
|
resolve(this._runTask(task));
|
|
192
193
|
// If use declines or question timeout is reached, print todos
|
|
193
194
|
} else if (["n", "no"].includes(received.toLowerCase())) {
|
|
@@ -7,7 +7,8 @@ const { mergeJSON, sort } = require('../../util/merge')
|
|
|
7
7
|
|
|
8
8
|
module.exports = class MtaTemplate extends require('../templateBase') {
|
|
9
9
|
|
|
10
|
-
static hasFacet(
|
|
10
|
+
static hasFacet() {
|
|
11
|
+
const { options } = cds.cli
|
|
11
12
|
if (!options?.add.has('mta') && options?.add.has('helm')) return false
|
|
12
13
|
return exists('mta.yaml')
|
|
13
14
|
}
|
|
@@ -17,7 +18,7 @@ module.exports = class MtaTemplate extends require('../templateBase') {
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
async run() {
|
|
20
|
-
const project = await readProject(
|
|
21
|
+
const project = await readProject()
|
|
21
22
|
if (!exists('mta.yaml')) {
|
|
22
23
|
await copyRenderedYAML(join(__dirname, 'files', 'mta.yaml.hbs'), 'mta.yaml', project)
|
|
23
24
|
}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
15
|
"start": "cds-serve"{{#isJava}},
|
|
16
|
-
"build": "cds build ../.. --for mtx-sidecar --production &&
|
|
16
|
+
"build": "cds build ../.. --for mtx-sidecar --production && npm ci --prefix gen"{{/isJava}}
|
|
17
17
|
},
|
|
18
18
|
"cds": {
|
|
19
19
|
"profile": "mtx-sidecar"
|
|
@@ -15,8 +15,9 @@ const {
|
|
|
15
15
|
|
|
16
16
|
module.exports = class MultitenancyTemplate extends require('../templateBase') {
|
|
17
17
|
|
|
18
|
-
static hasFacet(env
|
|
18
|
+
static hasFacet(env) {
|
|
19
19
|
// REVISIT: Check if this can be simplified
|
|
20
|
+
const { options } = cds.cli.options
|
|
20
21
|
return options?.add?.has('mtx') || options?.add?.has('multitenancy') ||
|
|
21
22
|
!!env.requires?.multitenancy || !!env.requires?.db?.multiTenant ||
|
|
22
23
|
exists(join('mtx', 'sidecar')) || false
|
|
@@ -27,7 +28,7 @@ module.exports = class MultitenancyTemplate extends require('../templateBase') {
|
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
async run() {
|
|
30
|
-
const project = await readProject(
|
|
31
|
+
const project = await readProject()
|
|
31
32
|
const { isNodejs, isJava, configFile } = project
|
|
32
33
|
await mergeJSON(configFile, join(__dirname, 'files', `package.json.hbs`), project)
|
|
33
34
|
if (isJava) {
|
|
@@ -37,11 +38,10 @@ module.exports = class MultitenancyTemplate extends require('../templateBase') {
|
|
|
37
38
|
}
|
|
38
39
|
if (isNodejs) await sort('package.json', 'dependencies')
|
|
39
40
|
await copyRenderedJSON(join(__dirname, 'files', 'package.sidecar.json.hbs'), join('mtx', 'sidecar', 'package.json'), project)
|
|
40
|
-
await this.runDependentMerging()
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
async runDependentMerging(context = {}) {
|
|
44
|
-
const project = await readProject(
|
|
44
|
+
const project = await readProject()
|
|
45
45
|
const { isNodejs, isJava, hasMta, hasHelm, hasXsuaa, hasHana, srvPath } = project
|
|
46
46
|
|
|
47
47
|
if (hasMta) {
|
|
@@ -93,11 +93,7 @@ module.exports = class MultitenancyTemplate extends require('../templateBase') {
|
|
|
93
93
|
context.oldTrackingData = context.newTrackingData = await parseMd5File(join('chart', '.cds-add-helm-files.md5'))
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
await mergeYAML(
|
|
97
|
-
join('chart', 'values.yaml'),
|
|
98
|
-
join(__dirname, 'files', 'values.yaml.hbs'),
|
|
99
|
-
project
|
|
100
|
-
)
|
|
96
|
+
await mergeYAML(join('chart', 'values.yaml'), join(__dirname, 'files', 'values.yaml.hbs'), project)
|
|
101
97
|
|
|
102
98
|
const envFromObject = {
|
|
103
99
|
envFrom: [
|
|
@@ -130,7 +126,7 @@ module.exports = class MultitenancyTemplate extends require('../templateBase') {
|
|
|
130
126
|
|
|
131
127
|
// REVISIT: Don't reference other templates except for the safe `runDependentMerging` -> low coupling, high cohesion
|
|
132
128
|
const HelmTemplate = require(`../helm`);
|
|
133
|
-
const helmTemplate = new HelmTemplate(
|
|
129
|
+
const helmTemplate = new HelmTemplate(context.oldTrackingData, context.newTrackingData);
|
|
134
130
|
|
|
135
131
|
await helmTemplate.addDependency('web-application', 'sidecar');
|
|
136
132
|
|
|
@@ -159,33 +155,16 @@ module.exports = class MultitenancyTemplate extends require('../templateBase') {
|
|
|
159
155
|
}
|
|
160
156
|
|
|
161
157
|
if (hasXsuaa) {
|
|
162
|
-
await mergeJSON(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
)
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (hasXsuaa && hasHelm) {
|
|
176
|
-
await mergeYAML(
|
|
177
|
-
join('chart', 'values.yaml'),
|
|
178
|
-
{
|
|
179
|
-
xsuaa: {
|
|
180
|
-
parameters: {
|
|
181
|
-
'tenant-mode': 'shared'
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
},
|
|
185
|
-
null,
|
|
186
|
-
{ forceOverwrite: true }
|
|
187
|
-
)
|
|
188
|
-
if (isIndependentCommand) await writeMd5File(join('chart', '.cds-add-helm-files.md5'), context.newTrackingData)
|
|
158
|
+
await mergeJSON('xs-security.json',join(__dirname, 'files', 'xs-security.json.hbs'), project, {
|
|
159
|
+
additions: [{
|
|
160
|
+
in: 'scopes',
|
|
161
|
+
where: [{ property: 'name', isEqualTo: '$XSAPPNAME.mtcallback' }],
|
|
162
|
+
}]
|
|
163
|
+
})
|
|
164
|
+
if (hasHelm) {
|
|
165
|
+
await mergeYAML(join('chart', 'values.yaml'), { xsuaa: { parameters: { 'tenant-mode': 'shared' }}}, null, { forceOverwrite: true })
|
|
166
|
+
if (isIndependentCommand) await writeMd5File(join('chart', '.cds-add-helm-files.md5'), context.newTrackingData)
|
|
167
|
+
}
|
|
189
168
|
}
|
|
190
169
|
}
|
|
191
170
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { join } = require('path')
|
|
2
2
|
const cds = require('../../../cds')
|
|
3
|
-
const { exists, mkdirp } = cds.utils
|
|
3
|
+
const { exists, mkdirp, path } = cds.utils
|
|
4
4
|
const { URLS, OPTIONS: { NODEJS, JAVA }, COMMAND_ADD } = require('../../constants')
|
|
5
5
|
const term = require('../../../util/term')
|
|
6
6
|
const { copyFiles } = require('../../util/template')
|
|
@@ -24,8 +24,7 @@ module.exports = class NodejsTemplate extends require('../templateBase') {
|
|
|
24
24
|
|
|
25
25
|
async run() {
|
|
26
26
|
const { db, srv, app } = (await this.getEnv()).folders
|
|
27
|
-
|
|
28
|
-
await copyFiles(join(__dirname, 'files'), projectPath, { projectName }, this.options.force)
|
|
27
|
+
await copyFiles(join(__dirname, 'files'), cds.root, { projectName: path.basename(cds.root) }, cds.cli.options.force)
|
|
29
28
|
await Promise.all([db, srv, app].map(p => mkdirp(p)))
|
|
30
29
|
}
|
|
31
30
|
|
|
@@ -9,7 +9,7 @@ module.exports = class PipelineTemplate extends require('../templateBase') {
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
async canRun() {
|
|
12
|
-
if (
|
|
12
|
+
if (cds.cli.options.force) {
|
|
13
13
|
return true;
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -21,7 +21,7 @@ module.exports = class PipelineTemplate extends require('../templateBase') {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
async run() {
|
|
24
|
-
await copyFiles(join(__dirname, 'files'), cds.root, {},
|
|
24
|
+
await copyFiles(join(__dirname, 'files'), cds.root, {}, true);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
async finalize() {
|
|
@@ -8,7 +8,7 @@ const { srvNode4, srvJava4, redis } = require('../_merging/registry-mta')
|
|
|
8
8
|
module.exports = class RedisMessagingTemplate extends require('../templateBase') {
|
|
9
9
|
|
|
10
10
|
async canRun() {
|
|
11
|
-
const { hasMta, hasHelm, isJava } = await readProject(
|
|
11
|
+
const { hasMta, hasHelm, isJava } = await readProject()
|
|
12
12
|
if (isJava) throw `'cds add redis-messaging' is not available for Java yet`
|
|
13
13
|
if (hasHelm && !hasMta) throw `'cds add redis-messaging' is not available for Kyma yet`
|
|
14
14
|
return true
|
|
@@ -19,15 +19,14 @@ module.exports = class RedisMessagingTemplate extends require('../templateBase')
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
async run() {
|
|
22
|
-
const project = await readProject(
|
|
22
|
+
const project = await readProject()
|
|
23
23
|
const { configFile } = project
|
|
24
24
|
project.shortcut = !(await read(configFile)).cds?.requires?.messaging?.kind
|
|
25
25
|
await mergeJSON(configFile, join(__dirname, 'files', 'package.json.hbs'), project)
|
|
26
|
-
await this.runDependentMerging()
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
async runDependentMerging() {
|
|
30
|
-
const project = await readProject(
|
|
29
|
+
const project = await readProject()
|
|
31
30
|
const { hasMta, isNodejs, srvPath } = project
|
|
32
31
|
|
|
33
32
|
if (hasMta) {
|
|
@@ -6,7 +6,7 @@ const { copyFiles } = require('../../util/template')
|
|
|
6
6
|
module.exports = class SampleTemplate extends require('../templateBase') {
|
|
7
7
|
|
|
8
8
|
async canRun() {
|
|
9
|
-
const { isJava } = await readProject(
|
|
9
|
+
const { isJava } = await readProject()
|
|
10
10
|
if (isJava) throw `'cds add sample' is not available for Java yet`
|
|
11
11
|
return true
|
|
12
12
|
}
|
|
@@ -14,11 +14,12 @@ module.exports = class SampleTemplate extends require('../templateBase') {
|
|
|
14
14
|
async run() {
|
|
15
15
|
const { db, srv, app } = (await this.getEnv()).folders
|
|
16
16
|
const language = exists('pom.xml') ? 'java' : 'nodejs'
|
|
17
|
+
const { force } = cds.cli.options
|
|
17
18
|
await Promise.all([
|
|
18
|
-
copyFiles(join(__dirname, 'files', 'db'), db, {},
|
|
19
|
-
copyFiles(join(__dirname, 'files', 'app'), app, {},
|
|
20
|
-
copyFiles(join(__dirname, 'files', 'srv'), srv, {},
|
|
21
|
-
copyFiles(join(__dirname, 'files', language), srv, {},
|
|
19
|
+
copyFiles(join(__dirname, 'files', 'db'), db, {}, force),
|
|
20
|
+
copyFiles(join(__dirname, 'files', 'app'), app, {}, force),
|
|
21
|
+
copyFiles(join(__dirname, 'files', 'srv'), srv, {}, force),
|
|
22
|
+
copyFiles(join(__dirname, 'files', language), srv, {}, force)
|
|
22
23
|
])
|
|
23
24
|
}
|
|
24
25
|
}
|
|
@@ -7,7 +7,7 @@ const { mergeJSON } = require('../../util/merge')
|
|
|
7
7
|
module.exports = class SQLiteTemplate extends require('../templateBase') {
|
|
8
8
|
|
|
9
9
|
async run() {
|
|
10
|
-
const project = await readProject(
|
|
10
|
+
const project = await readProject()
|
|
11
11
|
const { configFile } = project
|
|
12
12
|
project.shortcut = !(await read(configFile)).cds?.requires?.db?.kind
|
|
13
13
|
await mergeJSON(configFile, join(__dirname, 'files', `package.json.hbs`), project)
|
|
@@ -1,25 +1,14 @@
|
|
|
1
|
-
const cds = require('../../cds')
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
const { PROJECT_TYPE } = require('../constants');
|
|
5
|
-
const { exists } = require('../../cds').utils;
|
|
1
|
+
const cds = require('../../cds')
|
|
2
|
+
const { exists } = require('../../cds').utils
|
|
3
|
+
const { PROJECT_TYPE } = require('../constants')
|
|
6
4
|
|
|
7
5
|
module.exports = class TemplateBase {
|
|
6
|
+
|
|
8
7
|
/**
|
|
9
8
|
* @constructor
|
|
10
9
|
*/
|
|
11
|
-
constructor(
|
|
12
|
-
if (generator.options?.for && typeof generator.options?.for !== 'string') {
|
|
13
|
-
throw 'The --for argument must not be empty.'
|
|
14
|
-
}
|
|
15
|
-
this.projectPath = cds.root;
|
|
16
|
-
this.options = generator.options || {};
|
|
17
|
-
this.generator = generator;
|
|
10
|
+
constructor() {
|
|
18
11
|
this.name = this.constructor.name.replace(/template/i, '').replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase()
|
|
19
|
-
|
|
20
|
-
this.cwd = this.options.cwd || process.cwd();
|
|
21
|
-
|
|
22
|
-
this.projectName = path.basename(cds.root);
|
|
23
12
|
}
|
|
24
13
|
|
|
25
14
|
/**
|
|
@@ -51,7 +40,7 @@ module.exports = class TemplateBase {
|
|
|
51
40
|
}
|
|
52
41
|
|
|
53
42
|
// eslint-disable-next-line no-unused-vars
|
|
54
|
-
static hasFacet(env
|
|
43
|
+
static hasFacet(env) {
|
|
55
44
|
return true;
|
|
56
45
|
}
|
|
57
46
|
|
|
@@ -85,13 +74,14 @@ module.exports = class TemplateBase {
|
|
|
85
74
|
}
|
|
86
75
|
|
|
87
76
|
/**
|
|
77
|
+
* @abstract
|
|
88
78
|
* Executes steps for related facets that are set up for the project.
|
|
89
79
|
*/
|
|
90
80
|
async runRelatedMerging() {
|
|
91
81
|
for (const facet of this.getRelatedFacets()) {
|
|
92
82
|
const Template = require('./'+facet)
|
|
93
|
-
const template = new Template(
|
|
94
|
-
if (Template.hasFacet(await this.getEnv()
|
|
83
|
+
const template = new Template()
|
|
84
|
+
if (Template.hasFacet(await this.getEnv())) await template.runDependentMerging()
|
|
95
85
|
}
|
|
96
86
|
}
|
|
97
87
|
|
|
@@ -16,11 +16,11 @@ module.exports = class TinySampleTemplate extends require('../templateBase') {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
async _addJavaSamples() {
|
|
19
|
-
if (!
|
|
20
|
-
const mvnAddSamplesArgs = mvnArchetypes.getAddSamplesCmdArgs(
|
|
19
|
+
if (!cds.cli.options.add.has(JAVA)) {
|
|
20
|
+
const mvnAddSamplesArgs = mvnArchetypes.getAddSamplesCmdArgs()
|
|
21
21
|
try {
|
|
22
22
|
await commandUtil.spawnCommand('mvn', mvnAddSamplesArgs, { cwd: cds.root })
|
|
23
|
-
const mvnAddTestsArgs = mvnArchetypes.getAddTestsCmdArgs(
|
|
23
|
+
const mvnAddTestsArgs = mvnArchetypes.getAddTestsCmdArgs()
|
|
24
24
|
await commandUtil.spawnCommand('mvn', mvnAddTestsArgs, { cwd: cds.root })
|
|
25
25
|
} catch (err) {
|
|
26
26
|
if (err.code === 'ENOENT' && err.path === 'mvn') {
|
|
@@ -33,7 +33,7 @@ module.exports = class TinySampleTemplate extends require('../templateBase') {
|
|
|
33
33
|
|
|
34
34
|
async _addNodejsSamples() {
|
|
35
35
|
const { db, srv } = (await this.getEnv()).folders
|
|
36
|
-
await copyFiles(join(__dirname, 'files', 'nodejs', 'db'), db, {},
|
|
37
|
-
await copyFiles(join(__dirname, 'files', 'nodejs', 'srv'), srv, { dbFolder: db.replace(/[\\/]+$/, '') },
|
|
36
|
+
await copyFiles(join(__dirname, 'files', 'nodejs', 'db'), db, {}, cds.cli.options.force)
|
|
37
|
+
await copyFiles(join(__dirname, 'files', 'nodejs', 'srv'), srv, { dbFolder: db.replace(/[\\/]+$/, '') }, cds.cli.options.force)
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -9,10 +9,9 @@ module.exports = class TogglesTemplate extends require('../templateBase') {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
async run() {
|
|
12
|
-
const project = await readProject(
|
|
12
|
+
const project = await readProject()
|
|
13
13
|
const { isNodejs , configFile} = project
|
|
14
14
|
await mergeJSON(configFile, join(__dirname, 'files', 'package.json.hbs'), project)
|
|
15
15
|
if (isNodejs) await sort('package.json', 'dependencies')
|
|
16
|
-
await this.runDependentMerging()
|
|
17
16
|
}
|
|
18
17
|
}
|
|
@@ -7,7 +7,7 @@ const { exists, read } = require('../../../cds').utils
|
|
|
7
7
|
|
|
8
8
|
module.exports = class TyperTemplate extends require('../templateBase') {
|
|
9
9
|
async canRun() {
|
|
10
|
-
const { isJava } = await readProject(
|
|
10
|
+
const { isJava } = await readProject()
|
|
11
11
|
if (isJava) {
|
|
12
12
|
console.warn(warn(`This appears to be a Java project. 'cds add ${TYPER}' is intended to be used in Node.js projects. Proceeding anyway.\n`))
|
|
13
13
|
}
|
|
@@ -17,15 +17,14 @@ module.exports = class XsuaaTemplate extends require('../templateBase') {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
async run() {
|
|
20
|
-
const project = await readProject(
|
|
20
|
+
const project = await readProject()
|
|
21
21
|
const { configFile } = project
|
|
22
22
|
project.shortcut = !(await read(configFile)).cds?.requires?.auth?.kind
|
|
23
23
|
await mergeJSON(configFile, join(__dirname, 'files', 'package.json.hbs'), project, { forceOverwrite: true })
|
|
24
|
-
await this.runDependentMerging()
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
async runDependentMerging( context = {}) {
|
|
28
|
-
const project = await readProject(
|
|
27
|
+
const project = await readProject()
|
|
29
28
|
const { isMultitenant, hasMta, hasHelm, isJava, srvPath } = project
|
|
30
29
|
|
|
31
30
|
const cds = require('../../../../lib')
|
|
@@ -71,7 +70,7 @@ module.exports = class XsuaaTemplate extends require('../templateBase') {
|
|
|
71
70
|
|
|
72
71
|
// copy service-instance chart
|
|
73
72
|
const HelmTemplate = require(`../helm`);
|
|
74
|
-
const helmTemplate = new HelmTemplate(
|
|
73
|
+
const helmTemplate = new HelmTemplate(context.oldTrackingData, context.newTrackingData);
|
|
75
74
|
isIndependentCommand = isIndependentCommand | await helmTemplate.addSubChart('service-instance');
|
|
76
75
|
|
|
77
76
|
// add dependency entry in chart.yaml
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const indentRegEx = new RegExp(/^(\s*)/)
|
|
2
|
+
const leadingSpacesRegEx = new RegExp(/^( +)/)
|
|
3
|
+
const leadingTabsRegEx = new RegExp(/^(\t+)/)
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Greatest Common Divisor Euclidean algorithm
|
|
7
|
+
* @param {number[]} xs - list of number to find the gcd of.
|
|
8
|
+
* @returns {number} - greatest common divisor of all numbers in xs.
|
|
9
|
+
*/
|
|
10
|
+
function gcd (xs) {
|
|
11
|
+
const euclid = (a, b) => b === 0 ? a : euclid(b, a % b)
|
|
12
|
+
const [a, b, ...tail] = xs
|
|
13
|
+
return tail.length
|
|
14
|
+
? gcd([euclid(a, b)].concat(tail))
|
|
15
|
+
: euclid(a, b ?? 0) // coalesce in case xs consists of exactly one element
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Detects indent used for a file.
|
|
20
|
+
* The algorithm inspects the indentation of every line to find whether tabs or spaces are more prevalent.
|
|
21
|
+
* Once that has been determined, it derives the spacing by calculating the gcd of all relevant lines.
|
|
22
|
+
* I.e. if there are lines indented with 2, 4, or 8 spaces, it will find ' ' as indent.
|
|
23
|
+
* If lines are indented using 1 or 2 tabs, '\t' will be returned.
|
|
24
|
+
* TODO: filter out outliers, i.e. if the user used three spaces in one line, should ' ' space be used for spacing? Or should that be ignored?
|
|
25
|
+
* @param {string[]} file - lines of a file.
|
|
26
|
+
* @returns {string | null} - the string used to space (e.g. 2 spaces, 4 spaces, 1 tab, etc.) or null if the file was empty.
|
|
27
|
+
*/
|
|
28
|
+
function detectIndent (file) {
|
|
29
|
+
if (file.length === 0) return null
|
|
30
|
+
if (file.length === 1) return indentRegEx.exec(file[0])[0]
|
|
31
|
+
|
|
32
|
+
const indents = file
|
|
33
|
+
.map(line => indentRegEx.exec(line)[0])
|
|
34
|
+
.filter(Boolean)
|
|
35
|
+
.reduce((bins, indent) => {
|
|
36
|
+
const type = leadingSpacesRegEx.test(indent)
|
|
37
|
+
? 'spaces'
|
|
38
|
+
: leadingTabsRegEx.test(indent)
|
|
39
|
+
? 'tabs'
|
|
40
|
+
: undefined
|
|
41
|
+
if (type) {
|
|
42
|
+
const length = indent.split('').length
|
|
43
|
+
const bin = bins[type]
|
|
44
|
+
bin.total++
|
|
45
|
+
bin.indents[length] = (bin.indents[length] ?? 0) + 1
|
|
46
|
+
}
|
|
47
|
+
return bins
|
|
48
|
+
}, { tabs: { indents: {}, total: 0, character: '\t' }, spaces: { indents: {}, total: 0, character: ' ' } })
|
|
49
|
+
|
|
50
|
+
const preferred = indents.tabs.total > indents.spaces.total ? indents.tabs : indents.spaces
|
|
51
|
+
const width = gcd(Object.keys(preferred.indents))
|
|
52
|
+
return preferred.character.repeat(width)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = {
|
|
56
|
+
detectIndent
|
|
57
|
+
}
|