npm adduser via bash

前端 未结 9 1411
清歌不尽
清歌不尽 2021-02-01 18:48

I want to automate the npm login process via a bash script.

I tried it with this snippet:

/usr/bin/expect -f - <

        
9条回答
  •  太阳男子
    2021-02-01 19:03

    @Aurélien Thieriot: thanks for the hint.

    I have two solutions for my problem:

    Solution 1

    export NPM_AUTH_TOKEN=myToken
    export NPM_EMAIL=myEmail
    

    create/override ~/.npmrc by following shell script:

    echo "_auth = $NPM_AUTH_TOKEN" > ~/.npmrc
    echo "email = $NPM_EMAIL" >> ~/.npmrc
    

    Solution 2

    export NPM_USERNAME=myUsername
    export NPM_PASSWORD=myPassword
    export NPM_EMAIL=myEmail
    

    I know the order of the questions. So I can do the following:

    npm adduser <

    Note: solution 2 works only when the user isn't added yet
    Otherwise the $NPM_PASSWORD is not necessary

提交回复
热议问题