#!/usr/bin/env node
const fse = require('fs-extra')
const {join, resolve} = require('path')

const srcDir = resolve(__dirname, '../src/__generated__')
const iconsSrc = join(srcDir, 'icons.d.ts')
const indexSrc = join(srcDir, '../index.d.ts')

const destDir = resolve(__dirname, '../dist')
const iconsDest = join(destDir, 'icons.d.ts')
const indexDest = join(destDir, 'index.d.ts')

fse.copy(iconsSrc, iconsDest).catch(die)
fse
  .readFile(indexSrc, 'utf8')
  .then(content => content.replace(/.\/__generated__\//g, './'))
  .then(fse.writeFile.bind(fse, indexDest))
  .catch(die)

function die(err) {
  console.error(err.stack)
  process.exit(1)
}

@@ -378,16 +378,19 @@
 s')%0A%0Afse
+%0A  
 .copy(ic
@@ -411,24 +411,44 @@
 est)
-.catch(die)%0Afse%0A
+%0A  .then(() =%3E %7B%0A    return fse%0A    
   .r
@@ -473,16 +473,20 @@
 'utf8')%0A
+    
   .then(
@@ -542,24 +542,28 @@
  './'))%0A
+    
   .then(
 fse.writ
@@ -554,16 +554,27 @@
   .then(
+content =%3E 
 fse.writ
@@ -582,29 +582,41 @@
 File
-.bind(fse, indexDest)
+(indexDest, content, 'utf8'))%0A  %7D
 )%0A  
@@ -693,10 +693,15 @@
 exit
-(1)
+Code = 1
 %0A%7D%0A

tidy up types.js