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