Last active
June 17, 2018 14:41
-
-
Save dantheman213/7a505004d26c480e8274 to your computer and use it in GitHub Desktop.
Allows NodeJS projects with long path dependancies to run inside Windows vagrant VMs
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
| #!/bin/bash | |
| # | |
| # Summary: | |
| # Exeucute Node.JS projects with 'long path' npm dependancies | |
| # while using Vagrant on Windows | |
| # | |
| # Description: | |
| # Vagrant with a Windows host and a Linux guest has issues with | |
| # very long paths between shared folders. The goal of this script | |
| # is to solve the problem by copying, syncing, and updating dependancies | |
| # in a target build path that is not accessible by the host machine thus | |
| # ensuring that all packages and sub-packages from npm get installed | |
| # correctly within the VM environment. | |
| # | |
| # Author: Daniel E. Gillespie (2016) | |
| ############### Change the variables ONLY in this section! ############ | |
| # | |
| PROJECT_PATH="/vagrant/my-shared-project-path-with-host-machine" # Project Source Location | |
| # | |
| EXECUTION_PATH="/tmp/nodejs-project" # Project Build Location | |
| # NOTE for EXECUTION_PATH: The parent directory (/tmp in this case) | |
| # needs to exist. This path should not be shared with the host machine. | |
| # | |
| ####################################################################### | |
| packageUpdated=false | |
| package_json="package.json" | |
| source_package="$PROJECT_PATH/$package_json" | |
| dest_package="$EXECUTION_PATH/$package_json" | |
| echo "" | |
| if [ ! -d $EXECUTION_PATH ]; then | |
| # project doesn't exist | |
| rm -rf $PROJECT_PATH/node_modules 2> /dev/null # fail quietly if not found | |
| echo "Copying base project to execution location..." | |
| cp -Ra $PROJECT_PATH $EXECUTION_PATH | |
| echo "Project copy complete." | |
| cd $EXECUTION_PATH | |
| npm install | |
| else | |
| cd $EXECUTION_PATH | |
| if ! cmp -s "$source_package" "$dest_package"; then | |
| # package.json is different than before | |
| packageUpdated=true | |
| fi | |
| echo -e "Updating target location with latest code changes...\n\nFile(s) changed:\n" | |
| cp -rauTv $PROJECT_PATH $EXECUTION_PATH | |
| echo -e "\nProject sync complete." | |
| fi | |
| if $packageUpdated; then | |
| echo "The package.json has been updated. Updating packages..." | |
| npm install | |
| echo -e "\n\n" | |
| fi | |
| echo -e "\nStarting project..." | |
| npm start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment