Release script prompts for NPM 2FA code (#12908)
* Release script prompts for NPM 2fa code
Brian Vaughn committed
May 29, 2018 at 12:50 UTC
001f9ef4717a0928b4875cbad3421a17f49f95a5
6 files changed
+48
-3
scripts/release/build.js
-1
@@ -31,7 +31,6 @@ const run = async () => {
31
try {
32
const params = parseBuildParameters();
33
params.packages = getPublicPackages();
34
-
34
await checkEnvironmentVariables(params);
35
await validateVersion(params);
36
await checkUncommittedChanges(params);
scripts/release/package.json
+1
@@ -13,6 +13,7 @@
13
"figlet": "^1.2.0",
14
"fs-extra": "^4.0.2",
15
"log-update": "^2.1.0",
16
+ "prompt-promise": "^1.0.3",
17
"request-promise-json": "^1.0.4",
18
"semver": "^5.4.1"
19
}
scripts/release/publish-commands/get-npm-two-factor-auth.js
new
+15
@@ -0,0 +1,15 @@
1
+#!/usr/bin/env node
2
+
3
+'use strict';
4
+
5
+const chalk = require('chalk');
6
+const logUpdate = require('log-update');
7
+const prompt = require('prompt-promise');
8
+
9
+module.exports = async params => {
10
+ logUpdate(chalk`{green ✓} Npm two-factor auth code {gray (or blank)}: `);
11
+ const otp = await prompt('');
12
+ prompt.done();
13
+ logUpdate.clear();
14
+ return otp.trim() || null;
15
+};
scripts/release/publish-commands/publish-to-npm.js
+9
-2
@@ -8,7 +8,7 @@ const {join} = require('path');
8
const semver = require('semver');
9
const {execRead, execUnlessDry, logPromise} = require('../utils');
10
11
-const push = async ({cwd, dry, packages, version, tag}) => {
11
+const push = async ({cwd, dry, otp, packages, version, tag}) => {
12
const errors = [];
13
const isPrerelease = semver.prerelease(version);
14
if (tag === undefined) {
@@ -19,10 +19,17 @@ const push = async ({cwd, dry, packages, version, tag}) => {
19
throw new Error('The tag `latest` can only be used for stable versions.');
20
}
21
22
+ // Pass two factor auth code if provided:
23
+ // https://docs.npmjs.com/getting-started/using-two-factor-authentication
24
+ const twoFactorAuth = otp != null ? `--otp ${otp}` : '';
25
+
26
const publishProject = async project => {
27
try {
28
const path = join(cwd, 'build', 'node_modules', project);
25
- await execUnlessDry(`npm publish --tag ${tag}`, {cwd: path, dry});
29
+ await execUnlessDry(`npm publish --tag ${tag} ${twoFactorAuth}`, {
30
+ cwd: path,
31
+ dry,
32
+ });
33
34
const packagePath = join(
35
cwd,
scripts/release/publish.js
+2
@@ -8,6 +8,7 @@ const {getPublicPackages} = require('./utils');
8
9
const checkBuildStatus = require('./publish-commands/check-build-status');
10
const commitChangelog = require('./publish-commands/commit-changelog');
11
+const getNpmTwoFactorAuth = require('./publish-commands/get-npm-two-factor-auth');
12
const parsePublishParams = require('./publish-commands/parse-publish-params');
13
const printPostPublishSummary = require('./publish-commands/print-post-publish-summary');
14
const pushGitRemote = require('./publish-commands/push-git-remote');
@@ -22,6 +23,7 @@ const run = async () => {
23
await checkBuildStatus(params);
24
await commitChangelog(params);
25
await pushGitRemote(params);
26
+ params.otp = await getNpmTwoFactorAuth(params);
27
await publishToNpm(params);
28
await printPostPublishSummary(params);
29
} catch (error) {
scripts/release/yarn.lock
+21
@@ -335,6 +335,10 @@ jsprim@^1.2.2:
335
json-schema "0.2.3"
336
verror "1.10.0"
337
338
+keypress@~0.2.1:
339
+ version "0.2.1"
340
+ resolved "https://registry.yarnpkg.com/keypress/-/keypress-0.2.1.tgz#1e80454250018dbad4c3fe94497d6e67b6269c77"
341
+
342
lodash.padend@^4.6.1:
343
version "4.6.1"
344
resolved "https://registry.yarnpkg.com/lodash.padend/-/lodash.padend-4.6.1.tgz#53ccba047d06e158d311f45da625f4e49e6f166e"
@@ -368,6 +372,16 @@ mimic-fn@^1.0.0:
372
version "1.1.0"
373
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.1.0.tgz#e667783d92e89dbd342818b5230b9d62a672ad18"
374
375
+native-or-another@~2.0.0:
376
+ version "2.0.0"
377
+ resolved "https://registry.yarnpkg.com/native-or-another/-/native-or-another-2.0.0.tgz#17a567f92beea9cd71acff96a7681a735eca3bff"
378
+ dependencies:
379
+ native-or-bluebird "^1.1.2"
380
+
381
+native-or-bluebird@^1.1.2:
382
+ version "1.2.0"
383
+ resolved "https://registry.yarnpkg.com/native-or-bluebird/-/native-or-bluebird-1.2.0.tgz#39c47bfd7825d1fb9ffad32210ae25daadf101c9"
384
+
385
node-version@^1.0.0:
386
version "1.1.0"
387
resolved "https://registry.yarnpkg.com/node-version/-/node-version-1.1.0.tgz#f437d7ba407e65e2c4eaef8887b1718ba523d4f0"
@@ -390,6 +404,13 @@ promise-polyfill@^6.0.1:
404
version "6.0.2"
405
resolved "https://registry.yarnpkg.com/promise-polyfill/-/promise-polyfill-6.0.2.tgz#d9c86d3dc4dc2df9016e88946defd69b49b41162"
406
407
+prompt-promise@^1.0.3:
408
+ version "1.0.3"
409
+ resolved "https://registry.yarnpkg.com/prompt-promise/-/prompt-promise-1.0.3.tgz#78ce4fcb9a14a108c49174f2d808c440d1bde265"
410
+ dependencies:
411
+ keypress "~0.2.1"
412
+ native-or-another "~2.0.0"
413
+
414
pseudomap@^1.0.2:
415
version "1.0.2"
416
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"