-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
73 lines (69 loc) · 1.61 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env node
import inq from 'inquirer';
import * as rl from 'replit-login';
import conf from 'conf';
import { deploy } from './src/client.js';
const argv = process.argv.slice(2);
const loginQuestions = [
{
type: 'input',
name: 'username',
message: 'Enter your username:'
},
{
type: 'password',
name: 'password',
message: 'Enter your password:'
},
{
type: 'password',
name: 'token',
message: 'Enter your Captcha token (crkl.ml/captcha):'
}
];
const config = new conf();
const login = async (usr, pwd, t) => {
const REPLIT_LOGIN = await rl.authenticate(usr, pwd, t);
if (REPLIT_LOGIN) {
config.set('username', usr);
config.set('login', REPLIT_LOGIN);
console.log('logged in as', usr);
} else {
console.log('could not login.');
}
};
const help = () => {
console.log(`
Usage: mvrepl [x]
------------------------
Avaliable commands:
- login: login with replit (asks for username and password and a captcha token from crkl.ml/captcha)
- deploy: deploys the current directory to replit (asks for a repl name and language)
`);
};
if (argv[0]) {
if (argv[0] === 'login') {
if (!config.get('login')) {
inq.prompt(loginQuestions).then(({ username, password, token }) => {
login(username, password, token);
});
} else {
console.log('you are already logged in!');
}
} else if (argv[0] === 'deploy') {
if (config.get('login')) {
deploy();
} else {
console.log('you are not logged in!');
}
} else {
console.log('this is not a valid command.');
}
} else {
if (!config.get('login')) {
console.log('you are not logged in by the way!');
help();
} else {
help();
}
}