var fs = require('fs-extra');

var glob = require('glob');

var path = require('path');

var args = process.argv.slice(2);
var destinationFolder = args[0] || 'lib';
var declarationFolder = 'src';
glob(declarationFolder + "/**/*.d.ts", function (err, files) {
  if (err) {
    throw err;
  }

  files.map(function (file) {
    var destinationPath = file.split('/').slice(1).join('/'); // eslint-disable-next-line no-console

    console.log('Copied', file, ' -> ', destinationPath);
    fs.ensureFile(path.join(destinationFolder, destinationPath), function (err) {
      if (err) {
        throw err;
      }

      fs.copyFile(file, path.join(destinationFolder, destinationPath), function (err) {
        if (err) {
          throw err;
        }
      });
    });
  });
});