vtasks-automate-cli 0.4.3 → 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.
- package/init.js +70 -0
- 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);
|
|
@@ -152,6 +191,37 @@ node ./vTasks/index.js`;
|
|
|
152
191
|
console.log(LOG_COLORS.YELLOW, ".gitignore file not found");
|
|
153
192
|
}
|
|
154
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
|
+
|
|
155
225
|
console.log(LOG_COLORS.GREEN, "Set Up completed ✓");
|
|
156
226
|
};
|
|
157
227
|
|