gromjs v0.1.4
#GROM.js Awesome co-powered build system.
npm install -g gromjsWhy?
The goal of grom.js is to be a plugin-less build system that will allow to use any node module to process files without pain. Gives more control
Super simple
In gromfile.js:
var processor = require('files-processor')
var R = require('ramda')
module.exports.task = function* (){
var filesSet = yield this.read(['path/to/files'])
var mappedFilesSet = filesSet.map(function*(file){
var newSource = processor(yield file.source())
return file.clone(newSource, { ext: '.processed'})
})
return yield this.write('path/to/dist', mappedFilesSet)
}In terminal:
$ gromjs taskThat's it. No special grom-whatever plugins, use whatever you want.
API
yield this.read(glob)Returns ordered Set of Filesyield this.watch(glob)Returns events emitter, uses npm modulewatchandwatch.createMonitormethod
yield this.write(glob, Set)Accepts glob, Set of Files and writes everything in right place.
yield this.async(tasks)Accepts array of tasks and runs in asynchronously and independent to each other.
yield this.seq(tasks)Runs tasks one by one from left to right, every next one get result from previous.
Set
Is a set of Files uniq by glob, have next methods:
elements()ReturnsSet's elementsisContains(file)Checks iffileis inSetby file's globadd(file)Returns newSetwith all elements plus new oneremove(element)Returns newSetwithout singleelementunion(set)Returns newSetthat is union of elements from both setsintersection(set)Returns newSetthat is intersection between setsdifference(set)Returns newSetthat is difference between setsfilter(interator*)Returns newSetwith filtered elementssort(interator*)Returns newSetwith sorted elementsreduce(interator*, accumulator)Returns reduced valuemap(interator*)Returns newSetwith mapped elementsforEach(interator*)Iterates over elements and returns currentSet
File
path()Returns full pathglob()Returns globname()Returns name with extensionsource()Generator, returns file's source codeclone([glob], [source])Creates new File, glob can be presented as hash withdir,name,extfields which will be merged with parent file's path, path also can be just a string, ifgloborsourceisn't provided,clonetakes it from parent.
Examples:
run tasks in sequence:
var filesProcessor = require('files-processor')
var read = function* (){
return yield this.read('/some/path/to/**.ext')
}
var processSet = function* (set){
return set.map(function* (file){
var source = yield file.source()
return file.clone(yield extProcessor(source), { ext: 'js' })
})
}
var write = function* (set){
return yield this.write('/another/path', set)
}
module.exports.default = function* three(){
yield this.seq([read, processSet, write])
}watch files:
module.exports.default = function* three(){
var monitor = yield this.watch('*.js')
monitor.on('change', function* (Set){
yield this.async(someTask)
})
}compile less:
var less = require('less')
module.exports.compileLess = function* compileLess (){
var lessFilesSet = yield this.read('./code/**.less')
var cssFilesSet = yield lessFilesSet.map(function* (file){
var lessContents = (yield file.source()).toString()
var css = (yield less.render(lessContents, {})).css
return file.clone(css, { ext: 'css' })
})
return yield this.write('./dist', cssFilesSet)
}CLI
$ gromjs <task-name>TODO
- Tasks logger
- Tests
- More examples