Skip to content

Commit

Permalink
Add ES6 support via 6to5.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberdelia committed Feb 3, 2015
1 parent 4751a12 commit 57593e7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
28 changes: 28 additions & 0 deletions docs/compilers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,34 @@ To use it add this to your ``PIPELINE_COMPILERS`` ::
Defaults to ``''``.


ES6 compiler
============

The ES6 compiler uses `6to5 <https://6to5.org>`_
to convert ES6+ code into vanilla ES5.

To use it add this to your ``PIPELINE_COMPILERS`` ::

PIPELINE_COMPILERS = (
'pipeline.compilers.es6.ES6Compiler',
)


``PIPELINE_6TO5_BINARY``
--------------------------

Command line to execute for 6to5 program.
You will most likely change this to the location of 6to5 on your system.

Defaults to ``'/usr/bin/env 6to5'``.

``PIPELINE_6TO5_ARGUMENTS``
-----------------------------

Additional arguments to use when 6to5 is called.

Defaults to ``''``.


Write your own compiler class
=============================
Expand Down
22 changes: 22 additions & 0 deletions pipeline/compilers/es6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from __future__ import unicode_literals

from pipeline.conf import settings
from pipeline.compilers import SubProcessCompiler


class ES6Compiler(SubProcessCompiler):
output_extension = 'js'

def match_file(self, path):
return path.endswith('.es6')

def compile_file(self, infile, outfile, outdated=False, force=False):
if not outdated and not force:
return # File doesn't need to be recompiled
command = "%s %s %s -o %s" % (
settings.PIPELINE_6TO5_BINARY,
settings.PIPELINE_6TO5_ARGUMENTS,
infile,
outfile
)
return self.execute_command(command)
3 changes: 3 additions & 0 deletions pipeline/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
'PIPELINE_COFFEE_SCRIPT_BINARY': '/usr/bin/env coffee',
'PIPELINE_COFFEE_SCRIPT_ARGUMENTS': '',

'PIPELINE_6TO5_BINARY': '/usr/bin/env 6to5',
'PIPELINE_6TO5_ARGUMENTS': '',

'PIPELINE_LIVE_SCRIPT_BINARY': '/usr/bin/env lsc',
'PIPELINE_LIVE_SCRIPT_ARGUMENTS': '',

Expand Down

0 comments on commit 57593e7

Please sign in to comment.