Skip to content

Instantly share code, notes, and snippets.

@mengstr
Last active May 6, 2021 11:16
Show Gist options
  • Save mengstr/950bfbd35b6e139e5f27 to your computer and use it in GitHub Desktop.
Save mengstr/950bfbd35b6e139e5f27 to your computer and use it in GitHub Desktop.
How to store npm packages in github branches
#1) Create a new repo named "my-npm" and let github initialize it with a README (screenshot below)
#2) Clone it to your computer
git clone git@github.com:SmallRoomLabs/my-npm.git
#3) Go to the clone and create a new empty branch for the first package
cd my-npm
git checkout --orphan logger
#4) Delete all files in the folder
rm -f *
#5) Create the files for the new package/branch
echo '### THE LOGGER' > README.md
echo 'console.log("This is logger");' > logger.js
echo -e '{\n"name":"logger",\n"description":"The logger",\n"version":"1.0.0",\n"main":"logger.js",\n"repository":{}\n}' > package.json
#6) Add & Commit the files to this branch
git add -A .
git commit -m "Initial commit for logger"
#7) Push the changes to github
git push --set-upstream origin logger
#8) Repeat this for another package
git checkout --orphan crypter
rm -f *
echo '### THE CRYPTER' > README.md
echo 'console.log("This is crypter");' > crypter.js
echo -e '{\n"name":"crypter",\n"description":"The crypter",\n"version":"1.0.0",\n"main":"crypter.js",\n"repository":{}\n}' > package.json
git add -A .
git commit -m "Initial commit for crypter"
git push --set-upstream origin crypter
#9) Go back to the master branch
git checkout master
#10) Create a node project using the two new packages
echo -e "require('logger');\nrequire('crypter');\n" > mycode.js
#11) Create the package.json and add the packages to it
echo -e '{"name":"mycode",\n"description":"The mycode",\n"version":"1.0.0",\n"main":"mycode.js",\n"repository":{}\n}' > package.json
npm install --save git+ssh://git@github.com:SmallRoomLabs/my-npm.git#logger
npm install --save git+ssh://git@github.com:SmallRoomLabs/my-npm.git#crypter
#12) Run the node too see if it works
node mycode.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment