You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
48 lines
1.2 KiB
5 years ago
|
#!/usr/bin/env python3
|
||
|
# -*- coding: utf-8 -*-
|
||
|
|
||
|
#==================
|
||
|
# Author: Alvis Zhao
|
||
|
# Date: 2020-08-14 15:27:05
|
||
|
# LastEditTime: 2020-08-14 15:30:46
|
||
|
# Description: 批量上传npm包到内网nexus源
|
||
|
#==================
|
||
|
|
||
|
import os
|
||
|
import sys
|
||
|
|
||
|
def showUsage():
|
||
|
print("Usage:")
|
||
|
print(" npm adduser --register http://nexus3.developer.com/repository/npm-public")
|
||
|
print(" python upload-npm.py dir-to-upload")
|
||
|
|
||
|
USERNAME="uploader"
|
||
|
PASSWORD="uploader"
|
||
|
URL="http://nexus3.developer.com/repository/npm-public"
|
||
|
|
||
|
def loginNpmRepo():
|
||
|
pipeline = os.popen('npm config set registry ' + URL)
|
||
|
cmd = 'npm-cli-login -u "' + USERNAME + '" -p "' + PASSWORD + '" -e test@example.com -r ' + URL
|
||
|
pipeline = os.popen(cmd)
|
||
|
print(pipeline)
|
||
|
|
||
|
def main():
|
||
|
if len(sys.argv) < 2:
|
||
|
print("用法错误!")
|
||
|
showUsage()
|
||
|
return
|
||
|
|
||
|
uploadDir=sys.argv[1]
|
||
|
if not os.path.isdir(uploadDir):
|
||
|
print("用法错误!")
|
||
|
showUsage()
|
||
|
return
|
||
|
|
||
|
fileList=os.listdir(uploadDir)
|
||
|
for file in fileList:
|
||
|
filepath = os.getcwd() + os.sep + uploadDir + os.sep + file
|
||
|
cmd = "npm publish " + filepath
|
||
|
os.system(cmd)
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
main()
|