Skip to content

Creating a volofile

jrburke edited this page Jun 7, 2012 · 2 revisions

A volofile is a small batch file that can list a few commands in them. The commands can have dependencies on each other. It is like a makefile, but works more natively on windows and is written in JavaScript.

A volofile is implemented as a node module and it exports an API that volo understands. Let's walk through a simple example.

Prerequisites

Make sure to have node and volo installed.

Project setup

We will create a volofile that will jshint a javascript file and then uglify it. In addition, it will run jshint before running the uglify command.

mkdir example
cd example
mkdir node_modules
npm install jshint uglify-js
touch a.js
touch volofile

Edit a.js to have these contents:

var a = {
    name: 'a'
};

and edit the volofile to have these contents:

module.exports = {
    clean: {
        summary: 'removes a.min.js',
        run: 'v.rm a.min.js'
    },
    lint: {
        summary: 'runs jshint on a.js',
        run: 'n.jshint a.js'
    },
    uglify: {
        summary: 'minifies a.js to a.min.js',
        depends: ['clean', 'lint'],
        run: 'n.uglifyjs -o a.min.js a.js'
    }
};

The full command API that is used to implement the clean, lint and uglify commands is detailed the Creating a volo command page, but this volofile is using a shortened string syntax for the run portions of the command.

Notice the v. and n. used in some of the strings. These are special modifiers for the command.

v. means "convert the string to a call on a v helper object". For the clean command above, it translates to v.rm('a.min.js'). The v helper object is described at the end of the Creating a volo command page. But it allows you to do some basic file operations in a cross-platform way.

n. means "look in the local node_modules/.bin/ folder for an executable by that name, if there is not one there, then use any globally installed node executable script". Since this example locally installed jshint and uglify-js, it will find those commands in the node_module/.bin/ directory.

If there is no v. or n. then the string command is passed directly to the shell. Be careful with those calls, they may not work across platforms, where the v and n prefixed ones likely will.

You can also pass an array of strings for run. The uglify command could have been written as:

module.exports = {
    uglify: {
        run: [
            'v.rm a.min.js',
            'n.jshint a.js',
            'n.uglifyjs -o a.min.js a.js'
        ]
    }
};

If you need to do more advanced control flow, look at the full command API in Creating a volo command.

Clone this wiki locally