diff --git a/package.json b/package.json index 6336956211a..b83664c91bd 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "start": "webpack-dev-server --port 8030 --inline --hot --config=src-docs/webpack.config.js", "test-docker": "docker pull $npm_package_docker_image && docker run --rm -i -e GIT_COMMITTER_NAME=test -e GIT_COMMITTER_EMAIL=test --user=$(id -u):$(id -g) -e HOME=/tmp -v $(pwd):/app -w /app $npm_package_docker_image bash -c 'npm config set spin false && /opt/yarn*/bin/yarn && npm run test && npm run build'", "sync-docs": "node ./scripts/docs-sync.js", - "build-docs": "cross-env NODE_ENV=production webpack --config=src-docs/webpack.config.js", + "build-docs": "cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=4096 webpack --config=src-docs/webpack.config.js", "build": "yarn extract-i18n-strings && node ./scripts/compile-clean.js && node ./scripts/compile-eui.js && node ./scripts/compile-scss.js $npm_package_name", "compile-icons": "node ./scripts/compile-icons.js && prettier --write --loglevel=warn \"./src/components/icon/assets/**/*.js\"", "extract-i18n-strings": "node ./scripts/babel/fetch-i18n-strings", diff --git a/scripts/release.js b/scripts/release.js index caa520277fb..e384690aa56 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -50,8 +50,11 @@ const humanReadableTypes = { // push the version commit & tag to upstream execSync('git push upstream --tags', execOptions); + // prompt user for npm 2FA + const otp = await getOneTimePassword(); + // publish new version to npm - execSync('npm publish', execOptions); + execSync(`npm publish --otp=${otp}`, execOptions); // update docs, git commit, git push execSync('npm run sync-docs', execOptions); @@ -75,7 +78,7 @@ async function getVersionTypeFromChangelog() { // Sanity check, if the changelog contains "No public interface changes"then we shouldn't be releasing if (changelog.indexOf('No public interface changes') !== -1) { - console.error(`Unable to release: CHANGELOG.md indicates "No public interface changes"`); + console.error('Unable to release: CHANGELOG.md indicates "No public interface changes"'); process.exit(1); } @@ -153,3 +156,39 @@ async function promptUserForVersionType() { ); }); } + +async function getOneTimePassword() { + const version = require('../package.json').version + console.log(chalk.magenta(`Preparing to publish @elastic/eui@${version} to npm registry`)); + console.log(''); + console.log(chalk.magenta('The @elastic organization requires membership and 2FA to publish')); + console.log(chalk.magenta('What is your one-time password?')); + + return await promptUserForOneTimePassword(); +} + +async function promptUserForOneTimePassword() { + return new Promise((resolve, reject) => { + prompt.message = ''; + prompt.delimiter = ''; + prompt.start(); + prompt.get( + { + properties: { + otp: { + description: 'Enter password:', + message: 'One-time password is required', + required: true + }, + } + }, + (err, { otp }) => { + if (err) { + reject(err); + } else { + resolve(otp); + } + } + ); + }); +}