UNPKG

stratumn-cli

Version:
67 lines (58 loc) 1.86 kB
import readline from 'readline'; import commander from 'commander'; import readPackageSync from '../utils/readPackageSync'; import question from '../utils/question'; import post from '../utils/post'; commander .version(readPackageSync('version')) .parse(process.argv); function handleError(err) { if (err.message.indexOf('tos') > -1) { process.stderr.write( 'You must first accept the Terms of Services in order to use the Stratumn Developer API!' + '\n', () => process.exit(1)); } else { process.stderr.write(err.message + '\n', () => process.exit(1)); } } const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); const payload = {}; function password() { const pwds = {}; return question(rl, 'Password: ', 'password1', pwds, { hidden: true }) .then(() => { return question(rl, 'Re-enter password: ', 'password2', pwds, { hidden: true }); }) .then(() => { if (pwds.password1 !== pwds.password2) { process.stderr.write('Passwords are not the same!\n'); return password(); } payload.password = pwds.password1; }); } question(rl, 'Invite Token: ', 'inviteToken', payload) .then(() => { return question(rl, 'Email: ', 'email', payload); }) .then(() => { return question(rl, 'First name: ', 'firstName', payload); }) .then(() => { return question(rl, 'Last name: ', 'lastName', payload); }) .then(() => { return question(rl, '[Company]: ', 'company', payload, { required: false }); }) .then(password) .then(() => { return question(rl, 'Do you accept the ToS at https://stratumn.com/tos.html (Y/N) ? ', 'tos', payload); }) .then(() => post('/signup', payload)) .then(() => { process.stdout.write('You may now login with `stratumn login`\n', process.exit); }) .catch(handleError);