Created
January 27, 2016 07:30
-
-
Save miguelfrias/20ad2d33fa890ab62bc2 to your computer and use it in GitHub Desktop.
installJSDependencies
This file contains hidden or 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
(function installJSDependencies() { | |
'use strict'; | |
console.log('------------------'); | |
console.log('Post install: install dependencies'); | |
console.log('------------------'); | |
var nodeModulesFolder = '/node_modules/'; | |
var pluginsForlder = '/dumbometeranalyzer/app/webroot/plugins/lib/'; | |
var fse = require('fs-extra'); | |
var packageJSON = require('../package.json'); | |
var dependencies = packageJSON.dependencies; | |
var arrOfDependenciesName = []; | |
// Get the dependencies name -- DONE | |
for (var i in dependencies) { | |
if (dependencies.hasOwnProperty(i)) { | |
arrOfDependenciesName.push(i); | |
} | |
} | |
var rootDirectory = __dirname.slice(0, __dirname.lastIndexOf('/')); | |
// Copy files from to dumbometeranalyzer/app/webroot/plugins/lib/ | |
arrOfDependenciesName.forEach(function(dependency, index) { | |
var srcFolder = '' + rootDirectory; | |
var destFolder = '' + rootDirectory; | |
var isTheLastItem = false; | |
srcFolder += nodeModulesFolder + dependency; | |
destFolder += pluginsForlder + dependency; | |
if (arrOfDependenciesName.length - 1 === index) { | |
isTheLastItem = true; | |
} | |
copy(srcFolder, destFolder, isTheLastItem); | |
}); | |
function copy(src, dest, isEnd) { | |
fse.copy(src, dest, function(err) { | |
if (err) { | |
return console.error(err); | |
} | |
if (isEnd) { | |
triggerEndMessage(); | |
} | |
}); | |
} | |
function triggerEndMessage() { | |
console.log('------------------'); | |
console.log('Post install: end'); | |
console.log('------------------'); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment