#!/bin/node
import path from 'path';

import {DIST_DIR, KATAS_DIR} from './config';
import {all as rawMetadata} from '../katas/es6/language/__raw-metadata__';

import {writeToFileAsJson} from './_external-deps/filesystem';
import MetaData from './metadata.js';
import FlatMetaData from './flat-metadata';
import GroupedMetaData from './grouped-metadata';

const destinationDir = path.join(DIST_DIR, 'katas/es6/language');

const buildMetadata = () => {
  const allJsonFile = path.join(destinationDir, '__all__.json');
  const groupedJsonFile = path.join(destinationDir, '__grouped__.json');

  new MetaData(writeToFileAsJson)
    .convertWith(rawMetadata, FlatMetaData)
    .writeToFile(allJsonFile);

  new MetaData(writeToFileAsJson)
    .convertWith(rawMetadata, GroupedMetaData)
    .writeToFile(groupedJsonFile);
};

import {convertTestsToKatas} from './convert-tests-to-katas';
convertTestsToKatas({sourceDir: KATAS_DIR, destinationDir: path.join(DIST_DIR, 'katas')})
  .then(buildMetadata)
;

@@ -107,28 +107,187 @@
 data
-%7D from '../katas/es6
+Es1%7D from '../katas/es1/language/__raw-metadata__';%0Aimport %7Ball as rawMetadataEs6%7D from '../katas/es6/language/__raw-metadata__';%0Aimport %7Ball as rawMetadataEs8%7D from '../katas/es8
 /lan
@@ -528,16 +528,19 @@
 ationDir
+Es1
  = path.
@@ -567,75 +567,289 @@
 s/es
-6/language');%0A%0Aconst buildMetadata = () =%3E %7B%0A  const allJsonFile = 
+1/language');%0Aconst destinationDirEs6 = path.join(DIST_DIR, 'katas/es6/language');%0Aconst destinationDirEs8 = path.join(DIST_DIR, 'katas/es8/language');%0A%0Aconst buildMetadata = () =%3E %7B%0A  new MetaData(writeToFileAsJson)%0A    .convertWith(rawMetadataEs1, FlatMetaData)%0A    .writeToFile(
 path
@@ -864,24 +864,27 @@
 stinationDir
+Es1
 , '__all__.j
@@ -892,36 +892,412 @@
 on')
+)
 ;%0A
+%0A
   
-const groupedJsonFile = 
+new MetaData(writeToFileAsJson)%0A    .convertWith(rawMetadataEs1, GroupedMetaData)%0A    .writeToFile(path.join(destinationDirEs1, '__grouped__.json'));%0A%0A  new MetaData(writeToFileAsJson)%0A    .convertWith(rawMetadataEs6, FlatMetaData)%0A    .writeToFile(path.join(destinationDirEs6, '__all__.json'));%0A%0A  new MetaData(writeToFileAsJson)%0A    .convertWith(rawMetadataEs6, GroupedMetaData)%0A    .writeToFile(
 path
@@ -1316,16 +1316,19 @@
 ationDir
+Es6
 , '__gro
@@ -1340,16 +1340,17 @@
 _.json')
+)
 ;%0A%0A  new
@@ -1406,16 +1406,19 @@
 Metadata
+Es8
 , FlatMe
@@ -1446,19 +1446,52 @@
 ile(
-allJsonFile
+path.join(destinationDirEs8, '__all__.json')
 );%0A%0A
@@ -1552,16 +1552,19 @@
 Metadata
+Es8
 , Groupe
@@ -1595,23 +1595,56 @@
 ile(
-groupedJsonFile
+path.join(destinationDirEs8, '__grouped__.json')
 );%0A%7D

Build ES1, ES6 and ES8 metadata.