{"size": 1820, "ext": "js", "max_stars_repo_path": "config/config.js", "max_stars_repo_name": "tapatun2005/website-2020", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "config/config.js", "max_issues_repo_name": "tapatun2005/website-2020", "max_issues_repo_issues_event_min_datetime": "2021-05-11T10:39:41.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T03:06:24.000Z", "max_forks_repo_path": "config/config.js", "max_forks_repo_name": "tapatun2005/website-2020", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 24.5945945946, "max_line_length": 108, "alphanum_fraction": 0.5972527473}
// Packages
const fs = require('fs')
const path = require('path')
const HtmlWebpackPlugin = require("html-webpack-plugin")
const transformImports = require('babel-plugin-transform-imports');

// Routes
const $views = './src/scripts/Views/'
const $pages = './src/templates/Views/'

export const Config = {
    views: _readFiles($views),
    pages: _readFiles($pages),
    htmlPlugins: _generateHTMLplugins($pages),
    babelLoader: _babelLoader()
}

function _readFiles(dir) {
    
  const obj = {}

  fs.readdirSync(dir).forEach(filename => {
    
    const name = path.parse(filename).name
    const filepath = path.resolve(dir, filename);
    const stat = fs.lstatSync(filepath)
    const isFile = stat.isFile();

    if (isFile) obj[name.toLowerCase()] = `${dir}${filename}`

  })

  return obj
}


function _generateHTMLplugins(dir) {
  return fs.readdirSync(dir).map(item => {
    // Split names and extension
    const parts = item.split('.')
    const name = parts[0]
    const extension = parts[1]
    return new HtmlWebpackPlugin({
      filename: `${name}.html`,
      template: `${dir}/${name}.${extension}`,
      chunks: [name, 'vendors', 'runtime']
    })
  })
}

function _babelLoader() {
  return {
    loader: 'babel-loader',
    query: {
      plugins: [
        [transformImports, {
          'Functions': {
            transform: function(importName, matches) {
              return path.join(__dirname, "../src/scripts/Lib/Functions/") + importName;
            },
            preventFullImport: true
          },
          'Components': {
            transform: function(importName, matches) {
              return path.join(__dirname, "../src/scripts/Lib/Components/") + importName + '/' + importName;
            },
            preventFullImport: false
          }
        }]
      ]
    }
  }
}
