Last active
December 27, 2017 07:52
-
-
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)
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
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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