diff options
Diffstat (limited to 'dev')
-rw-r--r-- | dev/build.js | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/dev/build.js b/dev/build.js index 3fd62893..72dce283 100644 --- a/dev/build.js +++ b/dev/build.js @@ -82,10 +82,16 @@ function applyModifications(manifest, modifications) { switch (action) { case 'set': { - const {value: newValue} = modification; - const value = getObjectProperties(manifest, path2, path2.length - 1); - const last = path2[path2.length - 1]; - value[last] = clone(newValue); + const {value, before, after} = modification; + const object = getObjectProperties(manifest, path2, path2.length - 1); + const key = path2[path2.length - 1]; + + let {index} = modification; + if (typeof index !== 'number') { index = -1; } + if (typeof before === 'string') { index = getObjectKeyIndex(object, before); } + if (typeof after === 'string') { index = getObjectKeyIndex(object, after); } + + setObjectKeyAtIndex(object, key, value, index); } break; case 'replace': @@ -143,6 +149,14 @@ function applyModifications(manifest, modifications) { } } break; + case 'add': + { + const {items} = modification; + const value = getObjectProperties(manifest, path2, path2.length); + const itemsNew = items.map((v) => clone(v)); + value.push(...itemsNew); + } + break; } } } @@ -165,7 +179,7 @@ function getObjectKeyIndex(object, key) { } function setObjectKeyAtIndex(object, key, value, index) { - if (index < 0 || Object.prototype.hasOwnProperty.call(object, key)) { + if (index < 0 || typeof key === 'number' || Object.prototype.hasOwnProperty.call(object, key)) { object[key] = value; return; } |