vtasks-automate-cli 0.5.0 → 0.6.1
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/README.md +0 -0
- package/content/index.js +56 -21
- package/init.js +30 -142
- package/package.json +1 -1
package/README.md
ADDED
|
File without changes
|
package/content/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
const { exec } = require("child_process");
|
|
2
|
-
const config = require("./config");
|
|
1
|
+
// const { exec } = require("child_process");
|
|
2
|
+
// const config = require("./config");
|
|
3
|
+
|
|
4
|
+
import { exec } from "child_process";
|
|
3
5
|
|
|
4
6
|
const LOG_COLORS = {
|
|
5
7
|
RED: "\x1b[31m",
|
|
@@ -8,6 +10,9 @@ const LOG_COLORS = {
|
|
|
8
10
|
BLUE: "\x1b[34m",
|
|
9
11
|
};
|
|
10
12
|
|
|
13
|
+
const VTASKS_URL =
|
|
14
|
+
"https://vtasks.venturing.com.ar/vTasks/api/project/action/track";
|
|
15
|
+
|
|
11
16
|
class GitService {
|
|
12
17
|
static async getCurrentBranch() {
|
|
13
18
|
return new Promise((resolve, reject) => {
|
|
@@ -44,21 +49,50 @@ class GitService {
|
|
|
44
49
|
});
|
|
45
50
|
});
|
|
46
51
|
}
|
|
52
|
+
|
|
53
|
+
static async getCurrentProject() {
|
|
54
|
+
return new Promise((resolve, reject) => {
|
|
55
|
+
exec("git remote -v", (error, stdout, stderr) => {
|
|
56
|
+
if (error) {
|
|
57
|
+
console.log(
|
|
58
|
+
LOG_COLORS.RED,
|
|
59
|
+
"Error getting project name: Error executing git cmd"
|
|
60
|
+
);
|
|
61
|
+
reject("Error getting user email: Error executing git cmd");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const list = stdout.split("\n");
|
|
65
|
+
const item = list.find((t) => t.startsWith("origin"));
|
|
66
|
+
if (!item) {
|
|
67
|
+
reject("Error getting project name: origin not found");
|
|
68
|
+
reject("Error getting prject name: origin not found");
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const split = item.split(" ");
|
|
72
|
+
const url = split.find((t) => t.includes("http"));
|
|
73
|
+
|
|
74
|
+
const urlSplit = url.split("/");
|
|
75
|
+
const gitfile = urlSplit[urlSplit.length - 1];
|
|
76
|
+
const projectName = gitfile.replace(".git", "");
|
|
77
|
+
resolve(projectName);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
47
81
|
}
|
|
48
82
|
|
|
49
83
|
async function main() {
|
|
50
84
|
console.log(LOG_COLORS.BLUE, "Checking vTasks config:");
|
|
51
|
-
if (!config) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
85
|
+
// if (!config) {
|
|
86
|
+
// console.log(LOG_COLORS.RED, "Git user email not found");
|
|
87
|
+
// throw new Error("Missing config.js file");
|
|
88
|
+
// }
|
|
55
89
|
const userEmail = await GitService.getCurrentUser();
|
|
56
90
|
if (!userEmail) {
|
|
57
91
|
console.log(LOG_COLORS.RED, "Git user email not found");
|
|
58
92
|
throw new Error("Git user email not found");
|
|
59
93
|
}
|
|
60
94
|
console.log(LOG_COLORS.GREEN, `User email: ${userEmail}`);
|
|
61
|
-
const projectName =
|
|
95
|
+
const projectName = await GitService.getCurrentProject();
|
|
62
96
|
if (!projectName) {
|
|
63
97
|
console.log(LOG_COLORS.RED, "Missing project name configuration");
|
|
64
98
|
throw new Error("Missing Project name");
|
|
@@ -66,22 +100,22 @@ async function main() {
|
|
|
66
100
|
console.log(LOG_COLORS.GREEN, `Project: ${projectName}`);
|
|
67
101
|
let issueNumber;
|
|
68
102
|
const branch = await GitService.getCurrentBranch();
|
|
69
|
-
if (branch != "qa" && branch != "dev") {
|
|
103
|
+
if (branch != "qa" && branch != "dev" && branch != "master") {
|
|
70
104
|
issueNumber = Number(branch.split("_")[0]);
|
|
71
105
|
console.log(LOG_COLORS.GREEN, `Currently working on issue: ${issueNumber}`);
|
|
72
|
-
const response = await fetch(`${config.vTasksUrl}`, {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
});
|
|
84
|
-
const parsed = await response.json();
|
|
106
|
+
// const response = await fetch(`${config.vTasksUrl}`, {
|
|
107
|
+
// method: "POST",
|
|
108
|
+
// body: JSON.stringify({
|
|
109
|
+
// projectName,
|
|
110
|
+
// branch,
|
|
111
|
+
// userEmail,
|
|
112
|
+
// issueNumber,
|
|
113
|
+
// }),
|
|
114
|
+
// headers: {
|
|
115
|
+
// "Content-Type": "application/json",
|
|
116
|
+
// },
|
|
117
|
+
// });
|
|
118
|
+
// const parsed = await response.json();
|
|
85
119
|
console.log(LOG_COLORS.GREEN, "vTasks status changed successfully!");
|
|
86
120
|
} else {
|
|
87
121
|
console.log(
|
|
@@ -89,6 +123,7 @@ async function main() {
|
|
|
89
123
|
"Warning: you are working in a not issue branch"
|
|
90
124
|
);
|
|
91
125
|
}
|
|
126
|
+
console.log(userEmail, VTASKS_URL, branch, projectName);
|
|
92
127
|
}
|
|
93
128
|
|
|
94
129
|
main();
|
package/init.js
CHANGED
|
@@ -1,26 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import readline from "readline";
|
|
3
3
|
import axios from "axios";
|
|
4
|
-
import {
|
|
4
|
+
import { execSync } from "child_process";
|
|
5
5
|
|
|
6
6
|
import fs from "fs";
|
|
7
7
|
import path from "path";
|
|
8
|
-
import { fileURLToPath } from "url";
|
|
9
|
-
import { dirname } from "path";
|
|
10
|
-
|
|
11
|
-
const VTASKS_URL = "https://vtasks.venturing.com.ar/vTasks/api";
|
|
12
|
-
|
|
13
|
-
class ApiHelpers {
|
|
14
|
-
static async checkProjectName(projectName) {
|
|
15
|
-
return axios.get(`${VTASKS_URL}/project/check/${projectName}`);
|
|
16
|
-
}
|
|
17
|
-
static async checkGitUserEmail(userEmail) {
|
|
18
|
-
return axios.get(`${VTASKS_URL}/user/check/${userEmail}`);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const VTASKS_CONFIG_URL =
|
|
23
|
-
"https://vtasks.venturing.com.ar/vTasks/api/project/action/track";
|
|
24
8
|
|
|
25
9
|
const LOG_COLORS = {
|
|
26
10
|
RED: "\x1b[31m",
|
|
@@ -29,63 +13,12 @@ const LOG_COLORS = {
|
|
|
29
13
|
BLUE: "\x1b[34m",
|
|
30
14
|
};
|
|
31
15
|
|
|
32
|
-
class GitService {
|
|
33
|
-
static async getCurrentBranch() {
|
|
34
|
-
return new Promise((resolve, reject) => {
|
|
35
|
-
exec("git branch --show-current", (error, stdout, stderr) => {
|
|
36
|
-
if (error) {
|
|
37
|
-
console.log("Error: ", error);
|
|
38
|
-
reject("Error gettig current branch: Error executing git cmd");
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const branch = stdout.trim();
|
|
42
|
-
resolve(branch);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
static async getCurrentUser() {
|
|
48
|
-
return new Promise((resolve, reject) => {
|
|
49
|
-
exec("git config --list", (error, stdout, stderr) => {
|
|
50
|
-
if (error) {
|
|
51
|
-
console.log("Error: ", error);
|
|
52
|
-
reject("Error getting user email: Error executing git cmd");
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const list = stdout.split("\n");
|
|
56
|
-
const item = list.find((t) => t.startsWith("user.email"));
|
|
57
|
-
if (!item) {
|
|
58
|
-
reject("Error getting user email: user.email not found");
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
const split = item.split("=");
|
|
62
|
-
|
|
63
|
-
const email = split[1].trim();
|
|
64
|
-
resolve(email);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function readLine() {
|
|
71
|
-
const rl = readline.createInterface({
|
|
72
|
-
input: process.stdin,
|
|
73
|
-
output: process.stdout,
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
return new Promise((resolve) =>
|
|
77
|
-
rl.question("", (answer) => {
|
|
78
|
-
rl.close();
|
|
79
|
-
resolve(answer);
|
|
80
|
-
})
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
16
|
const MAIN_FOLDERS = {
|
|
85
17
|
REACT: "client",
|
|
86
18
|
NEXT: "client-nextjs",
|
|
87
19
|
SERVER: "server",
|
|
88
20
|
};
|
|
21
|
+
|
|
89
22
|
const PKJSON = "package.json";
|
|
90
23
|
|
|
91
24
|
function getCmdContent(content = "", cmd = "start") {
|
|
@@ -116,99 +49,54 @@ function getCmdContent(content = "", cmd = "start") {
|
|
|
116
49
|
}
|
|
117
50
|
|
|
118
51
|
const main = async () => {
|
|
119
|
-
let projectName;
|
|
120
|
-
|
|
121
|
-
console.log(LOG_COLORS.BLUE, "Checking git email:");
|
|
122
|
-
const userEmail = await GitService.getCurrentUser();
|
|
123
|
-
try {
|
|
124
|
-
await ApiHelpers.checkGitUserEmail(userEmail);
|
|
125
|
-
} catch (error) {
|
|
126
|
-
console.log(
|
|
127
|
-
LOG_COLORS.RED,
|
|
128
|
-
`Error: User email not found (${userEmail}) - Try again`
|
|
129
|
-
);
|
|
130
|
-
return process.exit(1);
|
|
131
|
-
}
|
|
132
|
-
console.log(LOG_COLORS.GREEN, `User email checked: ${userEmail} ✓`);
|
|
133
|
-
|
|
134
|
-
console.log(
|
|
135
|
-
LOG_COLORS.BLUE,
|
|
136
|
-
"Enter the EXACT name of the project (Venturing-Fullstack-Boilerplate) or the github repository link(https://github.com/venturing/Venturing-Fullstack-Boilerplate):"
|
|
137
|
-
);
|
|
138
|
-
projectName = await readLine();
|
|
139
|
-
try {
|
|
140
|
-
if (projectName.includes("https://")) {
|
|
141
|
-
projectName = projectName.trim();
|
|
142
|
-
const items = projectName.split("/");
|
|
143
|
-
projectName = items[items.length - 1];
|
|
144
|
-
}
|
|
145
|
-
await ApiHelpers.checkProjectName(projectName);
|
|
146
|
-
console.log(LOG_COLORS.GREEN, `Project name checked: ${projectName} ✓`);
|
|
147
|
-
} catch (error) {
|
|
148
|
-
console.log(
|
|
149
|
-
LOG_COLORS.RED,
|
|
150
|
-
`Error: Project not found (${projectName}) - Try again`
|
|
151
|
-
);
|
|
152
|
-
return process.exit(1);
|
|
153
|
-
}
|
|
154
52
|
console.log(LOG_COLORS.BLUE, "Generating scripts");
|
|
155
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
156
|
-
const __dirname = dirname(__filename);
|
|
157
53
|
|
|
158
|
-
const
|
|
159
|
-
|
|
54
|
+
const folders = ["client", "client-nextjs", "server"];
|
|
55
|
+
|
|
56
|
+
folders.forEach((folder) => {
|
|
57
|
+
const fullPath = path.join(process.cwd(), folder);
|
|
58
|
+
if (fs.existsSync(fullPath) && fs.lstatSync(fullPath).isDirectory()) {
|
|
59
|
+
console.log(LOG_COLORS.BLUE, `Installing dependencies at ./${folder}...`);
|
|
60
|
+
try {
|
|
61
|
+
execSync("npm install vtasks-automate-cli", {
|
|
62
|
+
cwd: fullPath,
|
|
63
|
+
stdio: "inherit",
|
|
64
|
+
});
|
|
65
|
+
console.log(LOG_COLORS.GREEN, `Ready at ${folder}\n`);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error(
|
|
68
|
+
LOG_COLORS.RED,
|
|
69
|
+
`Error installing dependencies at ${folder}:`,
|
|
70
|
+
error.message
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
console.log(LOG_COLORS.YELLOW, `"${folder}" directory not founded.\n`);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
160
77
|
|
|
161
|
-
const
|
|
162
|
-
const archivoDestino = path.join(carpetaDestino, "index.js");
|
|
163
|
-
const archivoConfig = path.join(carpetaDestino, "config.js");
|
|
78
|
+
const githooksFolder = path.join(process.cwd(), ".githooks");
|
|
164
79
|
const postCommitFile = path.join(githooksFolder, "post-checkout");
|
|
165
80
|
|
|
166
|
-
const gitIgnoreFile = path.join(process.cwd(), ".gitignore");
|
|
167
|
-
|
|
168
81
|
//Replace start cmd
|
|
169
82
|
const reactPath = path.join(process.cwd(), MAIN_FOLDERS.REACT);
|
|
170
83
|
const nextPath = path.join(process.cwd(), MAIN_FOLDERS.NEXT);
|
|
171
84
|
const serverPath = path.join(process.cwd(), MAIN_FOLDERS.SERVER);
|
|
172
85
|
|
|
173
|
-
if (fs.existsSync(carpetaDestino)) {
|
|
174
|
-
console.error(LOG_COLORS.RED, "Error: vTasks directory already exist");
|
|
175
|
-
process.exit(1);
|
|
176
|
-
}
|
|
177
|
-
fs.mkdirSync(carpetaDestino, { recursive: true });
|
|
178
|
-
fs.copyFileSync(archivoOrigen, archivoDestino);
|
|
179
|
-
|
|
180
|
-
const configContent = `module.exports = {
|
|
181
|
-
projectName: '${projectName}',
|
|
182
|
-
vTasksUrl: '${VTASKS_CONFIG_URL}'
|
|
183
|
-
};
|
|
184
|
-
`;
|
|
185
86
|
const postCommitContent = `#!/bin/bash
|
|
186
87
|
|
|
187
88
|
echo -e "\e[34mSwitching current branch\e[0m"
|
|
188
89
|
node ./vTasks/index.js`;
|
|
189
|
-
|
|
190
|
-
fs.writeFileSync(archivoConfig, configContent);
|
|
90
|
+
|
|
191
91
|
console.log(LOG_COLORS.GREEN, "Post-checkout hook added");
|
|
192
92
|
fs.writeFileSync(postCommitFile, postCommitContent);
|
|
193
93
|
|
|
194
|
-
if (fs.existsSync(gitIgnoreFile)) {
|
|
195
|
-
let gitIgnoreContent = fs.readFileSync(gitIgnoreFile, "utf-8");
|
|
196
|
-
|
|
197
|
-
gitIgnoreContent += "\n\n";
|
|
198
|
-
gitIgnoreContent += "#vTasks config\n";
|
|
199
|
-
gitIgnoreContent += "vTasks/config.js\n";
|
|
200
|
-
fs.writeFileSync(gitIgnoreFile, gitIgnoreContent);
|
|
201
|
-
console.log(LOG_COLORS.GREEN, "vTasks config added to .gitignore file");
|
|
202
|
-
} else {
|
|
203
|
-
console.log(LOG_COLORS.YELLOW, ".gitignore file not found");
|
|
204
|
-
}
|
|
205
|
-
|
|
206
94
|
if (fs.existsSync(reactPath)) {
|
|
207
95
|
const packagePath = path.join(reactPath, PKJSON);
|
|
208
96
|
let packageContent = fs.readFileSync(packagePath, "utf-8");
|
|
209
97
|
const oldCmd = getCmdContent(packageContent, "start");
|
|
210
98
|
if (oldCmd) {
|
|
211
|
-
const newCmd = `node
|
|
99
|
+
const newCmd = `node node_modules/vtasks-automate-cli/content/index.js && ${oldCmd}`;
|
|
212
100
|
const newContent = packageContent.replace(oldCmd, newCmd);
|
|
213
101
|
fs.writeFileSync(packagePath, newContent);
|
|
214
102
|
console.log(LOG_COLORS.GREEN, "React app start script modified");
|
|
@@ -223,7 +111,7 @@ node ./vTasks/index.js`;
|
|
|
223
111
|
let packageContent = fs.readFileSync(packagePath, "utf-8");
|
|
224
112
|
const oldCmd = getCmdContent(packageContent, "dev");
|
|
225
113
|
if (oldCmd) {
|
|
226
|
-
const newCmd = `node
|
|
114
|
+
const newCmd = `node node_modules/vtasks-automate-cli/content/index.js && ${oldCmd}`;
|
|
227
115
|
const newContent = packageContent.replace(oldCmd, newCmd);
|
|
228
116
|
fs.writeFileSync(packagePath, newContent);
|
|
229
117
|
console.log(LOG_COLORS.GREEN, "Next app dev script modified");
|
|
@@ -238,7 +126,7 @@ node ./vTasks/index.js`;
|
|
|
238
126
|
let packageContent = fs.readFileSync(packagePath, "utf-8");
|
|
239
127
|
const oldCmd = getCmdContent(packageContent, "start");
|
|
240
128
|
if (oldCmd) {
|
|
241
|
-
const newCmd = `node
|
|
129
|
+
const newCmd = `node node_modules/vtasks-automate-cli/content/index.js && ${oldCmd}`;
|
|
242
130
|
const newContent = packageContent.replace(oldCmd, newCmd);
|
|
243
131
|
fs.writeFileSync(packagePath, newContent);
|
|
244
132
|
console.log(LOG_COLORS.GREEN, "Server app start script modified");
|