create-prisma-php-app 1.20.508 → 1.20.510
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/dist/index.js +976 -773
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10,57 +10,62 @@ const __filename = fileURLToPath(import.meta.url);
|
|
|
10
10
|
const __dirname = path.dirname(__filename);
|
|
11
11
|
let updateAnswer = null;
|
|
12
12
|
const nonBackendFiles = [
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
"favicon.ico",
|
|
14
|
+
"\\src\\app\\index.php",
|
|
15
|
+
"metadata.php",
|
|
16
|
+
"not-found.php",
|
|
17
17
|
];
|
|
18
18
|
const dockerFiles = [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
".dockerignore",
|
|
20
|
+
"docker-compose.yml",
|
|
21
|
+
"Dockerfile",
|
|
22
|
+
"apache.conf",
|
|
23
23
|
];
|
|
24
24
|
function bsConfigUrls(projectRootPath) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
bsPathRewrite: {},
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
// Extract the path up to and including 'htdocs\\'
|
|
35
|
-
const basePathToRemove = projectRootPath.substring(0, htdocsIndex + "\\htdocs\\".length);
|
|
36
|
-
// Escape backslashes for the regex pattern
|
|
37
|
-
const escapedBasePathToRemove = basePathToRemove.replace(/\\/g, "\\\\");
|
|
38
|
-
// Remove the base path and replace backslashes with forward slashes for URL compatibility
|
|
39
|
-
const relativeWebPath = projectRootPath
|
|
40
|
-
.replace(new RegExp(`^${escapedBasePathToRemove}`), "")
|
|
41
|
-
.replace(/\\/g, "/");
|
|
42
|
-
// Construct the Browser Sync command with the correct proxy URL, being careful not to affect the protocol part
|
|
43
|
-
let proxyUrl = `http://localhost/${relativeWebPath}`;
|
|
44
|
-
// Ensure the proxy URL does not end with a slash before appending '/public'
|
|
45
|
-
proxyUrl = proxyUrl.endsWith("/") ? proxyUrl.slice(0, -1) : proxyUrl;
|
|
46
|
-
// Clean the URL by replacing "//" with "/" but not affecting "http://"
|
|
47
|
-
// We replace instances of "//" that are not preceded by ":"
|
|
48
|
-
const cleanUrl = proxyUrl.replace(/(?<!:)(\/\/+)/g, "/");
|
|
49
|
-
const cleanRelativeWebPath = relativeWebPath.replace(/\/\/+/g, "/");
|
|
50
|
-
// Correct the relativeWebPath to ensure it does not start with a "/"
|
|
51
|
-
const adjustedRelativeWebPath = cleanRelativeWebPath.startsWith("/")
|
|
52
|
-
? cleanRelativeWebPath.substring(1)
|
|
53
|
-
: cleanRelativeWebPath;
|
|
25
|
+
// Identify the base path dynamically up to and including 'htdocs'
|
|
26
|
+
const htdocsIndex = projectRootPath.indexOf("\\htdocs\\");
|
|
27
|
+
if (htdocsIndex === -1) {
|
|
28
|
+
console.error(
|
|
29
|
+
"Invalid PROJECT_ROOT_PATH. The path does not contain \\htdocs\\"
|
|
30
|
+
);
|
|
54
31
|
return {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
"^/": `/${adjustedRelativeWebPath}/`,
|
|
58
|
-
},
|
|
32
|
+
bsTarget: "",
|
|
33
|
+
bsPathRewrite: {},
|
|
59
34
|
};
|
|
35
|
+
}
|
|
36
|
+
// Extract the path up to and including 'htdocs\\'
|
|
37
|
+
const basePathToRemove = projectRootPath.substring(
|
|
38
|
+
0,
|
|
39
|
+
htdocsIndex + "\\htdocs\\".length
|
|
40
|
+
);
|
|
41
|
+
// Escape backslashes for the regex pattern
|
|
42
|
+
const escapedBasePathToRemove = basePathToRemove.replace(/\\/g, "\\\\");
|
|
43
|
+
// Remove the base path and replace backslashes with forward slashes for URL compatibility
|
|
44
|
+
const relativeWebPath = projectRootPath
|
|
45
|
+
.replace(new RegExp(`^${escapedBasePathToRemove}`), "")
|
|
46
|
+
.replace(/\\/g, "/");
|
|
47
|
+
// Construct the Browser Sync command with the correct proxy URL, being careful not to affect the protocol part
|
|
48
|
+
let proxyUrl = `http://localhost/${relativeWebPath}`;
|
|
49
|
+
// Ensure the proxy URL does not end with a slash before appending '/public'
|
|
50
|
+
proxyUrl = proxyUrl.endsWith("/") ? proxyUrl.slice(0, -1) : proxyUrl;
|
|
51
|
+
// Clean the URL by replacing "//" with "/" but not affecting "http://"
|
|
52
|
+
// We replace instances of "//" that are not preceded by ":"
|
|
53
|
+
const cleanUrl = proxyUrl.replace(/(?<!:)(\/\/+)/g, "/");
|
|
54
|
+
const cleanRelativeWebPath = relativeWebPath.replace(/\/\/+/g, "/");
|
|
55
|
+
// Correct the relativeWebPath to ensure it does not start with a "/"
|
|
56
|
+
const adjustedRelativeWebPath = cleanRelativeWebPath.startsWith("/")
|
|
57
|
+
? cleanRelativeWebPath.substring(1)
|
|
58
|
+
: cleanRelativeWebPath;
|
|
59
|
+
return {
|
|
60
|
+
bsTarget: `${cleanUrl}/`,
|
|
61
|
+
bsPathRewrite: {
|
|
62
|
+
"^/": `/${adjustedRelativeWebPath}/`,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
60
65
|
}
|
|
61
66
|
function configureBrowserSyncCommand(baseDir) {
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
// TypeScript content to write
|
|
68
|
+
const bsConfigTsContent = `const { createProxyMiddleware } = require("http-proxy-middleware");
|
|
64
69
|
const fs = require("fs");
|
|
65
70
|
|
|
66
71
|
const jsonData = fs.readFileSync("prisma-php.json", "utf8");
|
|
@@ -86,322 +91,389 @@ module.exports = {
|
|
|
86
91
|
open: false,
|
|
87
92
|
ghostMode: false,
|
|
88
93
|
};`;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
+
// Determine the path and write the bs-config.js
|
|
95
|
+
const bsConfigPath = path.join(baseDir, "settings", "bs-config.cjs");
|
|
96
|
+
fs.writeFileSync(bsConfigPath, bsConfigTsContent, "utf8");
|
|
97
|
+
// Return the Browser Sync command string, using the cleaned URL
|
|
98
|
+
return `browser-sync start --config settings/bs-config.cjs`;
|
|
94
99
|
}
|
|
95
100
|
async function updatePackageJson(baseDir, answer) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
101
|
+
const packageJsonPath = path.join(baseDir, "package.json");
|
|
102
|
+
if (checkExcludeFiles(packageJsonPath)) return;
|
|
103
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
104
|
+
// Use the new function to configure the Browser Sync command
|
|
105
|
+
const browserSyncCommand = configureBrowserSyncCommand(baseDir);
|
|
106
|
+
packageJson.scripts = Object.assign(Object.assign({}, packageJson.scripts), {
|
|
107
|
+
projectName: "node settings/project-name.cjs",
|
|
108
|
+
});
|
|
109
|
+
let answersToInclude = [];
|
|
110
|
+
if (answer.tailwindcss) {
|
|
111
|
+
packageJson.scripts = Object.assign(
|
|
112
|
+
Object.assign({}, packageJson.scripts),
|
|
113
|
+
{
|
|
114
|
+
tailwind:
|
|
115
|
+
"postcss ./src/app/css/tailwind.css -o ./src/app/css/styles.css --watch",
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
answersToInclude.push("tailwind");
|
|
119
|
+
}
|
|
120
|
+
if (answer.websocket) {
|
|
121
|
+
packageJson.scripts = Object.assign(
|
|
122
|
+
Object.assign({}, packageJson.scripts),
|
|
123
|
+
{ websocket: "node ./settings/restart-websocket.cjs" }
|
|
124
|
+
);
|
|
125
|
+
answersToInclude.push("websocket");
|
|
126
|
+
}
|
|
127
|
+
// if (answer.prisma) {
|
|
128
|
+
// packageJson.scripts = {
|
|
129
|
+
// ...packageJson.scripts,
|
|
130
|
+
// postinstall: "prisma generate",
|
|
131
|
+
// };
|
|
132
|
+
// }
|
|
133
|
+
if (answer.docker) {
|
|
134
|
+
packageJson.scripts = Object.assign(
|
|
135
|
+
Object.assign({}, packageJson.scripts),
|
|
136
|
+
{ docker: "docker-compose up" }
|
|
137
|
+
);
|
|
138
|
+
answersToInclude.push("docker");
|
|
139
|
+
}
|
|
140
|
+
if (answer.swaggerDocs) {
|
|
141
|
+
packageJson.scripts = Object.assign(
|
|
142
|
+
Object.assign({}, packageJson.scripts),
|
|
143
|
+
{ "create-swagger-docs": "node settings/swagger-setup.js" }
|
|
144
|
+
);
|
|
145
|
+
answersToInclude.push("swaggerDocs");
|
|
146
|
+
}
|
|
147
|
+
if (answer.swaggerDocs) {
|
|
148
|
+
packageJson.scripts = Object.assign(
|
|
149
|
+
Object.assign({}, packageJson.scripts),
|
|
150
|
+
{ dev: "node settings/start-dev.js" }
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
// Initialize with existing scripts
|
|
154
|
+
const updatedScripts = Object.assign({}, packageJson.scripts);
|
|
155
|
+
// Conditionally add "browser-sync" command
|
|
156
|
+
updatedScripts["browser-sync"] = browserSyncCommand;
|
|
157
|
+
// Conditionally set the "dev" command
|
|
158
|
+
if (!answer.swaggerDocs) {
|
|
159
|
+
updatedScripts.dev =
|
|
160
|
+
answersToInclude.length > 0
|
|
161
|
+
? `npm-run-all --parallel projectName browser-sync ${answersToInclude.join(
|
|
162
|
+
" "
|
|
163
|
+
)}`
|
|
164
|
+
: `npm-run-all --parallel projectName browser-sync`;
|
|
165
|
+
}
|
|
166
|
+
// Finally, assign the updated scripts back to packageJson
|
|
167
|
+
packageJson.scripts = updatedScripts;
|
|
168
|
+
packageJson.type = "module";
|
|
169
|
+
if (answer.prisma)
|
|
170
|
+
packageJson.prisma = {
|
|
171
|
+
seed: "node prisma/seed.js",
|
|
172
|
+
};
|
|
173
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
148
174
|
}
|
|
149
175
|
async function updateComposerJson(baseDir, answer) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
176
|
+
const composerJsonPath = path.join(baseDir, "composer.json");
|
|
177
|
+
if (checkExcludeFiles(composerJsonPath)) return;
|
|
178
|
+
let composerJson;
|
|
179
|
+
// Check if the composer.json file exists
|
|
180
|
+
if (fs.existsSync(composerJsonPath)) {
|
|
181
|
+
// Read the current composer.json content
|
|
182
|
+
const composerJsonContent = fs.readFileSync(composerJsonPath, "utf8");
|
|
183
|
+
composerJson = JSON.parse(composerJsonContent);
|
|
184
|
+
} else {
|
|
185
|
+
console.error("composer.json does not exist.");
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
// Conditionally add WebSocket dependency
|
|
189
|
+
if (answer.websocket) {
|
|
190
|
+
composerJson.require = Object.assign(
|
|
191
|
+
Object.assign({}, composerJson.require),
|
|
192
|
+
{ "cboden/ratchet": "^0.4.4" }
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
if (answer.prisma) {
|
|
196
|
+
composerJson.require = Object.assign(
|
|
197
|
+
Object.assign({}, composerJson.require),
|
|
198
|
+
{ "ramsey/uuid": "5.x-dev", "hidehalo/nanoid-php": "1.x-dev" }
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
// Write the modified composer.json back to the file
|
|
202
|
+
fs.writeFileSync(composerJsonPath, JSON.stringify(composerJson, null, 2));
|
|
203
|
+
console.log("composer.json updated successfully.");
|
|
174
204
|
}
|
|
175
205
|
async function updateIndexJsForWebSocket(baseDir, answer) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const webSocketCode = `
|
|
206
|
+
if (!answer.websocket) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const indexPath = path.join(baseDir, "src", "app", "js", "index.js");
|
|
210
|
+
if (checkExcludeFiles(indexPath)) return;
|
|
211
|
+
let indexContent = fs.readFileSync(indexPath, "utf8");
|
|
212
|
+
// WebSocket initialization code to be appended
|
|
213
|
+
const webSocketCode = `
|
|
185
214
|
// WebSocket initialization
|
|
186
215
|
const ws = new WebSocket("ws://localhost:8080");
|
|
187
216
|
`;
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
217
|
+
// Append WebSocket code if user chose to use WebSocket
|
|
218
|
+
indexContent += webSocketCode;
|
|
219
|
+
fs.writeFileSync(indexPath, indexContent, "utf8");
|
|
220
|
+
console.log("WebSocket code added to index.js successfully.");
|
|
192
221
|
}
|
|
193
222
|
// This function updates the .gitignore file
|
|
194
223
|
async function createUpdateGitignoreFile(baseDir, additions) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
fs.writeFileSync(gitignorePath, gitignoreContent);
|
|
224
|
+
const gitignorePath = path.join(baseDir, ".gitignore");
|
|
225
|
+
if (checkExcludeFiles(gitignorePath)) return;
|
|
226
|
+
let gitignoreContent = "";
|
|
227
|
+
additions.forEach((addition) => {
|
|
228
|
+
if (!gitignoreContent.includes(addition)) {
|
|
229
|
+
gitignoreContent += `\n${addition}`;
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
// Ensure there's no leading newline if the file was just created
|
|
233
|
+
gitignoreContent = gitignoreContent.trimStart();
|
|
234
|
+
fs.writeFileSync(gitignorePath, gitignoreContent);
|
|
207
235
|
}
|
|
208
236
|
// Recursive copy function
|
|
209
237
|
function copyRecursiveSync(src, dest, answer) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
238
|
+
var _a;
|
|
239
|
+
console.log("🚀 ~ copyRecursiveSync ~ dest:", dest);
|
|
240
|
+
console.log("🚀 ~ copyRecursiveSync ~ src:", src);
|
|
241
|
+
const exists = fs.existsSync(src);
|
|
242
|
+
const stats = exists && fs.statSync(src);
|
|
243
|
+
const isDirectory = exists && stats && stats.isDirectory();
|
|
244
|
+
if (isDirectory) {
|
|
245
|
+
const destLower = dest.toLowerCase();
|
|
246
|
+
if (!answer.websocket && destLower.includes("src\\lib\\websocket")) return;
|
|
247
|
+
if (!answer.prisma && destLower.includes("src\\lib\\prisma")) return;
|
|
248
|
+
if (
|
|
249
|
+
(answer.backendOnly && destLower.includes("src\\app\\js")) ||
|
|
250
|
+
(answer.backendOnly && destLower.includes("src\\app\\css"))
|
|
251
|
+
)
|
|
252
|
+
return;
|
|
253
|
+
if (
|
|
254
|
+
answer.backendOnly &&
|
|
255
|
+
!answer.swaggerDocs &&
|
|
256
|
+
destLower.includes("src\\app\\swagger-docs")
|
|
257
|
+
)
|
|
258
|
+
return;
|
|
259
|
+
const destModified = dest.replace(/\\/g, "/");
|
|
260
|
+
if (
|
|
261
|
+
(_a =
|
|
262
|
+
updateAnswer === null || updateAnswer === void 0
|
|
263
|
+
? void 0
|
|
264
|
+
: updateAnswer.excludeFilePath) === null || _a === void 0
|
|
265
|
+
? void 0
|
|
266
|
+
: _a.includes(destModified)
|
|
267
|
+
)
|
|
268
|
+
return;
|
|
269
|
+
if (!fs.existsSync(dest)) fs.mkdirSync(dest, { recursive: true });
|
|
270
|
+
fs.readdirSync(src).forEach((childItemName) => {
|
|
271
|
+
copyRecursiveSync(
|
|
272
|
+
path.join(src, childItemName),
|
|
273
|
+
path.join(dest, childItemName),
|
|
274
|
+
answer
|
|
275
|
+
);
|
|
276
|
+
});
|
|
277
|
+
} else {
|
|
278
|
+
if (checkExcludeFiles(dest)) return;
|
|
279
|
+
if (
|
|
280
|
+
!answer.tailwindcss &&
|
|
281
|
+
(dest.includes("tailwind.css") || dest.includes("styles.css"))
|
|
282
|
+
)
|
|
283
|
+
return;
|
|
284
|
+
if (
|
|
285
|
+
!answer.websocket &&
|
|
286
|
+
(dest.includes("restart-websocket.cjs") ||
|
|
287
|
+
dest.includes("restart-websocket.bat"))
|
|
288
|
+
)
|
|
289
|
+
return;
|
|
290
|
+
if (!answer.docker && dockerFiles.some((file) => dest.includes(file))) {
|
|
291
|
+
return;
|
|
237
292
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
return;
|
|
244
|
-
if (!answer.websocket &&
|
|
245
|
-
(dest.includes("restart-websocket.cjs") ||
|
|
246
|
-
dest.includes("restart-websocket.bat")))
|
|
247
|
-
return;
|
|
248
|
-
if (!answer.docker && dockerFiles.some((file) => dest.includes(file))) {
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
if (answer.backendOnly &&
|
|
252
|
-
nonBackendFiles.some((file) => dest.includes(file))) {
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
if (!answer.backendOnly && dest.includes("route.php"))
|
|
256
|
-
return;
|
|
257
|
-
if (answer.backendOnly &&
|
|
258
|
-
!answer.swaggerDocs &&
|
|
259
|
-
(dest.includes("start-dev.js") || dest.includes("swagger-setup.js"))) {
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
fs.copyFileSync(src, dest, 0);
|
|
293
|
+
if (
|
|
294
|
+
answer.backendOnly &&
|
|
295
|
+
nonBackendFiles.some((file) => dest.includes(file))
|
|
296
|
+
) {
|
|
297
|
+
return;
|
|
263
298
|
}
|
|
299
|
+
if (!answer.backendOnly && dest.includes("route.php")) return;
|
|
300
|
+
if (
|
|
301
|
+
answer.backendOnly &&
|
|
302
|
+
!answer.swaggerDocs &&
|
|
303
|
+
(dest.includes("start-dev.js") || dest.includes("swagger-setup.js"))
|
|
304
|
+
) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
fs.copyFileSync(src, dest, 0);
|
|
308
|
+
}
|
|
264
309
|
}
|
|
265
310
|
// Function to execute the recursive copy for entire directories
|
|
266
311
|
async function executeCopy(baseDir, directoriesToCopy, answer) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
312
|
+
directoriesToCopy.forEach(({ srcDir, destDir }) => {
|
|
313
|
+
const sourcePath = path.join(__dirname, srcDir);
|
|
314
|
+
const destPath = path.join(baseDir, destDir);
|
|
315
|
+
copyRecursiveSync(sourcePath, destPath, answer);
|
|
316
|
+
});
|
|
272
317
|
}
|
|
273
318
|
function createOrUpdateTailwindConfig(baseDir) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
319
|
+
console.log("🚀 ~ createOrUpdateTailwindConfig ~ baseDir:", baseDir);
|
|
320
|
+
const filePath = path.join(baseDir, "tailwind.config.js");
|
|
321
|
+
if (checkExcludeFiles(filePath)) return;
|
|
322
|
+
const newContent = [
|
|
323
|
+
"./src/app/**/*.{html,js,php}",
|
|
324
|
+
// Add more paths as needed
|
|
325
|
+
];
|
|
326
|
+
let configData = fs.readFileSync(filePath, "utf8");
|
|
327
|
+
console.log("🚀 ~ createOrUpdateTailwindConfig ~ configData:", configData);
|
|
328
|
+
const contentArrayString = newContent
|
|
329
|
+
.map((item) => ` "${item}"`)
|
|
330
|
+
.join(",\n");
|
|
331
|
+
configData = configData.replace(
|
|
332
|
+
/content: \[\],/g,
|
|
333
|
+
`content: [\n${contentArrayString}\n],`
|
|
334
|
+
);
|
|
335
|
+
fs.writeFileSync(filePath, configData, { flag: "w" });
|
|
336
|
+
console.log(chalk.green("Tailwind configuration updated successfully."));
|
|
290
337
|
}
|
|
291
338
|
function modifyPostcssConfig(baseDir) {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
const newContent = `export default {
|
|
339
|
+
const filePath = path.join(baseDir, "postcss.config.js");
|
|
340
|
+
if (checkExcludeFiles(filePath)) return;
|
|
341
|
+
const newContent = `export default {
|
|
296
342
|
plugins: {
|
|
297
343
|
tailwindcss: {},
|
|
298
344
|
autoprefixer: {},
|
|
299
345
|
cssnano: {},
|
|
300
346
|
},
|
|
301
347
|
};`;
|
|
302
|
-
|
|
303
|
-
|
|
348
|
+
fs.writeFileSync(filePath, newContent, { flag: "w" });
|
|
349
|
+
console.log(chalk.green("postcss.config.js updated successfully."));
|
|
304
350
|
}
|
|
305
351
|
function modifyLayoutPHP(baseDir, answer) {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
352
|
+
const layoutPath = path.join(baseDir, "src", "app", "layout.php");
|
|
353
|
+
if (checkExcludeFiles(layoutPath)) return;
|
|
354
|
+
try {
|
|
355
|
+
let indexContent = fs.readFileSync(layoutPath, "utf8");
|
|
356
|
+
const stylesAndLinks = `\n <link href="<?php echo $baseUrl; ?>css/index.css" rel="stylesheet">\n <script src="<?php echo $baseUrl; ?>js/index.js"></script>`;
|
|
357
|
+
// Tailwind CSS link or CDN script
|
|
358
|
+
const tailwindLink = answer.tailwindcss
|
|
359
|
+
? ` <link href="<?php echo $baseUrl; ?>css/styles.css" rel="stylesheet"> ${stylesAndLinks}`
|
|
360
|
+
: ` <script src="https://cdn.tailwindcss.com"></script> ${stylesAndLinks}`;
|
|
361
|
+
// Insert before the closing </head> tag
|
|
362
|
+
indexContent = indexContent.replace("</head>", `${tailwindLink}\n</head>`);
|
|
363
|
+
fs.writeFileSync(layoutPath, indexContent, { flag: "w" });
|
|
364
|
+
console.log(
|
|
365
|
+
chalk.green(
|
|
366
|
+
`layout.php modified successfully for ${
|
|
367
|
+
answer.tailwindcss ? "local Tailwind CSS" : "Tailwind CSS CDN"
|
|
368
|
+
}.`
|
|
369
|
+
)
|
|
370
|
+
);
|
|
371
|
+
} catch (error) {
|
|
372
|
+
console.error(chalk.red("Error modifying layout.php:"), error);
|
|
373
|
+
}
|
|
324
374
|
}
|
|
325
375
|
// This function updates or creates the .env file
|
|
326
376
|
async function createOrUpdateEnvFile(baseDir, content) {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
fs.writeFileSync(envPath, content, { flag: "w" });
|
|
377
|
+
const envPath = path.join(baseDir, ".env");
|
|
378
|
+
if (checkExcludeFiles(envPath)) return;
|
|
379
|
+
console.log("🚀 ~ content:", content);
|
|
380
|
+
fs.writeFileSync(envPath, content, { flag: "w" });
|
|
332
381
|
}
|
|
333
382
|
function checkExcludeFiles(destPath) {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
383
|
+
var _a, _b;
|
|
384
|
+
if (
|
|
385
|
+
!(updateAnswer === null || updateAnswer === void 0
|
|
386
|
+
? void 0
|
|
387
|
+
: updateAnswer.isUpdate)
|
|
388
|
+
)
|
|
389
|
+
return false;
|
|
390
|
+
return (_b =
|
|
391
|
+
(_a =
|
|
392
|
+
updateAnswer === null || updateAnswer === void 0
|
|
393
|
+
? void 0
|
|
394
|
+
: updateAnswer.excludeFilePath) === null || _a === void 0
|
|
395
|
+
? void 0
|
|
396
|
+
: _a.includes(destPath.replace(/\\/g, "/"))) !== null && _b !== void 0
|
|
397
|
+
? _b
|
|
398
|
+
: false;
|
|
338
399
|
}
|
|
339
400
|
async function createDirectoryStructure(baseDir, answer) {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
{
|
|
359
|
-
srcDir: "/src",
|
|
360
|
-
destDir: "/src",
|
|
361
|
-
},
|
|
362
|
-
];
|
|
363
|
-
if (answer.backendOnly && answer.swaggerDocs) {
|
|
364
|
-
directoriesToCopy.push({
|
|
365
|
-
srcDir: "/swagger-docs-layout.php",
|
|
366
|
-
destDir: "/src/app/layout.php",
|
|
367
|
-
}, {
|
|
368
|
-
srcDir: "/swagger-docs-index.php",
|
|
369
|
-
destDir: "/src/app/swagger-docs/index.php",
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
if (answer.prisma) {
|
|
373
|
-
directoriesToCopy.push({
|
|
374
|
-
srcDir: "/prisma",
|
|
375
|
-
destDir: "/prisma",
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
if (answer.docker) {
|
|
379
|
-
directoriesToCopy.push({ srcDir: "/.dockerignore", destDir: "/.dockerignore" }, { srcDir: "/docker-compose.yml", destDir: "/docker-compose.yml" }, { srcDir: "/Dockerfile", destDir: "/Dockerfile" }, { srcDir: "/apache.conf", destDir: "/apache.conf" });
|
|
401
|
+
console.log("🚀 ~ baseDir:", baseDir);
|
|
402
|
+
console.log("🚀 ~ answer:", answer);
|
|
403
|
+
const filesToCopy = [
|
|
404
|
+
{ src: "/bootstrap.php", dest: "/bootstrap.php" },
|
|
405
|
+
{ src: "/.htaccess", dest: "/.htaccess" },
|
|
406
|
+
{ src: "/../composer.json", dest: "/composer.json" },
|
|
407
|
+
];
|
|
408
|
+
if (
|
|
409
|
+
updateAnswer === null || updateAnswer === void 0
|
|
410
|
+
? void 0
|
|
411
|
+
: updateAnswer.isUpdate
|
|
412
|
+
) {
|
|
413
|
+
filesToCopy.push({ src: "/tsconfig.json", dest: "/tsconfig.json" });
|
|
414
|
+
if (updateAnswer.tailwindcss) {
|
|
415
|
+
filesToCopy.push(
|
|
416
|
+
{ src: "/postcss.config.js", dest: "/postcss.config.js" },
|
|
417
|
+
{ src: "/tailwind.config.js", dest: "/tailwind.config.js" }
|
|
418
|
+
);
|
|
380
419
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
420
|
+
}
|
|
421
|
+
const directoriesToCopy = [
|
|
422
|
+
{
|
|
423
|
+
srcDir: "/settings",
|
|
424
|
+
destDir: "/settings",
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
srcDir: "/src",
|
|
428
|
+
destDir: "/src",
|
|
429
|
+
},
|
|
430
|
+
];
|
|
431
|
+
if (answer.backendOnly && answer.swaggerDocs) {
|
|
432
|
+
directoriesToCopy.push(
|
|
433
|
+
{
|
|
434
|
+
srcDir: "/swagger-docs-layout.php",
|
|
435
|
+
destDir: "/src/app/layout.php",
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
srcDir: "/swagger-docs-index.php",
|
|
439
|
+
destDir: "/src/app/swagger-docs/index.php",
|
|
440
|
+
}
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
if (answer.prisma) {
|
|
444
|
+
directoriesToCopy.push({
|
|
445
|
+
srcDir: "/prisma",
|
|
446
|
+
destDir: "/prisma",
|
|
389
447
|
});
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
const
|
|
448
|
+
}
|
|
449
|
+
if (answer.docker) {
|
|
450
|
+
directoriesToCopy.push(
|
|
451
|
+
{ srcDir: "/.dockerignore", destDir: "/.dockerignore" },
|
|
452
|
+
{ srcDir: "/docker-compose.yml", destDir: "/docker-compose.yml" },
|
|
453
|
+
{ srcDir: "/Dockerfile", destDir: "/Dockerfile" },
|
|
454
|
+
{ srcDir: "/apache.conf", destDir: "/apache.conf" }
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
console.log("🚀 ~ directoriesToCopy:", directoriesToCopy);
|
|
458
|
+
filesToCopy.forEach(({ src, dest }) => {
|
|
459
|
+
const sourcePath = path.join(__dirname, src);
|
|
460
|
+
const destPath = path.join(baseDir, dest);
|
|
461
|
+
if (checkExcludeFiles(destPath)) return;
|
|
462
|
+
const code = fs.readFileSync(sourcePath, "utf8");
|
|
463
|
+
fs.writeFileSync(destPath, code, { flag: "w" });
|
|
464
|
+
});
|
|
465
|
+
await executeCopy(baseDir, directoriesToCopy, answer);
|
|
466
|
+
await updatePackageJson(baseDir, answer);
|
|
467
|
+
await updateComposerJson(baseDir, answer);
|
|
468
|
+
if (!answer.backendOnly) await updateIndexJsForWebSocket(baseDir, answer);
|
|
469
|
+
if (answer.tailwindcss) {
|
|
470
|
+
createOrUpdateTailwindConfig(baseDir);
|
|
471
|
+
modifyLayoutPHP(baseDir, answer);
|
|
472
|
+
modifyPostcssConfig(baseDir);
|
|
473
|
+
} else {
|
|
474
|
+
if (!answer.backendOnly) modifyLayoutPHP(baseDir, answer);
|
|
475
|
+
}
|
|
476
|
+
const prismaPHPEnvContent = `# Prisma PHP Auth Secret Key For development only - Change this in production
|
|
405
477
|
AUTH_SECRET=uxsjXVPHN038DEYls2Kw0QUgBcXKUyrjv416nIFWPY4=
|
|
406
478
|
|
|
407
479
|
# PHPMailer
|
|
@@ -421,164 +493,200 @@ SHOW_ERRORS=true
|
|
|
421
493
|
|
|
422
494
|
# APP TIMEZONE - Set your application timezone - Default is "UTC"
|
|
423
495
|
APP_TIMEZONE="UTC"`;
|
|
424
|
-
|
|
425
|
-
|
|
496
|
+
if (answer.prisma) {
|
|
497
|
+
const prismaEnvContent = `# Environment variables declared in this file are automatically made available to Prisma.
|
|
426
498
|
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
|
|
427
499
|
|
|
428
500
|
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
|
|
429
501
|
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
|
|
430
502
|
|
|
431
503
|
DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"`;
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
await createUpdateGitignoreFile(baseDir, ["vendor", ".env", "node_modules"]);
|
|
504
|
+
const envContent = `${prismaEnvContent}\n\n${prismaPHPEnvContent}`;
|
|
505
|
+
await createOrUpdateEnvFile(baseDir, envContent);
|
|
506
|
+
} else {
|
|
507
|
+
await createOrUpdateEnvFile(baseDir, prismaPHPEnvContent);
|
|
508
|
+
}
|
|
509
|
+
// Add vendor to .gitignore
|
|
510
|
+
await createUpdateGitignoreFile(baseDir, ["vendor", ".env", "node_modules"]);
|
|
440
511
|
}
|
|
441
512
|
async function getAnswer(predefinedAnswers = {}) {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
513
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
514
|
+
console.log("🚀 ~ predefinedAnswers:", predefinedAnswers);
|
|
515
|
+
const questionsArray = [];
|
|
516
|
+
if (!predefinedAnswers.projectName) {
|
|
517
|
+
questionsArray.push({
|
|
518
|
+
type: "text",
|
|
519
|
+
name: "projectName",
|
|
520
|
+
message: "What is your project named?",
|
|
521
|
+
initial: "my-app",
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
if (!predefinedAnswers.backendOnly) {
|
|
525
|
+
questionsArray.push({
|
|
526
|
+
type: "toggle",
|
|
527
|
+
name: "backendOnly",
|
|
528
|
+
message: "Would you like to create a backend-only project?",
|
|
529
|
+
initial: false,
|
|
530
|
+
active: "Yes",
|
|
531
|
+
inactive: "No",
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
// Execute the initial questionsArray first
|
|
535
|
+
const onCancel = () => {
|
|
536
|
+
console.log(chalk.red("Operation cancelled by the user."));
|
|
537
|
+
process.exit(0);
|
|
538
|
+
};
|
|
539
|
+
const initialResponse = await prompts(questionsArray, { onCancel });
|
|
540
|
+
console.log("🚀 ~ initialResponse:", initialResponse);
|
|
541
|
+
const nonBackendOnlyQuestionsArray = [];
|
|
542
|
+
if (initialResponse.backendOnly || predefinedAnswers.backendOnly) {
|
|
543
|
+
// If it's a backend-only project, skip Tailwind CSS, but ask other questions
|
|
544
|
+
if (!predefinedAnswers.swaggerDocs) {
|
|
545
|
+
nonBackendOnlyQuestionsArray.push({
|
|
546
|
+
type: "toggle",
|
|
547
|
+
name: "swaggerDocs",
|
|
548
|
+
message: `Would you like to use ${chalk.blue("Swagger Docs")}?`,
|
|
549
|
+
initial: false,
|
|
550
|
+
active: "Yes",
|
|
551
|
+
inactive: "No",
|
|
552
|
+
});
|
|
452
553
|
}
|
|
453
|
-
if (!predefinedAnswers.
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
554
|
+
if (!predefinedAnswers.websocket) {
|
|
555
|
+
nonBackendOnlyQuestionsArray.push({
|
|
556
|
+
type: "toggle",
|
|
557
|
+
name: "websocket",
|
|
558
|
+
message: `Would you like to use ${chalk.blue("Websocket")}?`,
|
|
559
|
+
initial: true,
|
|
560
|
+
active: "Yes",
|
|
561
|
+
inactive: "No",
|
|
562
|
+
});
|
|
462
563
|
}
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
// If it's a backend-only project, skip Tailwind CSS, but ask other questions
|
|
473
|
-
if (!predefinedAnswers.swaggerDocs) {
|
|
474
|
-
nonBackendOnlyQuestionsArray.push({
|
|
475
|
-
type: "toggle",
|
|
476
|
-
name: "swaggerDocs",
|
|
477
|
-
message: `Would you like to use ${chalk.blue("Swagger Docs")}?`,
|
|
478
|
-
initial: false,
|
|
479
|
-
active: "Yes",
|
|
480
|
-
inactive: "No",
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
|
-
if (!predefinedAnswers.websocket) {
|
|
484
|
-
nonBackendOnlyQuestionsArray.push({
|
|
485
|
-
type: "toggle",
|
|
486
|
-
name: "websocket",
|
|
487
|
-
message: `Would you like to use ${chalk.blue("Websocket")}?`,
|
|
488
|
-
initial: true,
|
|
489
|
-
active: "Yes",
|
|
490
|
-
inactive: "No",
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
if (!predefinedAnswers.prisma) {
|
|
494
|
-
nonBackendOnlyQuestionsArray.push({
|
|
495
|
-
type: "toggle",
|
|
496
|
-
name: "prisma",
|
|
497
|
-
message: `Would you like to use ${chalk.blue("Prisma PHP ORM")}?`,
|
|
498
|
-
initial: true,
|
|
499
|
-
active: "Yes",
|
|
500
|
-
inactive: "No",
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
|
-
if (!predefinedAnswers.docker) {
|
|
504
|
-
nonBackendOnlyQuestionsArray.push({
|
|
505
|
-
type: "toggle",
|
|
506
|
-
name: "docker",
|
|
507
|
-
message: `Would you like to use ${chalk.blue("Docker")}?`,
|
|
508
|
-
initial: false,
|
|
509
|
-
active: "Yes",
|
|
510
|
-
inactive: "No",
|
|
511
|
-
});
|
|
512
|
-
}
|
|
564
|
+
if (!predefinedAnswers.prisma) {
|
|
565
|
+
nonBackendOnlyQuestionsArray.push({
|
|
566
|
+
type: "toggle",
|
|
567
|
+
name: "prisma",
|
|
568
|
+
message: `Would you like to use ${chalk.blue("Prisma PHP ORM")}?`,
|
|
569
|
+
initial: true,
|
|
570
|
+
active: "Yes",
|
|
571
|
+
inactive: "No",
|
|
572
|
+
});
|
|
513
573
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
inactive: "No",
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
if (!predefinedAnswers.tailwindcss) {
|
|
527
|
-
nonBackendOnlyQuestionsArray.unshift({
|
|
528
|
-
type: "toggle",
|
|
529
|
-
name: "tailwindcss",
|
|
530
|
-
message: `Would you like to use ${chalk.blue("Tailwind CSS")}?`,
|
|
531
|
-
initial: true,
|
|
532
|
-
active: "Yes",
|
|
533
|
-
inactive: "No",
|
|
534
|
-
});
|
|
535
|
-
}
|
|
536
|
-
if (!predefinedAnswers.websocket) {
|
|
537
|
-
nonBackendOnlyQuestionsArray.push({
|
|
538
|
-
type: "toggle",
|
|
539
|
-
name: "websocket",
|
|
540
|
-
message: `Would you like to use ${chalk.blue("Websocket")}?`,
|
|
541
|
-
initial: true,
|
|
542
|
-
active: "Yes",
|
|
543
|
-
inactive: "No",
|
|
544
|
-
});
|
|
545
|
-
}
|
|
546
|
-
if (!predefinedAnswers.prisma) {
|
|
547
|
-
nonBackendOnlyQuestionsArray.push({
|
|
548
|
-
type: "toggle",
|
|
549
|
-
name: "prisma",
|
|
550
|
-
message: `Would you like to use ${chalk.blue("Prisma PHP ORM")}?`,
|
|
551
|
-
initial: true,
|
|
552
|
-
active: "Yes",
|
|
553
|
-
inactive: "No",
|
|
554
|
-
});
|
|
555
|
-
}
|
|
556
|
-
if (!predefinedAnswers.docker) {
|
|
557
|
-
nonBackendOnlyQuestionsArray.push({
|
|
558
|
-
type: "toggle",
|
|
559
|
-
name: "docker",
|
|
560
|
-
message: `Would you like to use ${chalk.blue("Docker")}?`,
|
|
561
|
-
initial: false,
|
|
562
|
-
active: "Yes",
|
|
563
|
-
inactive: "No",
|
|
564
|
-
});
|
|
565
|
-
}
|
|
574
|
+
if (!predefinedAnswers.docker) {
|
|
575
|
+
nonBackendOnlyQuestionsArray.push({
|
|
576
|
+
type: "toggle",
|
|
577
|
+
name: "docker",
|
|
578
|
+
message: `Would you like to use ${chalk.blue("Docker")}?`,
|
|
579
|
+
initial: false,
|
|
580
|
+
active: "Yes",
|
|
581
|
+
inactive: "No",
|
|
582
|
+
});
|
|
566
583
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
584
|
+
} else {
|
|
585
|
+
// If it's not a backend-only project, ask Tailwind CSS as well
|
|
586
|
+
if (!predefinedAnswers.swaggerDocs) {
|
|
587
|
+
nonBackendOnlyQuestionsArray.push({
|
|
588
|
+
type: "toggle",
|
|
589
|
+
name: "swaggerDocs",
|
|
590
|
+
message: `Would you like to use ${chalk.blue("Swagger Docs")}?`,
|
|
591
|
+
initial: false,
|
|
592
|
+
active: "Yes",
|
|
593
|
+
inactive: "No",
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
if (!predefinedAnswers.tailwindcss) {
|
|
597
|
+
nonBackendOnlyQuestionsArray.push({
|
|
598
|
+
type: "toggle",
|
|
599
|
+
name: "tailwindcss",
|
|
600
|
+
message: `Would you like to use ${chalk.blue("Tailwind CSS")}?`,
|
|
601
|
+
initial: true,
|
|
602
|
+
active: "Yes",
|
|
603
|
+
inactive: "No",
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
if (!predefinedAnswers.websocket) {
|
|
607
|
+
nonBackendOnlyQuestionsArray.push({
|
|
608
|
+
type: "toggle",
|
|
609
|
+
name: "websocket",
|
|
610
|
+
message: `Would you like to use ${chalk.blue("Websocket")}?`,
|
|
611
|
+
initial: true,
|
|
612
|
+
active: "Yes",
|
|
613
|
+
inactive: "No",
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
if (!predefinedAnswers.prisma) {
|
|
617
|
+
nonBackendOnlyQuestionsArray.push({
|
|
618
|
+
type: "toggle",
|
|
619
|
+
name: "prisma",
|
|
620
|
+
message: `Would you like to use ${chalk.blue("Prisma PHP ORM")}?`,
|
|
621
|
+
initial: true,
|
|
622
|
+
active: "Yes",
|
|
623
|
+
inactive: "No",
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
if (!predefinedAnswers.docker) {
|
|
627
|
+
nonBackendOnlyQuestionsArray.push({
|
|
628
|
+
type: "toggle",
|
|
629
|
+
name: "docker",
|
|
630
|
+
message: `Would you like to use ${chalk.blue("Docker")}?`,
|
|
631
|
+
initial: false,
|
|
632
|
+
active: "Yes",
|
|
633
|
+
inactive: "No",
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
const nonBackendOnlyResponse = await prompts(nonBackendOnlyQuestionsArray, {
|
|
638
|
+
onCancel,
|
|
639
|
+
});
|
|
640
|
+
console.log("🚀 ~ nonBackendOnlyResponse:", nonBackendOnlyResponse);
|
|
641
|
+
return {
|
|
642
|
+
projectName: initialResponse.projectName
|
|
643
|
+
? String(initialResponse.projectName).trim().replace(/ /g, "-")
|
|
644
|
+
: (_a = predefinedAnswers.projectName) !== null && _a !== void 0
|
|
645
|
+
? _a
|
|
646
|
+
: "my-app",
|
|
647
|
+
backendOnly:
|
|
648
|
+
(_c =
|
|
649
|
+
(_b = initialResponse.backendOnly) !== null && _b !== void 0
|
|
650
|
+
? _b
|
|
651
|
+
: predefinedAnswers.backendOnly) !== null && _c !== void 0
|
|
652
|
+
? _c
|
|
653
|
+
: false,
|
|
654
|
+
swaggerDocs:
|
|
655
|
+
(_e =
|
|
656
|
+
(_d = nonBackendOnlyResponse.swaggerDocs) !== null && _d !== void 0
|
|
657
|
+
? _d
|
|
658
|
+
: predefinedAnswers.swaggerDocs) !== null && _e !== void 0
|
|
659
|
+
? _e
|
|
660
|
+
: false,
|
|
661
|
+
tailwindcss:
|
|
662
|
+
(_g =
|
|
663
|
+
(_f = nonBackendOnlyResponse.tailwindcss) !== null && _f !== void 0
|
|
664
|
+
? _f
|
|
665
|
+
: predefinedAnswers.tailwindcss) !== null && _g !== void 0
|
|
666
|
+
? _g
|
|
667
|
+
: false,
|
|
668
|
+
websocket:
|
|
669
|
+
(_j =
|
|
670
|
+
(_h = nonBackendOnlyResponse.websocket) !== null && _h !== void 0
|
|
671
|
+
? _h
|
|
672
|
+
: predefinedAnswers.websocket) !== null && _j !== void 0
|
|
673
|
+
? _j
|
|
674
|
+
: false,
|
|
675
|
+
prisma:
|
|
676
|
+
(_l =
|
|
677
|
+
(_k = nonBackendOnlyResponse.prisma) !== null && _k !== void 0
|
|
678
|
+
? _k
|
|
679
|
+
: predefinedAnswers.prisma) !== null && _l !== void 0
|
|
680
|
+
? _l
|
|
681
|
+
: false,
|
|
682
|
+
docker:
|
|
683
|
+
(_o =
|
|
684
|
+
(_m = nonBackendOnlyResponse.docker) !== null && _m !== void 0
|
|
685
|
+
? _m
|
|
686
|
+
: predefinedAnswers.docker) !== null && _o !== void 0
|
|
687
|
+
? _o
|
|
688
|
+
: false,
|
|
689
|
+
};
|
|
582
690
|
}
|
|
583
691
|
/**
|
|
584
692
|
* Install dependencies in the specified directory.
|
|
@@ -587,334 +695,429 @@ async function getAnswer(predefinedAnswers = {}) {
|
|
|
587
695
|
* @param {boolean} [isDev=false] - Whether to install the dependencies as devDependencies.
|
|
588
696
|
*/
|
|
589
697
|
async function installDependencies(baseDir, dependencies, isDev = false) {
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
});
|
|
597
|
-
// Log the dependencies being installed
|
|
598
|
-
console.log(`${isDev ? "Installing development dependencies" : "Installing dependencies"}:`);
|
|
599
|
-
dependencies.forEach((dep) => console.log(`- ${chalk.blue(dep)}`));
|
|
600
|
-
// Prepare the npm install command with the appropriate flag for dev dependencies
|
|
601
|
-
const npmInstallCommand = `npm install ${isDev ? "--save-dev" : ""} ${dependencies.join(" ")}`;
|
|
602
|
-
// Execute the npm install command
|
|
603
|
-
execSync(npmInstallCommand, {
|
|
604
|
-
stdio: "inherit",
|
|
605
|
-
cwd: baseDir,
|
|
698
|
+
console.log("Initializing new Node.js project...");
|
|
699
|
+
// Initialize a package.json if it doesn't exist
|
|
700
|
+
if (!fs.existsSync(path.join(baseDir, "package.json")))
|
|
701
|
+
execSync("npm init -y", {
|
|
702
|
+
stdio: "inherit",
|
|
703
|
+
cwd: baseDir,
|
|
606
704
|
});
|
|
705
|
+
// Log the dependencies being installed
|
|
706
|
+
console.log(
|
|
707
|
+
`${
|
|
708
|
+
isDev ? "Installing development dependencies" : "Installing dependencies"
|
|
709
|
+
}:`
|
|
710
|
+
);
|
|
711
|
+
dependencies.forEach((dep) => console.log(`- ${chalk.blue(dep)}`));
|
|
712
|
+
// Prepare the npm install command with the appropriate flag for dev dependencies
|
|
713
|
+
const npmInstallCommand = `npm install ${
|
|
714
|
+
isDev ? "--save-dev" : ""
|
|
715
|
+
} ${dependencies.join(" ")}`;
|
|
716
|
+
// Execute the npm install command
|
|
717
|
+
execSync(npmInstallCommand, {
|
|
718
|
+
stdio: "inherit",
|
|
719
|
+
cwd: baseDir,
|
|
720
|
+
});
|
|
607
721
|
}
|
|
608
722
|
async function uninstallDependencies(baseDir, dependencies, isDev = false) {
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
723
|
+
console.log("Uninstalling dependencies:");
|
|
724
|
+
dependencies.forEach((dep) => console.log(`- ${chalk.blue(dep)}`));
|
|
725
|
+
// Prepare the npm uninstall command with the appropriate flag for dev dependencies
|
|
726
|
+
const npmUninstallCommand = `npm uninstall ${
|
|
727
|
+
isDev ? "--save-dev" : "--save"
|
|
728
|
+
} ${dependencies.join(" ")}`;
|
|
729
|
+
// Execute the npm uninstall command
|
|
730
|
+
execSync(npmUninstallCommand, {
|
|
731
|
+
stdio: "inherit",
|
|
732
|
+
cwd: baseDir,
|
|
733
|
+
});
|
|
618
734
|
}
|
|
619
735
|
function fetchPackageVersion(packageName) {
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
});
|
|
736
|
+
return new Promise((resolve, reject) => {
|
|
737
|
+
https
|
|
738
|
+
.get(`https://registry.npmjs.org/${packageName}`, (res) => {
|
|
739
|
+
let data = "";
|
|
740
|
+
res.on("data", (chunk) => (data += chunk));
|
|
741
|
+
res.on("end", () => {
|
|
742
|
+
try {
|
|
743
|
+
const parsed = JSON.parse(data);
|
|
744
|
+
resolve(parsed["dist-tags"].latest);
|
|
745
|
+
} catch (error) {
|
|
746
|
+
reject(new Error("Failed to parse JSON response"));
|
|
747
|
+
}
|
|
748
|
+
});
|
|
749
|
+
})
|
|
750
|
+
.on("error", (err) => reject(err));
|
|
751
|
+
});
|
|
637
752
|
}
|
|
638
753
|
const readJsonFile = (filePath) => {
|
|
639
|
-
|
|
640
|
-
|
|
754
|
+
const jsonData = fs.readFileSync(filePath, "utf8");
|
|
755
|
+
return JSON.parse(jsonData);
|
|
641
756
|
};
|
|
642
757
|
function compareVersions(installedVersion, currentVersion) {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
return -1;
|
|
651
|
-
}
|
|
758
|
+
const installedVersionArray = installedVersion.split(".").map(Number);
|
|
759
|
+
const currentVersionArray = currentVersion.split(".").map(Number);
|
|
760
|
+
for (let i = 0; i < installedVersionArray.length; i++) {
|
|
761
|
+
if (installedVersionArray[i] > currentVersionArray[i]) {
|
|
762
|
+
return 1;
|
|
763
|
+
} else if (installedVersionArray[i] < currentVersionArray[i]) {
|
|
764
|
+
return -1;
|
|
652
765
|
}
|
|
653
|
-
|
|
766
|
+
}
|
|
767
|
+
return 0;
|
|
654
768
|
}
|
|
655
769
|
function getInstalledPackageVersion(packageName) {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
}
|
|
667
|
-
catch (error) {
|
|
668
|
-
console.error(error instanceof Error ? error.message : String(error));
|
|
669
|
-
return null;
|
|
770
|
+
try {
|
|
771
|
+
const output = execSync(`npm list -g ${packageName} --depth=0`).toString();
|
|
772
|
+
const versionMatch = output.match(
|
|
773
|
+
new RegExp(`${packageName}@(\\d+\\.\\d+\\.\\d+)`)
|
|
774
|
+
);
|
|
775
|
+
if (versionMatch) {
|
|
776
|
+
return versionMatch[1];
|
|
777
|
+
} else {
|
|
778
|
+
console.error(`Package ${packageName} is not installed`);
|
|
779
|
+
return null;
|
|
670
780
|
}
|
|
781
|
+
} catch (error) {
|
|
782
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
783
|
+
return null;
|
|
784
|
+
}
|
|
671
785
|
}
|
|
672
786
|
async function main() {
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
787
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
788
|
+
try {
|
|
789
|
+
const args = process.argv.slice(2);
|
|
790
|
+
let projectName = args[0];
|
|
791
|
+
let answer = null;
|
|
792
|
+
if (projectName) {
|
|
793
|
+
let useBackendOnly = args.includes("--backend-only");
|
|
794
|
+
let useSwaggerDocs = args.includes("--swagger-docs");
|
|
795
|
+
let useTailwind = args.includes("--tailwindcss");
|
|
796
|
+
let useWebsocket = args.includes("--websocket");
|
|
797
|
+
let usePrisma = args.includes("--prisma");
|
|
798
|
+
let useDocker = args.includes("--docker");
|
|
799
|
+
const predefinedAnswers = {
|
|
800
|
+
projectName,
|
|
801
|
+
backendOnly: useBackendOnly,
|
|
802
|
+
swaggerDocs: useSwaggerDocs,
|
|
803
|
+
tailwindcss: useTailwind,
|
|
804
|
+
websocket: useWebsocket,
|
|
805
|
+
prisma: usePrisma,
|
|
806
|
+
docker: useDocker,
|
|
807
|
+
};
|
|
808
|
+
console.log("🚀 ~ main ~ predefinedAnswers:", predefinedAnswers);
|
|
809
|
+
answer = await getAnswer(predefinedAnswers);
|
|
810
|
+
if (answer === null) {
|
|
811
|
+
console.log(chalk.red("Installation cancelled."));
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
const currentDir = process.cwd();
|
|
815
|
+
const configPath = path.join(currentDir, "prisma-php.json");
|
|
816
|
+
const localSettings = readJsonFile(configPath);
|
|
817
|
+
let excludeFiles = [];
|
|
818
|
+
(_a = localSettings.excludeFiles) === null || _a === void 0
|
|
819
|
+
? void 0
|
|
820
|
+
: _a.map((file) => {
|
|
821
|
+
const filePath = path.join(currentDir, file);
|
|
822
|
+
if (fs.existsSync(filePath))
|
|
823
|
+
excludeFiles.push(filePath.replace(/\\/g, "/"));
|
|
824
|
+
});
|
|
825
|
+
updateAnswer = {
|
|
826
|
+
projectName,
|
|
827
|
+
backendOnly:
|
|
828
|
+
(_b =
|
|
829
|
+
answer === null || answer === void 0
|
|
830
|
+
? void 0
|
|
831
|
+
: answer.backendOnly) !== null && _b !== void 0
|
|
832
|
+
? _b
|
|
833
|
+
: false,
|
|
834
|
+
swaggerDocs:
|
|
835
|
+
(_c =
|
|
836
|
+
answer === null || answer === void 0
|
|
837
|
+
? void 0
|
|
838
|
+
: answer.swaggerDocs) !== null && _c !== void 0
|
|
839
|
+
? _c
|
|
840
|
+
: false,
|
|
841
|
+
tailwindcss:
|
|
842
|
+
(_d =
|
|
843
|
+
answer === null || answer === void 0
|
|
844
|
+
? void 0
|
|
845
|
+
: answer.tailwindcss) !== null && _d !== void 0
|
|
846
|
+
? _d
|
|
847
|
+
: false,
|
|
848
|
+
websocket:
|
|
849
|
+
(_e =
|
|
850
|
+
answer === null || answer === void 0
|
|
851
|
+
? void 0
|
|
852
|
+
: answer.websocket) !== null && _e !== void 0
|
|
853
|
+
? _e
|
|
854
|
+
: false,
|
|
855
|
+
prisma:
|
|
856
|
+
(_f =
|
|
857
|
+
answer === null || answer === void 0 ? void 0 : answer.prisma) !==
|
|
858
|
+
null && _f !== void 0
|
|
859
|
+
? _f
|
|
860
|
+
: false,
|
|
861
|
+
docker:
|
|
862
|
+
(_g =
|
|
863
|
+
answer === null || answer === void 0 ? void 0 : answer.docker) !==
|
|
864
|
+
null && _g !== void 0
|
|
865
|
+
? _g
|
|
866
|
+
: false,
|
|
867
|
+
isUpdate: true,
|
|
868
|
+
excludeFiles:
|
|
869
|
+
(_h = localSettings.excludeFiles) !== null && _h !== void 0 ? _h : [],
|
|
870
|
+
excludeFilePath:
|
|
871
|
+
excludeFiles !== null && excludeFiles !== void 0 ? excludeFiles : [],
|
|
872
|
+
filePath: currentDir,
|
|
873
|
+
};
|
|
874
|
+
} else {
|
|
875
|
+
answer = await getAnswer();
|
|
876
|
+
}
|
|
877
|
+
if (answer === null) {
|
|
878
|
+
console.log(chalk.red("Installation cancelled."));
|
|
879
|
+
return;
|
|
880
|
+
}
|
|
881
|
+
const latestVersionOfCreatePrismaPhpApp = await fetchPackageVersion(
|
|
882
|
+
"create-prisma-php-app"
|
|
883
|
+
);
|
|
884
|
+
const isCreatePrismaPhpAppInstalled = getInstalledPackageVersion(
|
|
885
|
+
"create-prisma-php-app"
|
|
886
|
+
);
|
|
887
|
+
if (isCreatePrismaPhpAppInstalled) {
|
|
888
|
+
if (
|
|
889
|
+
compareVersions(
|
|
890
|
+
isCreatePrismaPhpAppInstalled,
|
|
891
|
+
latestVersionOfCreatePrismaPhpApp
|
|
892
|
+
) === -1
|
|
893
|
+
) {
|
|
894
|
+
execSync(`npm uninstall -g create-prisma-php-app`, {
|
|
895
|
+
stdio: "inherit",
|
|
896
|
+
});
|
|
897
|
+
execSync(`npm install -g create-prisma-php-app`, {
|
|
898
|
+
stdio: "inherit",
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
} else {
|
|
902
|
+
execSync("npm install -g create-prisma-php-app", { stdio: "inherit" });
|
|
903
|
+
}
|
|
904
|
+
const latestVersionOfBrowserSync = await fetchPackageVersion(
|
|
905
|
+
"browser-sync"
|
|
906
|
+
);
|
|
907
|
+
const isBrowserSyncInstalled = getInstalledPackageVersion("browser-sync");
|
|
908
|
+
if (isBrowserSyncInstalled) {
|
|
909
|
+
if (
|
|
910
|
+
compareVersions(isBrowserSyncInstalled, latestVersionOfBrowserSync) ===
|
|
911
|
+
-1
|
|
912
|
+
) {
|
|
913
|
+
execSync(`npm uninstall -g browser-sync`, {
|
|
914
|
+
stdio: "inherit",
|
|
915
|
+
});
|
|
916
|
+
execSync(`npm install -g browser-sync`, {
|
|
917
|
+
stdio: "inherit",
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
} else {
|
|
921
|
+
execSync("npm install -g browser-sync", { stdio: "inherit" });
|
|
922
|
+
}
|
|
923
|
+
// Create the project directory
|
|
924
|
+
if (!projectName) fs.mkdirSync(answer.projectName);
|
|
925
|
+
const currentDir = process.cwd();
|
|
926
|
+
let projectPath = projectName
|
|
927
|
+
? currentDir
|
|
928
|
+
: path.join(currentDir, answer.projectName);
|
|
929
|
+
if (!projectName) process.chdir(answer.projectName);
|
|
930
|
+
const dependencies = [
|
|
931
|
+
"typescript",
|
|
932
|
+
"@types/node",
|
|
933
|
+
"ts-node",
|
|
934
|
+
"http-proxy-middleware@^3.0.0",
|
|
935
|
+
"chalk",
|
|
936
|
+
];
|
|
937
|
+
if (answer.swaggerDocs) {
|
|
938
|
+
dependencies.push("swagger-jsdoc");
|
|
939
|
+
}
|
|
940
|
+
if (!answer.backendOnly && !answer.swaggerDocs) {
|
|
941
|
+
dependencies.push("npm-run-all");
|
|
942
|
+
}
|
|
943
|
+
if (answer.tailwindcss) {
|
|
944
|
+
dependencies.push(
|
|
945
|
+
"tailwindcss",
|
|
946
|
+
"autoprefixer",
|
|
947
|
+
"postcss",
|
|
948
|
+
"postcss-cli",
|
|
949
|
+
"cssnano"
|
|
950
|
+
);
|
|
951
|
+
}
|
|
952
|
+
if (answer.websocket) {
|
|
953
|
+
dependencies.push("chokidar-cli");
|
|
954
|
+
}
|
|
955
|
+
if (answer.prisma) {
|
|
956
|
+
dependencies.push("prisma", "@prisma/client");
|
|
957
|
+
}
|
|
958
|
+
await installDependencies(projectPath, dependencies, true);
|
|
959
|
+
if (!projectName) {
|
|
960
|
+
execSync(`npx tsc --init`, { stdio: "inherit" });
|
|
961
|
+
}
|
|
962
|
+
if (answer.tailwindcss)
|
|
963
|
+
execSync(`npx tailwindcss init -p`, { stdio: "inherit" });
|
|
964
|
+
if (answer.prisma) {
|
|
965
|
+
if (!fs.existsSync(path.join(projectPath, "prisma")))
|
|
966
|
+
execSync(`npx prisma init`, { stdio: "inherit" });
|
|
967
|
+
}
|
|
968
|
+
await createDirectoryStructure(projectPath, answer);
|
|
969
|
+
const publicDirPath = path.join(projectPath, "public");
|
|
970
|
+
if (!fs.existsSync(publicDirPath)) {
|
|
971
|
+
fs.mkdirSync(publicDirPath);
|
|
972
|
+
}
|
|
973
|
+
if (
|
|
974
|
+
updateAnswer === null || updateAnswer === void 0
|
|
975
|
+
? void 0
|
|
976
|
+
: updateAnswer.isUpdate
|
|
977
|
+
) {
|
|
978
|
+
const updateUninstallDependencies = [];
|
|
979
|
+
if (updateAnswer.backendOnly) {
|
|
980
|
+
nonBackendFiles.forEach((file) => {
|
|
981
|
+
const filePath = path.join(projectPath, "src", "app", file);
|
|
982
|
+
if (fs.existsSync(filePath)) {
|
|
983
|
+
fs.unlinkSync(filePath); // Delete each file if it exists
|
|
984
|
+
console.log(`${file} was deleted successfully.`);
|
|
985
|
+
} else {
|
|
986
|
+
console.log(`${file} does not exist.`);
|
|
987
|
+
}
|
|
988
|
+
});
|
|
989
|
+
const backendOnlyFolders = ["js", "css"];
|
|
990
|
+
backendOnlyFolders.forEach((folder) => {
|
|
991
|
+
const folderPath = path.join(projectPath, "src", "app", folder);
|
|
992
|
+
if (fs.existsSync(folderPath)) {
|
|
993
|
+
fs.rmSync(folderPath, { recursive: true, force: true }); // Use fs.rmSync instead of fs.rmdirSync
|
|
994
|
+
console.log(`${folder} was deleted successfully.`);
|
|
995
|
+
} else {
|
|
996
|
+
console.log(`${folder} does not exist.`);
|
|
997
|
+
}
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
if (!updateAnswer.swaggerDocs) {
|
|
1001
|
+
const swaggerDocsFolder = path.join(
|
|
1002
|
+
projectPath,
|
|
1003
|
+
"src",
|
|
1004
|
+
"app",
|
|
1005
|
+
"swagger-docs"
|
|
1006
|
+
);
|
|
1007
|
+
if (fs.existsSync(swaggerDocsFolder)) {
|
|
1008
|
+
fs.rmSync(swaggerDocsFolder, { recursive: true, force: true }); // Use fs.rmSync instead of fs.rmdirSync
|
|
1009
|
+
console.log(`swagger-docs was deleted successfully.`);
|
|
760
1010
|
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
const
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
1011
|
+
updateUninstallDependencies.push("swagger-jsdoc");
|
|
1012
|
+
}
|
|
1013
|
+
if (!updateAnswer.tailwindcss) {
|
|
1014
|
+
const tailwindFiles = ["postcss.config.js", "tailwind.config.js"];
|
|
1015
|
+
tailwindFiles.forEach((file) => {
|
|
1016
|
+
const filePath = path.join(projectPath, file);
|
|
1017
|
+
if (fs.existsSync(filePath)) {
|
|
1018
|
+
fs.unlinkSync(filePath); // Delete each file if it exists
|
|
1019
|
+
console.log(`${file} was deleted successfully.`);
|
|
1020
|
+
} else {
|
|
1021
|
+
console.log(`${file} does not exist.`);
|
|
1022
|
+
}
|
|
1023
|
+
});
|
|
1024
|
+
updateUninstallDependencies.push(
|
|
1025
|
+
"tailwindcss",
|
|
1026
|
+
"autoprefixer",
|
|
1027
|
+
"postcss",
|
|
1028
|
+
"postcss-cli",
|
|
1029
|
+
"cssnano"
|
|
1030
|
+
);
|
|
1031
|
+
}
|
|
1032
|
+
if (!updateAnswer.websocket) {
|
|
1033
|
+
updateUninstallDependencies.push("chokidar-cli");
|
|
1034
|
+
}
|
|
1035
|
+
if (!updateAnswer.prisma) {
|
|
1036
|
+
updateUninstallDependencies.push("prisma", "@prisma/client");
|
|
1037
|
+
}
|
|
1038
|
+
if (!updateAnswer.docker) {
|
|
1039
|
+
const dockerFiles = [
|
|
1040
|
+
".dockerignore",
|
|
1041
|
+
"docker-compose.yml",
|
|
1042
|
+
"Dockerfile",
|
|
1043
|
+
"apache.conf",
|
|
776
1044
|
];
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
fs.rmSync(swaggerDocsFolder, { recursive: true, force: true }); // Use fs.rmSync instead of fs.rmdirSync
|
|
836
|
-
console.log(`swagger-docs was deleted successfully.`);
|
|
837
|
-
}
|
|
838
|
-
updateUninstallDependencies.push("swagger-jsdoc");
|
|
839
|
-
}
|
|
840
|
-
if (!updateAnswer.tailwindcss) {
|
|
841
|
-
const tailwindFiles = ["postcss.config.js", "tailwind.config.js"];
|
|
842
|
-
tailwindFiles.forEach((file) => {
|
|
843
|
-
const filePath = path.join(projectPath, file);
|
|
844
|
-
if (fs.existsSync(filePath)) {
|
|
845
|
-
fs.unlinkSync(filePath); // Delete each file if it exists
|
|
846
|
-
console.log(`${file} was deleted successfully.`);
|
|
847
|
-
}
|
|
848
|
-
else {
|
|
849
|
-
console.log(`${file} does not exist.`);
|
|
850
|
-
}
|
|
851
|
-
});
|
|
852
|
-
updateUninstallDependencies.push("tailwindcss", "autoprefixer", "postcss", "postcss-cli", "cssnano");
|
|
853
|
-
}
|
|
854
|
-
if (!updateAnswer.websocket) {
|
|
855
|
-
updateUninstallDependencies.push("chokidar-cli");
|
|
856
|
-
}
|
|
857
|
-
if (!updateAnswer.prisma) {
|
|
858
|
-
updateUninstallDependencies.push("prisma", "@prisma/client");
|
|
859
|
-
}
|
|
860
|
-
if (!updateAnswer.docker) {
|
|
861
|
-
const dockerFiles = [
|
|
862
|
-
".dockerignore",
|
|
863
|
-
"docker-compose.yml",
|
|
864
|
-
"Dockerfile",
|
|
865
|
-
"apache.conf",
|
|
866
|
-
];
|
|
867
|
-
dockerFiles.forEach((file) => {
|
|
868
|
-
const filePath = path.join(projectPath, file);
|
|
869
|
-
if (fs.existsSync(filePath)) {
|
|
870
|
-
fs.unlinkSync(filePath); // Delete each file if it exists
|
|
871
|
-
console.log(`${file} was deleted successfully.`);
|
|
872
|
-
}
|
|
873
|
-
else {
|
|
874
|
-
console.log(`${file} does not exist.`);
|
|
875
|
-
}
|
|
876
|
-
});
|
|
877
|
-
}
|
|
878
|
-
if (updateUninstallDependencies.length > 0) {
|
|
879
|
-
await uninstallDependencies(projectPath, updateUninstallDependencies, true);
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
const projectPathModified = projectPath.replace(/\\/g, "\\");
|
|
883
|
-
const bsConfig = bsConfigUrls(projectPathModified);
|
|
884
|
-
const phpGenerateClassPath = answer.prisma ? "src/Lib/Prisma/Classes" : "";
|
|
885
|
-
const prismaPhpConfig = {
|
|
886
|
-
projectName: answer.projectName,
|
|
887
|
-
projectRootPath: projectPathModified,
|
|
888
|
-
phpEnvironment: "XAMPP",
|
|
889
|
-
phpRootPathExe: "C:\\xampp\\php\\php.exe",
|
|
890
|
-
phpGenerateClassPath,
|
|
891
|
-
bsTarget: bsConfig.bsTarget,
|
|
892
|
-
bsPathRewrite: bsConfig.bsPathRewrite,
|
|
893
|
-
backendOnly: answer.backendOnly,
|
|
894
|
-
swaggerDocs: answer.swaggerDocs,
|
|
895
|
-
tailwindcss: answer.tailwindcss,
|
|
896
|
-
websocket: answer.websocket,
|
|
897
|
-
prisma: answer.prisma,
|
|
898
|
-
docker: answer.docker,
|
|
899
|
-
version: latestVersionOfCreatePrismaPhpApp,
|
|
900
|
-
excludeFiles: (_j = updateAnswer === null || updateAnswer === void 0 ? void 0 : updateAnswer.excludeFiles) !== null && _j !== void 0 ? _j : [],
|
|
901
|
-
};
|
|
902
|
-
fs.writeFileSync(path.join(projectPath, "prisma-php.json"), JSON.stringify(prismaPhpConfig, null, 2), { flag: "w" });
|
|
903
|
-
if (updateAnswer === null || updateAnswer === void 0 ? void 0 : updateAnswer.isUpdate) {
|
|
904
|
-
execSync(`C:\\xampp\\php\\php.exe C:\\ProgramData\\ComposerSetup\\bin\\composer.phar update`, {
|
|
905
|
-
stdio: "inherit",
|
|
906
|
-
});
|
|
1045
|
+
dockerFiles.forEach((file) => {
|
|
1046
|
+
const filePath = path.join(projectPath, file);
|
|
1047
|
+
if (fs.existsSync(filePath)) {
|
|
1048
|
+
fs.unlinkSync(filePath); // Delete each file if it exists
|
|
1049
|
+
console.log(`${file} was deleted successfully.`);
|
|
1050
|
+
} else {
|
|
1051
|
+
console.log(`${file} does not exist.`);
|
|
1052
|
+
}
|
|
1053
|
+
});
|
|
1054
|
+
}
|
|
1055
|
+
if (updateUninstallDependencies.length > 0) {
|
|
1056
|
+
await uninstallDependencies(
|
|
1057
|
+
projectPath,
|
|
1058
|
+
updateUninstallDependencies,
|
|
1059
|
+
true
|
|
1060
|
+
);
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
const projectPathModified = projectPath.replace(/\\/g, "\\");
|
|
1064
|
+
const bsConfig = bsConfigUrls(projectPathModified);
|
|
1065
|
+
const phpGenerateClassPath = answer.prisma ? "src/Lib/Prisma/Classes" : "";
|
|
1066
|
+
const prismaPhpConfig = {
|
|
1067
|
+
projectName: answer.projectName,
|
|
1068
|
+
projectRootPath: projectPathModified,
|
|
1069
|
+
phpEnvironment: "XAMPP",
|
|
1070
|
+
phpRootPathExe: "C:\\xampp\\php\\php.exe",
|
|
1071
|
+
phpGenerateClassPath,
|
|
1072
|
+
bsTarget: bsConfig.bsTarget,
|
|
1073
|
+
bsPathRewrite: bsConfig.bsPathRewrite,
|
|
1074
|
+
backendOnly: answer.backendOnly,
|
|
1075
|
+
swaggerDocs: answer.swaggerDocs,
|
|
1076
|
+
tailwindcss: answer.tailwindcss,
|
|
1077
|
+
websocket: answer.websocket,
|
|
1078
|
+
prisma: answer.prisma,
|
|
1079
|
+
docker: answer.docker,
|
|
1080
|
+
version: latestVersionOfCreatePrismaPhpApp,
|
|
1081
|
+
excludeFiles:
|
|
1082
|
+
(_j =
|
|
1083
|
+
updateAnswer === null || updateAnswer === void 0
|
|
1084
|
+
? void 0
|
|
1085
|
+
: updateAnswer.excludeFiles) !== null && _j !== void 0
|
|
1086
|
+
? _j
|
|
1087
|
+
: [],
|
|
1088
|
+
};
|
|
1089
|
+
fs.writeFileSync(
|
|
1090
|
+
path.join(projectPath, "prisma-php.json"),
|
|
1091
|
+
JSON.stringify(prismaPhpConfig, null, 2),
|
|
1092
|
+
{ flag: "w" }
|
|
1093
|
+
);
|
|
1094
|
+
if (
|
|
1095
|
+
updateAnswer === null || updateAnswer === void 0
|
|
1096
|
+
? void 0
|
|
1097
|
+
: updateAnswer.isUpdate
|
|
1098
|
+
) {
|
|
1099
|
+
execSync(
|
|
1100
|
+
`C:\\xampp\\php\\php.exe C:\\ProgramData\\ComposerSetup\\bin\\composer.phar update`,
|
|
1101
|
+
{
|
|
1102
|
+
stdio: "inherit",
|
|
907
1103
|
}
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
1104
|
+
);
|
|
1105
|
+
} else {
|
|
1106
|
+
execSync(
|
|
1107
|
+
`C:\\xampp\\php\\php.exe C:\\ProgramData\\ComposerSetup\\bin\\composer.phar install`,
|
|
1108
|
+
{
|
|
1109
|
+
stdio: "inherit",
|
|
912
1110
|
}
|
|
913
|
-
|
|
914
|
-
}
|
|
915
|
-
catch (error) {
|
|
916
|
-
console.error("Error while creating the project:", error);
|
|
917
|
-
process.exit(1);
|
|
1111
|
+
);
|
|
918
1112
|
}
|
|
1113
|
+
console.log(
|
|
1114
|
+
`${chalk.green("Success!")} Prisma PHP project successfully created in ${
|
|
1115
|
+
answer.projectName
|
|
1116
|
+
}!`
|
|
1117
|
+
);
|
|
1118
|
+
} catch (error) {
|
|
1119
|
+
console.error("Error while creating the project:", error);
|
|
1120
|
+
process.exit(1);
|
|
1121
|
+
}
|
|
919
1122
|
}
|
|
920
1123
|
main();
|