vtasks-automate-cli 0.4.2 → 0.4.4

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 (2) hide show
  1. package/init.js +72 -1
  2. package/package.json +1 -1
package/init.js CHANGED
@@ -80,6 +80,40 @@ function readLine() {
80
80
  );
81
81
  }
82
82
 
83
+ const MAIN_FOLDERS = {
84
+ REACT: "client",
85
+ NEXT: "client-nextjs",
86
+ SERVER: "server",
87
+ };
88
+ const PKJSON = "package.json";
89
+
90
+ function getCmdContent(content = "", cmd = "start") {
91
+ const cmdToGet = `"${cmd}":`;
92
+ const cmdLength = cmdToGet.length;
93
+ let endCmdIndex;
94
+ for (let i = cmdLength; i < content.length; i++) {
95
+ const str = content.substring(i - cmdLength, i);
96
+ if (str == cmdToGet) {
97
+ endCmdIndex = i;
98
+ let startMarkIndex;
99
+ let endMarkIndex;
100
+ while ((!startMarkIndex || !endMarkIndex) && i < content.length) {
101
+ if (content[i] == `"`) {
102
+ if (!startMarkIndex) {
103
+ startMarkIndex = i;
104
+ } else {
105
+ endMarkIndex = i;
106
+ return content.substring(startMarkIndex + 1, endMarkIndex);
107
+ }
108
+ }
109
+
110
+ i++;
111
+ }
112
+ }
113
+ }
114
+ console.log("Not found");
115
+ }
116
+
83
117
  const main = async () => {
84
118
  let projectName;
85
119
 
@@ -122,6 +156,11 @@ const main = async () => {
122
156
 
123
157
  const gitIgnoreFile = path.join(process.cwd(), ".gitignore");
124
158
 
159
+ //Replace start cmd
160
+ const reactPath = path.join(__dirname, MAIN_FOLDERS.REACT);
161
+ const nextPath = path.join(__dirname, MAIN_FOLDERS.NEXT);
162
+ const serverPath = path.join(__dirname, MAIN_FOLDERS.SERVER);
163
+
125
164
  if (fs.existsSync(carpetaDestino)) {
126
165
  console.error(LOG_COLORS.RED, "Error: vTasks directory already exist");
127
166
  process.exit(1);
@@ -141,16 +180,48 @@ node ./vTasks/index.js`;
141
180
  fs.writeFileSync(archivoConfig, configContent);
142
181
  fs.writeFileSync(postCommitFile, postCommitContent);
143
182
 
144
- if (fs.existsSync(gitIgnoreContent)) {
183
+ if (fs.existsSync(gitIgnoreFile)) {
145
184
  let gitIgnoreContent = fs.readFileSync(gitIgnoreFile, "utf-8");
146
185
 
147
186
  gitIgnoreContent += "\n\n";
148
187
  gitIgnoreContent += "#vTasks config\n";
149
188
  gitIgnoreContent += "vTasks/config.js\n";
189
+ fs.writeFileSync(gitIgnoreFile, gitIgnoreContent);
150
190
  } else {
151
191
  console.log(LOG_COLORS.YELLOW, ".gitignore file not found");
152
192
  }
153
193
 
194
+ if (fs.existsSync(reactPath)) {
195
+ const packagePath = path.join(reactPath, PKJSON);
196
+ let packageContent = fs.readFileSync(packagePath, "utf-8");
197
+ const oldCmd = getCmdContent(packageContent, "start");
198
+ const newCmd = `node ../vTasks/index.js && ${oldCmd}`;
199
+ const newContent = packageContent.replace(oldCmd, newCmd);
200
+ fs.writeFileSync(packagePath, newContent);
201
+ } else {
202
+ console.log(LOG_COLORS.YELLOW, "React app not found");
203
+ }
204
+ if (fs.existsSync(nextPath)) {
205
+ const packagePath = path.join(nextPath, PKJSON);
206
+ let packageContent = fs.readFileSync(packagePath, "utf-8");
207
+ const oldCmd = getCmdContent(packageContent, "dev");
208
+ const newCmd = `node ../vTasks/index.js && ${oldCmd}`;
209
+ const newContent = packageContent.replace(oldCmd, newCmd);
210
+ fs.writeFileSync(packagePath, newContent);
211
+ } else {
212
+ console.log(LOG_COLORS.YELLOW, "Next app not found");
213
+ }
214
+ if (fs.existsSync(serverPath)) {
215
+ const packagePath = path.join(serverPath, PKJSON);
216
+ let packageContent = fs.readFileSync(packagePath, "utf-8");
217
+ const oldCmd = getCmdContent(packageContent, "start");
218
+ const newCmd = `node ../vTasks/index.js && ${oldCmd}`;
219
+ const newContent = packageContent.replace(oldCmd, newCmd);
220
+ fs.writeFileSync(packagePath, newContent);
221
+ } else {
222
+ console.log(LOG_COLORS.YELLOW, "Server app not found");
223
+ }
224
+
154
225
  console.log(LOG_COLORS.GREEN, "Set Up completed ✓");
155
226
  };
156
227
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vtasks-automate-cli",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
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"