grunt-depsconcat
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "grunt-depsconcat", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Concatenate files in order based on dependencies", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -1,9 +0,9 @@ | ||
var path, util, deptree; | ||
module.exports = function(grunt) { | ||
var path, util, deptree; | ||
path = require('path'); | ||
util = require('util'); | ||
deptree = require('serialize-deptree'); | ||
path = require('path'); | ||
util = require('util'); | ||
deptree = require('serialize-deptree'); | ||
module.exports = function(grunt) { | ||
grunt.registerMultiTask('depsconcat', 'Concatenate files, ordered by dependencies', function() { | ||
grunt.registerMultiTask('depsconcat', 'Concatenate files, ordered by dependencies.', function() { | ||
var options; | ||
@@ -14,10 +14,10 @@ | ||
requireTemplate: null, | ||
ext: null, | ||
except: [], | ||
ext: null | ||
}); | ||
this.files.forEach(function(file) { | ||
var regex, ext, files, tree; | ||
this.files.forEach(function(f) { | ||
var ext, files, tree, regex, serialized; | ||
var filePath, i; | ||
ext = options.ext || file.dest.match(/\.[a-z]+$/i)[0]; | ||
ext = options.ext || f.dest.match(/\.[a-z]+$/i)[0]; | ||
files = {}; | ||
@@ -27,17 +27,21 @@ tree = {}; | ||
if (!options.requireTemplate) { | ||
if (ext === '.css') { | ||
if (ext === '.css') | ||
regex = '@import\\s+url\\(["\']?([^"\'()]+)["\']?\\);?[\\n\\r]*'; | ||
} else { | ||
else { | ||
ext = '.js'; | ||
regex = '\\/\\/@require\\s+([^\\n\\r]+)[\\n\\r]*'; | ||
} | ||
} else { | ||
} else | ||
regex = options.requireTemplate; | ||
} | ||
regex = new RegExp(regex, 'gi'); | ||
file.src.filter(function(filePath) { | ||
filePath = path.normalize(filePath); | ||
f.src.filter(function(filePath) { | ||
if (!grunt.file.exists(filePath)) { | ||
grunt.log.warn('Source file ' + filepath + ' not found.'); | ||
return false; | ||
} | ||
return !grunt.file.isDir(filePath); | ||
}).map(function(filePath) { | ||
files[path.basename(filePath, ext)] = filePath; | ||
@@ -47,26 +51,26 @@ tree[filePath] = []; | ||
file.src.filter(function(filePath) { | ||
var matches, depfilePath; | ||
for (filePath in tree) { | ||
var matches, name; | ||
matches = grunt.file.read(filePath).match(regex) || []; | ||
for (var i = 0; i < matches.length; i++) { | ||
for (i = 0; i < matches.length; i++) { | ||
regex.lastIndex = 0; | ||
depfilePath = regex.exec(matches[i])[1]; | ||
name = regex.exec(matches[i])[1]; | ||
if (!(/\.\w+$/).test(depfilePath)) { | ||
tree[path.normalize(filePath)].push(files[depfilePath]); | ||
} | ||
if (files[name]) | ||
tree[filePath].push(files[name]); | ||
else | ||
grunt.log.warn('Dependency ' + name + ' of ' + filePath + ' not found.'); | ||
} | ||
}); | ||
} | ||
var serialized = deptree.serialize(tree).map(function(filePath) { | ||
serialized = deptree.serialize(tree).map(function(filePath) { | ||
return grunt.file.read(filePath); | ||
}); | ||
grunt.file.write(file.dest, serialized.join(grunt.util.linefeed)); | ||
grunt.log.writeln('Dest File "' + file.dest + '" created.'); | ||
grunt.file.write(f.dest, serialized.join(grunt.util.linefeed)); | ||
grunt.log.writeln('File ' + f.dest + ' created.'); | ||
}); | ||
}); | ||
}; |
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
2538
58