import multiInput from 'rollup-plugin-multi-input'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import { babel } from '@rollup/plugin-babel'
import commonjs from '@rollup/plugin-commonjs'
import styles from 'rollup-plugin-styles'
import autoprefixer from 'autoprefixer'
import path from 'path'

export default {
  external: [
    'tty',
    'os',
    'path',
    'fs',
    'util',
    'url',
    'react',
    'react-dom',
    'classnames',
    'downshift',
    'framer-motion',
    'prop-types',
    '@reach/visually-hidden',
    /@fortawesome/,
    /@testing-library/,
  ],
  input: ['src/components/**/*.js','src/hooks/**/*.js','src/dummy/**/*.js'],
  output: [
    {
      format: 'es',
      dir: 'dist',
      exports: 'named'
    },
  ],
  plugins: [
    nodeResolve({ preferBuiltins: false }),
    commonjs({
      include: /node_modules/,
    }),
    babel({ babelHelpers: 'runtime' }),
    styles({
      mode: 'inject',
      plugins: [
        autoprefixer
      ]
    }),
    multiInput.default({
      relative: 'src',
      transformOutputPath: function(output, input) {
        const parentFolders = path.dirname(input).split(path.sep)
        // Remove the src/{hooks|components} directories
        const newDestination = parentFolders.slice(2, parentFolders.length)
        return `${newDestination.join(path.sep)}/${path.basename(output)}`
      }
    }),
  ],
  preserveEntrySignatures: 'strict',
}
