vtasks-automate-cli 0.1.0 → 0.3.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.
@@ -0,0 +1,94 @@
1
+ const { exec } = require('child_process');
2
+ const config = require('./config');
3
+
4
+ const LOG_COLORS = {
5
+ RED: '\x1b[31m',
6
+ GREEN: '\x1b[32m',
7
+ YELLOW: '\x1b[33m',
8
+ BLUE: '\x1b[34m',
9
+ };
10
+
11
+ class GitService {
12
+ static async getCurrentBranch() {
13
+ return new Promise((resolve, reject) => {
14
+ exec('git branch --show-current', (error, stdout, stderr) => {
15
+ if (error) {
16
+ console.log('Error: ', error);
17
+ reject('Error gettig current branch: Error executing git cmd');
18
+ return;
19
+ }
20
+ const branch = stdout.trim();
21
+ resolve(branch);
22
+ });
23
+ });
24
+ }
25
+
26
+ static async getCurrentUser() {
27
+ return new Promise((resolve, reject) => {
28
+ exec('git config --list', (error, stdout, stderr) => {
29
+ if (error) {
30
+ console.log('Error: ', error);
31
+ reject('Error getting user email: Error executing git cmd');
32
+ return;
33
+ }
34
+ const list = stdout.split('\n');
35
+ const item = list.find(t => t.startsWith('user.email'));
36
+ if (!item) {
37
+ reject('Error getting user email: user.email not found');
38
+ return;
39
+ }
40
+ const split = item.split('=');
41
+
42
+ const email = split[1].trim();
43
+ resolve(email);
44
+ });
45
+ });
46
+ }
47
+ }
48
+
49
+ async function main() {
50
+ console.log(LOG_COLORS.BLUE, 'Checking vTasks config:');
51
+ if (!config) {
52
+ console.log(LOG_COLORS.RED, 'Git user email not found');
53
+ throw new Error('Missing config.js file');
54
+ }
55
+ const userEmail = await GitService.getCurrentUser();
56
+ if (!userEmail) {
57
+ console.log(LOG_COLORS.RED, 'Git user email not found');
58
+ throw new Error('Git user email not found');
59
+ }
60
+ console.log(LOG_COLORS.GREEN, `User email: ${userEmail}`);
61
+ const projectName = config.projectName;
62
+ if (!projectName) {
63
+ console.log(LOG_COLORS.RED, 'Missing project name configuration');
64
+ throw new Error('Missing Project name');
65
+ }
66
+ console.log(LOG_COLORS.GREEN, `Project: ${projectName}`);
67
+ let issueNumber;
68
+ const branch = await GitService.getCurrentBranch();
69
+ if (branch != 'qa' && !branch != 'dev') {
70
+ issueNumber = Number(branch.split('_')[0]);
71
+ console.log(LOG_COLORS.GREEN, `Currently working on issue: ${issueNumber}`);
72
+ const response = await fetch(`${config.vTasksUrl}`, {
73
+ method: 'POST',
74
+ body: JSON.stringify({
75
+ projectName,
76
+ branch,
77
+ userEmail,
78
+ issueNumber,
79
+ }),
80
+ headers: {
81
+ 'Content-Type': 'application/json',
82
+ },
83
+ });
84
+ const parsed = await response.json();
85
+ console.log(LOG_COLORS.GREEN, 'vTasks status changed successfully!');
86
+ } else {
87
+ console.log(
88
+ LOG_COLORS.YELLOW,
89
+ 'Warning: you are working in a not issue branch',
90
+ );
91
+ }
92
+ }
93
+
94
+ main();
package/init.js CHANGED
@@ -1,7 +1,12 @@
1
1
  #!/usr/bin/env node
2
- const readline = require("readline");
3
- const axios = require("axios");
4
- const { exec } = require("child_process");
2
+ import readline from "readline";
3
+ import axios from "axios";
4
+ import { exec } from "child_process";
5
+
6
+ import fs from "fs";
7
+ import path from "path";
8
+ import { fileURLToPath } from "url";
9
+ import { dirname } from "path";
5
10
 
6
11
  const VTASKS_URL = "http://localhost:3040";
7
12
 
@@ -14,6 +19,8 @@ class ApiHelpers {
14
19
  }
15
20
  }
16
21
 
22
+ const VTASKS_CONFIG_URL = "http://localhost:3040/project/action/track";
23
+
17
24
  const LOG_COLORS = {
18
25
  RED: "\x1b[31m",
19
26
  GREEN: "\x1b[32m",
@@ -85,7 +92,7 @@ const main = async () => {
85
92
  LOG_COLORS.RED,
86
93
  `Error: User email not found (${userEmail}) - Try again`
87
94
  );
88
- return 1;
95
+ return process.exit(1);
89
96
  }
90
97
  console.log(LOG_COLORS.GREEN, `User email checked: ${userEmail} ✓`);
91
98
 
@@ -99,8 +106,31 @@ const main = async () => {
99
106
  LOG_COLORS.RED,
100
107
  `Error: Project not found (${projectName}) - Try again`
101
108
  );
102
- return 1;
109
+ return process.exit(1);
110
+ }
111
+ console.log(LOG_COLORS.BLUE, "Generating scripts");
112
+ const __filename = fileURLToPath(import.meta.url);
113
+ const __dirname = dirname(__filename);
114
+
115
+ const carpetaDestino = path.join(process.cwd(), "vTasks");
116
+ const archivoOrigen = path.join(__dirname, "content", "index.js");
117
+ const archivoDestino = path.join(carpetaDestino, "index.js");
118
+ const archivoConfig = path.join(carpetaDestino, "config.js");
119
+ if (fs.existsSync(carpetaDestino)) {
120
+ console.error(LOG_COLORS.RED, "Error: vTasks directory already exist");
121
+ process.exit(1);
103
122
  }
123
+ fs.mkdirSync(carpetaDestino, { recursive: true });
124
+ fs.copyFileSync(archivoOrigen, archivoDestino);
125
+
126
+ const configContent = `module.exports = {
127
+ projectName: '${projectName}',
128
+ vTasksUrl: '${VTASKS_CONFIG_URL}'
129
+ };
130
+ `;
131
+ fs.writeFileSync(archivoConfig, configContent);
132
+
133
+ console.log(LOG_COLORS.GREEN, "Set Up completed ✓");
104
134
  };
105
135
 
106
136
  main();
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "vtasks-automate-cli",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
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"
7
7
  },
8
+ "type": "module",
8
9
  "author": "nahuel-venturing",
9
10
  "license": "ISC",
10
11
  "dependencies": {