PogoScript Plugin for Grunt

PogoScript

PogoScript is a programming language that emphasises readability, is friendly to domain specific languages and compiles to regular Javascript.

It’s written and maintained by featurist, so report issues with the actual compilation directly here.

A… transpiler… you?

Those who know me will know I’m not a massive fan of transpilers (I recently turned down some work due to them forcing the use of a Java to JavaScript compiler) but I’d rather use PogoScript over something like CoffeeScript, if there was no choice.

Automation

I use Grunt for automating JavaScript tasks (if you don’t know what Grunt is, where have you been?). The Grunt ecosystem is huge and it’s growing every day. With literally hundreds of plugins to choose from, you can use Grunt to automate just about anything with a minimum of effort.

Although PogoScript already has a CLI pogo -c file.pogo, there wasn’t a Grunt plugin. Knowing how easy Grunt plugins are to write, I wrote one for fun.

Using grunt-pogo

The grunt-pogo plugin requires Grunt ~0.4.x

Install as a dev dependency

1
npm install grunt-pogo --save-dev

Load “grunt-pogo” in your Gruntfile.js

1
grunt.loadNpmTasks("grunt-pogo");

The pogo task

You can run the pogo task with the grunt pogo command, or combine it with other tasks in the usual way. See configuring tasks for more info.

Example configuration

1
2
3
4
5
6
7
pogo: {
compile: {
files: {
"file.js": ["file.pogo", "file2.pogo"]
}
}
}

The input files are an array, so you can combine the output of the PogoScript compilation into a single output JavaScript file.

The code

functional.js

Oh yes, the plugin harnesses the power of currying and point free programming via the awesome functional.js library. λ.each, λ.select, λ.map all with a lovely dollop of curry, spice and all things nice.

1
2
3
4
5
6
7
8
9
10
11
12
13
var processFiles = λ.each(function (files) {
var compiled = compile(exists(files.src)),
combined = compiled.join(grunt.util.normalizelf(grunt.util.linefeed));
grunt.file.write(files.dest, combined);
});
var exists = λ.select(function (file) {
return grunt.file.exists(file);
});
var compile = λ.map(function (src) {
return compilePogo(grunt.file.read(src));
});

Testing

It’s tested and hooked into Travis CI.

Source code

The full source code is available on github. You can log issues and pull request there too.

Future enhancements

I’d like to expose more options for compilation via the Gruntfile.js, however uglification etc could always be performed as a separate Grunt task. Let me know what you think.

Compilation automation for the nation