function outputFile(file, data, mode) {
  return mkdir(dirname(file), { recursive: true })
    .then(() => writeFile(file, data))
    .then(() => (mode ? chmod(file, mode) : Promise.resolve()))
}
Output a file and create any non-existing directories in the process
@private