Skip to content

Commit

Permalink
feat(generate): support all 3 package locations
Browse files Browse the repository at this point in the history
During the transition to ionic-angular package name, tooling could be
located in 3 places: ionic-framework, ionic-framework/tooling or
ionic-angular/tooling.
  • Loading branch information
tlancina committed Mar 28, 2016
1 parent 96b79ec commit db3db0e
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions lib/ionic/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ IonicTask.prototype.run = function(ionic, argv) {
var generator = argv._[1];
var name = argv._[2] //TODO support multiple names

try {
ionicModule = require(path.join(process.cwd(), 'node_modules', 'ionic-framework'));
} catch (err) {
Utils.fail(err);
}
var ionicModule = loadToolingModule();

if (argv.list) {
ionicModule.Generate.printAvailableGenerators();
Expand All @@ -54,4 +50,39 @@ IonicTask.prototype.run = function(ionic, argv) {
}
}

function loadToolingModule(){
//First try node_modules/ionic-angular/tooling
var toolingPath, ionicModule;
try {
toolingPath = path.join(process.cwd(), 'node_modules', 'ionic-angular', 'tooling');
ionicModule = require(toolingPath);
} catch (err) {
// if this isn't found, that's fine, check for ionic-framework
if (err.code !== 'MODULE_NOT_FOUND') {
Utils.fail('Error when requiring ' + toolingPath + ':\n ' + err);
}
}

//Then try node_modules/ionic-framework/tooling
if (!ionicModule) {
try {
ionicModule = require(path.join(process.cwd(), 'node_modules', 'ionic-framework', 'tooling'));
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') {
Utils.fail('No ionic-angular or ionic-framework package found, do you have Ionic installed?');
}
}
}

//Last, try node_modules/ionic-framework (beta.1 and below)
if (!ionicModule) {
try {
ionicModule = require(path.join(process.cwd(), 'node_modules', 'ionic-framework'));
} catch (err) {
Utils.fail(err);
}
}
return ionicModule;
}

exports.IonicTask = IonicTask;

0 comments on commit db3db0e

Please sign in to comment.