-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
96 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,30 @@ | ||
/*jshint node:true*/ | ||
var isPackageMissing = require('../../lib/utilities/is-package-missing'); | ||
|
||
module.exports = { | ||
description: 'Generates a server directory for mocks and proxies.', | ||
|
||
normalizeEntityName: function() {}, | ||
|
||
afterInstall: function() { | ||
return this.addPackagesToProject([ | ||
{ name: 'morgan', target: '^1.3.2' }, | ||
{ name: 'glob', target: '^4.0.5' } | ||
]); | ||
afterInstall: function(options) { | ||
|
||
var isMorganMissing = isPackageMissing(this, 'morgan'); | ||
var isGlobMissing = isPackageMissing(this, 'glob'); | ||
|
||
var areDependenciesMissing = isMorganMissing || isGlobMissing; | ||
var libsToInstall = []; | ||
|
||
if (isMorganMissing) { | ||
libsToInstall.push({ name: 'morgan', target: '^1.3.2' }); | ||
} | ||
|
||
if (isGlobMissing) { | ||
libsToInstall.push({ name: 'glob', target: '^4.0.5' }); | ||
} | ||
|
||
if (!options.dryRun && areDependenciesMissing) { | ||
return this.addPackagesToProject(libsToInstall); | ||
} | ||
|
||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
/* | ||
* | ||
* Given the context and library that's supposed to be looked up in the package.json, | ||
* this method detects if its already available. | ||
* | ||
* @method isPackageMissing | ||
* @param context The context of the method its called from (ie., this) | ||
* @param packageName The package that's supposed to be looked up | ||
* @return Boolean | ||
* | ||
*/ | ||
module.exports = function (context, packageName) { | ||
var pkgContent = context.project.pkg; | ||
var isAvailableInDevDependency = pkgContent.devDependencies && pkgContent.devDependencies[packageName]; | ||
var isAvailableInDependency = pkgContent.dependencies && pkgContent.dependencies[packageName]; | ||
return !(isAvailableInDevDependency || isAvailableInDependency); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
|
||
var expect = require('chai').expect; | ||
var isPackageMissing = require('../../../lib/utilities/is-package-missing'); | ||
|
||
|
||
var getContext = function(setDevDependency, setDependency) { | ||
var context = { | ||
project: { | ||
pkg: {} | ||
} | ||
}; | ||
|
||
if (setDevDependency) { | ||
context.project.pkg['devDependencies'] = { | ||
'sivakumar': 'kailasam' | ||
}; | ||
} | ||
|
||
if (setDependency) { | ||
context.project.pkg['dependencies'] = { | ||
'sivakumar': 'kailasam' | ||
}; | ||
} | ||
return context; | ||
}; | ||
|
||
|
||
describe('Is package missing in package.json', function() { | ||
|
||
it('Package is declared in dependencies', function() { | ||
expect(isPackageMissing(getContext(false, true), 'sivakumar')).to.be.false; | ||
}); | ||
|
||
it('Package is declared in dev dependencies', function() { | ||
expect(isPackageMissing(getContext(true, false), 'sivakumar')).to.be.false; | ||
}); | ||
|
||
it('Package is declared in both dependencies and dev dependencies', function() { | ||
expect(isPackageMissing(getContext(true, true), 'sivakumar')).to.be.false; | ||
}); | ||
|
||
it('Package is missing', function() { | ||
expect(isPackageMissing(getContext(false, false), 'sivakumar')).to.be.true; | ||
}); | ||
|
||
}); |