@sap/cds-dk 7.1.1 → 7.3.0
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/activate.js +2 -2
- package/bin/build.js +5 -2
- package/bin/compile/index.js +13 -5
- package/bin/env.js +0 -3
- package/bin/extend.js +25 -3
- package/bin/gen.js +27 -0
- package/bin/help.js +2 -1
- package/bin/import.js +7 -3
- package/bin/push.js +10 -6
- package/bin/watch.js +3 -4
- package/bin/watched.js +2 -3
- package/lib/bind/bindingUtil.js +1 -0
- package/lib/build/{buildTaskHandler.js → buildPlugin.js} +25 -30
- package/lib/build/buildTaskEngine.js +84 -89
- package/lib/build/buildTaskFactory.js +23 -44
- package/lib/build/buildTaskProvider.js +24 -19
- package/lib/build/buildTaskProviderFactory.js +176 -66
- package/lib/build/constants.js +6 -5
- package/lib/build/index.js +4 -3
- package/lib/build/provider/{buildTaskHandlerEdmx.js → edmxBuildPlugin.js} +6 -6
- package/lib/build/provider/{buildTaskHandlerFeatureToggles.js → featureToggleBuildPlugin.js} +3 -3
- package/lib/build/provider/fiori/index.js +5 -6
- package/lib/build/provider/hana/index.js +67 -36
- package/lib/build/provider/{buildTaskHandlerInternal.js → internalBuildPlugin.js} +11 -11
- package/lib/build/provider/{buildTaskProviderInternal.js → internalBuildTaskProvider.js} +42 -53
- package/lib/build/provider/java/index.js +24 -24
- package/lib/build/provider/mtx/index.js +4 -4
- package/lib/build/provider/mtx/resourcesTarBuilder.js +8 -8
- package/lib/build/provider/mtx-extension/index.js +17 -9
- package/lib/build/provider/mtx-sidecar/index.js +17 -11
- package/lib/build/provider/nodejs/index.js +63 -29
- package/lib/build/util.js +11 -19
- package/lib/client/auth_manager.js +6 -12
- package/lib/client/base_command.js +1 -1
- package/lib/client/download_legacy.js +48 -0
- package/lib/client/params.js +5 -0
- package/lib/client/push.js +41 -1
- package/lib/client/settings_manager.js +12 -3
- package/lib/compile/openapi/csdl2openapi.js +30 -21
- package/lib/compile/openapi/index.js +7 -3
- package/lib/env/schema.js +36 -0
- package/lib/env/schemas/cds-rc.json +101 -0
- package/lib/import/common.js +24 -11
- package/lib/import/importapi.js +2 -2
- package/lib/import/message.js +3 -1
- package/lib/import/odata/v4parser.js +23 -7
- package/lib/index.js +5 -0
- package/lib/init/constants.js +9 -12
- package/lib/init/index.js +86 -74
- package/lib/init/template/_merging/registry-mta.js +21 -12
- package/lib/init/template/approuter/files/mta.yaml.hbs +1 -1
- package/lib/init/template/approuter/index.js +3 -2
- package/lib/init/template/cf-manifest/files/services-manifest.yml.hbs +0 -5
- package/lib/init/template/cf-manifest/index.js +2 -2
- package/lib/init/template/connectivity/index.js +5 -4
- package/lib/init/template/destination/index.js +2 -5
- package/lib/init/template/h2/index.js +16 -0
- package/lib/init/template/hana/index.js +2 -3
- package/lib/init/template/helm/chart/values.root.schema.json +0 -5
- package/lib/init/template/helm/chart/values.schema.json +0 -4
- package/lib/init/template/helm/index.js +1 -1
- package/lib/init/template/html5-repo/index.js +27 -3
- package/lib/init/template/lint/index.js +3 -7
- package/lib/init/template/mta/index.js +9 -3
- package/lib/init/template/multitenancy/files/package.json.hbs +0 -3
- package/lib/init/template/multitenancy/index.js +2 -0
- package/lib/init/template/nodejs/index.js +3 -3
- package/lib/init/template/pipeline/index.js +2 -4
- package/lib/init/template/postgres/files/mta.yaml.hbs +27 -0
- package/lib/init/template/postgres/files/package.json.hbs +5 -0
- package/lib/init/template/postgres/index.js +52 -0
- package/lib/init/template/sample/index.js +5 -7
- package/lib/init/template/sqlite/index.js +8 -3
- package/lib/init/template/tiny-sample/index.js +16 -30
- package/lib/init/util/mvn.js +25 -1
- package/lib/init/util/projectReader.js +2 -7
- package/lib/init/util/template.js +7 -6
- package/lib/util/pruneAxiosErrors.js +22 -8
- package/lib/watch/node-watch.js +6 -1
- package/npm-shrinkwrap.json +2207 -384
- package/package.json +3 -3
- package/lib/init/template/auditlog/files/mta.yaml.hbs +0 -14
- package/lib/init/template/auditlog/files/package.json.hbs +0 -27
- package/lib/init/template/auditlog/index.js +0 -74
|
@@ -5,35 +5,33 @@ const { sortMessagesSeverityAware, deduplicateMessages, CompilationError } = cds
|
|
|
5
5
|
const { relativePaths, BuildError, resolveRequiredSapModels } = require('./util')
|
|
6
6
|
const { SEVERITIES, LOG_LEVELS } = require('./constants')
|
|
7
7
|
const BuildTaskFactory = require('./buildTaskFactory')
|
|
8
|
-
const
|
|
9
|
-
const BuildTaskHandlerInternal = require('./provider/buildTaskHandlerInternal')
|
|
8
|
+
const InternalBuildPlugin = require('./provider/internalBuildPlugin')
|
|
10
9
|
|
|
11
10
|
const COMPILATION_ERROR = 'CompilationError'
|
|
12
11
|
const COMPILE_MESSAGE = 'CompileMessage'
|
|
13
12
|
|
|
14
13
|
class BuildTaskEngine {
|
|
15
14
|
constructor(options) {
|
|
16
|
-
this.
|
|
15
|
+
this._taskFactory = new BuildTaskFactory(options)
|
|
17
16
|
}
|
|
18
|
-
get
|
|
19
|
-
return this.
|
|
17
|
+
get taskFactory() {
|
|
18
|
+
return this._taskFactory
|
|
20
19
|
}
|
|
21
20
|
get logger() {
|
|
22
|
-
return this.
|
|
21
|
+
return this.taskFactory.logger
|
|
23
22
|
}
|
|
24
|
-
get
|
|
25
|
-
return this.
|
|
23
|
+
get options() {
|
|
24
|
+
return this.taskFactory.options
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
async processTasks(tasks) {
|
|
29
28
|
const startTime = Date.now()
|
|
30
29
|
|
|
31
|
-
this.logger.log(`building project [${cds.root}], clean [${this.
|
|
30
|
+
this.logger.log(`building project [${cds.root}], clean [${this.options.clean}]`)
|
|
32
31
|
this.logger.log(`cds-dk [${require('../../package.json').version}], cds [${cds.version}], compiler [${cds.compiler.version()}], home [${cds.home}]\n`)
|
|
33
32
|
|
|
34
33
|
if (!tasks) {
|
|
35
|
-
|
|
36
|
-
tasks = await buildTaskFactory.getTasks()
|
|
34
|
+
tasks = await this.taskFactory.getTasks()
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
// validate required @sap namespace models - log only
|
|
@@ -42,69 +40,66 @@ class BuildTaskEngine {
|
|
|
42
40
|
throw new BuildError(`Required CDS models [${unresolved.join(', ')}] cannot be resolved. Make sure up-to-date versions of the missing modules are installed.`)
|
|
43
41
|
}
|
|
44
42
|
|
|
45
|
-
// create build
|
|
46
|
-
const
|
|
43
|
+
// create build plugins
|
|
44
|
+
const plugins = []
|
|
47
45
|
tasks.forEach((task) => {
|
|
48
46
|
if (task) {
|
|
49
|
-
const
|
|
50
|
-
|
|
47
|
+
const plugin = this._createPlugin(task)
|
|
48
|
+
plugins.push(plugin)
|
|
51
49
|
}
|
|
52
50
|
})
|
|
53
51
|
|
|
54
|
-
// use resolved tasks
|
|
55
|
-
this.providerFactory.context.tasks = handlers.map(handler => handler.task)
|
|
56
|
-
|
|
57
52
|
try {
|
|
58
|
-
await this._executePrepare(
|
|
59
|
-
await this._executeCleanBuildTasks(
|
|
53
|
+
await this._executePrepare(plugins)
|
|
54
|
+
await this._executeCleanBuildTasks(plugins)
|
|
60
55
|
|
|
61
56
|
// throwing Exception in case of compilation errors
|
|
62
|
-
const buildResult = await this._executeBuildTasks(
|
|
57
|
+
const buildResult = await this._executeBuildTasks(plugins)
|
|
63
58
|
|
|
64
|
-
await this._writeGenerationLog(
|
|
65
|
-
this.
|
|
66
|
-
this._logMessages(BuildTaskEngine.
|
|
59
|
+
await this._writeGenerationLog(plugins)
|
|
60
|
+
this._logOutput(plugins)
|
|
61
|
+
this._logMessages(BuildTaskEngine._getMessages(plugins))
|
|
67
62
|
this._logTimer(startTime, Date.now())
|
|
68
63
|
|
|
69
64
|
return buildResult
|
|
70
65
|
} catch (error) {
|
|
71
|
-
this.
|
|
66
|
+
this._logOutput(plugins)
|
|
72
67
|
throw error
|
|
73
68
|
}
|
|
74
69
|
}
|
|
75
70
|
|
|
76
71
|
/**
|
|
77
|
-
*
|
|
78
|
-
* Currently only used by internal
|
|
72
|
+
* BuildPlugin#prepare has been deprecated and was never part of the public API.
|
|
73
|
+
* Currently only used by internal FioriBuildPlugin.
|
|
79
74
|
* @deprecated
|
|
80
|
-
* @param {*}
|
|
75
|
+
* @param {*} plugins
|
|
81
76
|
* @returns
|
|
82
77
|
*/
|
|
83
|
-
async _executePrepare(
|
|
84
|
-
const
|
|
78
|
+
async _executePrepare(plugins) {
|
|
79
|
+
const pluginGroups = new Map()
|
|
85
80
|
|
|
86
|
-
// group
|
|
87
|
-
|
|
88
|
-
|
|
81
|
+
// group plugins by type
|
|
82
|
+
plugins.forEach(plugin => {
|
|
83
|
+
pluginGroups.has(plugin.task.for) ? pluginGroups.get(plugin.task.for).push(plugin) : pluginGroups.set(plugin.task.for, [plugin])
|
|
89
84
|
})
|
|
90
85
|
|
|
91
86
|
const promises = []
|
|
92
|
-
for (let
|
|
93
|
-
promises.push(this._doPrepare(
|
|
87
|
+
for (let pluginGroup of pluginGroups.values()) {
|
|
88
|
+
promises.push(this._doPrepare(pluginGroup))
|
|
94
89
|
}
|
|
95
90
|
return Promise.all(promises)
|
|
96
91
|
}
|
|
97
92
|
|
|
98
93
|
/**
|
|
99
94
|
* @deprecated
|
|
100
|
-
* @param {*}
|
|
95
|
+
* @param {*} pluginGroup
|
|
101
96
|
*/
|
|
102
|
-
async _doPrepare(
|
|
103
|
-
for (let
|
|
97
|
+
async _doPrepare(pluginGroup) {
|
|
98
|
+
for (let plugin of pluginGroup) {
|
|
104
99
|
// prepare has been deprecated
|
|
105
|
-
if (
|
|
106
|
-
this.logger._debug && this.logger.debug(`preparing,
|
|
107
|
-
const result = await
|
|
100
|
+
if (plugin instanceof InternalBuildPlugin) {
|
|
101
|
+
this.logger._debug && this.logger.debug(`preparing, plugin [${plugin.constructor.name}], src [${relativePaths(cds.root, plugin.task.src)}]`)
|
|
102
|
+
const result = await plugin.prepare()
|
|
108
103
|
if (result === false) {
|
|
109
104
|
break
|
|
110
105
|
}
|
|
@@ -112,8 +107,8 @@ class BuildTaskEngine {
|
|
|
112
107
|
}
|
|
113
108
|
}
|
|
114
109
|
|
|
115
|
-
async _executeCleanBuildTasks(
|
|
116
|
-
if (this.
|
|
110
|
+
async _executeCleanBuildTasks(plugins) {
|
|
111
|
+
if (this.options.clean) {
|
|
117
112
|
// clean entire build staging folder once
|
|
118
113
|
if (cds.env.build.target !== '.') {
|
|
119
114
|
const target = path.resolve(cds.root, cds.env.build.target)
|
|
@@ -121,30 +116,30 @@ class BuildTaskEngine {
|
|
|
121
116
|
await fs.promises.rm(target, { force: true, recursive: true })
|
|
122
117
|
}
|
|
123
118
|
|
|
124
|
-
const results = await Promise.allSettled(
|
|
125
|
-
this.logger._debug && this.logger.debug(`cleaning,
|
|
126
|
-
return
|
|
119
|
+
const results = await Promise.allSettled(plugins.map((plugin) => {
|
|
120
|
+
this.logger._debug && this.logger.debug(`cleaning, plugin [${plugin.constructor.name}], src [${relativePaths(cds.root, plugin.task.src)}]`)
|
|
121
|
+
return plugin.clean()
|
|
127
122
|
}))
|
|
128
123
|
// check for errors and throw exception
|
|
129
124
|
this._resolveHandlerResponse(results)
|
|
130
125
|
}
|
|
131
126
|
}
|
|
132
127
|
|
|
133
|
-
async _executeBuildTasks(
|
|
134
|
-
// sort
|
|
135
|
-
|
|
128
|
+
async _executeBuildTasks(plugins) {
|
|
129
|
+
// sort plugins based on priority in
|
|
130
|
+
plugins = plugins.sort((a, b) => {
|
|
136
131
|
return a.priority === b.priority ? 0 : a.priority > b.priority ? -1 : 1
|
|
137
132
|
})
|
|
138
|
-
// group
|
|
139
|
-
const buildPipeline =
|
|
133
|
+
// group plugins with same priority in order to execute in parallel
|
|
134
|
+
const buildPipeline = plugins.reduce((acc, plugin) => {
|
|
140
135
|
if (acc.length === 0) {
|
|
141
|
-
acc.push([
|
|
136
|
+
acc.push([plugin])
|
|
142
137
|
} else {
|
|
143
138
|
const currGroup = acc[acc.length - 1]
|
|
144
|
-
if (currGroup[0].priority ===
|
|
145
|
-
currGroup.push(
|
|
139
|
+
if (currGroup[0].priority === plugin.priority) {
|
|
140
|
+
currGroup.push(plugin)
|
|
146
141
|
} else {
|
|
147
|
-
acc.push([
|
|
142
|
+
acc.push([plugin])
|
|
148
143
|
}
|
|
149
144
|
}
|
|
150
145
|
return acc
|
|
@@ -153,20 +148,20 @@ class BuildTaskEngine {
|
|
|
153
148
|
const results = await this._executePipeline(buildPipeline)
|
|
154
149
|
|
|
155
150
|
// check for errors and throw exception - return results otherwise including any compiler and build status messages
|
|
156
|
-
return this._resolveHandlerResponse(results, BuildTaskEngine.
|
|
151
|
+
return this._resolveHandlerResponse(results, BuildTaskEngine._getMessages(plugins))
|
|
157
152
|
}
|
|
158
153
|
|
|
159
154
|
async _executePipeline(pipeline) {
|
|
160
155
|
let allResults = []
|
|
161
156
|
for (const group of pipeline) {
|
|
162
|
-
const results = await Promise.allSettled(group.map((
|
|
163
|
-
this.logger._debug && this.logger.debug(`building,
|
|
164
|
-
return
|
|
165
|
-
.then(
|
|
157
|
+
const results = await Promise.allSettled(group.map((plugin) => {
|
|
158
|
+
this.logger._debug && this.logger.debug(`building, plugin [${plugin.constructor.name}], src [${relativePaths(cds.root, plugin.task.src)}]`)
|
|
159
|
+
return plugin.build()
|
|
160
|
+
.then(pluginResult => {
|
|
166
161
|
return Promise.resolve({
|
|
167
|
-
task:
|
|
168
|
-
result:
|
|
169
|
-
messages: this._sortMessagesUnique(
|
|
162
|
+
task: plugin.task,
|
|
163
|
+
result: pluginResult,
|
|
164
|
+
messages: this._sortMessagesUnique(plugin.messages)
|
|
170
165
|
})
|
|
171
166
|
})
|
|
172
167
|
}))
|
|
@@ -175,7 +170,7 @@ class BuildTaskEngine {
|
|
|
175
170
|
return allResults
|
|
176
171
|
}
|
|
177
172
|
|
|
178
|
-
_resolveHandlerResponse(results,
|
|
173
|
+
_resolveHandlerResponse(results, pluginMessages = []) {
|
|
179
174
|
const errors = []
|
|
180
175
|
const resolvedResults = results.reduce((acc, r) => {
|
|
181
176
|
if (r.status === 'fulfilled') {
|
|
@@ -197,9 +192,9 @@ class BuildTaskEngine {
|
|
|
197
192
|
|
|
198
193
|
// propagate existing CompilationErrors
|
|
199
194
|
// merge all existing compilation messages into a single CompilationError
|
|
200
|
-
// compiler warning and info messages are returned as
|
|
195
|
+
// compiler warning and info messages are returned as plugin messages
|
|
201
196
|
const compileErrors = errors.filter(e => e.constructor.name === COMPILATION_ERROR)
|
|
202
|
-
const compileMessages =
|
|
197
|
+
const compileMessages = pluginMessages.filter(message => message.constructor.name === COMPILE_MESSAGE)
|
|
203
198
|
if (compileErrors.length) {
|
|
204
199
|
throw new CompilationError(this._sortMessagesUnique(BuildTaskEngine._getErrorMessages(compileErrors), compileMessages))
|
|
205
200
|
}
|
|
@@ -207,31 +202,31 @@ class BuildTaskEngine {
|
|
|
207
202
|
return resolvedResults
|
|
208
203
|
}
|
|
209
204
|
|
|
210
|
-
|
|
211
|
-
const
|
|
212
|
-
|
|
205
|
+
_createPlugin(task) {
|
|
206
|
+
const plugin = this.taskFactory.createPlugin(task)
|
|
207
|
+
plugin.init()
|
|
213
208
|
|
|
214
|
-
if (!(
|
|
215
|
-
// Custom build
|
|
209
|
+
if (!(plugin instanceof InternalBuildPlugin) && plugin.priority !== 1) {
|
|
210
|
+
// Custom build plugins are executed before internal plugins to ensure
|
|
216
211
|
// that generated content cannot be overwritten by mistake
|
|
217
|
-
throw new Error(`Illegal priority for ${
|
|
212
|
+
throw new Error(`Illegal priority for ${plugin.constructor.name} encountered for custom plugin - in this version only priority value '1' is allowed`)
|
|
218
213
|
}
|
|
219
|
-
this._logTaskHandler(
|
|
220
|
-
return
|
|
214
|
+
this._logTaskHandler(plugin)
|
|
215
|
+
return plugin
|
|
221
216
|
}
|
|
222
217
|
|
|
223
|
-
|
|
218
|
+
_logOutput(plugins) {
|
|
224
219
|
// log all generated files
|
|
225
|
-
const files = BuildTaskEngine.
|
|
220
|
+
const files = BuildTaskEngine._getOutput(plugins)
|
|
226
221
|
if (files.length > 0) {
|
|
227
222
|
this.logger.log(`done > wrote output to:\n ${files.join("\n ")}\n`)
|
|
228
223
|
}
|
|
229
224
|
}
|
|
230
225
|
|
|
231
|
-
async _writeGenerationLog(
|
|
226
|
+
async _writeGenerationLog(plugins) {
|
|
232
227
|
const outputFile = cds.env.build.outputfile || process.env.GENERATION_LOG
|
|
233
228
|
if (outputFile) {
|
|
234
|
-
const files = BuildTaskEngine.
|
|
229
|
+
const files = BuildTaskEngine._getOutput(plugins)
|
|
235
230
|
this.logger.log(`writing generation log to [${outputFile}]\n`)
|
|
236
231
|
try {
|
|
237
232
|
await fs.promises.mkdir(path.dirname(outputFile), { recursive: true })
|
|
@@ -243,8 +238,8 @@ class BuildTaskEngine {
|
|
|
243
238
|
}
|
|
244
239
|
}
|
|
245
240
|
|
|
246
|
-
static
|
|
247
|
-
const files =
|
|
241
|
+
static _getOutput(plugins) {
|
|
242
|
+
const files = plugins.reduce((acc, plugin) => acc.concat(plugin.files), []).sort()
|
|
248
243
|
return files.map(file => {
|
|
249
244
|
if (path.isAbsolute(cds.env.build.target)) {
|
|
250
245
|
return file
|
|
@@ -257,9 +252,9 @@ class BuildTaskEngine {
|
|
|
257
252
|
this.logger.log(`build completed in ${end - start} ms\n`)
|
|
258
253
|
}
|
|
259
254
|
|
|
260
|
-
_logTaskHandler(
|
|
261
|
-
this.logger._debug && this.logger.debug(`
|
|
262
|
-
this.logger._debug && this.logger.debug(`details src [${relativePaths(cds.root,
|
|
255
|
+
_logTaskHandler(plugin) {
|
|
256
|
+
this.logger._debug && this.logger.debug(`plugin ${plugin.constructor.name}`)
|
|
257
|
+
this.logger._debug && this.logger.debug(`details src [${relativePaths(cds.root, plugin.task.src)}], dest [${relativePaths(cds.root, plugin.task.dest)}], use [${plugin.task.use}], options [${JSON.stringify(plugin.task.options)}]`) //NOSONAR
|
|
263
258
|
}
|
|
264
259
|
|
|
265
260
|
_logMessages(messages) {
|
|
@@ -308,17 +303,17 @@ class BuildTaskEngine {
|
|
|
308
303
|
}
|
|
309
304
|
|
|
310
305
|
/**
|
|
311
|
-
* Returns compiler messages and validation messages issued by
|
|
312
|
-
* @param {Array<
|
|
306
|
+
* Returns compiler messages and validation messages issued by plugins.
|
|
307
|
+
* @param {Array<BuildPlugin>} plugins
|
|
313
308
|
*/
|
|
314
|
-
static
|
|
315
|
-
return
|
|
309
|
+
static _getMessages(plugins) {
|
|
310
|
+
return plugins.reduce((acc, plugin) => acc.concat(plugin.messages), [])
|
|
316
311
|
}
|
|
317
312
|
|
|
318
313
|
/**
|
|
319
314
|
* Sort and filter the given errors of type CompileMessage or BuildMessage according to their severity and location,
|
|
320
315
|
* but leave any other errors untouched as part of the result array.<br>
|
|
321
|
-
* The log level
|
|
316
|
+
* The log level ('command line' or 'cds.env' option) is used to filter the given messages.
|
|
322
317
|
* @param {...Error} messages
|
|
323
318
|
*/
|
|
324
319
|
_sortMessagesUnique(...messages) {
|
|
@@ -337,7 +332,7 @@ class BuildTaskEngine {
|
|
|
337
332
|
* Return user defined log level or default value 'warn'
|
|
338
333
|
*/
|
|
339
334
|
_getLogLevel() {
|
|
340
|
-
return this.
|
|
335
|
+
return this.options["log-level"] || cds.env["log-level"]
|
|
341
336
|
}
|
|
342
337
|
}
|
|
343
338
|
module.exports = BuildTaskEngine
|
|
@@ -15,8 +15,8 @@ class BuildTaskFactory {
|
|
|
15
15
|
get logger() {
|
|
16
16
|
return this.providerFactory.logger
|
|
17
17
|
}
|
|
18
|
-
get
|
|
19
|
-
return this.providerFactory.
|
|
18
|
+
get options() {
|
|
19
|
+
return this.providerFactory.options
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
// the following order for determining build tasks is used
|
|
@@ -41,12 +41,16 @@ class BuildTaskFactory {
|
|
|
41
41
|
|
|
42
42
|
// always resolve tasks for input validation
|
|
43
43
|
const resolvedTasks = this.providerFactory.resolveTasks(tasks)
|
|
44
|
-
if (this.
|
|
44
|
+
if (this.options.resolve) {
|
|
45
45
|
return resolvedTasks
|
|
46
46
|
}
|
|
47
47
|
return tasks
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
createPlugin(task) {
|
|
51
|
+
return this.providerFactory.createPlugin(task)
|
|
52
|
+
}
|
|
53
|
+
|
|
50
54
|
async _createTasks() {
|
|
51
55
|
this.logger.debug(`determining build tasks for project [${cds.root}].`)
|
|
52
56
|
|
|
@@ -61,7 +65,7 @@ class BuildTaskFactory {
|
|
|
61
65
|
// 1. apply default values including task.for and task.use and ensure that for all tasks a provider exists - throwing error otherwise
|
|
62
66
|
await this.providerFactory.applyTaskDefaults(tasks)
|
|
63
67
|
// ensure that dependencies get wired up before filtering
|
|
64
|
-
await this.providerFactory.lookupTasks(tasks)
|
|
68
|
+
await this.providerFactory.lookupTasks(tasks, true)
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
// 3. filters the list of build tasks and adapts according to given CLI options
|
|
@@ -79,7 +83,7 @@ class BuildTaskFactory {
|
|
|
79
83
|
|
|
80
84
|
// 2. add dependencies
|
|
81
85
|
existingTasks = [...tasks]
|
|
82
|
-
await this.providerFactory.lookupTasks(tasks)
|
|
86
|
+
await this.providerFactory.lookupTasks(tasks, true)
|
|
83
87
|
if (tasks.length > existingTasks.length) {
|
|
84
88
|
const newTasks = tasks.filter(task => !existingTasks.includes(task))
|
|
85
89
|
// a dependant task was added
|
|
@@ -89,9 +93,6 @@ class BuildTaskFactory {
|
|
|
89
93
|
// obligatory task defaults shared by all tasks
|
|
90
94
|
BuildTaskFactory._applyCommonTaskDefaults(tasks)
|
|
91
95
|
|
|
92
|
-
// ensure correct values for optional build task properties, error for missing mandatory properties
|
|
93
|
-
BuildTaskFactory._validateBuildTasks(tasks)
|
|
94
|
-
|
|
95
96
|
this._setDefaultBuildTargetFolder(tasks)
|
|
96
97
|
return tasks
|
|
97
98
|
}
|
|
@@ -111,14 +112,6 @@ class BuildTaskFactory {
|
|
|
111
112
|
})
|
|
112
113
|
}
|
|
113
114
|
|
|
114
|
-
static _validateBuildTasks(tasks) {
|
|
115
|
-
tasks.forEach(task => {
|
|
116
|
-
if (!task.src) {
|
|
117
|
-
throw new Error(`Invalid build task definition - value of property 'src' is missing in [${task.for || task.use}].`)
|
|
118
|
-
}
|
|
119
|
-
})
|
|
120
|
-
}
|
|
121
|
-
|
|
122
115
|
_setDefaultBuildTargetFolder(tasks) {
|
|
123
116
|
const task = tasks.find(task => task.for === BUILD_TASK_JAVA_CF || task.for === BUILD_TASK_JAVA)
|
|
124
117
|
const srv = task ? task.src : BuildTaskFactory._getModuleFolder(flatten([cds.env.folders.srv])) || "srv"
|
|
@@ -148,28 +141,22 @@ class BuildTaskFactory {
|
|
|
148
141
|
}
|
|
149
142
|
|
|
150
143
|
_applyCliOptionsFilter(tasks) {
|
|
151
|
-
const
|
|
144
|
+
const options = this.options
|
|
152
145
|
// filter tasks using either option for, use, src
|
|
153
146
|
let resultTasks = tasks.filter(task => {
|
|
154
|
-
return (!
|
|
155
|
-
&& (!
|
|
156
|
-
&& (!
|
|
147
|
+
return (!options.use || options.use === task.use)
|
|
148
|
+
&& (!options.for || options.for === task.for)
|
|
149
|
+
&& (!options.src || options.src === task.src)
|
|
157
150
|
})
|
|
158
151
|
if (resultTasks.length === 0) {
|
|
159
|
-
if (
|
|
160
|
-
const task = {}
|
|
161
|
-
if (
|
|
162
|
-
task.
|
|
163
|
-
}
|
|
164
|
-
if ((buildOptions.use)) {
|
|
165
|
-
task.use = buildOptions.use
|
|
166
|
-
}
|
|
167
|
-
if (buildOptions.src) {
|
|
168
|
-
task.src = buildOptions.src
|
|
152
|
+
if (options.for || options.use) {
|
|
153
|
+
const task = this.providerFactory.getTask(options.for ? { for: options.for } : { use: options.use })
|
|
154
|
+
if (options.src) {
|
|
155
|
+
task.src = options.src
|
|
169
156
|
}
|
|
170
157
|
resultTasks.push(task)
|
|
171
158
|
}
|
|
172
|
-
} else if (resultTasks.length
|
|
159
|
+
} else if (resultTasks.length <= tasks.length) {
|
|
173
160
|
// return the same array as long as it contains a subset of the given tasks
|
|
174
161
|
tasks.length = 0
|
|
175
162
|
resultTasks.forEach(task => tasks.push(task))
|
|
@@ -180,14 +167,14 @@ class BuildTaskFactory {
|
|
|
180
167
|
}
|
|
181
168
|
|
|
182
169
|
_applyCliOptions(tasks) {
|
|
183
|
-
const
|
|
170
|
+
const options = this.options
|
|
184
171
|
// apply remaining cli options to filtered tasks
|
|
185
172
|
tasks.forEach(task => {
|
|
186
|
-
if (
|
|
187
|
-
task.dest =
|
|
173
|
+
if (options.dest) {
|
|
174
|
+
task.dest = options.dest
|
|
188
175
|
}
|
|
189
|
-
if (
|
|
190
|
-
const opts = BuildTaskFactory._scanTaskOptionParams(
|
|
176
|
+
if (options.opts) {
|
|
177
|
+
const opts = BuildTaskFactory._scanTaskOptionParams(options.opts)
|
|
191
178
|
task.options = task.options ? Object.assign(task.options, opts) : opts
|
|
192
179
|
}
|
|
193
180
|
})
|
|
@@ -237,14 +224,6 @@ class BuildTaskFactory {
|
|
|
237
224
|
return taskOptions
|
|
238
225
|
}
|
|
239
226
|
|
|
240
|
-
/**
|
|
241
|
-
* For valid paths remove trailing '/'. Otherwise return as is - important!!
|
|
242
|
-
* @param {*} dir
|
|
243
|
-
*/
|
|
244
|
-
static _normalizePath(dir) {
|
|
245
|
-
return typeof dir === "string" ? dir.replace(/\/$/, '') : dir
|
|
246
|
-
}
|
|
247
|
-
|
|
248
227
|
/**
|
|
249
228
|
* Determines the module folder from the past list that may represent files or folders w or w/o .cds file extension.
|
|
250
229
|
* @param {Array} filesOrFolders
|
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
/* eslint-disable no-unused-vars */
|
|
2
|
+
/**
|
|
3
|
+
* @abstract
|
|
4
|
+
*/
|
|
2
5
|
module.exports = class BuildTaskProvider {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
6
|
+
/**
|
|
7
|
+
* @param {object} task
|
|
8
|
+
*/
|
|
9
|
+
providesTask(key) { }
|
|
10
|
+
/**
|
|
11
|
+
* @returns {object} task
|
|
12
|
+
*/
|
|
13
|
+
getTask(key) { return key }
|
|
14
|
+
/**
|
|
15
|
+
* @param {object} task
|
|
16
|
+
*/
|
|
17
|
+
loadPlugin(task) { }
|
|
18
|
+
/**
|
|
19
|
+
* @param {Array} tasks
|
|
20
|
+
* @param {boolean} dependencies
|
|
21
|
+
*/
|
|
22
|
+
async lookupTasks(tasks, dependencies) { }
|
|
23
|
+
/**
|
|
24
|
+
* @param {object} task
|
|
25
|
+
*/
|
|
26
|
+
async applyTaskDefaults(task) { }
|
|
22
27
|
}
|