Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overwrite of exisiting .npmrc #42

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/LPM.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,21 @@ def importLibraries():

# Login silently by manually creating a the .npmrc file in the user directory.
def login(token):
f = open(os.path.join(os.path.expanduser('~'), '.npmrc'), 'w')
text = []
text.append('@loupeteam:registry=https://npm.pkg.github.com')
text.append('//npm.pkg.github.com/:_authToken=' + token)
f.write('\n'.join(text))
npm_cfg_file = os.path.join(os.path.expanduser('~'), '.npmrc')
f = open(npm_cfg_file, 'r')
content = f.readlines()
f.close()
try:
idx = content.index('@loupeteam:registry=https://npm.pkg.github.com')
# no expection; already present lets update the token
content[idx+1] = '//npm.pkg.github.com/:_authToken=' + token
except ValueError as _exp:
# Ok not present lets add it
content.append('@loupeteam:registry=https://npm.pkg.github.com')
content.append('//npm.pkg.github.com/:_authToken=' + token)

f = open(npm_cfg_file, 'w')
f.write('\n'.join(content))
f.close()

# Logout of the Github registry.
Expand Down Expand Up @@ -1267,4 +1277,4 @@ def executeAndReturnStdOut(cmd):
kernel32 = ctypes.windll.kernel32
kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), 7)

main()
main()