File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,21 +26,25 @@ const service = process.argv[3];
2626const volume = process.argv[4];
2727const lines = fs.readFileSync( file, 'utf8' ).split( '\n' );
2828
29- if ( lines.some( line => line.trim() === volume.trim() ) ) {
30- process.exit( 0 );
31- }
32-
3329const serviceIndex = lines.findIndex( line => line === ` ${ service }:` );
3430if ( serviceIndex === -1 ) {
3531 throw new Error( `Service ${ service } not found in ${ file }.` );
3632}
3733
38- let volumesIndex = -1 ;
34+ let serviceEnd = lines.length ;
3935for ( let i = serviceIndex + 1; i < lines.length; i++ ) {
4036 if ( /^ [A-Za-z0-9_-]+:/.test( lines[i] ) ) {
37+ serviceEnd = i;
4138 break;
4239 }
40+ }
4341
42+ if ( lines.slice( serviceIndex, serviceEnd ).some( line => line.trim() === volume.trim() ) ) {
43+ process.exit( 0 );
44+ }
45+
46+ let volumesIndex = -1;
47+ for ( let i = serviceIndex + 1; i < serviceEnd; i++ ) {
4448 if ( lines[i].trim() === 'volumes:' ) {
4549 volumesIndex = i;
4650 break;
@@ -52,7 +56,7 @@ if ( volumesIndex === -1 ) {
5256}
5357
5458let insertAt = volumesIndex + 1;
55- while ( insertAt < lines.length && /^\s{6}- /.test( lines[insertAt] ) ) {
59+ while ( insertAt < serviceEnd && /^\s{6}- /.test( lines[insertAt] ) ) {
5660 insertAt++;
5761}
5862
You can’t perform that action at this time.
0 commit comments