<commit_before>import json
import os

from ievv_opensource.utils.ievvbuildstatic import pluginbase
from ievv_opensource.utils.ievvbuildstatic.installers.npm import NpmInstaller
from ievv_opensource.utils.shellcommandmixin import ShellCommandError
from ievv_opensource.utils.shellcommandmixin import ShellCommandMixin


class Plugin(pluginbase.Plugin, ShellCommandMixin):
    """
    Bower install plugin --- installs bower packages.

    The packages are installed when ``ievv buildstatic`` starts up.
    The plugin creates a ``bower.json`` file, and runs ``bower install``
    using the created ``bower.json``-file.

    You will most likely want to add ``bower.json`` and ``bower_components``
    to your VCS ignore file.

    Examples:

        Install bootstrap 3.1.1 and angularjs 1.4.1::

            IEVVTASKS_BUILDSTATIC_APPS = ievvbuildstatic.config.Apps(
                ievvbuildstatic.config.App(
                    appname='demoapp',
                    version='1.0.0',
                    plugins=[
                        ievvbuildstatic.browserify_jsbuild.Plugin(
                            sourcefile='app.js',
                            destinationfile='app.js',
                        ),
                    ]
                )
            )
    """
    name = 'browserify_jsbuild'

    def __init__(self, sourcefile, destinationfile,
                 sourcefolder=os.path.join('scripts', 'javascript'),
                 destinationfolder=os.path.join('scripts'),
                 extra_watchfolders=None,
                 transform_es2015=False):
        """
        Parameters:
            sourcefile: The source file relative to ``sourcefolder``.
            destinationfile: Path to destination file relative to ``destinationfolder``.
            sourcefolder: The folder where ``sourcefiles`` is located relative to
                the source folder of the :class:`~ievv_opensource.utils.ievvbuild.config.App`.
                Defaults to ``scripts/coffeescript``.
            destinationfolder: The folder where ``destinationfile`` is located relative to
                the destination folder of the :class:`~ievv_opensource.utils.ievvbuild.config.App`.
                Defaults to ``scripts/``.
            extra_watchfolders: List of extra folders to watch for changes.
                Relative to the source folder of the
                :class:`~ievv_opensource.utils.ievvbuild.config.App`.
        """
        super(Plugin, self).__init__()
        self.sourcefile = sourcefile
        self.destinationfile = destinationfile
        self.destinationfolder = destinationfolder
        self.sourcefolder = sourcefolder
        self.extra_watchfolders = extra_watchfolders or []
        self.transform_es2015 = transform_es2015

    def get_sourcefile_path(self):
        return self.app.get_source_path(self.sourcefolder, self.sourcefile)

    def get_destinationfile_path(self):
        return self.app.get_destination_path(self.destinationfolder, self.destinationfile)

    def get_browserify_version(self):
        return None

    def install(self):
        self.app.get_installer(NpmInstaller).queue_install(
            'browserify', version=self.get_browserify_version())
        if self.transform_es2015:
            self.app.get_installer(NpmInstaller).queue_install(
                'babel-preset-es2015', version='^6.6.0')
            self.app.get_installer(NpmInstaller).queue_install(
                'babelify', version='^7.3.0')

    def get_browserify_executable(self):
        return self.app.get_installer(NpmInstaller).find_executable('browserify')

    def run(self):
        self.get_logger().command_start(
            'Running browserify with {sourcefile} as input and {destinationfile} as output'.format(
                sourcefile=self.get_sourcefile_path(),
                destinationfile=self.get_destinationfile_path()))
        executable = self.get_browserify_executable()
        args = [
           self.get_sourcefile_path(),
           '-o', self.get_destinationfile_path(),
        ]
        if self.transform_es2015:
            args.extend([
                '-t', '[', 'babelify', '--presets', '[', 'es2015', ']', ']'
            ])
<commit_msg>ievvbuildstatic.browserify_jsbuild: Create the destination directory before running browserify.<commit_after>import os

from ievv_opensource.utils.ievvbuildstatic import pluginbase
from ievv_opensource.utils.ievvbuildstatic.installers.npm import NpmInstaller
from ievv_opensource.utils.shellcommandmixin import ShellCommandError
from ievv_opensource.utils.shellcommandmixin import ShellCommandMixin


class Plugin(pluginbase.Plugin, ShellCommandMixin):
    """
    Bower install plugin --- installs bower packages.

    The packages are installed when ``ievv buildstatic`` starts up.
    The plugin creates a ``bower.json`` file, and runs ``bower install``
    using the created ``bower.json``-file.

    You will most likely want to add ``bower.json`` and ``bower_components``
    to your VCS ignore file.

    Examples:

        Install bootstrap 3.1.1 and angularjs 1.4.1::

            IEVVTASKS_BUILDSTATIC_APPS = ievvbuildstatic.config.Apps(
                ievvbuildstatic.config.App(
                    appname='demoapp',
                    version='1.0.0',
                    plugins=[
                        ievvbuildstatic.browserify_jsbuild.Plugin(
                            sourcefile='app.js',
                            destinationfile='app.js',
                        ),
                    ]
                )
            )
    """
    name = 'browserify_jsbuild'

    def __init__(self, sourcefile, destinationfile,
                 sourcefolder=os.path.join('scripts', 'javascript'),
                 destinationfolder=os.path.join('scripts'),
                 extra_watchfolders=None,
                 transform_es2015=False):
        """
        Parameters:
            sourcefile: The source file relative to ``sourcefolder``.
            destinationfile: Path to destination file relative to ``destinationfolder``.
            sourcefolder: The folder where ``sourcefiles`` is located relative to
                the source folder of the :class:`~ievv_opensource.utils.ievvbuild.config.App`.
                Defaults to ``scripts/coffeescript``.
            destinationfolder: The folder where ``destinationfile`` is located relative to
                the destination folder of the :class:`~ievv_opensource.utils.ievvbuild.config.App`.
                Defaults to ``scripts/``.
            extra_watchfolders: List of extra folders to watch for changes.
                Relative to the source folder of the
                :class:`~ievv_opensource.utils.ievvbuild.config.App`.
        """
        super(Plugin, self).__init__()
        self.sourcefile = sourcefile
        self.destinationfile = destinationfile
        self.destinationfolder = destinationfolder
        self.sourcefolder = sourcefolder
        self.extra_watchfolders = extra_watchfolders or []
        self.transform_es2015 = transform_es2015

    def get_sourcefile_path(self):
        return self.app.get_source_path(self.sourcefolder, self.sourcefile)

    def get_destinationfile_path(self):
        return self.app.get_destination_path(self.destinationfolder, self.destinationfile)

    def get_browserify_version(self):
        return None

    def install(self):
        self.app.get_installer(NpmInstaller).queue_install(
            'browserify', version=self.get_browserify_version())
        if self.transform_es2015:
            self.app.get_installer(NpmInstaller).queue_install(
                'babel-preset-es2015', version='^6.6.0')
            self.app.get_installer(NpmInstaller).queue_install(
                'babelify', version='^7.3.0')

    def get_browserify_executable(self):
        return self.app.get_installer(NpmInstaller).find_executable('browserify')

    def run(self):
        self.get_logger().command_start(
            'Running browserify with {sourcefile} as input and {destinationfile} as output'.format(
                sourcefile=self.get_sourcefile_path(),
                destinationfile=self.get_destinationfile_path()))
        executable = self.get_browserify_executable()
        destination_folder = self.app.get_destination_path(self.destinationfolder)
        if not os.path.exists(destination_folder):
            os.makedirs(destination_folder)
        args = [
           self.get_sourcefile_path(),
           '-o', self.get_destinationfile_path(),
        ]
        if self.transform_es2015:
            args.extend([
                '-t', '[', 'babelify', '--presets', '[', 'es2015', ']', ']'
            ])

{'fraction_non_alphanumeric': 0.09385076001842468, 'fraction_numerical': 0.009903270382312299, 'mean_word_length': 2.349402236791361, 'pattern_counts': {'":': 0, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4330757', 'n_tokens_mistral': 2405, 'n_tokens_neox': 2262, 'n_words': 485}