Skip to content

Instantly share code, notes, and snippets.

@arvsr1988
Last active December 27, 2017 07:52
Show Gist options
  • Save arvsr1988/6979d5ff3fb526fc0455d9bba3d74453 to your computer and use it in GitHub Desktop.
Save arvsr1988/6979d5ff3fb526fc0455d9bba3d74453 to your computer and use it in GitHub Desktop.
Copy node modules from your dependencies recursively to your artifact directory using this code. This will work with npmjs version 3 and node js version 6(supporting ES 6)
let shell = require('shelljs');
const path = require('path');
const rootDir = path.resolve('./');
const alreadyCopied = (module, deployDir) => {
return shell.test('-d', deployDir + '/node_modules/' + module);
}
function copyDeps(packageFile, deployDir){
let moduleDeps = require(packageFile).dependencies;
if(!moduleDeps){
return;
}
for(let dep in moduleDeps){
if(alreadyCopied(dep, deployDir)){
continue;
}
const moduleDirectory = `${rootDir}/node_modules/${dep}`;
const deployDirectory = `${deployDir}/node_modules/`;
shell.mkdir('-p', deployDirectory);
shell.cp('-rf', moduleDirectory, deployDirectory);
console.log("copied and processing deps for ", dep);
copyDeps(`${moduleDirectory}/package.json`, deployDir);
}
}
class NodeModuleCopier {
static copy(deployDir){
shell.mkdir('-p', deployDir + '/node_modules');
copyDeps(`${rootDir}/package.json`, 'dist/');
}
}
module.exports = NodeModuleCopier;
@gvsphani
Copy link

can we get a depolyable artifact, so that we can put it in the artifactory and have a release number to it and deploy the builds into the server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment