Mercurial > piecrust2
changeset 1038:7487e2df8a56
bake: Add support for Browserify.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 16 Jan 2018 08:41:46 -0800 |
parents | 89d94955b818 |
children | 3133ddc3cb73 |
files | piecrust/plugins/builtin.py piecrust/processing/browserify.py |
diffstat | 2 files changed, 59 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/piecrust/plugins/builtin.py Tue Jan 16 08:41:25 2018 -0800 +++ b/piecrust/plugins/builtin.py Tue Jan 16 08:41:46 2018 -0800 @@ -120,6 +120,7 @@ TextileFormatter()] def getProcessors(self): + from piecrust.processing.browserify import BrowserifyProcessor from piecrust.processing.compass import CompassProcessor from piecrust.processing.compressors import ( CleanCssProcessor, UglifyJSProcessor) @@ -132,6 +133,7 @@ from piecrust.processing.util import ConcatProcessor return [ + BrowserifyProcessor(), CopyFileProcessor(), ConcatProcessor(), PygmentsStyleProcessor(),
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/piecrust/processing/browserify.py Tue Jan 16 08:41:46 2018 -0800 @@ -0,0 +1,57 @@ +import os +import os.path +import logging +import platform +import subprocess +from piecrust.processing.base import Processor, PRIORITY_FIRST, FORCE_BUILD + + +logger = logging.getLogger(__name__) + + +class BrowserifyProcessor(Processor): + PROCESSOR_NAME = 'browserify' + + def __init__(self): + super(BrowserifyProcessor, self).__init__() + self.priority = PRIORITY_FIRST + self.is_bypassing_structured_processing = True + self._conf = None + + def initialize(self, app): + super(BrowserifyProcessor, self).initialize(app) + + self._conf = app.config.get('browserify') + if self._conf is None: + return + + if self._conf is True: + self._conf = {} + + self._conf.setdefault('bin', 'browserify') + + def matches(self, path): + return self._conf is not None and os.path.splitext(path)[1] == '.js' + + def getDependencies(self, path): + return FORCE_BUILD + + def process(self, path, out_dir): + _, fname = os.path.split(path) + out_path = os.path.join(out_dir, fname) + + args = [self._conf['bin'], path, '-o', out_path] + cwd = self.app.root_dir + logger.debug("Running Browserify: %s" % ' '.join(args)) + try: + retcode = subprocess.call(args, cwd=cwd) + except FileNotFoundError as ex: + logger.error("Tried running Browserify processor " + "with command: %s" % args) + raise Exception("Error running Browserify. " + "Did you install it?") from ex + if retcode != 0: + raise Exception("Error occured in Browserify compiler. " + "Please check log messages above for " + "more information.") + return True