nitro
NodeJS code building library, focused on simplicicy
![npm](https://img.shields.io/npm/dt/nitro.svg?maxAge=2592000)
nitro
was developed to provide an easy build system for modern languages stack like,
sass, less, coffeescript, or custom stuff through syncronous but fast processing
Installation
npm install nitro --save-dev
Quick Example
var nitro = require('nitro');
nitro.dir('src').load('{,**/}*.{sass,scss}')
.process('sass', {
autoprefix: true,
minify: true,
groupmedia: true
})
.write('public/assets/css');
nitro.dir('src').load('{,**/}*.js')
.process('uglify')
.write('public/js');
nitro.watch('src')
.when('{,**/}*.{scss,sass}', function (filename) {
console.log('sass file', filename, 'has been changed');
})
.when('{,**/}*.js', function (filename) {
console.log('js file', filename, 'has been changed');
})
;
Basics
nitro.cwd()
nitro.cwd('path/to/folder', function (cwd) {
console.log('value of cwd should match process.cwd()', cwd === process.cwd() );
});
nitro.exec()
allows syncronous execution of shell commands
nitro.exec('ls -la');
Files and Directories Processing
nitro.file
var file = nitro.file;
file.exists('path/to/file.txt');
file.read('path/to/file.txt');
file.readJSON('path/to/file.json');
file.write('path/to/file.txt', 'new content');
file.writeJSON('path/to/file.json', { new: 'content' });
file.copy('path/to/file.txt', 'destination/file.txt');
file.filter(filter);
nitro.dir()
returns a dir object
var dirSrc = nitro.dir('src');
dirSrc.create('sub/folder');
dirSrc.exists();
dirSrc.copy(filter, dest);
dirSrc.remove();
dirSrc.expand(filter);
dirSrc.watch(handler);
dirSrc.load(filter);
nitro.load(filter, options)
var filesList = nitro.load(filter, options)
class Files()
instance methods, applied to loaded files
var filesList = nitro.dir('src').load('{,**/}*.js');
filesList.each(function (f) {
console.log('filename', f.filename );
console.log('path', f.path );
console.log('src', f.src );
});
filesList.load('{,**/}*.coffee');
filesList.process('uglify');
filesList.process('{,**/}*.coffee', 'coffee-script');
filesList.write('destination/folder');
filesList.writeFile('destination/folder/bundle.js');
filesList.join('bundle.js').write('destination/folder');
Working with Tasks
var nitro = require('nitro');
nitro.task('sass', function (target) {
var dev = target === 'dev';
nitro.dir('src').load('{,**/}*.{sass,scss}')
.process('sass', {
autoprefix: true,
minify: !dev,
groupmedia: true
})
.write('public/assets/css');
})
nitro.task('js', function (target) {
var js = nitro.dir('src').load('{,**/}*.js');
if( target === 'dev' ) {
js = js.process('uglify').join('app.js');
}
js.write('public/js');
});
nitro.task('build', ['sass', 'js']);
nitro.task('build-dev', ['sass:dev', 'js:dev']);
nitro.task('watch', function () {
nitro.watch('src')
.when('{,**/}*.{scss,sass}', ['sass:dev'], function (filename) {
console.log('sass file', filename, 'has been changed');
})
.when('{,**/}*.js', ['js:dev'], function (filename) {
console.log('js file', filename, 'has been changed');
});
});
nitro.task('dev', ['build-dev', 'watch'], function () {
nitro.livereload('public', { port: 35729 });
});
nitro.task('live', ['dev'], function () {
nitro.server('public', {
livereload: { port: 35729 },
openInBrowser: true
});
});
nitro.run();
main options from shell
node make dev
node make live
node make build
Tests
make test
Wercker: ![wercker status wercker status](https://app.wercker.com/status/4518d69bc996c3a4b3e20249ccacb487/s)
Travis: ![Build Status](https://travis-ci.org/nitrojs/nitro.svg?branch=master)