runy v0.1.0
runy
The jviz task runner
Installation
Use npm to install runy:
npm install --save runy
Usage
//Import runy
var runy = require('runy');
//Copy all .js files from /my/path/folder to /my/path/folder2
runy().cwd('/my/path/').src('./folder/**.js').dest('./folder2');
//Remove all the contents of a folder
runy().cwd('/my/path/').clear('./unused-folder/');
API
cwd(path)
Sets the current working directory. This methods accepts a string with the path that will be used as a cwd. If this method is not used, runy will use the process.cwd()
method as a cwd.
//Sets the cwd to /path/to/my/cwd
runy().cwd('/path/to/my/cwd/');
path
A string with the path that will be used as a cwd.
src(globs)
Sets the source files using a glob or array of globs.
//Select all js files on /path/to/my/cwd and /path/to/my/cwd/folder
runy().cwd('/path/to/my/cwd/').src([ '**.js', 'folder/**.js' ]);
globs
Glob or array of globs to be used.
dest(path)
Sets the output folder or file.
//Copy all js files from /my/folder to /my/new/folder
runy().cwd('/my/').src('folder/**.js').dest('new/folder/');
path
A string with the path where runy will write the output files.
addTask(name, callback)
This method registers a new task. Read the developing a task for getting more information about how to develop a task for runy.
//Add a new task that displays on console the all the files names
runy().addTask('displayNames', function(cwd, args, opt, file)
{
//Display the file name
console.log(file.name);
//Return the file
return file;
});
//Display all the files on /my/folder
runy().src('/my/folder/**/*').display();
name
A string with the task name. The name must be in camel-case format.
callback
The function that will be executed with each file. This function will be called with the following arguments:
cwd
: a string with the current working directory.args
: an array with the arguments provided to the task.opt
: an object with the task options.file
: an object with the information about the file.
Tasks provided
Runy comes with a set of tasks ready to execute.
concat(path)
Concat all files into one new file
//Concat all js files
runy().src('/my/folder/**.js').concat('foo.js').dest('./build');
path
A string with the output file.
exec(cmd)
Execute a shell command.
//Create a folder
runy().cwd('/my/folder').exec('mkdir test');
//Create a folder and a file
runy().cwd('/my/folder').exec([ 'mkdir test', 'cd test && touch my-file.txt' ]);
cmd
A string or array with the commands that will be executed on the current working directory.
replace(findRep, options)
Replace in each file.
//Replace the blue word
runy().src('/my/folder/**.js').replace([ 'blue', 'red' ], { flags: 'g' }).dest('/my/folder2');
findRep
An array with two elements: the first element is the string that will be replaced with the second element of the array.
options
An object with the options. The following options are allowed:
flag
: flags that will be used on the replace method (example:g
,i
...).
rm(path)
Remove the contents of the provided path.
//Remove all the contents of the /my/test/folder folder
runy().cwd('/my/test/').rm('folder');
path
A string with the path to remove.
License
MIT © Josemi Juanes.