<commit_before>from ievv_opensource.utils.ievvbuildstatic import pluginbase
from ievv_opensource.utils.ievvbuildstatic.filepath import AbstractDjangoAppPath
from ievv_opensource.utils.ievvbuildstatic.watcher import ProcessWatchConfig
from ievv_opensource.utils.shellcommandmixin import ShellCommandError
from ievv_opensource.utils.shellcommandmixin import ShellCommandMixin


class Plugin(pluginbase.Plugin, ShellCommandMixin):
    """
    Webpack builder plugin.

    Examples:

        Simple example::

            IEVVTASKS_BUILDSTATIC_APPS = ievvbuildstatic.config.Apps(
                ievvbuildstatic.config.App(
                    appname='demoapp',
                    version='1.0.0',
                    plugins=[
                        ievvbuildstatic.npmrun_jsbuild.Plugin(),
                    ]
                )
            )

        Webpack example::

            Install webpack:

            $ yarn add webpack

            Add the following to your package.json:

                {
                    ...
                    "scripts": {
                        ...
                        "jsbuild": "webpack --config webpack.config.js",
                        "jsbuild-production": "webpack --config webpack.config.js -p"
                        ...
                    }
                    ...
                }

            Create a webpack.config.js with something like this:

                let path = require('path');

                const isProduction = process.env.IEVV_BUILDSTATIC_MODE == 'production';
                const appconfig = require("./ievv_buildstatic.appconfig.json");
                console.log(isProduction);
                console.log(appconfig);

                let webpackConfig = {
                    entry: './scripts/javascript/ievv_jsbase/ievv_jsbase_core.js',
                    output: {
                        filename: 'ievv_jsbase_core.js',
                        path: path.resolve(appconfig.destinationfolder, 'scripts')
                    },
                    module: {
                        loaders: [
                            {
                                test: /.jsx?$/,
                                loader: 'babel-loader',
                                // exclude: /node_modules/
                                include: [
                                    path.resolve(__dirname, "scripts/javascript/ievv_jsbase"),
                                ]
                            }
                        ]
                    }
                };

                if(isProduction) {
                    webpackConfig.devtool = 'source-map';
                } else {
                    webpackConfig.devtool = 'cheap-module-eval-source-map';
                    webpackConfig.output.pathinfo = true;
                }

                module.exports = webpackConfig;

    """
    name = 'npmrun_jsbuild'
    default_group = 'js'

    def __init__(self,
                 extra_import_paths=None,
                 **kwargs):
        super(Plugin, self).__init__(**kwargs)
        self.extra_import_paths = extra_import_paths or []

    @property
    def destinationfolder(self):
        return self.app.get_destination_path('scripts')

    def get_default_import_paths(self):
        return []

    def get_import_paths(self):
        return self.get_default_import_paths() + self.extra_import_paths

    def _get_import_paths_as_strlist(self):
        import_paths = []
        for path in self.get_import_paths():
            if isinstance(path, AbstractDjangoAppPath):
                path = path.abspath
            import_paths.append(path)
        return import_paths

    def install(self):
        self.app.add_pluginconfig_to_json_config(
            plugin_name=self.name,
            config_dict={
                'import_paths': self._get_import_paths_as_strlist()
            }
        )

    def get_npm_script(self):<commit_msg>npmrun_jsbuild: Add extra_import_aliases for webpack4.<commit_after>from ievv_opensource.utils.ievvbuildstatic import pluginbase
from ievv_opensource.utils.ievvbuildstatic.filepath import AbstractDjangoAppPath
from ievv_opensource.utils.ievvbuildstatic.watcher import ProcessWatchConfig
from ievv_opensource.utils.shellcommandmixin import ShellCommandError
from ievv_opensource.utils.shellcommandmixin import ShellCommandMixin


class Plugin(pluginbase.Plugin, ShellCommandMixin):
    """
    Webpack builder plugin.

    Examples:

        Simple example::

            IEVVTASKS_BUILDSTATIC_APPS = ievvbuildstatic.config.Apps(
                ievvbuildstatic.config.App(
                    appname='demoapp',
                    version='1.0.0',
                    plugins=[
                        ievvbuildstatic.npmrun_jsbuild.Plugin(),
                    ]
                )
            )

        Webpack example::

            Install webpack:

            $ yarn add webpack

            Add the following to your package.json:

                {
                    ...
                    "scripts": {
                        ...
                        "jsbuild": "webpack --config webpack.config.js",
                        "jsbuild-production": "webpack --config webpack.config.js -p"
                        ...
                    }
                    ...
                }

            Create a webpack.config.js with something like this:

                let path = require('path');

                const isProduction = process.env.IEVV_BUILDSTATIC_MODE == 'production';
                const appconfig = require("./ievv_buildstatic.appconfig.json");
                console.log(isProduction);
                console.log(appconfig);

                let webpackConfig = {
                    entry: './scripts/javascript/ievv_jsbase/ievv_jsbase_core.js',
                    output: {
                        filename: 'ievv_jsbase_core.js',
                        path: path.resolve(appconfig.destinationfolder, 'scripts')
                    },
                    module: {
                        loaders: [
                            {
                                test: /.jsx?$/,
                                loader: 'babel-loader',
                                // exclude: /node_modules/
                                include: [
                                    path.resolve(__dirname, "scripts/javascript/ievv_jsbase"),
                                ]
                            }
                        ]
                    }
                };

                if(isProduction) {
                    webpackConfig.devtool = 'source-map';
                } else {
                    webpackConfig.devtool = 'cheap-module-eval-source-map';
                    webpackConfig.output.pathinfo = true;
                }

                module.exports = webpackConfig;

    """
    name = 'npmrun_jsbuild'
    default_group = 'js'

    def __init__(self,
                 extra_import_paths=None,
                 extra_import_aliases=None,
                 **kwargs):
        super(Plugin, self).__init__(**kwargs)
        self.extra_import_paths = extra_import_paths or []
        self.extra_import_aliases = extra_import_aliases or {}

    @property
    def destinationfolder(self):
        return self.app.get_destination_path('scripts')

    def get_default_import_paths(self):
        return []

    def get_import_paths(self):
        return self.get_default_import_paths() + self.extra_import_paths

    def _get_import_paths_as_strlist(self):
        import_paths = []
        for path in self.get_import_paths():
            if isinstance(path, AbstractDjangoAppPath):
                path = path.abspath
            import_paths.append(path)
        return import_paths

    def _get_extra_import_aliases(self):
        import_aliases = {}
        for alias, path in self.extra_import_aliases.items():
            if isinstance(path, AbstractDjangoAppPath):
                path = path.abspath
            import_aliases[alias] = path
        return import_aliases

    def install(self):
        self.app.add_pluginconfig_to_json_config(
            plugin_name=self.name,
            config_dict={
                'import_paths': self._get_import_paths_as_strlist(),
                'extra_import_aliases': self._get_extra_import_aliases()
            }
        )

    def get_npm_script(self):
{'fraction_non_alphanumeric': 0.0814382664602929, 'fraction_numerical': 0.0008334325514942256, 'mean_word_length': 1.3529411764705883, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4226143', 'n_tokens_mistral': 2211, 'n_tokens_neox': 2026, 'n_words': 344}