vtasks-automate-cli 0.6.0 → 0.6.2

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 (3) hide show
  1. package/content/index.js +13 -14
  2. package/init.js +30 -142
  3. package/package.json +1 -1
package/content/index.js CHANGED
@@ -103,19 +103,19 @@ async function main() {
103
103
  if (branch != "qa" && branch != "dev" && branch != "master") {
104
104
  issueNumber = Number(branch.split("_")[0]);
105
105
  console.log(LOG_COLORS.GREEN, `Currently working on issue: ${issueNumber}`);
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();
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();
119
119
  console.log(LOG_COLORS.GREEN, "vTasks status changed successfully!");
120
120
  } else {
121
121
  console.log(
@@ -123,7 +123,6 @@ async function main() {
123
123
  "Warning: you are working in a not issue branch"
124
124
  );
125
125
  }
126
- console.log(userEmail, VTASKS_URL, branch, projectName);
127
126
  }
128
127
 
129
128
  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 { exec } from "child_process";
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 carpetaDestino = path.join(process.cwd(), "vTasks");
159
- const githooksFolder = path.join(process.cwd(), ".githooks");
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 archivoOrigen = path.join(__dirname, "content", "index.js");
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
- console.log(LOG_COLORS.GREEN, "vTasks config file added");
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 ../vTasks/index.js && ${oldCmd}`;
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 ../vTasks/index.js && ${oldCmd}`;
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 ../vTasks/index.js && ${oldCmd}`;
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");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vtasks-automate-cli",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Automate your vTasks workflow with ease — move tasks between states without opening the app",
5
5
  "bin": {
6
6
  "vtasks-automate": "init.js"