Comparing version 2.1.4 to 2.2.0
# Changelog | ||
## Version 2.2.0 | ||
* Feature: Add option to pass in complete file path to conditional processor's regexp instead of just the file name | ||
* Refactor: Add info/error log helpers | ||
## Version 2.1.4 | ||
@@ -4,0 +9,0 @@ |
@@ -141,5 +141,5 @@ # Lingon usage | ||
Lingon uses Gulp.js streams to process files. Lingon already includes a few commonly used processors, but it's simple to add more. A processor is added to a file extension. For instance, I you could add a CoffeeScript processor to the '.coffee' extension by doing: | ||
Lingon uses Gulp.js streams to process files. Lingon already includes a few commonly used processors, but it's simple to add more. A processor is added to a file extension. For instance, I you could add a CoffeeScript processor to the '.coffee' extension by doing: | ||
```JavaScript | ||
```JavaScript | ||
#!/usr/bin/env node | ||
@@ -156,3 +156,3 @@ | ||
return coffee(); | ||
}; | ||
}); | ||
@@ -211,3 +211,3 @@ ``` | ||
An extensions rewrite is what happens when your input file "source/index.ejs" is built to "build/index.html". Lingon include sane defaults to handle the most common files (ejs, less, coffee, etc). However, you can also add your own extension rewrites using the following api: | ||
An extensions rewrite is what happens when your input file "source/index.ejs" is built to "build/index.html". Lingon include sane defaults to handle the most common files (ejs, less, coffee, etc). However, you can also add your own extension rewrites using the following api: | ||
@@ -221,3 +221,3 @@ **Rewrite all *.fika files to *.js** | ||
You can also rewrite multiple extensions at the same time: | ||
You can also rewrite multiple extensions at the same time: | ||
@@ -231,3 +231,3 @@ **Rewrite all *.json.ejs files to *.json** | ||
If you rewrite to an empty string the extension will simply disappear: | ||
If you rewrite to an empty string the extension will simply disappear: | ||
@@ -241,3 +241,3 @@ **Remove .min from all filenames** | ||
## 05 Render EJS templates | ||
## 06 Render EJS templates | ||
@@ -289,4 +289,4 @@ Lingon comes with out of the box support for EJS templates using the [gulp-ejs](https://github.com/rogeriopvl/gulp-ejs) module. | ||
lingon.preProcessors.unshift('ejs', function(params) { | ||
// This functions takes an object of named params: | ||
// params.global The file-specific context object | ||
// This functions takes an object of named params: | ||
// params.global The file-specific context object | ||
// params.context The global data object | ||
@@ -335,3 +335,3 @@ | ||
## 06 Configure Lingon | ||
## 07 Configure Lingon | ||
@@ -353,3 +353,3 @@ The Lingon configuration can be directly accessed and mofied from inside the lingon.js file via the `lingon.config` object. The following properties are available: | ||
## 07 Advanced Lingon usage | ||
## 08 Advanced Lingon usage | ||
@@ -369,3 +369,3 @@ #### Allowing the usage of directives (includes) in additional file types | ||
Sometimes a processor is wanted only under certain conditions so the `push` and `unshift` functions accept an optional regular expression before the factory function. Only file names that meet this regular expression will register the processor. | ||
Sometimes a processor is wanted only under certain conditions so the `set`, `push`, `unshift` and `remove` functions accept an optional regular expression before the factory function. Only files that meet this regular expression will register the processor. By default only the file name itself will be returned but it can be configured to use the whole path form the root folder of the project. | ||
@@ -379,2 +379,6 @@ Additionally some processors are only needed in certain tasks, in that case we can make use of the `lingon.task` variable that contains the name of the current running task to return the array of stream modifiers. | ||
// match the regexp against the full path from the project's root | ||
lingon.preProcessors.setMatchFullPath(true); | ||
lingon.postProcessors.setMatchFullPath(true); | ||
// only process files that do not contain ".min" in their name | ||
@@ -381,0 +385,0 @@ lingon.postProcessors.push('js', /^((?!\.min).)*$/, function() { |
@@ -21,3 +21,3 @@ 'use strict'; | ||
var pkg = require('../package.json'); | ||
log('Lingon version:', pkg.version); | ||
log.info('Lingon version:', pkg.version); | ||
process.exit(); | ||
@@ -53,3 +53,3 @@ } | ||
log('Working directory:', chalk.magenta(rootPath)); | ||
log.info('Working directory:', chalk.magenta(rootPath)); | ||
lingon.run(tasks); | ||
@@ -56,0 +56,0 @@ }); |
@@ -16,3 +16,3 @@ var log = require('./utils/log'); | ||
var transforms = Array.prototype.slice.call(arguments, 1); | ||
for(var i=0;i<transforms.length;i++) { | ||
@@ -53,3 +53,3 @@ sourceFile = transforms[i].call(this, sourceFile); | ||
var pipes = streamHelper.pipesForFileExtensions( | ||
sourceFile.name, | ||
sourceFile.path, | ||
params['processorStore'], | ||
@@ -72,9 +72,9 @@ params['global'] | ||
// Only apply the rewrite to registered processors | ||
// (to allow the default extensions to be passed through if desired, | ||
// Only apply the rewrite to registered processors | ||
// (to allow the default extensions to be passed through if desired, | ||
// for instance to output a index.coffee file.) | ||
var registeredExtensionMap = utils.getRegisteredExtensions( | ||
sourceFilename, | ||
extensionMap, | ||
sourceFilename, | ||
extensionMap, | ||
processorStores | ||
@@ -84,3 +84,3 @@ ); | ||
var targetFilename = ExtensionRewriter.transform({ | ||
filename: sourceFilename, | ||
filename: sourceFilename, | ||
extensionMap: registeredExtensionMap | ||
@@ -106,3 +106,3 @@ }); | ||
Builder.print = function(sourceFile) { | ||
log(chalk.green(sourceFile.path, "->", path.join(sourceFile.targetPath, sourceFile.targetFilename))); | ||
log.info(chalk.green(sourceFile.path, "->", path.join(sourceFile.targetPath, sourceFile.targetFilename))); | ||
return sourceFile; | ||
@@ -133,2 +133,2 @@ }; | ||
module.exports = Builder; | ||
module.exports = Builder; |
'use strict'; | ||
var path = require('path'); | ||
// The actual processor store | ||
var ProcessorStore = function(processors) { | ||
this.processors = processors || {}; | ||
this.matchFullPath = false; // @TODO: refactor this option away with the next major release | ||
@@ -19,2 +24,6 @@ return this; | ||
if(!this.matchFullPath) { | ||
file = path.basename(file); | ||
} | ||
var filteredProcessors = this.processors[extension] || []; | ||
@@ -146,2 +155,8 @@ filteredProcessors = filteredProcessors.filter(function(item) { | ||
// @TODO: refactor this function away with the next major release | ||
ProcessorStoreManager.prototype.setMatchFullPath = function(value) { | ||
this.store.matchFullPath = !!value; | ||
return this; | ||
}; | ||
module.exports = ProcessorStoreManager; |
@@ -143,4 +143,4 @@ var path = require('path'); | ||
if(error.code == 'EADDRINUSE') { | ||
console.error('[ ' + chalk.red('Lingon') + ' ] ' + chalk.yellow('[Error] Port ' + port + ' is already in use, lingon server could not start!')); | ||
log('[Info] Try with a different one: ' + chalk.blue( 'lingon server -p <PORT>')); | ||
log.error('Port ' + port + ' is already in use, lingon server could not start!'); | ||
log.info('[Info] Try with a different one: ' + chalk.blue( 'lingon server -p <PORT>')); | ||
} | ||
@@ -150,3 +150,3 @@ }); | ||
app.listen(port, ip, function() { | ||
log('http server listening on: http://' + ip + ':' + port); | ||
log.info('http server listening on: http://' + ip + ':' + port); | ||
lingon.trigger('serverStarted'); | ||
@@ -153,0 +153,0 @@ }); |
@@ -73,3 +73,3 @@ var vfs = require('vinyl-fs'); | ||
if(cyclicDependencyDetected(node, sourceFile.path)) { | ||
log('[Warning] File is trying to include itself (ignored): "' + path.relative(env.rootPath, sourceFile.path +'"')); | ||
log.info('[Warning] File is trying to include itself (ignored): "' + path.relative(env.rootPath, sourceFile.path +'"')); | ||
@@ -131,3 +131,3 @@ if(sourceFile.path.indexOf(".js" > -1)) { | ||
// Pipe preProcessor streams | ||
// Pipe preProcessor streams | ||
// (applied to every included file before concatenation) | ||
@@ -134,0 +134,0 @@ fileStream = preProcess(fileStream); |
@@ -11,5 +11,5 @@ var path = require('path'); | ||
var filePath = file.path; | ||
var params = { | ||
global: global, | ||
global: global, | ||
context: context | ||
@@ -20,3 +20,3 @@ } | ||
var pipes = streamHelper.pipesForFileExtensions(path.basename(file.path), pipeMap, params); | ||
var pipes = streamHelper.pipesForFileExtensions(file.path, pipeMap, params); | ||
@@ -23,0 +23,0 @@ if(pipes.length === 0) { |
@@ -8,3 +8,3 @@ var rimraf = require('rimraf'); | ||
if (!error) { | ||
lingon.log('[Info] The ' + lingon.config.buildPath + ' folder has been cleaned'); | ||
lingon.log.info('[Info] The ' + lingon.config.buildPath + ' folder has been cleaned'); | ||
} else { | ||
@@ -11,0 +11,0 @@ console.error('[ ' + chalk.red('Lingon') + ' ] ' + chalk.yellow('[Error] The ' + lingon.config.buildPath + ' folder could not be cleaned')); |
@@ -48,3 +48,3 @@ var path = require('path'); | ||
// Instantiate a lexer | ||
// Pass in a default function that will add all | ||
// Pass in a default function that will add all | ||
// unmatched chars to the segments array. | ||
@@ -83,3 +83,3 @@ var lexer = new Lexer(function (char) { | ||
return segments.join(''); | ||
}; | ||
@@ -122,3 +122,3 @@ | ||
} | ||
}); | ||
@@ -147,2 +147,2 @@ | ||
module.exports = ExtensionRewriter; | ||
module.exports = ExtensionRewriter; |
@@ -26,3 +26,3 @@ var log = require('../utils/log'); | ||
show: function(cmd, task) { | ||
log('Usage:'); | ||
log.info('Usage:'); | ||
console.log(''); | ||
@@ -29,0 +29,0 @@ |
var chalk = require('chalk'); | ||
module.exports = function() { | ||
function Logger() { | ||
} | ||
Logger.prototype.info = function() { | ||
console.log.apply(null, ['[ ' + chalk.red('Lingon') + ' ]'].concat( | ||
@@ -8,1 +12,9 @@ Array.prototype.slice.call(arguments, 0) | ||
}; | ||
Logger.prototype.error = function() { | ||
console.error.apply(null, ['[ ' + chalk.red('Lingon') + ' ]'].concat( | ||
chalk.yellow('[Error] ' + Array.prototype.slice.call(arguments, 0)) | ||
)); | ||
}; | ||
module.exports = new Logger(); |
@@ -0,1 +1,2 @@ | ||
var path = require('path'); | ||
var chalk = require('chalk'); | ||
@@ -6,4 +7,5 @@ var from = require('from'); | ||
module.exports = { | ||
pipesForFileExtensions: function(filename, processorStore, global, context) { | ||
pipesForFileExtensions: function(file, processorStore, global, context) { | ||
var pipes = []; | ||
var filename = path.basename(file); | ||
@@ -15,3 +17,3 @@ var extensions = filename.split('.'); | ||
extensions.forEach(function(ext) { | ||
var pipeFactories = processorStore.get(ext, filename); | ||
var pipeFactories = processorStore.get(ext, file); | ||
@@ -18,0 +20,0 @@ if(pipeFactories) { |
{ | ||
"name": "lingon", | ||
"description": "A minimal static site generator inspired by Middleman and Sprockets, compatible with gulp plugins.", | ||
"version": "2.1.4", | ||
"version": "2.2.0", | ||
"homepage": "https://github.com/spotify/lingon", | ||
@@ -6,0 +6,0 @@ "author": { |
191646
1830