const fs = require('fs');

const ditty = require('parse-ditty');

const dataPath = `${__dirname}/../data`;
const rawCategories = fs.readdirSync(dataPath);
const categoryPattern = new RegExp(
  '^' +
    '(\\d+)' +  // (1) Category ID,
    '\\.\s*' +  // followed by a dot and optional whitespace,
    '(.+)' +    // followed by (2) the category name.
  '$'
);
const categoriesData = rawCategories.map((dirname) => {
  const matches = dirname.match(categoryPattern);
  return {
    id: parseInt(matches[1], 10),
    name: matches[2],
  };
});

const categoryDirs = rawCategories.map((dirname, index) => ({
  id: categoriesData[index].id,
  dirname,
}));

const songsData = categoryDirs.reduce((result, category) => {
  const categoryPath = `${dataPath}/${category.dirname}`;
  const songFiles = fs.readdirSync(categoryPath);
  const parsedSongs = songFiles.map(filename => {
    const rawSong = fs.readFileSync(`${categoryPath}/${filename}`, 'utf8');
    return Object.assign({},
      ditty(rawSong),
      { category: category.id }
    );
  });
  return result.concat(parsedSongs);
}, []);

module.exports = {
  categories: JSON.stringify(categoriesData),
  songs: JSON.stringify(songsData),
};

@@ -206,16 +206,18 @@
 %5C%5Cd+)' +
+  
   // (1)
@@ -243,13 +243,15 @@
 %5C%5C.%5C
+%5C
 s*' +
+ 
   //
@@ -302,24 +302,26 @@
     '(.+)' +
+  
     // follo

Fix typo