grunt-include-source
Advanced tools
Comparing version
@@ -7,2 +7,7 @@ # Changelog | ||
### 2015-05-24 ver. 0.6.0 | ||
* Switch to `grunt.file.expandMapping` to support `rename` and `flatten` options (see https://github.com/jwvdiermen/grunt-include-source/pull/37) | ||
* Support comma separated files pattern as an alternative of specifying an array. | ||
### 2015-02-21 ver. 0.5.1 | ||
@@ -9,0 +14,0 @@ |
@@ -43,2 +43,3 @@ /* | ||
jsPath: 'js', | ||
jsExcludePath: 'js-exclude', | ||
jsArray: [ | ||
@@ -57,3 +58,15 @@ 'js/_first.js', | ||
basePath: '<%= vars.testFilesPath %>', | ||
baseUrl: '' | ||
baseUrl: '', | ||
rename: function(dest, srcPath) { | ||
if(srcPath.indexOf('src/main/webapp') > -1) { | ||
var index = 0; | ||
for(var i = 0; i < 4; i++) { | ||
index = srcPath.indexOf('/', index ? index : 0); | ||
index++; | ||
} | ||
var newPath = srcPath.substr(index); | ||
return newPath; | ||
} else | ||
return srcPath; | ||
} | ||
}, | ||
@@ -60,0 +73,0 @@ htmlTest: { |
{ | ||
"name": "grunt-include-source", | ||
"description": "Include your sources into your HTML files automatically.", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"homepage": "https://github.com/jwvdiermen/grunt-include-source", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -119,2 +119,23 @@ # grunt-include-source | ||
#### options.rename | ||
Type: `function` | ||
A way of returning a custom filepath. | ||
See [grunt.file.expandMapping](http://gruntjs.com/api/grunt.file#grunt.file.expandmapping). | ||
If specified, this function will be responsible for returning the final dest filepath. By default, it joins dest and matchedSrcPath like so: | ||
```js | ||
rename: function(dest, matchedSrcPath, options) { | ||
return path.join(dest, matchedSrcPath); | ||
} | ||
``` | ||
#### options.flatten | ||
Type: `Boolean` | ||
Default value: `false` | ||
Remove the path component from all matched src files. The src file path is still joined to the specified dest. | ||
[grunt.file.expandMapping.flatten](http://gruntjs.com/api/grunt.file#grunt.file.expandmapping). | ||
### Include syntax | ||
@@ -160,3 +181,3 @@ Currently supported: `html`, `haml`, `jade`, `scss`, `less` and `ts` (TypeScript). | ||
#### include.files | ||
Include the given files. Files are passed through the `grunt.file.expand` method. | ||
Include the given files. Files are passed through the `grunt.file.expandMapping` method (see `include.rename` and `include.flatten` options). | ||
@@ -163,0 +184,0 @@ #### include.basePath |
@@ -105,6 +105,4 @@ /* | ||
var resolveFiles = function (basePath, includeOptions) { | ||
if (includeOptions.basePath) { | ||
basePath = includeOptions.basePath; | ||
} | ||
var resolveFiles = function (options, includeOptions) { | ||
var basePath = includeOptions.basePath || options.basePath; | ||
grunt.log.debug('Resolving files on base path "' + basePath + '"...'); | ||
@@ -139,4 +137,15 @@ grunt.log.debug('Include options: ' + util.inspect(includeOptions)); | ||
grunt.log.debug('Expanding files: ' + util.inspect(files)); | ||
// Split patterns. Apperently, grunt.file.expandMapping doesn't automatically split | ||
// comma seperated lists, even if it says so in the documentation. | ||
// Split here manually so the exclusion patterns work. | ||
if (typeof files == 'string') { | ||
files = files.split(','); | ||
} | ||
// Expand patterns. | ||
var expandedFiles, i; | ||
var expand = function(x, f) { return grunt.file.expand({cwd: x}, f) }; | ||
var expand = function(x, f) { | ||
return grunt.file.expandMapping(f, sourcePath, { cwd: x, rename: options.rename, flatten: options.flatten }); | ||
}; | ||
if (basePath instanceof Array) { | ||
@@ -154,3 +163,3 @@ expandedFiles = []; | ||
for (i = 0; i < expandedFiles.length; ++i) { | ||
var file = path.join(sourcePath, expandedFiles[i]).replace(/\\/g, '/'); | ||
var file = expandedFiles[i].dest.replace(/\\/g, '/'); | ||
grunt.log.debug('Found file "' + file + '".'); | ||
@@ -278,3 +287,3 @@ results.push(file); | ||
includes.forEach(function(include, includeIndex) { | ||
var files = resolveFiles(options.basePath, include.options); | ||
var files = resolveFiles(options, include.options); | ||
orderFiles(files, include.options); | ||
@@ -281,0 +290,0 @@ |
@@ -0,0 +0,0 @@ /// <!-- include: "type": "ts", "files": "<%= vars.tsPath %>/**/*.ts", "ordering": "top-down" --> |
/// <!-- include: "type": "ts", "files": "<%= vars.tsPath %>/**/*.ts", "ordering": "top-down" --> | ||
/// <!-- /include --> |
@@ -0,0 +0,0 @@ /// <!-- include: "type": "ts", "files": "<%= vars.tsPath %>/**/*.ts", "ordering": "top-down" --> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
68038
9.19%69
11.29%515
4.25%297
7.61%