simplify the npm login
This commit is contained in:
parent
b17ea7097a
commit
f6ab32d029
|
|
@ -0,0 +1,23 @@
|
||||||
|
var RegistryClient = require('npm-registry-client');
|
||||||
|
|
||||||
|
var client = new RegistryClient({});
|
||||||
|
|
||||||
|
// see https://github.com/npm/npm-registry-client/blob/v8.5.0/lib/adduser.js
|
||||||
|
client.adduser(
|
||||||
|
process.env.NPM_REGISTRY,
|
||||||
|
{
|
||||||
|
auth: {
|
||||||
|
username: process.env.NPM_USER,
|
||||||
|
password: process.env.NPM_PASS,
|
||||||
|
email: process.env.NPM_EMAIL,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(error, data, raw, response) => {
|
||||||
|
if (error) {
|
||||||
|
console.error(error)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
console.log(data.token)
|
||||||
|
process.exit()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
@ -45,25 +45,23 @@ EOF
|
||||||
npm install --save left-pad
|
npm install --save left-pad
|
||||||
node hello-world.js
|
node hello-world.js
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# publish a package to the npm-hosted repository.
|
# publish a package to the npm-hosted repository.
|
||||||
# see https://www.npmjs.com/package/npm-cli-login
|
|
||||||
|
|
||||||
# login.
|
# login.
|
||||||
npm install npm-cli-login
|
|
||||||
export NPM_USER=alice.doe
|
export NPM_USER=alice.doe
|
||||||
export NPM_PASS=password
|
export NPM_PASS=password
|
||||||
export NPM_EMAIL=alice.doe@example.com
|
export NPM_EMAIL=alice.doe@example.com
|
||||||
# NB npm-cli-login always adds the trailing slash to the registry url,
|
export NPM_REGISTRY=http://localhost:8081/repository/npm-hosted/
|
||||||
# BUT npm publish refuses to work without it, so workaround this.
|
npm install npm-registry-client@8.5.0
|
||||||
export NPM_REGISTRY=http://localhost:8081/repository/npm-hosted
|
npm_auth_token=$(NODE_PATH=$PWD/node_modules node /vagrant/provision/npm-login.js 2>/dev/null)
|
||||||
./node_modules/.bin/npm-cli-login
|
npm set //localhost:8081/repository/npm-hosted/:_authToken $npm_auth_token
|
||||||
export NPM_REGISTRY=$NPM_REGISTRY/
|
|
||||||
|
# publish.
|
||||||
npm publish --registry=$NPM_REGISTRY
|
npm publish --registry=$NPM_REGISTRY
|
||||||
popd
|
popd
|
||||||
|
|
||||||
# publish.
|
# use the published package.
|
||||||
mkdir use-hello-world-npm
|
mkdir use-hello-world-npm
|
||||||
pushd use-hello-world-npm
|
pushd use-hello-world-npm
|
||||||
cat >package.json <<'EOF'
|
cat >package.json <<'EOF'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue