vtasks-automate-cli 0.1.0
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.
- package/init.js +106 -0
- package/package.json +13 -0
package/init.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const readline = require("readline");
|
|
3
|
+
const axios = require("axios");
|
|
4
|
+
const { exec } = require("child_process");
|
|
5
|
+
|
|
6
|
+
const VTASKS_URL = "http://localhost:3040";
|
|
7
|
+
|
|
8
|
+
class ApiHelpers {
|
|
9
|
+
static async checkProjectName(projectName) {
|
|
10
|
+
return axios.get(`${VTASKS_URL}/project/check/${projectName}`);
|
|
11
|
+
}
|
|
12
|
+
static async checkGitUserEmail(userEmail) {
|
|
13
|
+
return axios.get(`${VTASKS_URL}/user/check/${userEmail}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const LOG_COLORS = {
|
|
18
|
+
RED: "\x1b[31m",
|
|
19
|
+
GREEN: "\x1b[32m",
|
|
20
|
+
YELLOW: "\x1b[33m",
|
|
21
|
+
BLUE: "\x1b[34m",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
class GitService {
|
|
25
|
+
static async getCurrentBranch() {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
exec("git branch --show-current", (error, stdout, stderr) => {
|
|
28
|
+
if (error) {
|
|
29
|
+
console.log("Error: ", error);
|
|
30
|
+
reject("Error gettig current branch: Error executing git cmd");
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const branch = stdout.trim();
|
|
34
|
+
resolve(branch);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static async getCurrentUser() {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
exec("git config --list", (error, stdout, stderr) => {
|
|
42
|
+
if (error) {
|
|
43
|
+
console.log("Error: ", error);
|
|
44
|
+
reject("Error getting user email: Error executing git cmd");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const list = stdout.split("\n");
|
|
48
|
+
const item = list.find((t) => t.startsWith("user.email"));
|
|
49
|
+
if (!item) {
|
|
50
|
+
reject("Error getting user email: user.email not found");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const split = item.split("=");
|
|
54
|
+
|
|
55
|
+
const email = split[1].trim();
|
|
56
|
+
resolve(email);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function readLine() {
|
|
63
|
+
const rl = readline.createInterface({
|
|
64
|
+
input: process.stdin,
|
|
65
|
+
output: process.stdout,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return new Promise((resolve) =>
|
|
69
|
+
rl.question("", (answer) => {
|
|
70
|
+
rl.close();
|
|
71
|
+
resolve(answer);
|
|
72
|
+
})
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const main = async () => {
|
|
77
|
+
let projectName;
|
|
78
|
+
|
|
79
|
+
console.log(LOG_COLORS.BLUE, "Checking git email:");
|
|
80
|
+
const userEmail = await GitService.getCurrentUser();
|
|
81
|
+
try {
|
|
82
|
+
await ApiHelpers.checkGitUserEmail(userEmail);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.log(
|
|
85
|
+
LOG_COLORS.RED,
|
|
86
|
+
`Error: User email not found (${userEmail}) - Try again`
|
|
87
|
+
);
|
|
88
|
+
return 1;
|
|
89
|
+
}
|
|
90
|
+
console.log(LOG_COLORS.GREEN, `User email checked: ${userEmail} ✓`);
|
|
91
|
+
|
|
92
|
+
console.log(LOG_COLORS.BLUE, "Enter the EXACT name of the project:");
|
|
93
|
+
projectName = await readLine();
|
|
94
|
+
try {
|
|
95
|
+
await ApiHelpers.checkProjectName(projectName);
|
|
96
|
+
console.log(LOG_COLORS.GREEN, `Project name checked: ${projectName} ✓`);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
console.log(
|
|
99
|
+
LOG_COLORS.RED,
|
|
100
|
+
`Error: Project not found (${projectName}) - Try again`
|
|
101
|
+
);
|
|
102
|
+
return 1;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vtasks-automate-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Automate your vTasks workflow with ease — move tasks between states without opening the app",
|
|
5
|
+
"bin": {
|
|
6
|
+
"vtasks-automate": "init.js"
|
|
7
|
+
},
|
|
8
|
+
"author": "nahuel-venturing",
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"axios": "^1.10.0"
|
|
12
|
+
}
|
|
13
|
+
}
|