<commit_before>"use strict";

const path = require("path");
const packageJSON = require(`${"./package.json"}`);

const productName = packageJSON.productName;

require("dotenv").config();

const webpack = require("webpack");

const outputDir = path.join(__dirname, "output");

const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const SentryWebpackPlugin = require("@sentry/webpack-plugin");
const ESLintPlugin = require("eslint-webpack-plugin");

const COMMIT_SHA = process.env.SENTRY_RELEASE || process.env.GITHUB_SHA;

var htmlPageOptions = function(id, title) {
  return {
    filename: `${id}.html`,
    template: path.resolve(__dirname, "src/index.ejs"),
    id: id,
    title: `${productName}: ${title}`,
    minify: {
      collapseWhitespace: false,
      removeAttributeQuotes: false,
      removeComments: false
    }
  };
};

/**
 * List of node_modules to include in webpack bundle
 *
 * Required for specific packages like Vue UI libraries
 * that provide pure *.vue files that need compiling
 * https://simulatedgreg.gitbooks.io/electron-vue/content/en/webpack-configurations.html#white-listing-externals
 */
// let whiteListedModules = [];

// let externals = [
//   ...Object.keys(dependencies || {}).filter(d => !whiteListedModules.includes(d))
// ];

// console.log("EXTERNALS", externals);

let rendererConfig = {
  devtool: "inline-source-map",
  entry: {
    renderer: path.join(__dirname, "src", "renderer", "main.js")
  },
  // externals: externals,
  module: {
    rules: [
      {
        test: /\.(sa|sc|c)ss$/,
        use: [
          MiniCssExtractPlugin.loader,
          "css-loader",
          "sass-loader",
        ]
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: {
            presets: ["@babel/preset-env"]
          }
        }
      },
      {
        test: /\.svelte$/,
        use: {
            loader: "svelte-loader",
        },
      },
    ]
  },
  node: {
    __dirname: false,
    __filename: false
  },
  plugins: [
    new ESLintPlugin({
      fix: false,
      extensions: ["js"]
    }),
    new HtmlWebpackPlugin(htmlPageOptions("prefs", "Preferences")),
    new HtmlWebpackPlugin(htmlPageOptions("settings", "Settings")),
    new HtmlWebpackPlugin(htmlPageOptions("editor", "Editor")),    
    new HtmlWebpackPlugin(htmlPageOptions("new", "Create Screensaver!")),
    new HtmlWebpackPlugin(htmlPageOptions("about", "About!")),
    new MiniCssExtractPlugin({
      filename: "[name].css",
      chunkFilename: "[id].css"
    }),
  ],
  optimization: {
    emitOnErrors: false,
    nodeEnv: (process.env.NODE_ENV === "production" ? "production" : "development")
  },
  output: {
    filename: "[name].js",
    library: "[name]",
    libraryTarget: "var",
    path: outputDir,
    publicPath: ""
  },
  mode: (process.env.NODE_ENV === "production" ? "production" : "development"),
  resolve: {
    alias: {
      // handy alias for the root path of render files
      "@": path.join(__dirname, "src", "renderer"),
      "~": path.join(__dirname, "src")
    },
    extensions: [".js", ".json", ".css"]
  },
  target: "web"
};


/**
 * Adjust rendererConfig for production settings
 */
if (process.env.NODE_ENV === "production") {
  rendererConfig.devtool = "source-map";


  rendererConfig.plugins.push(
    new webpack.EnvironmentPlugin(["SENTRY_DSN"]),
    new webpack.DefinePlugin({
      "process.env.NODE_ENV": JSON.stringify("production"),
      "process.env.BEFORE_DAWN_RELEASE_NAME": JSON.stringify(COMMIT_SHA),
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true
    })
  );

  if ( process.env.SENTRY_AUTH_TOKEN ) {
    console.log("Using SentryWebpackPlugin");

    rendererConfig.plugins.push(
      new SentryWebpackPlugin({
        include: "src",
        ignoreFile: ".sentrycliignore",
        ignore: ["node_modules", "webpack.config.js", "webpack.main.config.js", "webpack.renderer.config.js"],
        org: "colin-mitchell",<commit_msg>Add check for sentry env variable<commit_after>"use strict";

const path = require("path");
const packageJSON = require(`${"./package.json"}`);

const productName = packageJSON.productName;

require("dotenv").config();

const webpack = require("webpack");

const outputDir = path.join(__dirname, "output");

const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const SentryWebpackPlugin = require("@sentry/webpack-plugin");
const ESLintPlugin = require("eslint-webpack-plugin");

const COMMIT_SHA = process.env.SENTRY_RELEASE || process.env.GITHUB_SHA;

var htmlPageOptions = function(id, title) {
  return {
    filename: `${id}.html`,
    template: path.resolve(__dirname, "src/index.ejs"),
    id: id,
    title: `${productName}: ${title}`,
    minify: {
      collapseWhitespace: false,
      removeAttributeQuotes: false,
      removeComments: false
    }
  };
};

/**
 * List of node_modules to include in webpack bundle
 *
 * Required for specific packages like Vue UI libraries
 * that provide pure *.vue files that need compiling
 * https://simulatedgreg.gitbooks.io/electron-vue/content/en/webpack-configurations.html#white-listing-externals
 */
// let whiteListedModules = [];

// let externals = [
//   ...Object.keys(dependencies || {}).filter(d => !whiteListedModules.includes(d))
// ];

// console.log("EXTERNALS", externals);

let rendererConfig = {
  devtool: "inline-source-map",
  entry: {
    renderer: path.join(__dirname, "src", "renderer", "main.js")
  },
  // externals: externals,
  module: {
    rules: [
      {
        test: /\.(sa|sc|c)ss$/,
        use: [
          MiniCssExtractPlugin.loader,
          "css-loader",
          "sass-loader",
        ]
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: {
            presets: ["@babel/preset-env"]
          }
        }
      },
      {
        test: /\.svelte$/,
        use: {
            loader: "svelte-loader",
        },
      },
    ]
  },
  node: {
    __dirname: false,
    __filename: false
  },
  plugins: [
    new ESLintPlugin({
      fix: false,
      extensions: ["js"]
    }),
    new HtmlWebpackPlugin(htmlPageOptions("prefs", "Preferences")),
    new HtmlWebpackPlugin(htmlPageOptions("settings", "Settings")),
    new HtmlWebpackPlugin(htmlPageOptions("editor", "Editor")),    
    new HtmlWebpackPlugin(htmlPageOptions("new", "Create Screensaver!")),
    new HtmlWebpackPlugin(htmlPageOptions("about", "About!")),
    new MiniCssExtractPlugin({
      filename: "[name].css",
      chunkFilename: "[id].css"
    }),
  ],
  optimization: {
    emitOnErrors: false,
    nodeEnv: (process.env.NODE_ENV === "production" ? "production" : "development")
  },
  output: {
    filename: "[name].js",
    library: "[name]",
    libraryTarget: "var",
    path: outputDir,
    publicPath: ""
  },
  mode: (process.env.NODE_ENV === "production" ? "production" : "development"),
  resolve: {
    alias: {
      // handy alias for the root path of render files
      "@": path.join(__dirname, "src", "renderer"),
      "~": path.join(__dirname, "src")
    },
    extensions: [".js", ".json", ".css"]
  },
  target: "web"
};


/**
 * Adjust rendererConfig for production settings
 */
if (process.env.NODE_ENV === "production") {
  rendererConfig.devtool = "source-map";

  if ( process.env.SENTRY_DSN ) {
    rendererConfig.plugins.push(
      new webpack.EnvironmentPlugin(["SENTRY_DSN"])
    );
  }

  rendererConfig.plugins.push(
    new webpack.DefinePlugin({
      "process.env.NODE_ENV": JSON.stringify("production"),
      "process.env.BEFORE_DAWN_RELEASE_NAME": JSON.stringify(COMMIT_SHA),
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true
    })
  );

  if ( process.env.SENTRY_AUTH_TOKEN ) {
    console.log("Using SentryWebpackPlugin");

    rendererConfig.plugins.push(
      new SentryWebpackPlugin({
        include: "src",
        ignoreFile: ".sentrycliignore",
        ignore: ["node_modules", "webpack.config.js", "webpack.main.config.js", "webpack.renderer.config.js"],
        org: "colin-mitchell",
{'fraction_non_alphanumeric': 0.16091954022988506, 'fraction_numerical': 0.0, 'mean_word_length': 3.008729388942774, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1653299', 'n_tokens_mistral': 2639, 'n_tokens_neox': 2618, 'n_words': 499}