Node.js 如何以非交互方式登录到Thread?
使用Node.js 如何以非交互方式登录到Thread?,node.js,npm,terminal,continuous-integration,yarnpkg,Node.js,Npm,Terminal,Continuous Integration,Yarnpkg,使用npm时,我可以非交互方式登录: $ printf "jesstelford\n<password>\nexample@email.com\n" | npm login 在交互模式下,我可以成功运行: $ yarn login yarn login v0.21.3 question npm username: jesstelford question npm email: example@email.com ✨ Done in 22.53s. 如何以非交互方式运行Threa
npm
时,我可以非交互方式登录:
$ printf "jesstelford\n<password>\nexample@email.com\n" | npm login
在交互模式下,我可以成功运行:
$ yarn login
yarn login v0.21.3
question npm username: jesstelford
question npm email: example@email.com
✨ Done in 22.53s.
如何以非交互方式运行
Thread登录?Thread
在输入用户名后会暂停。在非交互模式下,您还需要暂停:
$ { echo "jesstelford"; sleep 1; echo "example@email.com"; } | yarn login
这将为您提供以下输出:
yarn login v0.21.3
question npm username: jesstelford
question npm email: example@email.com
✨ Done in 0.84s.
工作原理
echo“jesselford”
输入字符串,后跟换行符
sleep 1
将在输入用户名后插入1秒暂停,然后继续输入电子邮件:
echo”example@email.com“
输入第二个字符串,后跟一个换行符以结束命令。我知道如何在Dockerfile中使用nexus凭据。
如果nexus可以做到这一点,我相信它将适用于其他任何有问题的用例
以下是片段:
# Install necessary package to login automatically
RUN npm install -g npm-cli-adduser
# Whenever auth changes, this has to be incremented,
# so following calls are not cached by Docker (or always build with --no-cache).
ARG FORCE_NO_CACHE_FLAG=2
# Authenticate to Nexus via npm package that does the job
RUN npm-cli-adduser -u ${NPM_USER} -p ${NPM_PASS} -e ${NPM_EMAIL} -r ${NPM_REGISTRY} -s ${NPM_SCOPE} -a
# Now, the fun / missing part I struggled with
# To fix yarn being silly aby not using token from npm-cli-adduser
# You need to set it explicitly.
# I found this by comparing my local `yarn config list` with a docker one.
# On local yarn was able to talk to nexus, not on docker. This piece one missing somehow.
RUN npm config set ${NPM_SCOPE}:registry ${NPM_REGISTRY}
# Now this will work, yarn will auth properly with your register.
RUN yarn install
这整件事让我受够了。如果有像我(或未来的我)这样的人有这个问题,我希望这篇文章能有所帮助
# Install necessary package to login automatically
RUN npm install -g npm-cli-adduser
# Whenever auth changes, this has to be incremented,
# so following calls are not cached by Docker (or always build with --no-cache).
ARG FORCE_NO_CACHE_FLAG=2
# Authenticate to Nexus via npm package that does the job
RUN npm-cli-adduser -u ${NPM_USER} -p ${NPM_PASS} -e ${NPM_EMAIL} -r ${NPM_REGISTRY} -s ${NPM_SCOPE} -a
# Now, the fun / missing part I struggled with
# To fix yarn being silly aby not using token from npm-cli-adduser
# You need to set it explicitly.
# I found this by comparing my local `yarn config list` with a docker one.
# On local yarn was able to talk to nexus, not on docker. This piece one missing somehow.
RUN npm config set ${NPM_SCOPE}:registry ${NPM_REGISTRY}
# Now this will work, yarn will auth properly with your register.
RUN yarn install