{"size": 873, "ext": "js", "max_stars_repo_path": "app/ImportComponent.js", "max_stars_repo_name": "codetony25/FermionJS", "max_stars_repo_stars_event_min_datetime": "2017-08-07T19:20:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-07T07:54:57.000Z", "max_issues_repo_path": "app/ImportComponent.js", "max_issues_repo_name": "codetony25/FermionJS", "max_issues_repo_issues_event_min_datetime": "2017-08-11T05:07:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T18:47:51.000Z", "max_forks_repo_path": "app/ImportComponent.js", "max_forks_repo_name": "codetony25/FermionJS", "max_forks_repo_forks_event_min_datetime": "2017-09-04T20:17:13.000Z", "max_forks_repo_forks_event_max_datetime": "2019-11-18T01:00:39.000Z"}
{"max_stars_count": 222, "max_issues_count": 14, "max_forks_count": 5, "avg_line_length": 21.825, "max_line_length": 69, "alphanum_fraction": 0.6300114548}
// allows users to import Custom Components
import electron from 'electron';
const { dialog } = electron;
import fs from 'fs';
import path from 'path';

const libraryPath = path.join(__dirname + '/component-library/');
const options = {
  title: 'Select Components',
  buttonLabel: 'Import',
  filters: [
    {
      name: 'React Components',
      extensions: ['jsx'],
    },
  ],
  properties: [
    'openFile',
    'multiSelections',
  ],
};

const importWrapper = () => {
  return dialog.showOpenDialog(options, (fileNames) => {
    if (!fileNames) {
      return;
    }

    fileNames.forEach((file) => {
      const name = file.lastIndexOf('/');
      const fileName = file.slice(name + 1);
      const savePath = path.join(libraryPath + fileName);
      fs.createReadStream(file).pipe(fs.createWriteStream(savePath));
    });

  });
}

export default importWrapper;
