function safeWriteFile(filePath, data) {
  const fileDir = path.dirname(filePath);
  fs.mkdirSync(fileDir, {recursive: true});
  fs.writeFileSync(filePath, data);
}
Write a file to filePath, creating parent directories if needed.
@param {string} filePath
@param {string} data