/
report.js
113 lines (101 loc) · 4.11 KB
/
report.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
Copyright 2019 Adobe Inc. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
const RuntimeBaseCommand = require('../../../RuntimeBaseCommand')
const { processInputs, returnUnion, setPaths } = require('@adobe/aio-lib-runtime').utils
const { flags } = require('@oclif/command')
class DeployReport extends RuntimeBaseCommand {
async run () {
const { flags } = this.parse(DeployReport)
try {
const components = setPaths(flags)
const packages = components.packages
const deploymentTriggers = components.deploymentTriggers
const deploymentPackages = components.deploymentPackages
const proj = {
name: components.projectName,
Inputs: {}
}
const pkg = []
const actions = []
const triggers = []
Object.keys(packages).forEach((key) => {
const objPkg = { name: key, Inputs: {} }
if (packages[key]['public']) {
objPkg.public = packages[key]['public']
}
pkg.push(objPkg)
if (packages[key]['actions']) {
Object.keys(packages[key]['actions']).forEach((action) => {
const objAction = { name: action, Inputs: {} }
const packageInputs = packages[key]['actions'][action]['inputs'] || {}
let deploymentInputs = {}
if (deploymentPackages[key] && deploymentPackages[key]['actions'] && deploymentPackages[key]['actions'][action]) {
deploymentInputs = deploymentPackages[key]['actions'][action]['inputs'] || {}
}
const allInputs = returnUnion(packageInputs, deploymentInputs)
objAction.Inputs = processInputs(allInputs, {})
actions.push(objAction)
})
}
if (packages[key]['sequences']) {
Object.keys(packages[key]['sequences']).forEach((sequence) => {
const objSequence = { name: sequence, Inputs: {} }
actions.push(objSequence)
})
}
if (packages[key]['triggers']) {
Object.keys(packages[key]['triggers']).forEach((trigger) => {
const objTrigger = { name: trigger }
if (packages[key]['triggers'][trigger]['feed']) {
objTrigger.feed = packages[key]['triggers'][trigger]['feed']
}
const packageInputs = packages[key]['triggers'][trigger]['inputs'] || {}
let deploymentInputs = {}
if (trigger in deploymentTriggers) {
deploymentInputs = deploymentTriggers[trigger]
}
let allInputs = returnUnion(packageInputs, deploymentInputs)
allInputs = processInputs(allInputs, {})
objTrigger.Inputs = allInputs
triggers.push(objTrigger)
})
}
})
this.logJSON('', proj)
for (const packg of pkg) {
this.logJSON('', packg)
}
for (const action of actions) {
// TODO : Need to improve the fetching of namespace and addition to actions
this.logJSON('', action)
}
for (const trigger of triggers) {
this.logJSON('', trigger)
}
} catch (err) {
this.handleError('Failed to report', err)
}
}
}
DeployReport.flags = {
...RuntimeBaseCommand.flags,
manifest: flags.string({
char: 'm',
description: 'the manifest file location' // help description for flag
}),
deployment: flags.string({
char: 'd',
description: 'the deployment file location' // help description for flag
})
}
DeployReport.description = 'Provides a summary report of Runtime assets being deployed/undeployed based on manifest/deployment YAML'
DeployReport.aliases = ['rt:deploy:report']
module.exports = DeployReport