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

let project = {
  name: 'amotify',
  ver: 'v0.1.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( {
  define: {
    // 'process.env.NODE_ENV': '"production"'
  },
  bundle: true,
  minify: true,
  target: [ "ES6" ],
  platform: 'node',
  format: 'esm',
  entryPoints: [
    './@src/index.tsx',
    './@src/atoms/index.tsx',
    './@src/atoms/Box/index.tsx',
  ],
  outbase: './@src',
  // outfile: './dist/amotify.min.js',
  outdir: './dist',
  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
  },
} )

// npm publish --access=public