gulp-file-include
Advanced tools
Comparing version 0.4.2 to 0.5.0
25
index.js
@@ -23,2 +23,8 @@ 'use strict'; | ||
function stripCommentedIncludes(content) { | ||
// remove single line html comments that use the format: <!-- @@include() --> | ||
var regex = new RegExp('<\!--(.*)' + prefix + 'include([\\s\\S]*?)-->', 'g'); | ||
return content.replace(regex, ''); | ||
} | ||
function fileInclude(file) { | ||
@@ -32,2 +38,3 @@ var self = this; | ||
var text = String(data); | ||
text = stripCommentedIncludes(text); | ||
@@ -42,3 +49,3 @@ try { | ||
try { | ||
self.emit('data', include(file, String(file.contents), includeRegExp, prefix, basepath, filters)); | ||
self.emit('data', include(file, stripCommentedIncludes(String(file.contents)), includeRegExp, prefix, basepath, filters)); | ||
} catch (e) { | ||
@@ -54,2 +61,3 @@ self.emit('error', new gutil.PluginError('gulp-file-include', e.message)); | ||
function include(file, text, includeRegExp, prefix, basepath, filters) { | ||
var matches = includeRegExp.exec(text); | ||
@@ -67,9 +75,18 @@ | ||
} | ||
basepath = path.resolve(process.cwd(), basepath); | ||
// for checking if we are not including the current file again | ||
var currentFilename = path.resolve(file.base, file.path); | ||
while (matches) { | ||
var match = matches[0], | ||
includePath = matches[1], | ||
includeContent = fs.readFileSync(path.resolve(basepath, includePath)); | ||
var match = matches[0]; | ||
var includePath = path.resolve(basepath, matches[1]); | ||
if (currentFilename.toLowerCase() === includePath.toLowerCase()) { | ||
throw new Error('recursion detected in file: ' + currentFilename); | ||
} | ||
var includeContent = fs.readFileSync(includePath); | ||
// strip utf-8 BOM https://github.com/joyent/node/issues/1918 | ||
@@ -76,0 +93,0 @@ includeContent = includeContent.toString('utf-8').replace(/\uFEFF/, ''); |
{ | ||
"name": "gulp-file-include", | ||
"version": "0.4.2", | ||
"version": "0.5.0", | ||
"description": "a gulp plugin for file include", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "make test" | ||
"test": "./node_modules/.bin/_mocha --harmony -R spec -t 20 test/*.js", | ||
"test-cov": "node --harmony node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- -R dot -t 20 test/*.js", | ||
"test-travis": "node --harmony node_modules/.bin/istanbul cover node_modules/.bin/_mocha --report lcovonly -- -R dot -t 20 test/*.js" | ||
}, | ||
@@ -29,3 +31,4 @@ "repository": { | ||
"gulp": "*", | ||
"markdown": "^0.5.0", | ||
"istanbul": "*", | ||
"markdown": "*", | ||
"mocha": "*", | ||
@@ -39,2 +42,6 @@ "should": "*" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"Readme.md" | ||
], | ||
"directories": { | ||
@@ -41,0 +48,0 @@ "example": "example", |
@@ -1,5 +0,6 @@ | ||
[![NPM](https://nodei.co/npm/gulp-file-include.png?downloads=true)](https://nodei.co/npm/gulp-file-include) | ||
[![NPM version][npm-img]][npm-url] | ||
[![build status][travis-img]][travis-url] | ||
[![Build status][travis-img]][travis-url] | ||
[![Test coverage][coveralls-img]][coveralls-url] | ||
[![License][license-img]][license-url] | ||
[![Dependency status][david-img]][david-url] | ||
@@ -142,5 +143,11 @@ ### gulp-file-include | ||
[npm-img]: https://img.shields.io/npm/v/gulp-file-include.svg?style=flat | ||
[npm-url]: https://www.npmjs.org/package/gulp-file-include | ||
[travis-img]: https://img.shields.io/travis/coderhaoxin/gulp-file-include.svg?style=flat | ||
[npm-img]: https://img.shields.io/npm/v/gulp-file-include.svg?style=flat-square | ||
[npm-url]: https://npmjs.org/package/gulp-file-include | ||
[travis-img]: https://img.shields.io/travis/coderhaoxin/gulp-file-include.svg?style=flat-square | ||
[travis-url]: https://travis-ci.org/coderhaoxin/gulp-file-include | ||
[coveralls-img]: https://img.shields.io/coveralls/coderhaoxin/gulp-file-include.svg?style=flat-square | ||
[coveralls-url]: https://coveralls.io/r/coderhaoxin/gulp-file-include?branch=master | ||
[license-img]: http://img.shields.io/badge/license-MIT-green.svg?style=flat-square | ||
[license-url]: http://opensource.org/licenses/MIT | ||
[david-img]: https://img.shields.io/david/coderhaoxin/gulp-file-include.svg?style=flat-square | ||
[david-url]: https://david-dm.org/coderhaoxin/gulp-file-include |
8302
109
153
5
3