Skip to content

Commit

Permalink
chore: add OTP support to the publish script
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Jul 20, 2018
1 parent 45ffc5a commit a5bec3a
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions tools/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require('ts-node').register();
const BASE_DIR = path.resolve(__dirname, '..');
const PACKAGES_DIR = path.resolve(BASE_DIR, 'packages');

const publisher = new Listr([
const prepare = new Listr([
{
title: 'Checking working directory',
task: async () => {
Expand All @@ -30,6 +30,9 @@ const publisher = new Listr([
title: 'Fetching README\'s',
task: require('./sync-readmes'),
},
]);

const publisher = new Listr([
{
title: 'Collecting directories to publish',
task: async (ctx) => {
Expand All @@ -51,7 +54,7 @@ const publisher = new Listr([
title: `Publishing: ${`${name}@${version}`.cyan} (beta=${isBeta ? 'true'.green : 'red'.red})`,
task: async () => {
try {
await spawnPromise('npm', ['publish', '--access=public', `${isBeta ? '--tag=beta' : ''}`], {
await spawnPromise('npm', ['publish', '--access=public', `${isBeta ? '--tag=beta' : ''}`, `--otp=${ctx.otp}`], {
cwd: dir,
});
} catch (err) {
Expand All @@ -64,7 +67,22 @@ const publisher = new Listr([
},
]);

publisher.run().catch((err) => {
console.error(err);
process.exit(1);
});
const runPublisher = async () => {
const otp = await new Promise((resolve) => {
process.stdin.once('data', (chunk) => {
process.stdin.pause();
resolve(chunk.toString());
});
process.stdout.write('Enter OTP: ');
process.stdin.read();
});
publisher.run({ otp });
}

prepare
.run()
.then(runPublisher)
.catch((err) => {
console.error(err);
process.exit(1);
});

0 comments on commit a5bec3a

Please sign in to comment.