Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tsort command might not be available on all OS. #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -28,7 +28,9 @@
"test": "grunt test"
},
"dependencies": {
"when": "~1.8.0"
"when": "~1.8.0",
"path": "0.4.9",
"tsort": ">= 0.0.1"
},
"devDependencies": {
"grunt-contrib-jshint": "0.1.1",
Expand Down
2 changes: 1 addition & 1 deletion tasks/dep-concat.js
Expand Up @@ -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;
Expand Down
26 changes: 16 additions & 10 deletions tasks/lib/file-graph.js
Expand Up @@ -8,6 +8,7 @@

var path = require( 'path' );
var exec = require( 'child_process' ).exec;
var tsort = require('tsort');

exports.init = function( grunt ) {
var exports = {};
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 );
}
}
Expand All @@ -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 );
};

Expand Down