resulgit 1.0.20 → 1.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/resulgit.js +66 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resulgit",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "description": "A powerful CLI tool for version control system operations - clone, commit, push, pull, merge, branch management, and more",
5
5
  "main": "resulgit.js",
6
6
  "bin": {
package/resulgit.js CHANGED
@@ -3,6 +3,7 @@ const fs = require('fs')
3
3
  const path = require('path')
4
4
  const os = require('os')
5
5
  const crypto = require('crypto')
6
+ const readline = require('readline')
6
7
  const COLORS = { reset: '\x1b[0m', bold: '\x1b[1m', dim: '\x1b[2m', red: '\x1b[31m', green: '\x1b[32m', yellow: '\x1b[33m', blue: '\x1b[34m', magenta: '\x1b[35m', cyan: '\x1b[36m' }
7
8
  function color(str, c) { return (COLORS[c] || '') + String(str) + COLORS.reset }
8
9
 
@@ -85,6 +86,44 @@ function print(obj, json) {
85
86
  process.stdout.write(Object.entries(obj).map(([k, v]) => `${k}: ${typeof v === 'object' ? JSON.stringify(v) : v}`).join('\n') + '\n')
86
87
  }
87
88
 
89
+ async function prompt(msg, mask = false) {
90
+ if (mask) {
91
+ process.stdout.write(msg)
92
+ process.stdin.setRawMode(true)
93
+ process.stdin.resume()
94
+ return new Promise(resolve => {
95
+ let pw = ''
96
+ const onData = buf => {
97
+ const s = buf.toString('utf8')
98
+ if (s === '\r' || s === '\n') {
99
+ process.stdin.setRawMode(false)
100
+ process.stdin.pause()
101
+ process.stdin.removeListener('data', onData)
102
+ process.stdout.write('\n')
103
+ resolve(pw)
104
+ } else if (s === '\u0003') { // Ctrl-C
105
+ process.stdin.setRawMode(false)
106
+ process.stdin.pause()
107
+ process.stdout.write('\n')
108
+ process.exit(0)
109
+ } else if (s === '\u007f' || s === '\b' || s === '\x08') { // Backspace
110
+ if (pw.length > 0) {
111
+ pw = pw.slice(0, -1)
112
+ process.stdout.write('\b \b')
113
+ }
114
+ } else if (s.length === 1 && s.charCodeAt(0) >= 32) {
115
+ pw += s
116
+ process.stdout.write('*')
117
+ }
118
+ }
119
+ process.stdin.on('data', onData)
120
+ })
121
+ } else {
122
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
123
+ return new Promise(resolve => rl.question(msg, line => { rl.close(); resolve(line) }))
124
+ }
125
+ }
126
+
88
127
  async function cmdAuth(sub, opts) {
89
128
  if (sub === 'set-token') {
90
129
  const token = opts.token || ''
@@ -102,11 +141,22 @@ async function cmdAuth(sub, opts) {
102
141
  }
103
142
  if (sub === 'login') {
104
143
  const server = opts.server || loadConfig().server
105
- const email = opts.email
106
- const password = opts.password
107
- if (!email || !password) throw new Error('Missing --email and --password')
144
+ let email = opts.email
145
+ let password = opts.password
146
+
147
+ if (!email) {
148
+ email = await prompt('Email: ')
149
+ }
150
+ if (!password) {
151
+ password = await prompt('Password: ', true)
152
+ }
153
+
154
+ if (!email || !password) throw new Error('Email and password required')
155
+
108
156
  const url = new URL('/api/auth/login', server).toString()
109
- print({ server, email, password, url }, opts.json === 'true')
157
+ const maskedPassword = password.replace(/./g, '*')
158
+ print({ server, email, password: maskedPassword, url }, opts.json === 'true')
159
+
110
160
  const res = await request('POST', url, { email, password }, '')
111
161
  const token = res.token || ''
112
162
  if (token) saveConfig({ token })
@@ -115,12 +165,21 @@ async function cmdAuth(sub, opts) {
115
165
  }
116
166
  if (sub === 'register') {
117
167
  const server = opts.server || loadConfig().server
118
- const username = opts.username
119
- const email = opts.email
120
- const password = opts.password
168
+ let username = opts.username
169
+ let email = opts.email
170
+ let password = opts.password
121
171
  const displayName = opts.displayName || username
172
+
173
+ if (!username) username = await prompt('Username: ')
174
+ if (!email) email = await prompt('Email: ')
175
+ if (!password) password = await prompt('Password: ', true)
176
+
122
177
  if (!username || !email || !password) throw new Error('Missing --username --email --password')
178
+
123
179
  const url = new URL('/api/auth/register', server).toString()
180
+ const maskedPassword = password.replace(/./g, '*')
181
+ print({ server, username, email, password: maskedPassword, url }, opts.json === 'true')
182
+
124
183
  const res = await request('POST', url, { username, email, password, displayName }, '')
125
184
  const token = res.token || ''
126
185
  if (token) saveConfig({ token })