const { join } = require('path')
const { api } = require('../skypager-webpack')

module.exports = function (env, options = {}) {
  return Promise.resolve(api()
    .target('node')
    .node({
      __dirname: false,
      __filename: false,
      process: false,
    })
    .externals(require.resolve('./package.json'))
    .context(__dirname)
    .sourcemap('source-map')
    .entry({
      index: './src/index',
      portfolio: './src/portfolio',
      project: './src/project',
      cache: './src/cache',
      document: './src/document',
      collection: './src/collection',
      helper: './src/helper',
      entity: './src/entity',
      'markdown-ast-interface': './src/markdown-ast-interface.js',
      'document-utils': './src/document-utils',
      'document-types/markdown': './src/document-types/markdown.js',
      'document-types/babel-es6': './src/document-types/babel-es6.js',
      'document-types/packageManifest': './src/document-types/packageManifest.js',
      'document-types/page-config': './src/document-types/page-config.js',
      'document-types/screen-config': './src/document-types/screen-config.js',
      'document-types/spec': './src/document-types/spec.js',
      'transformers/docblock': './src/transformers/docblock.js',
      'transformers/markdown': './src/transformers/markdown.js',
      'helpers/project-type': './src/helpers/project-type.js',
      'helpers/document-type': './src/helpers/document-type.js',
      'helpers/transformer': './src/helpers/transformer.js',
      'helpers/model': './src/helpers/model.js',
    })
    .plugin('webpack.NamedModulesPlugin')
    .modules(
      join(__dirname, 'src')
    )
    .modules(join(__dirname, '..'))
    .output({
      path: join(__dirname, 'lib'),
      filename: '[name].js',
      chunkFilename: '[name].js',
    })
    .loader('babel', '.js', {
      include: [
        join(__dirname, 'src'),
      ],
      exclude: [
        /node_modules/,
      ],
    })
    .getConfig())
}
