import path from 'path'
import esbuild from 'esbuild'
import { sassPlugin,postcssModules } from 'esbuild-sass-plugin'

let project = {
  name: 'amotify',
  ver: 'v0.0.1',
  author: 'mingoo, LLC.',
  details: 'https://mingoo.co.jp/'
}

let jsBanner = `/**
* @license amotify
* ${ project.name } ${ project.ver }
* ${ project.details }
   
* Copyright (c) ${ project.author }
* Released under the MIT license
* ${ project.details }

* Latest updated at: ${ new Date().toLocaleDateString() }
*/
`

esbuild.build( {
  bundle: true,
  minify: true,
  target: [ "ES6" ],
  platform: 'node',
  format: 'esm',
  entryPoints: [
    './src/amotify.tsx'
  ],
  outbase: './src',
  outfile: './dist/amotify.min.js',
  external: [
    "./node_modules/*"
  ],
  plugins: [
    sassPlugin( {
      type: 'css',
      filter: /\.module\.scss$/,
      importMapper: ( path ) => {
        let resolvedPath = path
          .replace( /@props/,__dirname + '/src/@styles/props.scss' )
          .replace( /@mixin/,__dirname + '/src/@styles/mixin.scss' )
        return resolvedPath
      },
      transform: postcssModules( {

      } )
    } ),
    sassPlugin( {
      type: 'css'
    } )
  ],
  banner: {
    js: jsBanner
  },
} )