klei/gulp-angular-filesort

Wrong sorting in files - latest version

oviava opened this issue · 3 comments

Directory structure:
screen shot 2015-03-19 at 3 34 30 pm

Main app code:

(function () {

    'use strict';

    var module = angular.module('janus', ['janus.common', 'janus.security','janus.admin']);

}());

Gulp:

 var injectScripts = gulp.src([
         //paths.src + '/app/app.js',
         paths.src + '/app/**/*.js',
         '!' + paths.src + '/app/**/*.spec.js',
         '!' + paths.src + '/app/**/*.mock.js'
     ]).pipe($.naturalSort())
         .pipe($.angularFilesort());

My main app is added after janus.security & janus.common .. I've read the previous issues in here but can't seem to get this fixed.

Do you get any module loading error from Angular? What did you expect the sort order to be?
Your main app module is dependent on janus.common, etc, so it's logical that it's added after those modules.

i think he has the same problem than me.

security depends on common, but common gets imported first.

I have a hard time trying to recreate your issue.

I've created a simple app with the following structure:

├── app.js   # declares app, depends on mod1, mod2, mod3
├── index.html
├── mod1
│   ├── mod1-ctrl.js  # depends on mod1
│   └── mod1.js   # declares mod1, depends on mod2
├── mod2
│   ├── mod2-ctrl.js   # depends on mod2
│   ├── mod2-service.js  # depends on mod2
│   └── mod2.js  # declares mod2, depends on nothing
└── mod3
    ├── mod3-ctrl.js  # depends on mod3
    └── mod3.js  # declares mod3, depends on mod2

When running gulp-angular-filesort i get the following sortorder which is put in index.html:

  <script src="mod3/mod3.js"></script>
  <script src="mod3/mod3-ctrl.js"></script>
  <script src="mod2/mod2.js"></script>
  <script src="mod2/mod2-ctrl.js"></script>
  <script src="mod2/mod2-service.js"></script>
  <script src="mod1/mod1.js"></script>
  <script src="mod1/mod1-ctrl.js"></script>
  <script src="app.js"></script>

When opening index.html I get no errors and the app works as expected. It does not matter that mod3 is sorted before mod2, angular does not care about that, the important part is that each module is sorted before their respective controllers, services, etc.

You can download the sample files here yourself: https://drive.google.com/file/d/0Bw3qo-O7AmgId3gySmhNUHlJV2s/view?usp=sharing

Is there anything I'm missing?