Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

tsort command might not available on all OS

convert source file paths to OS specifc format
  • Loading branch information...
commit 9f19678901a93ad94091678a4a1899ccb0a748cb 1 parent 70ff7a7
Stephan Ziep authored
Showing with 17 additions and 11 deletions.
  1. +1 −1  tasks/dep-concat.js
  2. +16 −10 tasks/lib/file-graph.js
View
2  tasks/dep-concat.js
@@ -21,7 +21,7 @@ module.exports = function( grunt ) {
var options = this.options();
when.map( this.files, function( f ) {
- var sources = f.src.filter(function( path ) {
+ var sources = f.src.map( fileGraph.normalizePath ).filter(function( path ) {
if ( !grunt.file.exists( path )) {
grunt.log.warn( 'Source file "' + path + '" not found.' );
return false;
View
26 tasks/lib/file-graph.js
@@ -8,6 +8,7 @@
var path = require( 'path' );
var exec = require( 'child_process' ).exec;
+var tsort = require('tsort');
exports.init = function( grunt ) {
var exports = {};
@@ -97,17 +98,22 @@ exports.init = function( grunt ) {
}
}
- var command = 'echo "' + depGraphString + '" | tsort';
- exec( command, function( error, stdout, stderr ) {
- var tsortOrderedFiles = _( stdout ).words( '\n' ).reverse();
- push.apply( orderedFiles, tsortOrderedFiles );
+ var graph = tsort();
+ var unsorted = depGraphString.split( '\n' );
+ for(var i = 0; i < unsorted.length - 1; i ++) {
+ var split = unsorted[i].split( /\s+/ );
- if ( stderr !== '' ) {
- grunt.log.error( stderr );
+ if ( split[1] !== split[0] ) {
+ graph.add( split[1], split[0] );
+ } else {
+ graph.add( split[0] );
}
+ }
- callback( orderedFiles );
- });
+ var sortedGraph = graph.sort();
+ push.apply( orderedFiles, sortedGraph );
+
+ callback( orderedFiles );
};
exports.parseFile = function( filepath, options ) {
@@ -143,7 +149,7 @@ exports.init = function( grunt ) {
}
if ( fileList ) {
- var files = _.words( split[1], ',' ).map( trimElems ).map( normalizePath );
+ var files = _.words( split[1], ',' ).map( trimElems ).map( exports.normalizePath );
push.apply( fileList, files );
}
}
@@ -163,7 +169,7 @@ exports.init = function( grunt ) {
return _( str ).trim();
};
- var normalizePath = function( p ) {
+ exports.normalizePath = function( p ) {
return p.replace( /[\/\\]+/g, path.sep );
};
Please sign in to comment.
Something went wrong with that request. Please try again.