Compare commits

..

5 Commits

Author SHA1 Message Date
c14dbeccda add gitigonre 2022-11-12 15:42:23 +02:00
869474e8e6 add download all package function 2022-11-12 15:41:15 +02:00
aba37f05ee add path to download_npm_package function 2022-11-12 13:29:52 +02:00
05fa927fd3 add download_npm_package 2022-11-12 13:28:33 +02:00
d4ce4252f6 remove duplicate urls 2022-11-12 13:21:28 +02:00
2 changed files with 20 additions and 4 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
package.json
package-lock.json

View File

@@ -1,17 +1,31 @@
from os import system
from re import findall, match, search
from os import system, mkdir
from re import findall
from sys import argv
import requests
def npm_create_package_lock_file(package):
system("npm i --package-lock-only " + package)
def get_all_urls_packages():
return findall("https://.+.tgz", open("package-lock.json", "rt").read())
with open("package-lock.json", "rt") as package_lock_file:
content = package_lock_file.read()
return list(dict.fromkeys(findall("https://.+.tgz", content)))
def download_npm_package(url:str, path="./"):
try:
with open(path + url.split("/")[-1], "wb") as npm_package_file:
npm_package_file.write(requests.get(url))
except:
raise "Path not exist!\nPlease create the path: " + path
def download_all_package():
packages_urls = get_all_urls_packages()
for package_url in packages_urls:
download_npm_package(package_url, "npm-packages/")
def main():
npm_create_package_lock_file(argv[1])