Comparing version 0.4.8 to 0.5.0
@@ -19,2 +19,8 @@ 'use strict'; | ||
/** | ||
* Modules to install and modules we did install | ||
*/ | ||
var installModules = []; | ||
var installedModules = []; | ||
/** | ||
* Get package name based on given module name | ||
@@ -34,2 +40,60 @@ */ | ||
/** | ||
* Get the destination path | ||
*/ | ||
function getDestinationPath(projectDir, manifest) { | ||
var destinationPath = projectDir; | ||
if (manifest && manifest.destination) { | ||
destinationPath = path.join(destinationPath, manifest.destination); | ||
} | ||
return destinationPath; | ||
} | ||
/** | ||
* Check if a module has already been installed | ||
*/ | ||
function hasInstalled(module) { | ||
return installedModules.indexOf(module) === -1; | ||
} | ||
/** | ||
* Install dependencies | ||
*/ | ||
function installDependencies(manifest, meanie, cb) { | ||
//No manifest or dependencies? | ||
if (!manifest || !manifest.dependencies || typeof manifest.dependencies !== 'object') { | ||
return cb(null); | ||
} | ||
//Get number of dependencies | ||
var toInstall = []; | ||
//Go over the dependencies | ||
for (var dependency in manifest.dependencies) { | ||
if (manifest.dependencies.hasOwnProperty(dependency)) { | ||
var requiredVersion = manifest.dependencies[dependency]; | ||
//Check if we need to install it | ||
if (!meanie.config.hasModule(dependency, requiredVersion)) { | ||
console.log( | ||
'Module requires', chalk.magenta(dependency), | ||
'version', chalk.magenta(requiredVersion) | ||
); | ||
toInstall.push(dependency); | ||
} | ||
} | ||
} | ||
//Install the dependencies now | ||
if (toInstall.length) { | ||
install.call(meanie, toInstall, function(error) { | ||
if (error) { | ||
return cb(new Error('Failed to install dependencies')); | ||
} | ||
cb(null); | ||
}); | ||
} | ||
} | ||
/** | ||
* Install a meanie module | ||
@@ -44,4 +108,13 @@ */ | ||
//Log and load NPM | ||
//Log | ||
console.log(chalk.magenta('Meanie'), 'is installing module', chalk.magenta(installModule)); | ||
if (self.config.hasModule(installModule)) { | ||
if (!self.force) { | ||
console.log('Already installed, please run `meanie update` if you wish to update.'); | ||
return cb(null); | ||
} | ||
console.log('Already installed, but force installing anyway.'); | ||
} | ||
//Load NPM | ||
npm.load(function(error, npm) { | ||
@@ -98,9 +171,6 @@ if (error) { | ||
//Are there sources to move over? | ||
var sourcePath = getSourcePath(installPath); | ||
//Install dependencies | ||
installDependencies(manifest, self, function(error) { | ||
//Copy contents from install path to project dir | ||
copyFiles(sourcePath, self.projectDir, function(error) { | ||
//Failed to copy | ||
//Failed to install dependencies | ||
if (error) { | ||
@@ -110,25 +180,39 @@ return cb(error); | ||
//Add to config | ||
self.config.addModule(installModule, installVersion, function(error) { | ||
//Determine source and destination paths | ||
var sourcePath = getSourcePath(installPath); | ||
var destinationPath = getDestinationPath(self.projectDir, manifest); | ||
//Copy contents from install path to project dir | ||
copyFiles(sourcePath, destinationPath, function(error) { | ||
//Failed to copy | ||
if (error) { | ||
console.warn(chalk.yellow('Could not update meaniefile')); | ||
return cb(error); | ||
} | ||
}); | ||
//Module was installed successfully | ||
console.log(chalk.green( | ||
'Module', chalk.magenta(installModule), 'version', | ||
chalk.magenta(installVersion), 'installed successfully' | ||
)); | ||
if (manifest) { | ||
if (manifest.instructions) { | ||
console.log(chalk.grey( | ||
'Usage instructions: ', chalk.cyan(manifest.instructions) | ||
)); | ||
//Add to config | ||
self.config.addModule(installModule, installVersion, function(error) { | ||
if (error) { | ||
console.warn(chalk.yellow('Could not update meaniefile')); | ||
} | ||
}); | ||
//Module was installed successfully | ||
console.log(chalk.green( | ||
'Module', chalk.magenta(installModule), 'version', | ||
chalk.magenta(installVersion), 'installed successfully' | ||
)); | ||
if (manifest) { | ||
if (manifest.instructions) { | ||
console.log(chalk.grey( | ||
'Usage instructions: ', chalk.cyan(manifest.instructions) | ||
)); | ||
} | ||
if (manifest.postInstall) { | ||
console.log(chalk.grey(manifest.postInstall)); | ||
} | ||
} | ||
if (manifest.postInstall) { | ||
console.log(chalk.grey(manifest.postInstall)); | ||
} | ||
} | ||
cb(null, [installModule, installVersion, installPath]); | ||
installedModules.push(installModule); | ||
cb(null, [installModule, installVersion, installPath]); | ||
}); | ||
}); | ||
@@ -155,3 +239,3 @@ }); | ||
//Get modules to install | ||
var installModules = args; | ||
installModules = args; | ||
if (!Array.isArray(installModules)) { | ||
@@ -158,0 +242,0 @@ installModules = [installModules]; |
@@ -9,2 +9,3 @@ 'use strict'; | ||
var jf = require('jsonfile'); | ||
var semver = require('semver'); | ||
var replace = require('replace-in-file'); | ||
@@ -267,2 +268,19 @@ | ||
/** | ||
* Check if config has a module | ||
*/ | ||
hasModule: function(module, version) { | ||
var config = this.read(); | ||
if (typeof config.modules !== 'object' || config.modules === null) { | ||
return false; | ||
} | ||
if (!config.modules[module]) { | ||
return false; | ||
} | ||
if (!version || semver.satisfies(config.modules[module], version)) { | ||
return true; | ||
} | ||
return false; | ||
}, | ||
/** | ||
* Add module to config file | ||
@@ -269,0 +287,0 @@ */ |
{ | ||
"name": "meanie", | ||
"description": "Meanie is a boilerplate for developing, testing and building full-stack modular javascript applications using MEAN (MongoDB, Express, AngularJS and Node.js). Meanie is powered by the Gulp task runner.", | ||
"version": "0.4.8", | ||
"version": "0.5.0", | ||
"homepage": "https://github.com/meanie/#readme", | ||
@@ -6,0 +6,0 @@ "author": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38032
956