configuration-management 0.1.0 → 0.1.1
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/package.json +1 -1
- package/scripts/setup-app-config.js +58 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "configuration-management",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Schema-driven system configuration for Adobe Commerce App Builder sync apps. Magento-style scoped config in Adobe App Builder Database (ABDB) with encryption, Commerce REST helpers, and React Admin UI.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Adobe Inc.",
|
|
@@ -11,6 +11,10 @@ const EXTENSION_POINT = 'commerce/backend-ui/1'
|
|
|
11
11
|
const INCLUDE_REL = 'node_modules/configuration-management/actions/configurations/ext.config.yaml'
|
|
12
12
|
const MARKER = '# configuration-management (auto-linked on npm install)'
|
|
13
13
|
|
|
14
|
+
function escapeRe (str) {
|
|
15
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
16
|
+
}
|
|
17
|
+
|
|
14
18
|
function findProjectRoot (startDir) {
|
|
15
19
|
let dir = startDir
|
|
16
20
|
while (dir && dir !== path.dirname(dir)) {
|
|
@@ -35,6 +39,10 @@ function alreadyLinked (content) {
|
|
|
35
39
|
return content.includes('configuration-management/actions/configurations/ext.config.yaml')
|
|
36
40
|
}
|
|
37
41
|
|
|
42
|
+
function hasExtensionPoint (content) {
|
|
43
|
+
return /^[ \t]*commerce\/backend-ui\/1:/m.test(content)
|
|
44
|
+
}
|
|
45
|
+
|
|
38
46
|
function buildExtensionBlock () {
|
|
39
47
|
return [
|
|
40
48
|
MARKER,
|
|
@@ -44,32 +52,58 @@ function buildExtensionBlock () {
|
|
|
44
52
|
].join('\n')
|
|
45
53
|
}
|
|
46
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Update an existing `commerce/backend-ui/1` block in place (never add a duplicate key).
|
|
57
|
+
*/
|
|
58
|
+
function updateExistingExtensionBlock (content) {
|
|
59
|
+
const match = content.match(/^([ \t]*)commerce\/backend-ui\/1:/m)
|
|
60
|
+
if (!match) return null
|
|
61
|
+
|
|
62
|
+
const indent = match[1]
|
|
63
|
+
const includeIndent = `${indent} `
|
|
64
|
+
const blockRe = new RegExp(
|
|
65
|
+
`^${escapeRe(indent)}commerce/backend-ui/1:[ \\t]*\\n` +
|
|
66
|
+
`(?:${escapeRe(includeIndent)}\\$include:[^\\n]*\\n)?`,
|
|
67
|
+
'm'
|
|
68
|
+
)
|
|
69
|
+
const replacement =
|
|
70
|
+
`${indent}${EXTENSION_POINT}:\n${includeIndent}$include: ${INCLUDE_REL}\n`
|
|
71
|
+
const next = content.replace(blockRe, replacement)
|
|
72
|
+
return next !== content ? next : null
|
|
73
|
+
}
|
|
74
|
+
|
|
47
75
|
function patchAppConfig (content) {
|
|
48
76
|
if (alreadyLinked(content)) {
|
|
49
77
|
return { content, changed: false, reason: 'already-linked' }
|
|
50
78
|
}
|
|
51
79
|
|
|
52
|
-
if (
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
80
|
+
if (hasExtensionPoint(content)) {
|
|
81
|
+
const updated = updateExistingExtensionBlock(content)
|
|
82
|
+
if (updated) {
|
|
83
|
+
return { content: updated, changed: true, reason: 'updated-existing-extension' }
|
|
84
|
+
}
|
|
85
|
+
return { content, changed: false, reason: 'extension-exists-unmodified' }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (/^extensions:[ \t]*\n/m.test(content)) {
|
|
89
|
+
const injection = ` ${EXTENSION_POINT}:\n $include: ${INCLUDE_REL}\n`
|
|
90
|
+
const next = content.replace(/^extensions:[ \t]*\n/m, `extensions:\n${injection}`)
|
|
61
91
|
if (next !== content) {
|
|
62
|
-
return { content: next, changed: true, reason: '
|
|
92
|
+
return { content: next, changed: true, reason: 'added-under-extensions' }
|
|
63
93
|
}
|
|
64
94
|
}
|
|
65
95
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
96
|
+
if (!/^extensions:/m.test(content)) {
|
|
97
|
+
const trimmed = content.replace(/\s+$/, '')
|
|
98
|
+
const separator = trimmed.length > 0 ? '\n\n' : ''
|
|
99
|
+
return {
|
|
100
|
+
content: `${trimmed}${separator}${buildExtensionBlock()}\n`,
|
|
101
|
+
changed: true,
|
|
102
|
+
reason: 'appended'
|
|
103
|
+
}
|
|
72
104
|
}
|
|
105
|
+
|
|
106
|
+
return { content, changed: false, reason: 'no-change' }
|
|
73
107
|
}
|
|
74
108
|
|
|
75
109
|
function main () {
|
|
@@ -91,7 +125,7 @@ function main () {
|
|
|
91
125
|
const { content, changed, reason } = patchAppConfig(original)
|
|
92
126
|
|
|
93
127
|
if (!changed) {
|
|
94
|
-
console.log(`[configuration-management] app.config.yaml
|
|
128
|
+
console.log(`[configuration-management] app.config.yaml unchanged (${reason}).`)
|
|
95
129
|
return
|
|
96
130
|
}
|
|
97
131
|
|
|
@@ -111,4 +145,10 @@ if (require.main === module) {
|
|
|
111
145
|
}
|
|
112
146
|
}
|
|
113
147
|
|
|
114
|
-
module.exports = {
|
|
148
|
+
module.exports = {
|
|
149
|
+
patchAppConfig,
|
|
150
|
+
INCLUDE_REL,
|
|
151
|
+
EXTENSION_POINT,
|
|
152
|
+
alreadyLinked,
|
|
153
|
+
hasExtensionPoint
|
|
154
|
+
}
|