diff options
| author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-12-18 15:24:12 -0500 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-18 15:24:12 -0500 | 
| commit | df7834a8805aa813fe44bc20ae6d24f6bbe70dde (patch) | |
| tree | 4b6d3de198567343f03c025cb4e815256061d5b3 /dev | |
| parent | 5dc7bc0e1522482dd2262846a66b62a70f840ff4 (diff) | |
More build script improvements (#1123)
* Update set action to support an assignment index
* Add 'add' modification
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;      } |