grunt-depsconcat
Advanced tools
Comparing version 0.1.1 to 0.1.2
{ | ||
"name": "grunt-depsconcat", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Concatenate files in order based on dependencies", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -14,2 +14,3 @@ module.exports = function(grunt) { | ||
requireTemplate: null, | ||
nameTemplate: null, | ||
ext: null | ||
@@ -19,3 +20,3 @@ }); | ||
this.files.forEach(function(f) { | ||
var ext, files, tree, regex, serialized; | ||
var ext, files, tree, requireRegex, nameRegex, serialized; | ||
var filePath, i; | ||
@@ -26,18 +27,22 @@ | ||
tree = {}; | ||
nameRegex = null; | ||
if (!options.requireTemplate) { | ||
if (ext === '.css') | ||
regex = '@import\\s+url\\(["\']?([^"\'()]+)["\']?\\);?[\\n\\r]*'; | ||
requireRegex = '@import\\s+url\\(["\']?([^"\'()]+)["\']?\\);?[\\n\\r]*'; | ||
else { | ||
ext = '.js'; | ||
regex = '\\/\\/@require\\s+([^\\n\\r]+)[\\n\\r]*'; | ||
requireRegex = '\\/\\/@require\\s+([^\\n\\r]+)[\\n\\r]*'; | ||
} | ||
} else | ||
regex = options.requireTemplate; | ||
requireRegex = options.requireTemplate; | ||
regex = new RegExp(regex, 'gi'); | ||
requireRegex = new RegExp(requireRegex, 'gi'); | ||
if (options.nameTemplate) | ||
nameRegex = new RegExp(options.nameTemplate, 'gi'); | ||
f.src.filter(function(filePath) { | ||
if (!grunt.file.exists(filePath)) { | ||
grunt.log.warn('Source file ' + filepath + ' not found.'); | ||
grunt.log.warn('Source file ' + filePath + ' not found.'); | ||
return false; | ||
@@ -48,3 +53,13 @@ } | ||
}).map(function(filePath) { | ||
files[path.basename(filePath, ext)] = filePath; | ||
var matches; | ||
if (nameRegex) { | ||
nameRegex.lastIndex = 0; | ||
matches = grunt.file.read(filePath).match(nameRegex) || []; | ||
if (matches.length) | ||
files[nameRegex.exec(matches[0])[1]] = filePath; | ||
} else | ||
files[path.basename(filePath, ext)] = filePath; | ||
tree[filePath] = []; | ||
@@ -56,7 +71,7 @@ }); | ||
matches = grunt.file.read(filePath).match(regex) || []; | ||
matches = grunt.file.read(filePath).match(requireRegex) || []; | ||
for (i = 0; i < matches.length; i++) { | ||
regex.lastIndex = 0; | ||
name = regex.exec(matches[i])[1]; | ||
requireRegex.lastIndex = 0; | ||
name = requireRegex.exec(matches[i])[1]; | ||
@@ -63,0 +78,0 @@ if (files[name]) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3017
69