@@ -5,6 +5,7 @@ import { randomUUID } from 'crypto'
5
5
import { diff } from 'deep-diff'
6
6
import { copy , createFileSync , move , pathExists , renameSync , rm } from 'fs-extra'
7
7
import { mkdir , readFile , writeFile } from 'fs/promises'
8
+ import { glob } from 'glob'
8
9
import { cloneDeep , each , get , isObject , mapKeys , mapValues , omit , pick , pull , set , unset } from 'lodash'
9
10
import { basename , dirname , join } from 'path'
10
11
import { prepareEnvironment } from 'src/common/cli'
@@ -20,7 +21,6 @@ import { v4 as uuidv4 } from 'uuid'
20
21
import { parse } from 'yaml'
21
22
import { Argv } from 'yargs'
22
23
import { $ , cd } from 'zx'
23
- import { glob } from 'glob'
24
24
const cmdName = getFilename ( __filename )
25
25
26
26
interface Arguments extends BasicArguments {
@@ -372,14 +372,40 @@ export const applyChanges = async (
372
372
373
373
export const unparsePaths = ( path : string , values : Record < string , any > ) : Array < string > => {
374
374
if ( path . includes ( '{team}' ) ) {
375
- const paths : Array < string > = [ ]
375
+ let paths : Array < string > = [ ]
376
376
const teams : Array < string > = Object . keys ( values ?. teamConfig as Record < string , any > )
377
377
teams . forEach ( ( teamName ) => paths . push ( path . replace ( '{team}' , teamName ) ) )
378
+ paths = isArray ( paths , values )
378
379
return paths . sort ( )
379
380
} else {
380
- return [ path ]
381
+ const paths = isArray ( [ path ] , values )
382
+ return paths
381
383
}
382
384
}
385
+
386
+ function isArray ( paths : string [ ] , values : Record < string , any > ) : string [ ] {
387
+ const transformedPaths : string [ ] = [ ]
388
+
389
+ paths . forEach ( ( path ) => {
390
+ const match = path . match ( / ^ ( .* ) \. ( \w + ) \[ \] ( .* ) $ / )
391
+ if ( ! match ) {
392
+ transformedPaths . push ( path )
393
+ return
394
+ }
395
+
396
+ const [ , beforeArrayPath , arrayKey , afterArrayPath ] = match
397
+
398
+ const objectPath = beforeArrayPath . split ( '.' ) . reduce ( ( obj , key ) => obj ?. [ key ] , values )
399
+
400
+ if ( objectPath && objectPath [ arrayKey ] ) {
401
+ objectPath [ arrayKey ] . forEach ( ( _item : any , index : number ) => {
402
+ transformedPaths . push ( `${ beforeArrayPath } .${ arrayKey } [${ index } ]${ afterArrayPath } ` )
403
+ } )
404
+ }
405
+ } )
406
+
407
+ return transformedPaths
408
+ }
383
409
export const unsetAtPath = ( path : string , values : Record < string , any > ) : void => {
384
410
const paths = unparsePaths ( path , values )
385
411
paths . forEach ( ( p ) => unset ( values , p ) )
0 commit comments