const removeKataComments = (line) => line.replace(/\/\/\/\/\s*/, '');
const isKataLine = (line) => line.trim().startsWith('////');
const findFirstKataLine = (lines) => {
  let kataLineIndex = -1;
  lines.some((line, idx) => {
    if (isKataLine(line)) {
      kataLineIndex = idx;
      return true;
    }
    return false;
  });
  return kataLineIndex;
};
const kataifyAtLineIndex = (lines, firstKataLineIndex) => {
  return kataifyFile([
    ...lines.slice(0, firstKataLineIndex),
    removeKataComments(lines[firstKataLineIndex]),
    ...lines.slice(firstKataLineIndex + 2),
  ].join('\n'));
};
export const kataifyFile = (content) => {
  const lines = content.split('\n');
  const firstKataLineIndex = findFirstKataLine(lines);
  if (firstKataLineIndex > -1) {
    return kataifyAtLineIndex(lines, firstKataLineIndex);
  }
  return content;
};

export const kataify = (kataifyableList, deps) => {
  const kataifyableToTask = (kataifyable) =>
    deps.readFile(kataifyable.sourceFileName)
      .then(kataifyFile)
      .then(content => deps.writeFile(kataifyable.destinationFilename, content))
    ;

  return Promise.all(kataifyableList.map(kataifyableToTask));
};

const isKataLine = (line) => line.trim().startsWith('////');
const enableKataLine = (line) => line.replace(/\/\/\/\/\s*/, '');
const removeLinesAfterKataLine = (_, lineIndex, lines) => {
  if (lineIndex === 0) return true;
  const previousLine = lines[lineIndex-1];
  return !isKataLine(previousLine);
};

export const kataifyFile = (fileContent) => {
  const lines = fileContent.split('\n');
  return lines
    .filter(removeLinesAfterKataLine)
    .map(enableKataLine)
    .join('\n')
  ;
};

export const kataify = (kataifyableList, deps) => {
  const kataifyableToTask = (kataifyable) =>
    deps.readFile(kataifyable.sourceFileName)
      .then(kataifyFile)
      .then(content => deps.writeFile(kataifyable.destinationFilename, content))
    ;

  return Promise.all(kataifyableList.map(kataifyableToTask));
};

Use the better version I once wrote.