// @ts-check
const fs = require("fs")
const path = require("path")
const { basePath, isDevelopment } = require("../src/lib/environment")

// Helpers
export function getEntrypoints() {
  return findAssets("src/client/assets")
}

export function findAssets(rootPath) {
  const files = fs.readdirSync(path.join(basePath, rootPath))
  // Filter out .styl files
  const validAssets = file => {
    const isValid = /\.(js|ts|coffee)x?/.test(path.extname(file))
    return isValid
  }

  /**
   * Construct key/value pairs representing Webpack entrypoints; e.g.,
   * { desktop: [ path/to/subapp.asset.js ] }
   */
  const assets = files.filter(validAssets).reduce((assetMap, file) => {
    const fileName = path.basename(file, path.extname(file))
    const asset = {
      [fileName]: [path.join(basePath, rootPath, file)],
    }

    if (isDevelopment) {
      asset[fileName].unshift("webpack-hot-middleware/client?reload=true")
    }

    return {
      ...assetMap,
      ...asset,
    }
  }, {})

  return assets
}

@@ -142,23 +142,16 @@
 Helpers%0A
-export 
 function
@@ -218,15 +218,8 @@
 %0A%7D%0A%0A
-export 
 func
@@ -993,8 +993,56 @@
 ssets%0A%7D%0A
+%0Amodule.exports.getEntrypoints = getEntrypoints%0A

fix webpack helper exports for production mode