tasks/sass_bootstrapper.js
function orderByDependency(partialsArray) {
        var _doPass     = true,
            _reqCache   = {};
        // repeat sorting operation until
        // there is no replacing procedure during
        // one pass (bubble sorting).
        while (_doPass) {
            _doPass = false;

            // Iterate through every partial in the list and check its
            // dependency (requirements)
            partialsArray.forEach(function (partialName, partialIndex) {
                // Get require list for current partial
                var _requireList = mainPartialList[partialName].requires;

                // for each requirement in require object do...
                for (var rKey in _requireList) {

                    // Check if current key is _requireList property
                    if (!_requireList.hasOwnProperty(rKey)) {
                        // if not go to next iteration
                        continue;
                    }

                        // Current partial filename without root folder
                    var _fileName = mainPartialList[partialName].removedRoot,
                        // Index of current partial in partialsArray, -1 if not found.
                        _requireIndex = findIndexInArray(partialsArray, function (partialName) {
                            return (partialName.match(_requireList[rKey].requires) !== null);
                        }),
                        _requireObject = _requireList[rKey];

                    // Check require cache for dependency loop
                    if (_reqCache[_requireObject.requires + _fileName]) {
                        // dependency loop detected, throw an error and break program
                        grunt.fail.fatal(
                            'Dependency loop detected!!! \nFiles that have dependency loop: \n' +
                            mainPartialList[partialsArray[_requireIndex]].fileName + '\n' +
                            _requireObject.fileName
                        );
                    }

                    // If requirement is found and its position is incorrect
                    if (_requireIndex > -1 && _requireIndex > partialIndex) {
                        // Remove partial from current index and insert
                        // it before partial that requires it.
                        partialsArray = replaceInArray(partialsArray, _requireIndex, partialIndex);
                        // Replacing procedure occured so do one more pass.
                        _doPass = true;
                        // add requirement to require cache for dependency loop handling
                        _reqCache[_fileName + _requireObject.requires] = true;

                    } else if (_requireIndex === -1) {
                        // invalid requirement, throw a warning
                        grunt.log.warn(
                            'File: ' + mainPartialList[partialName].fileName +
                            ' is depending on non existing partial "' +
                            _requireObject.requires + '"'
                        );
                    }

                } // end for
            }); // end for each

        } // end while
        // Return reordered file list
        return partialsArray;
    }
function orderByDependency(partialsArray) {
        var _doPass     = true,
            _reqCache   = {};
        // repeat sorting operation until
        // there is no replacing procedure during
        // one pass (bubble sorting).
        while (_doPass) {
            _doPass = false;

            // Iterate through every partial in the list and check its
            // dependency (requirements)
            partialsArray.forEach(function (partialName, partialIndex) {
                // Get require list for current partial
                var _requireList = mainPartialList[partialName].requires;

                // for each requirement in require object do...
                for (var rKey in _requireList) {

                    // Check if current key is _requireList property
                    if (!_requireList.hasOwnProperty(rKey)) {
                        // if not go to next iteration
                        continue;
                    }

                        // Current partial filename without root folder
                    var _fileName = mainPartialList[partialName].removedRoot,
                        // Index of current partial in partialsArray, -1 if not found.
                        _requireIndex = findIndexInArray(partialsArray, function (partialName) {
                            return (partialName.match(_requireList[rKey].requires) !== null);
                        }),
                        _requireObject = _requireList[rKey];

                    // Check require cache for dependency loop
                    if (_reqCache[_requireObject.requires + _fileName]) {
                        // dependency loop detected, throw an error and break program
                        grunt.fail.fatal(
                            'Dependency loop detected!!! \nFiles that have dependency loop: \n' +
                            mainPartialList[partialsArray[_requireIndex]].fileName + '\n' +
                            _requireObject.fileName
                        );
                    }

                    // If requirement is found and its position is incorrect
                    if (_requireIndex > -1 && _requireIndex > partialIndex) {
                        // Remove partial from current index and insert
                        // it before partial that requires it.
                        partialsArray = replaceInArray(partialsArray, _requireIndex, partialIndex);
                        // Replacing procedure occured so do one more pass.
                        _doPass = true;
                        // add requirement to require cache for dependency loop handling
                        _reqCache[_fileName + _requireObject.requires] = true;

                    } else if (_requireIndex === -1) {
                        // invalid requirement, throw a warning
                        grunt.log.warn(
                            'File: ' + mainPartialList[partialName].fileName +
                            ' is depending on non existing partial "' +
                            _requireObject.requires + '"'
                        );
                    }

                } // end for
            }); // end for each

        } // end while
        // Return reordered file list
        return partialsArray;
    }
function orderByDependency ( partialsArray ) { var _doPass = true , _reqCache = { } ; // repeat sorting operation until // there is no replacing procedure during // one pass (bubble sorting). while ( _doPass ) { _doPass = false ; // Iterate through every partial in the list and check its // dependency (requirements) partialsArray . forEach ( function ( partialName , partialIndex ) { // Get require list for current partial var _requireList = mainPartialList [ partialName ] . requires ; // for each requirement in require object do... for ( var rKey in _requireList ) { // Check if current key is _requireList property if ( ! _requireList . hasOwnProperty ( rKey ) ) { // if not go to next iteration continue ; } // Current partial filename without root folder var _fileName = mainPartialList [ partialName ] . removedRoot , // Index of current partial in partialsArray, -1 if not found. _requireIndex = findIndexInArray ( partialsArray , function ( partialName ) { return ( partialName . match ( _requireList [ rKey ] . requires ) !== null ) ; } ) , _requireObject = _requireList [ rKey ] ; // Check require cache for dependency loop if ( _reqCache [ _requireObject . requires + _fileName ] ) { // dependency loop detected, throw an error and break program grunt . fail . fatal ( 'Dependency loop detected!!! \nFiles that have dependency loop: \n' + mainPartialList [ partialsArray [ _requireIndex ] ] . fileName + '\n' + _requireObject . fileName ) ; } // If requirement is found and its position is incorrect if ( _requireIndex > - 1 && _requireIndex > partialIndex ) { // Remove partial from current index and insert // it before partial that requires it. partialsArray = replaceInArray ( partialsArray , _requireIndex , partialIndex ) ; // Replacing procedure occured so do one more pass. _doPass = true ; // add requirement to require cache for dependency loop handling _reqCache [ _fileName + _requireObject . requires ] = true ; } else if ( _requireIndex === - 1 ) { // invalid requirement, throw a warning grunt . log . warn ( 'File: ' + mainPartialList [ partialName ] . fileName + ' is depending on non existing partial "' + _requireObject . requires + '"' ) ; } } // end for } ) ; // end for each } // end while // Return reordered file list return partialsArray ; }
Reorders partials in a given list by their dependencies.
Dependencies are taken from mainPartialList which has to be
generated first.

@param partialsArray {array} array of sass/scss partials
@returns {array} reordered array of partials
Reorders partials in a given list by their dependencies . Dependencies are taken from mainPartialList which has to be generated first .