DEV Community

Alexey Melezhik
Alexey Melezhik

Posted on

Sparrowdo as Gulp and Friends Alternative.

Nowadays developers use widely popular tools like Gulp or Gunt for routine task automation. Those tools are great, however:

  • You should use Java Script to write both build scenarios and extensions.
  • Extensions ( plugins ) are installed as npm packages.

Well, Sparrowdo/Sparrow provides reasonable alternative for those who want to stick to other languages:

  • Build scenarios are written on the nifty, high level language Rakudo Perl6.
  • Extensions are created on one of the languages - Bash/Perl5/Ruby/Python
  • Plugins gets installed as Sparrow plugins ( no explicit installation is required, see further ).

Following a simple example or Sparrowdo usage for task automation.

Install tool chain

All you need is 2 parts:

Sparrowdo which is lightweight Perl6 API for Sparrow plugins systems. And Sparrow itself as it acts as task runner. The installation process is pretty easy:

$ sudo cpanm Sparrow --notest -q
$ zef install Sparrowdo
Enter fullscreen mode Exit fullscreen mode

Create scenario

It should be file called sparrowfile and placed in the current working directory:

use IO::Glob;

directory "tmp/";

for glob("js/*.js") -> $file { 

  task-run "minify $file" , 'js-minify', %(
      in  => $file.absolute,      
      out => "tmp/" ~ ( $file.basename ),      


for glob("images/*.png") -> $file { 

  task-run "compress $file", "png-compress", %(
      in  => $file.absolute,      
      out => "tmp/" ~ ( $file.basename ),
      compression => 6       

Enter fullscreen mode Exit fullscreen mode

Let me explain a bit what's going on here.

We ran two tasks called "minify $file" and "compress $file" which do a following actions:

  • minifies input JS file and stores an updated version at tmp/ directory
  • compresses PNG file and stores an updated version at the same tmp/ directory

All the tasks get run in loop for every files found at the directories:
js/ and images/ accordingly.

Task_run function gets 3 parameters:

  • task_description - human readable task description.
  • plugin_name - the name of underlying sparrow plugin.
  • plugin_parameters- this is an optional parameter to set the parameters consumed by a plugin, they are passed as Perl6 Hash structure.

Sparrow plugins are work horses here do all the job. As I already told, they could be written on one of the 4 languages - Perl5, Bash, Ruby or Python.

I use here a couple of plugins:

  • png-compress - plugin to compress PNG images by using GD library.
  • js-minify - plugin to minify a JavaScript file by using JavaScript::Minifier CPAN module.

The cool thing about using Sparrow plugins is we don't have to install them priorly to use them. This is provided automatically, in run time. And more over, many plugins because they are written on Perl5 or Ruby or Python could have its own dependencies ( CPAN/RubyGems/Pip modules) and all such a dependencies get resolved for you by Sparrow ( yet again in runtime ) and installed locally, in safe way, not polluting your system wide paths and not requiring sudo to run.

Let's give it a run

Now we are all set. It's Sparrowdo's turn to execute our scenario:

$ sparrowdo  --local_mode --no_sudo --sparrow_root=$PWD/.sparrowdo-cache --cwd=$PWD  --format=production 
running sparrow tasks on ... 
target OS is - ubuntu
push [task] create directory tmp/ OK
push [task] minify js/in2.js [plg] js-minify OK
push [task] minify js/in1.js [plg] js-minify OK
push [task] minify js/in3.js [plg] js-minify OK
push [task] compress images/image1.png [plg] png-compress OK
push [task] compress images/image3.png [plg] png-compress OK
push [task] compress images/image2.png [plg] png-compress OK
SPL file /home/melezhik/projects/sparrowdo-test/task-runner/.sparrowdo-cache/sparrow.list is empty
get index updates from SparrowHub ... OK
set up task box file - /home/melezhik/.sparrowdo//home/melezhik/projects/sparrowdo-test/task-runner/.sparrowdo-cache/task-box.json - OK
installing public@directory version 0.001005 ...
Download --- 200
installing public@js-minify version 0.000002 ...
Download --- 200
Installing modules using /home/melezhik/projects/sparrowdo-test/task-runner/.sparrowdo-cache/plugins/public/js-minify/cpanfile
Successfully installed JavaScript-Minifier-1.14
1 distribution installed
Complete! Modules were installed into /home/melezhik/projects/sparrowdo-test/task-runner/.sparrowdo-cache/plugins/public/js-minify/local
installing public@png-compress version 0.000001 ...
Download --- 200
Installing modules using /home/melezhik/projects/sparrowdo-test/task-runner/.sparrowdo-cache/plugins/public/png-compress/cpanfile
Successfully installed ExtUtils-PkgConfig-1.16
Successfully installed GD-2.67
2 distributions installed
Complete! Modules were installed into /home/melezhik/projects/sparrowdo-test/task-runner/.sparrowdo-cache/plugins/public/png-compress/local
unknown project taskbox at /home/melezhik/perl5/perlbrew/perls/perl-5.23.6/lib/site_perl/5.23.6/Sparrow/Commands/ line 94.
running task box from /home/melezhik/projects/sparrowdo-test/task-runner/.sparrowdo-cache/sparrow-cache/task-box.json ... 
2017-11-30 12:08:23 : [task] create directory tmp/ [path] modules/create/
2017-11-30 12:08:23 : [task] minify js/in2.js [plg] js-minify [path] /
2017-11-30 12:08:23 : [task] minify js/in1.js [plg] js-minify [path] /
2017-11-30 12:08:23 : [task] minify js/in3.js [plg] js-minify [path] /
2017-11-30 12:08:24 : [task] compress images/image1.png [plg] png-compress [path] /
2017-11-30 12:08:24 : [task] compress images/image3.png [plg] png-compress [path] /
2017-11-30 12:08:24 : [task] compress images/image2.png [plg] png-compress [path] /
Enter fullscreen mode Exit fullscreen mode

The end

Of course Sparrowdo/Sparrow faces quite a stiff competitiveness from such a major tools like Grunt or Gunt. Though I see here a green field to play, especially for those ones who prefer languages other than Java Script to create automation scenarios.

PS the source code of an example project could be found here -

Top comments (4)

einenlum profile image
Yann Rabiller • Edited

Thanks ! That's interesting. I'm not sure most people use Grunt or Gulp anymore though. It seems the usual path is more Webpack + npm scripts now :).

melezhik profile image
Alexey Melezhik • Edited

Hi! Hm ... at the webpack's doc it says - "At its core, webpack is a static module bundler for modern JavaScript applications", anyway the same thing, one my use Perl6 to express build scenarios, not being limited by Java Script only.

spigell profile image


melezhik profile image
Alexey Melezhik

Thank you!