@@ -25,11 +25,7 @@ IonicTask.prototype.run = function(ionic, argv) {
2525 var generator = argv . _ [ 1 ] ;
2626 var name = argv . _ [ 2 ] //TODO support multiple names
2727
28- try {
29- ionicModule = require ( path . join ( process . cwd ( ) , 'node_modules' , 'ionic-framework' ) ) ;
30- } catch ( err ) {
31- Utils . fail ( err ) ;
32- }
28+ var ionicModule = loadToolingModule ( ) ;
3329
3430 if ( argv . list ) {
3531 ionicModule . Generate . printAvailableGenerators ( ) ;
@@ -54,4 +50,39 @@ IonicTask.prototype.run = function(ionic, argv) {
5450 }
5551}
5652
53+ function loadToolingModule ( ) {
54+ //First try node_modules/ionic-angular/tooling
55+ var toolingPath , ionicModule ;
56+ try {
57+ toolingPath = path . join ( process . cwd ( ) , 'node_modules' , 'ionic-angular' , 'tooling' ) ;
58+ ionicModule = require ( toolingPath ) ;
59+ } catch ( err ) {
60+ // if this isn't found, that's fine, check for ionic-framework
61+ if ( err . code !== 'MODULE_NOT_FOUND' ) {
62+ Utils . fail ( 'Error when requiring ' + toolingPath + ':\n ' + err ) ;
63+ }
64+ }
65+
66+ //Then try node_modules/ionic-framework/tooling
67+ if ( ! ionicModule ) {
68+ try {
69+ ionicModule = require ( path . join ( process . cwd ( ) , 'node_modules' , 'ionic-framework' , 'tooling' ) ) ;
70+ } catch ( err ) {
71+ if ( err . code === 'MODULE_NOT_FOUND' ) {
72+ Utils . fail ( 'No ionic-angular or ionic-framework package found, do you have Ionic installed?' ) ;
73+ }
74+ }
75+ }
76+
77+ //Last, try node_modules/ionic-framework (beta.1 and below)
78+ if ( ! ionicModule ) {
79+ try {
80+ ionicModule = require ( path . join ( process . cwd ( ) , 'node_modules' , 'ionic-framework' ) ) ;
81+ } catch ( err ) {
82+ Utils . fail ( err ) ;
83+ }
84+ }
85+ return ionicModule ;
86+ }
87+
5788exports . IonicTask = IonicTask ;
0 commit comments