src/fileUtil.js
function updateHeader(fileInfo, data, type, headerLineRegex, options) {
  const contents = fs.readFileSync(fileInfo.path, 'utf8') || ''
  const body = contents.split('\n')
  // assumes all comments at top of template are the header block

  const preheader = []
  while (body.length && !body[0].trim().match(headerLineRegex)) preheader.push(body.shift())
  while (body.length && body[0].trim().match(headerLineRegex)) body.shift()

  const template = renderTemplate(data, type, options)
  const header = []
  for (let hline of template.split('\n')) {
    if (!hline.trim().match(headerLineRegex)) break
    else header.push(hline)
  }
  const newContents = preheader.concat(header).concat(body).join('\n')
  fs.writeFileSync(fileInfo.path, newContents)
}
function updateHeader(fileInfo, data, type, headerLineRegex, options) {
  const contents = fs.readFileSync(fileInfo.path, 'utf8') || ''
  const body = contents.split('\n')
  // assumes all comments at top of template are the header block

  const preheader = []
  while (body.length && !body[0].trim().match(headerLineRegex)) preheader.push(body.shift())
  while (body.length && body[0].trim().match(headerLineRegex)) body.shift()

  const template = renderTemplate(data, type, options)
  const header = []
  for (let hline of template.split('\n')) {
    if (!hline.trim().match(headerLineRegex)) break
    else header.push(hline)
  }
  const newContents = preheader.concat(header).concat(body).join('\n')
  fs.writeFileSync(fileInfo.path, newContents)
}
function updateHeader ( fileInfo , data , type , headerLineRegex , options ) { const contents = fs . readFileSync ( fileInfo . path , 'utf8' ) || '' const body = contents . split ( '\n' ) // assumes all comments at top of template are the header block const preheader = [ ] while ( body . length && ! body [ 0 ] . trim ( ) . match ( headerLineRegex ) ) preheader . push ( body . shift ( ) ) while ( body . length && body [ 0 ] . trim ( ) . match ( headerLineRegex ) ) body . shift ( ) const template = renderTemplate ( data , type , options ) const header = [ ] for ( let hline of template . split ( '\n' ) ) { if ( ! hline . trim ( ) . match ( headerLineRegex ) ) break else header . push ( hline ) } const newContents = preheader . concat ( header ) . concat ( body ) . join ( '\n' ) fs . writeFileSync ( fileInfo . path , newContents ) }
Keeps the header block of your templated file in sync with your Swagger api.

@param {object} fileInfo info on the file to target
@param {object} data the operation which to gen the header from
@param {string} type the type of file being updated
@param {regex} headerLineRegex regex to find if a line is part of the header
@param {object} options options containing details on rendering the header
@return {void}
Keeps the header block of your templated file in sync with your Swagger api .