Skip to main content

zc.buildout recipe for closurebuilder

Project description

This is a simple wrapper around the closurebuilder tools from the Closure project from Google.

Dependencies

Setup some JavaScript files.

>>> import os.path
>>> os.mkdir(os.path.join(sample_buildout, 'js'))
>>> write('js/a.js', '''
... goog.provide('pwt.provideA');
...
... goog.require('pwt.provideB');
... ''')
>>> write('js/b.js', '''
... goog.provide('pwt.provideB');
... ''')
>>> mkdir('js/goog')
>>> write('js/goog/base.js', open(os.path.join(os.path.dirname(__file__), "goog/base.js")).read())

roots

Generate a dependency file specifing where all your JavaScript files are located within your project.

>>> write('buildout.cfg', '''
... [buildout]
... parts = deps.js
...
... [deps.js]
... recipe = pwt.recipe.closurebuilder:dependency
... output = %(dir)s/deps.js
... roots = %(dir)s/js
... ''' %{'dir': sample_buildout})
>>> print system(buildout)
Installing deps.js.
<BLANKLINE>
>>> cat('deps.js')
// This file was autogenerated by buildout[deps.js].
// Please do not edit.
goog.addDependency('a.js', ['pwt.provideA'], ['pwt.provideB']);
goog.addDependency('b.js', ['pwt.provideB'], []);
goog.addDependency('goog/base.js', [], []);

roots with prefix

Generate a dependency file specifing where all your JavaScript files are located within your project. Sometimes files are served under different namespaces, then we use the root_with_prefix option.

>>> write('buildout.cfg', '''
... [buildout]
... parts = deps.js
...
... [deps.js]
... recipe = pwt.recipe.closurebuilder:dependency
... output = %(dir)s/deps.js
... root_with_prefix = %(dir)s/js /media
... ''' %{'dir': sample_buildout})
>>> print system(buildout)
Uninstalling deps.js.
Installing deps.js.
<BLANKLINE>
>>> cat('deps.js')
// This file was autogenerated by buildout[deps.js].
// Please do not edit.
goog.addDependency('/media/a.js', ['pwt.provideA'], ['pwt.provideB']);
goog.addDependency('/media/b.js', ['pwt.provideB'], []);
goog.addDependency('/media/goog/base.js', [], []);

Compile

Using the information above, generate a small minimized version of your JavaScript application.

>>> write('buildout.cfg', '''
... [buildout]
... parts = deps.js compiled.js
...
... [deps.js]
... recipe = pwt.recipe.closurebuilder:dependency
... output = %(dir)s/d1.js
... roots = %(dir)s/js
...
... [compiled.js]
... recipe = pwt.recipe.closurebuilder:compile
... dependency = deps.js
... output = %(dir)s
... inputs = %(dir)s/js/a.js
... ''' %{'dir': sample_buildout})
>>> output = system(buildout)
>>> output == '''Uninstalling deps.js.
... Installing deps.js.
... Installing compiled.js.
... root: Compiling with the following command: java -jar %(jar)s --js %(dir)s/js/goog/base.js --js %(dir)s/js/b.js --js %(dir)s/js/a.js
... ''' %{'jar': os.path.join(os.path.dirname(__file__), 'compiler-961.jar'),
...       'dir': sample_buildout}
True
>>> ls(sample_buildout)
-  .installed.cfg
-  bc41220de966d83def110b37e3fefc73.js
d  bin
-  buildout.cfg
-  d1.js
d  develop-eggs
d  eggs
d  js
d  parts

We can also specify extra files that might not have goog.provide declarations in them so won’t be picked up by the depswriter recipe.

>>> write('js/c.js', '''
... alert('c');
... ''')
>>> write('buildout.cfg', '''
... [buildout]
... parts = deps.js compiled.js
...
... [deps.js]
... recipe = pwt.recipe.closurebuilder:dependency
... output = %(dir)s/d1.js
... roots = %(dir)s/js
...
... [compiled.js]
... recipe = pwt.recipe.closurebuilder:compile
... dependency = deps.js
... output = %(dir)s
... inputs = %(dir)s/js/a.js
... extra_js = js/c.js
... ''' %{'dir': sample_buildout})
>>> output = system(buildout)
>>> output == '''Uninstalling compiled.js.
... Updating deps.js.
... Installing compiled.js.
... root: Compiling with the following command: java -jar %(jar)s --js js/c.js --js %(dir)s/js/goog/base.js --js %(dir)s/js/b.js --js %(dir)s/js/a.js
... ''' %{'jar': os.path.join(os.path.dirname(__file__), 'compiler-961.jar'),
...       'dir': sample_buildout}
True
>>> ls(sample_buildout)
-  .installed.cfg
d  bin
-  buildout.cfg
-  cd01d46dee31867866de7a1fb0784944.js
-  d1.js
d  develop-eggs
d  eggs
d  js
d  parts

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pwt.recipe.closurebuilder-0.9.4.tar.gz (3.9 MB view details)

Uploaded Source

File details

Details for the file pwt.recipe.closurebuilder-0.9.4.tar.gz.

File metadata

File hashes

Hashes for pwt.recipe.closurebuilder-0.9.4.tar.gz
Algorithm Hash digest
SHA256 c34839a9b7126ced40d55bb98e6b52594ecf871c05490ce1ac6cb0d9b548a599
MD5 80480eed62e02fd2946988a7a0011bd7
BLAKE2b-256 7d167376a4829ba4a2bb72ac41a3b952eadce60b6d846697759e6762676d6040

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page