Created
June 8, 2018 11:32
-
-
Save dev-rowbot/38b7ad3b0e0b951598e9df144160e17f to your computer and use it in GitHub Desktop.
Import packages from an exported verdaccio "storage" folder to a running Verdaccio instance
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
#!/usr/bin/python | |
from os import listdir, chdir, getcwd | |
from os.path import isfile, join | |
import re | |
from subprocess import call | |
import json | |
with open('.sinopia-db.json') as f: | |
data = json.load(f) | |
# Our current "home" directory | |
home = getcwd() | |
for directory in data["list"]: | |
# For each directory get a list of files | |
files = [f for f in listdir("./"+directory) if isfile(join("./"+directory, f))] | |
# print files | |
print "---------- " + directory | |
# change to the directory before we push any packages | |
chdir("./"+directory) | |
# for each file | |
for fileName in files: | |
if not fileName.endswith('.tgz'): | |
continue | |
match = re.search('(.*)-(\d+\.\d+\..*)\.tgz', fileName) | |
print "Publishing [" + fileName +"] as " + match.group(1)+"@"+match.group(2) | |
call(["npm", "publish", fileName, "--tag", match.group(1)+"@"+match.group(2)]) | |
# change back to home | |
chdir(home) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
Probably a unique scenario but we are migrating all our data to new servers and need to move our running Private NPM repository to the new location.
We are running an older version of Verdaccio (2.x) in docker and the new instance is based on 3.1.0.
Just copying the
storage
folder to the new location does not work for me since the Verdaccio UI is not showing the new packages. I also encountered some folder permissions issues - the old instance seems to run asroot
while the new instance runs asverdaccio
.It seemed easier/simpler to read the
.sinopia-db.json
file and see what packages our team had published and then republish them to the new Verdaccio instance.This may help with these tickets:
verdaccio/verdaccio#209
verdaccio/verdaccio#69
verdaccio/verdaccio#451
Usage
If you are using docker and have mounted the storage volume somewhere on the host, simply run this script from the root of that folder:
If you don't have a .sinopia-db.json file, modify the code to remove the part that reads the file and looks up the list. Simply loop through all tgz files in a folder and push them