utils/utils.js
function (travisYML, newVersion, newCodeName, existingVersions) {
  // Should only remove the old version if it is actually present in any form
  if (existingVersions.versions.length === 0) return travisYML
  const nodeVersionIndex = getNodeVersionIndex(existingVersions.versions, newVersion, newCodeName, true)
  let travisYMLLines = travisYML.split('\n')
  // We only need to do something if the old version is present
  if (nodeVersionIndex !== -1) {
    // If it’s the only version we don’t want to remove it
    if (existingVersions.versions.length !== 1) {
      // Multiple node versions were defined in array format
      // set lines we want to remove to undefined in existingVersion.versions and filter them out afterwards
      const updatedVersionsArray = _.filter(existingVersions.versions.map((version) => {
        return hasNodeVersion(version, newVersion, newCodeName, true) ? undefined : version
      }), Boolean)
      // splice the updated existingversions into travisymllines
      travisYMLLines.splice(existingVersions.startIndex + 1, existingVersions.endIndex - existingVersions.startIndex, updatedVersionsArray)
      // has an array in an array, needs to be flattened
      travisYMLLines = _.flatten(travisYMLLines)
    }
  }
  return travisYMLLines.join('\n')
}
function (travisYML, newVersion, newCodeName, existingVersions) {
  // Should only remove the old version if it is actually present in any form
  if (existingVersions.versions.length === 0) return travisYML
  const nodeVersionIndex = getNodeVersionIndex(existingVersions.versions, newVersion, newCodeName, true)
  let travisYMLLines = travisYML.split('\n')
  // We only need to do something if the old version is present
  if (nodeVersionIndex !== -1) {
    // If it’s the only version we don’t want to remove it
    if (existingVersions.versions.length !== 1) {
      // Multiple node versions were defined in array format
      // set lines we want to remove to undefined in existingVersion.versions and filter them out afterwards
      const updatedVersionsArray = _.filter(existingVersions.versions.map((version) => {
        return hasNodeVersion(version, newVersion, newCodeName, true) ? undefined : version
      }), Boolean)
      // splice the updated existingversions into travisymllines
      travisYMLLines.splice(existingVersions.startIndex + 1, existingVersions.endIndex - existingVersions.startIndex, updatedVersionsArray)
      // has an array in an array, needs to be flattened
      travisYMLLines = _.flatten(travisYMLLines)
    }
  }
  return travisYMLLines.join('\n')
}
function ( travisYML , newVersion , newCodeName , existingVersions ) { // Should only remove the old version if it is actually present in any form if ( existingVersions . versions . length === 0 ) return travisYML const nodeVersionIndex = getNodeVersionIndex ( existingVersions . versions , newVersion , newCodeName , true ) let travisYMLLines = travisYML . split ( '\n' ) // We only need to do something if the old version is present if ( nodeVersionIndex !== - 1 ) { // If it’s the only version we don’t want to remove it if ( existingVersions . versions . length !== 1 ) { // Multiple node versions were defined in array format // set lines we want to remove to undefined in existingVersion.versions and filter them out afterwards const updatedVersionsArray = _ . filter ( existingVersions . versions . map ( ( version ) => { return hasNodeVersion ( version , newVersion , newCodeName , true ) ? undefined : version } ) , Boolean ) // splice the updated existingversions into travisymllines travisYMLLines . splice ( existingVersions . startIndex + 1 , existingVersions . endIndex - existingVersions . startIndex , updatedVersionsArray ) // has an array in an array, needs to be flattened travisYMLLines = _ . flatten ( travisYMLLines ) } } return travisYMLLines . join ( '\n' ) }
existingVersions is the output of getNodeVersionsFromTravisYML
existingVersions is the output of getNodeVersionsFromTravisYML