create-prisma-php-app 1.20.507 → 1.20.508

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +773 -976
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -10,62 +10,57 @@ const __filename = fileURLToPath(import.meta.url);
10
10
  const __dirname = path.dirname(__filename);
11
11
  let updateAnswer = null;
12
12
  const nonBackendFiles = [
13
- "favicon.ico",
14
- "src/app/index.php",
15
- "metadata.php",
16
- "not-found.php",
13
+ "favicon.ico",
14
+ "\\src\\app\\index.php",
15
+ "metadata.php",
16
+ "not-found.php",
17
17
  ];
18
18
  const dockerFiles = [
19
- ".dockerignore",
20
- "docker-compose.yml",
21
- "Dockerfile",
22
- "apache.conf",
19
+ ".dockerignore",
20
+ "docker-compose.yml",
21
+ "Dockerfile",
22
+ "apache.conf",
23
23
  ];
24
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
- );
25
+ // Identify the base path dynamically up to and including 'htdocs'
26
+ const htdocsIndex = projectRootPath.indexOf("\\htdocs\\");
27
+ if (htdocsIndex === -1) {
28
+ console.error("Invalid PROJECT_ROOT_PATH. The path does not contain \\htdocs\\");
29
+ return {
30
+ bsTarget: "",
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;
31
54
  return {
32
- bsTarget: "",
33
- bsPathRewrite: {},
55
+ bsTarget: `${cleanUrl}/`,
56
+ bsPathRewrite: {
57
+ "^/": `/${adjustedRelativeWebPath}/`,
58
+ },
34
59
  };
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
60
  }
66
61
  function configureBrowserSyncCommand(baseDir) {
67
- // TypeScript content to write
68
- const bsConfigTsContent = `const { createProxyMiddleware } = require("http-proxy-middleware");
62
+ // TypeScript content to write
63
+ const bsConfigTsContent = `const { createProxyMiddleware } = require("http-proxy-middleware");
69
64
  const fs = require("fs");
70
65
 
71
66
  const jsonData = fs.readFileSync("prisma-php.json", "utf8");
@@ -91,389 +86,322 @@ module.exports = {
91
86
  open: false,
92
87
  ghostMode: false,
93
88
  };`;
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`;
89
+ // Determine the path and write the bs-config.js
90
+ const bsConfigPath = path.join(baseDir, "settings", "bs-config.cjs");
91
+ fs.writeFileSync(bsConfigPath, bsConfigTsContent, "utf8");
92
+ // Return the Browser Sync command string, using the cleaned URL
93
+ return `browser-sync start --config settings/bs-config.cjs`;
99
94
  }
100
95
  async function updatePackageJson(baseDir, answer) {
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.backendOnly && 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.backendOnly && !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));
96
+ const packageJsonPath = path.join(baseDir, "package.json");
97
+ if (checkExcludeFiles(packageJsonPath))
98
+ return;
99
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
100
+ // Use the new function to configure the Browser Sync command
101
+ const browserSyncCommand = configureBrowserSyncCommand(baseDir);
102
+ packageJson.scripts = Object.assign(Object.assign({}, packageJson.scripts), { projectName: "node settings/project-name.cjs" });
103
+ let answersToInclude = [];
104
+ if (answer.tailwindcss) {
105
+ packageJson.scripts = Object.assign(Object.assign({}, packageJson.scripts), { tailwind: "postcss ./src/app/css/tailwind.css -o ./src/app/css/styles.css --watch" });
106
+ answersToInclude.push("tailwind");
107
+ }
108
+ if (answer.websocket) {
109
+ packageJson.scripts = Object.assign(Object.assign({}, packageJson.scripts), { websocket: "node ./settings/restart-websocket.cjs" });
110
+ answersToInclude.push("websocket");
111
+ }
112
+ // if (answer.prisma) {
113
+ // packageJson.scripts = {
114
+ // ...packageJson.scripts,
115
+ // postinstall: "prisma generate",
116
+ // };
117
+ // }
118
+ if (answer.docker) {
119
+ packageJson.scripts = Object.assign(Object.assign({}, packageJson.scripts), { docker: "docker-compose up" });
120
+ answersToInclude.push("docker");
121
+ }
122
+ if (answer.swaggerDocs) {
123
+ packageJson.scripts = Object.assign(Object.assign({}, packageJson.scripts), { "create-swagger-docs": "node settings/swagger-setup.js" });
124
+ answersToInclude.push("swaggerDocs");
125
+ }
126
+ if (answer.backendOnly && answer.swaggerDocs) {
127
+ packageJson.scripts = Object.assign(Object.assign({}, packageJson.scripts), { dev: "node settings/start-dev.js" });
128
+ }
129
+ // Initialize with existing scripts
130
+ const updatedScripts = Object.assign({}, packageJson.scripts);
131
+ // Conditionally add "browser-sync" command
132
+ updatedScripts["browser-sync"] = browserSyncCommand;
133
+ // Conditionally set the "dev" command
134
+ if (!answer.backendOnly && !answer.swaggerDocs) {
135
+ updatedScripts.dev =
136
+ answersToInclude.length > 0
137
+ ? `npm-run-all --parallel projectName browser-sync ${answersToInclude.join(" ")}`
138
+ : `npm-run-all --parallel projectName browser-sync`;
139
+ }
140
+ // Finally, assign the updated scripts back to packageJson
141
+ packageJson.scripts = updatedScripts;
142
+ packageJson.type = "module";
143
+ if (answer.prisma)
144
+ packageJson.prisma = {
145
+ seed: "node prisma/seed.js",
146
+ };
147
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
174
148
  }
175
149
  async function updateComposerJson(baseDir, answer) {
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.");
150
+ const composerJsonPath = path.join(baseDir, "composer.json");
151
+ if (checkExcludeFiles(composerJsonPath))
152
+ return;
153
+ let composerJson;
154
+ // Check if the composer.json file exists
155
+ if (fs.existsSync(composerJsonPath)) {
156
+ // Read the current composer.json content
157
+ const composerJsonContent = fs.readFileSync(composerJsonPath, "utf8");
158
+ composerJson = JSON.parse(composerJsonContent);
159
+ }
160
+ else {
161
+ console.error("composer.json does not exist.");
162
+ return;
163
+ }
164
+ // Conditionally add WebSocket dependency
165
+ if (answer.websocket) {
166
+ composerJson.require = Object.assign(Object.assign({}, composerJson.require), { "cboden/ratchet": "^0.4.4" });
167
+ }
168
+ if (answer.prisma) {
169
+ composerJson.require = Object.assign(Object.assign({}, composerJson.require), { "ramsey/uuid": "5.x-dev", "hidehalo/nanoid-php": "1.x-dev" });
170
+ }
171
+ // Write the modified composer.json back to the file
172
+ fs.writeFileSync(composerJsonPath, JSON.stringify(composerJson, null, 2));
173
+ console.log("composer.json updated successfully.");
204
174
  }
205
175
  async function updateIndexJsForWebSocket(baseDir, answer) {
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 = `
176
+ if (!answer.websocket) {
177
+ return;
178
+ }
179
+ const indexPath = path.join(baseDir, "src", "app", "js", "index.js");
180
+ if (checkExcludeFiles(indexPath))
181
+ return;
182
+ let indexContent = fs.readFileSync(indexPath, "utf8");
183
+ // WebSocket initialization code to be appended
184
+ const webSocketCode = `
214
185
  // WebSocket initialization
215
186
  const ws = new WebSocket("ws://localhost:8080");
216
187
  `;
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.");
188
+ // Append WebSocket code if user chose to use WebSocket
189
+ indexContent += webSocketCode;
190
+ fs.writeFileSync(indexPath, indexContent, "utf8");
191
+ console.log("WebSocket code added to index.js successfully.");
221
192
  }
222
193
  // This function updates the .gitignore file
223
194
  async function createUpdateGitignoreFile(baseDir, additions) {
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);
195
+ const gitignorePath = path.join(baseDir, ".gitignore");
196
+ if (checkExcludeFiles(gitignorePath))
197
+ return;
198
+ let gitignoreContent = "";
199
+ additions.forEach((addition) => {
200
+ if (!gitignoreContent.includes(addition)) {
201
+ gitignoreContent += `\n${addition}`;
202
+ }
203
+ });
204
+ // Ensure there's no leading newline if the file was just created
205
+ gitignoreContent = gitignoreContent.trimStart();
206
+ fs.writeFileSync(gitignorePath, gitignoreContent);
235
207
  }
236
208
  // Recursive copy function
237
209
  function copyRecursiveSync(src, dest, answer) {
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;
292
- }
293
- if (
294
- answer.backendOnly &&
295
- nonBackendFiles.some((file) => dest.includes(file))
296
- ) {
297
- return;
210
+ var _a;
211
+ console.log("🚀 ~ copyRecursiveSync ~ dest:", dest);
212
+ console.log("🚀 ~ copyRecursiveSync ~ src:", src);
213
+ const exists = fs.existsSync(src);
214
+ const stats = exists && fs.statSync(src);
215
+ const isDirectory = exists && stats && stats.isDirectory();
216
+ if (isDirectory) {
217
+ const destLower = dest.toLowerCase();
218
+ if (!answer.websocket && destLower.includes("src\\lib\\websocket"))
219
+ return;
220
+ if (!answer.prisma && destLower.includes("src\\lib\\prisma"))
221
+ return;
222
+ if ((answer.backendOnly && destLower.includes("src\\app\\js")) ||
223
+ (answer.backendOnly && destLower.includes("src\\app\\css")))
224
+ return;
225
+ if (answer.backendOnly &&
226
+ !answer.swaggerDocs &&
227
+ destLower.includes("src\\app\\swagger-docs"))
228
+ return;
229
+ const destModified = dest.replace(/\\/g, "/");
230
+ if ((_a = updateAnswer === null || updateAnswer === void 0 ? void 0 : updateAnswer.excludeFilePath) === null || _a === void 0 ? void 0 : _a.includes(destModified))
231
+ return;
232
+ if (!fs.existsSync(dest))
233
+ fs.mkdirSync(dest, { recursive: true });
234
+ fs.readdirSync(src).forEach((childItemName) => {
235
+ copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName), answer);
236
+ });
298
237
  }
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;
238
+ else {
239
+ if (checkExcludeFiles(dest))
240
+ return;
241
+ if (!answer.tailwindcss &&
242
+ (dest.includes("tailwind.css") || dest.includes("styles.css")))
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);
306
263
  }
307
- fs.copyFileSync(src, dest, 0);
308
- }
309
264
  }
310
265
  // Function to execute the recursive copy for entire directories
311
266
  async function executeCopy(baseDir, directoriesToCopy, answer) {
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
- });
267
+ directoriesToCopy.forEach(({ srcDir, destDir }) => {
268
+ const sourcePath = path.join(__dirname, srcDir);
269
+ const destPath = path.join(baseDir, destDir);
270
+ copyRecursiveSync(sourcePath, destPath, answer);
271
+ });
317
272
  }
318
273
  function createOrUpdateTailwindConfig(baseDir) {
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."));
274
+ console.log("🚀 ~ createOrUpdateTailwindConfig ~ baseDir:", baseDir);
275
+ const filePath = path.join(baseDir, "tailwind.config.js");
276
+ if (checkExcludeFiles(filePath))
277
+ return;
278
+ const newContent = [
279
+ "./src/app/**/*.{html,js,php}",
280
+ // Add more paths as needed
281
+ ];
282
+ let configData = fs.readFileSync(filePath, "utf8");
283
+ console.log("🚀 ~ createOrUpdateTailwindConfig ~ configData:", configData);
284
+ const contentArrayString = newContent
285
+ .map((item) => ` "${item}"`)
286
+ .join(",\n");
287
+ configData = configData.replace(/content: \[\],/g, `content: [\n${contentArrayString}\n],`);
288
+ fs.writeFileSync(filePath, configData, { flag: "w" });
289
+ console.log(chalk.green("Tailwind configuration updated successfully."));
337
290
  }
338
291
  function modifyPostcssConfig(baseDir) {
339
- const filePath = path.join(baseDir, "postcss.config.js");
340
- if (checkExcludeFiles(filePath)) return;
341
- const newContent = `export default {
292
+ const filePath = path.join(baseDir, "postcss.config.js");
293
+ if (checkExcludeFiles(filePath))
294
+ return;
295
+ const newContent = `export default {
342
296
  plugins: {
343
297
  tailwindcss: {},
344
298
  autoprefixer: {},
345
299
  cssnano: {},
346
300
  },
347
301
  };`;
348
- fs.writeFileSync(filePath, newContent, { flag: "w" });
349
- console.log(chalk.green("postcss.config.js updated successfully."));
302
+ fs.writeFileSync(filePath, newContent, { flag: "w" });
303
+ console.log(chalk.green("postcss.config.js updated successfully."));
350
304
  }
351
305
  function modifyLayoutPHP(baseDir, answer) {
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
- }
306
+ const layoutPath = path.join(baseDir, "src", "app", "layout.php");
307
+ if (checkExcludeFiles(layoutPath))
308
+ return;
309
+ try {
310
+ let indexContent = fs.readFileSync(layoutPath, "utf8");
311
+ const stylesAndLinks = `\n <link href="<?php echo $baseUrl; ?>css/index.css" rel="stylesheet">\n <script src="<?php echo $baseUrl; ?>js/index.js"></script>`;
312
+ // Tailwind CSS link or CDN script
313
+ const tailwindLink = answer.tailwindcss
314
+ ? ` <link href="<?php echo $baseUrl; ?>css/styles.css" rel="stylesheet"> ${stylesAndLinks}`
315
+ : ` <script src="https://cdn.tailwindcss.com"></script> ${stylesAndLinks}`;
316
+ // Insert before the closing </head> tag
317
+ indexContent = indexContent.replace("</head>", `${tailwindLink}\n</head>`);
318
+ fs.writeFileSync(layoutPath, indexContent, { flag: "w" });
319
+ console.log(chalk.green(`layout.php modified successfully for ${answer.tailwindcss ? "local Tailwind CSS" : "Tailwind CSS CDN"}.`));
320
+ }
321
+ catch (error) {
322
+ console.error(chalk.red("Error modifying layout.php:"), error);
323
+ }
374
324
  }
375
325
  // This function updates or creates the .env file
376
326
  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" });
327
+ const envPath = path.join(baseDir, ".env");
328
+ if (checkExcludeFiles(envPath))
329
+ return;
330
+ console.log("🚀 ~ content:", content);
331
+ fs.writeFileSync(envPath, content, { flag: "w" });
381
332
  }
382
333
  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;
334
+ var _a, _b;
335
+ if (!(updateAnswer === null || updateAnswer === void 0 ? void 0 : updateAnswer.isUpdate))
336
+ return false;
337
+ return ((_b = (_a = updateAnswer === null || updateAnswer === void 0 ? void 0 : updateAnswer.excludeFilePath) === null || _a === void 0 ? void 0 : _a.includes(destPath.replace(/\\/g, "/"))) !== null && _b !== void 0 ? _b : false);
399
338
  }
400
339
  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
- );
340
+ console.log("🚀 ~ baseDir:", baseDir);
341
+ console.log("🚀 ~ answer:", answer);
342
+ const filesToCopy = [
343
+ { src: "/bootstrap.php", dest: "/bootstrap.php" },
344
+ { src: "/.htaccess", dest: "/.htaccess" },
345
+ { src: "/../composer.json", dest: "/composer.json" },
346
+ ];
347
+ if (updateAnswer === null || updateAnswer === void 0 ? void 0 : updateAnswer.isUpdate) {
348
+ filesToCopy.push({ src: "/tsconfig.json", dest: "/tsconfig.json" });
349
+ if (updateAnswer.tailwindcss) {
350
+ filesToCopy.push({ src: "/postcss.config.js", dest: "/postcss.config.js" }, { src: "/tailwind.config.js", dest: "/tailwind.config.js" });
351
+ }
419
352
  }
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",
353
+ const directoriesToCopy = [
354
+ {
355
+ srcDir: "/settings",
356
+ destDir: "/settings",
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" });
380
+ }
381
+ console.log("🚀 ~ directoriesToCopy:", directoriesToCopy);
382
+ filesToCopy.forEach(({ src, dest }) => {
383
+ const sourcePath = path.join(__dirname, src);
384
+ const destPath = path.join(baseDir, dest);
385
+ if (checkExcludeFiles(destPath))
386
+ return;
387
+ const code = fs.readFileSync(sourcePath, "utf8");
388
+ fs.writeFileSync(destPath, code, { flag: "w" });
447
389
  });
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
390
+ await executeCopy(baseDir, directoriesToCopy, answer);
391
+ await updatePackageJson(baseDir, answer);
392
+ await updateComposerJson(baseDir, answer);
393
+ if (!answer.backendOnly)
394
+ await updateIndexJsForWebSocket(baseDir, answer);
395
+ if (answer.tailwindcss) {
396
+ createOrUpdateTailwindConfig(baseDir);
397
+ modifyLayoutPHP(baseDir, answer);
398
+ modifyPostcssConfig(baseDir);
399
+ }
400
+ else {
401
+ if (!answer.backendOnly)
402
+ modifyLayoutPHP(baseDir, answer);
403
+ }
404
+ const prismaPHPEnvContent = `# Prisma PHP Auth Secret Key For development only - Change this in production
477
405
  AUTH_SECRET=uxsjXVPHN038DEYls2Kw0QUgBcXKUyrjv416nIFWPY4=
478
406
 
479
407
  # PHPMailer
@@ -493,200 +421,164 @@ SHOW_ERRORS=true
493
421
 
494
422
  # APP TIMEZONE - Set your application timezone - Default is "UTC"
495
423
  APP_TIMEZONE="UTC"`;
496
- if (answer.prisma) {
497
- const prismaEnvContent = `# Environment variables declared in this file are automatically made available to Prisma.
424
+ if (answer.prisma) {
425
+ const prismaEnvContent = `# Environment variables declared in this file are automatically made available to Prisma.
498
426
  # See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
499
427
 
500
428
  # Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
501
429
  # See the documentation for all the connection string options: https://pris.ly/d/connection-strings
502
430
 
503
431
  DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"`;
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"]);
511
- }
512
- async function getAnswer(predefinedAnswers = {}) {
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
- });
553
- }
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
- });
563
- }
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
- });
573
- }
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
- });
432
+ const envContent = `${prismaEnvContent}\n\n${prismaPHPEnvContent}`;
433
+ await createOrUpdateEnvFile(baseDir, envContent);
583
434
  }
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
- });
435
+ else {
436
+ await createOrUpdateEnvFile(baseDir, prismaPHPEnvContent);
595
437
  }
596
- if (!predefinedAnswers.tailwindcss) {
597
- nonBackendOnlyQuestionsArray.unshift({
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
- });
438
+ // Add vendor to .gitignore
439
+ await createUpdateGitignoreFile(baseDir, ["vendor", ".env", "node_modules"]);
440
+ }
441
+ async function getAnswer(predefinedAnswers = {}) {
442
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
443
+ console.log("🚀 ~ predefinedAnswers:", predefinedAnswers);
444
+ const questionsArray = [];
445
+ if (!predefinedAnswers.projectName) {
446
+ questionsArray.push({
447
+ type: "text",
448
+ name: "projectName",
449
+ message: "What is your project named?",
450
+ initial: "my-app",
451
+ });
605
452
  }
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
- });
453
+ if (!predefinedAnswers.backendOnly) {
454
+ questionsArray.push({
455
+ type: "toggle",
456
+ name: "backendOnly",
457
+ message: "Would you like to create a backend-only project?",
458
+ initial: false,
459
+ active: "Yes",
460
+ inactive: "No",
461
+ });
615
462
  }
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
- });
463
+ // Execute the initial questionsArray first
464
+ const onCancel = () => {
465
+ console.log(chalk.red("Operation cancelled by the user."));
466
+ process.exit(0);
467
+ };
468
+ const initialResponse = await prompts(questionsArray, { onCancel });
469
+ console.log("🚀 ~ initialResponse:", initialResponse);
470
+ const nonBackendOnlyQuestionsArray = [];
471
+ if (initialResponse.backendOnly || predefinedAnswers.backendOnly) {
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
+ }
625
513
  }
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
- });
514
+ else {
515
+ // If it's not a backend-only project, ask Tailwind CSS as well
516
+ if (!predefinedAnswers.swaggerDocs) {
517
+ nonBackendOnlyQuestionsArray.push({
518
+ type: "toggle",
519
+ name: "swaggerDocs",
520
+ message: `Would you like to use ${chalk.blue("Swagger Docs")}?`,
521
+ initial: false,
522
+ active: "Yes",
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
+ }
635
566
  }
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
- };
567
+ const nonBackendOnlyResponse = await prompts(nonBackendOnlyQuestionsArray, {
568
+ onCancel,
569
+ });
570
+ console.log("🚀 ~ nonBackendOnlyResponse:", nonBackendOnlyResponse);
571
+ return {
572
+ projectName: initialResponse.projectName
573
+ ? String(initialResponse.projectName).trim().replace(/ /g, "-")
574
+ : (_a = predefinedAnswers.projectName) !== null && _a !== void 0 ? _a : "my-app",
575
+ backendOnly: (_c = (_b = initialResponse.backendOnly) !== null && _b !== void 0 ? _b : predefinedAnswers.backendOnly) !== null && _c !== void 0 ? _c : false,
576
+ swaggerDocs: (_e = (_d = nonBackendOnlyResponse.swaggerDocs) !== null && _d !== void 0 ? _d : predefinedAnswers.swaggerDocs) !== null && _e !== void 0 ? _e : false,
577
+ tailwindcss: (_g = (_f = nonBackendOnlyResponse.tailwindcss) !== null && _f !== void 0 ? _f : predefinedAnswers.tailwindcss) !== null && _g !== void 0 ? _g : false,
578
+ websocket: (_j = (_h = nonBackendOnlyResponse.websocket) !== null && _h !== void 0 ? _h : predefinedAnswers.websocket) !== null && _j !== void 0 ? _j : false,
579
+ prisma: (_l = (_k = nonBackendOnlyResponse.prisma) !== null && _k !== void 0 ? _k : predefinedAnswers.prisma) !== null && _l !== void 0 ? _l : false,
580
+ docker: (_o = (_m = nonBackendOnlyResponse.docker) !== null && _m !== void 0 ? _m : predefinedAnswers.docker) !== null && _o !== void 0 ? _o : false,
581
+ };
690
582
  }
691
583
  /**
692
584
  * Install dependencies in the specified directory.
@@ -695,429 +587,334 @@ async function getAnswer(predefinedAnswers = {}) {
695
587
  * @param {boolean} [isDev=false] - Whether to install the dependencies as devDependencies.
696
588
  */
697
589
  async function installDependencies(baseDir, dependencies, isDev = false) {
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,
590
+ console.log("Initializing new Node.js project...");
591
+ // Initialize a package.json if it doesn't exist
592
+ if (!fs.existsSync(path.join(baseDir, "package.json")))
593
+ execSync("npm init -y", {
594
+ stdio: "inherit",
595
+ cwd: baseDir,
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,
704
606
  });
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
- });
721
607
  }
722
608
  async function uninstallDependencies(baseDir, dependencies, isDev = false) {
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
- });
609
+ console.log("Uninstalling dependencies:");
610
+ dependencies.forEach((dep) => console.log(`- ${chalk.blue(dep)}`));
611
+ // Prepare the npm uninstall command with the appropriate flag for dev dependencies
612
+ const npmUninstallCommand = `npm uninstall ${isDev ? "--save-dev" : "--save"} ${dependencies.join(" ")}`;
613
+ // Execute the npm uninstall command
614
+ execSync(npmUninstallCommand, {
615
+ stdio: "inherit",
616
+ cwd: baseDir,
617
+ });
734
618
  }
735
619
  function fetchPackageVersion(packageName) {
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
- });
620
+ return new Promise((resolve, reject) => {
621
+ https
622
+ .get(`https://registry.npmjs.org/${packageName}`, (res) => {
623
+ let data = "";
624
+ res.on("data", (chunk) => (data += chunk));
625
+ res.on("end", () => {
626
+ try {
627
+ const parsed = JSON.parse(data);
628
+ resolve(parsed["dist-tags"].latest);
629
+ }
630
+ catch (error) {
631
+ reject(new Error("Failed to parse JSON response"));
632
+ }
633
+ });
634
+ })
635
+ .on("error", (err) => reject(err));
636
+ });
752
637
  }
753
638
  const readJsonFile = (filePath) => {
754
- const jsonData = fs.readFileSync(filePath, "utf8");
755
- return JSON.parse(jsonData);
639
+ const jsonData = fs.readFileSync(filePath, "utf8");
640
+ return JSON.parse(jsonData);
756
641
  };
757
642
  function compareVersions(installedVersion, currentVersion) {
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;
643
+ const installedVersionArray = installedVersion.split(".").map(Number);
644
+ const currentVersionArray = currentVersion.split(".").map(Number);
645
+ for (let i = 0; i < installedVersionArray.length; i++) {
646
+ if (installedVersionArray[i] > currentVersionArray[i]) {
647
+ return 1;
648
+ }
649
+ else if (installedVersionArray[i] < currentVersionArray[i]) {
650
+ return -1;
651
+ }
765
652
  }
766
- }
767
- return 0;
653
+ return 0;
768
654
  }
769
655
  function getInstalledPackageVersion(packageName) {
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;
656
+ try {
657
+ const output = execSync(`npm list -g ${packageName} --depth=0`).toString();
658
+ const versionMatch = output.match(new RegExp(`${packageName}@(\\d+\\.\\d+\\.\\d+)`));
659
+ if (versionMatch) {
660
+ return versionMatch[1];
661
+ }
662
+ else {
663
+ console.error(`Package ${packageName} is not installed`);
664
+ return null;
665
+ }
666
+ }
667
+ catch (error) {
668
+ console.error(error instanceof Error ? error.message : String(error));
669
+ return null;
780
670
  }
781
- } catch (error) {
782
- console.error(error instanceof Error ? error.message : String(error));
783
- return null;
784
- }
785
671
  }
786
672
  async function main() {
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.`);
673
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
674
+ try {
675
+ const args = process.argv.slice(2);
676
+ let projectName = args[0];
677
+ let answer = null;
678
+ if (projectName) {
679
+ let useBackendOnly = args.includes("--backend-only");
680
+ let useSwaggerDocs = args.includes("--swagger-docs");
681
+ let useTailwind = args.includes("--tailwindcss");
682
+ let useWebsocket = args.includes("--websocket");
683
+ let usePrisma = args.includes("--prisma");
684
+ let useDocker = args.includes("--docker");
685
+ const predefinedAnswers = {
686
+ projectName,
687
+ backendOnly: useBackendOnly,
688
+ swaggerDocs: useSwaggerDocs,
689
+ tailwindcss: useTailwind,
690
+ websocket: useWebsocket,
691
+ prisma: usePrisma,
692
+ docker: useDocker,
693
+ };
694
+ console.log("🚀 ~ main ~ predefinedAnswers:", predefinedAnswers);
695
+ answer = await getAnswer(predefinedAnswers);
696
+ if (answer === null) {
697
+ console.log(chalk.red("Installation cancelled."));
698
+ return;
699
+ }
700
+ const currentDir = process.cwd();
701
+ const configPath = path.join(currentDir, "prisma-php.json");
702
+ const localSettings = readJsonFile(configPath);
703
+ let excludeFiles = [];
704
+ (_a = localSettings.excludeFiles) === null || _a === void 0 ? void 0 : _a.map((file) => {
705
+ const filePath = path.join(currentDir, file);
706
+ if (fs.existsSync(filePath))
707
+ excludeFiles.push(filePath.replace(/\\/g, "/"));
708
+ });
709
+ updateAnswer = {
710
+ projectName,
711
+ backendOnly: (_b = answer === null || answer === void 0 ? void 0 : answer.backendOnly) !== null && _b !== void 0 ? _b : false,
712
+ swaggerDocs: (_c = answer === null || answer === void 0 ? void 0 : answer.swaggerDocs) !== null && _c !== void 0 ? _c : false,
713
+ tailwindcss: (_d = answer === null || answer === void 0 ? void 0 : answer.tailwindcss) !== null && _d !== void 0 ? _d : false,
714
+ websocket: (_e = answer === null || answer === void 0 ? void 0 : answer.websocket) !== null && _e !== void 0 ? _e : false,
715
+ prisma: (_f = answer === null || answer === void 0 ? void 0 : answer.prisma) !== null && _f !== void 0 ? _f : false,
716
+ docker: (_g = answer === null || answer === void 0 ? void 0 : answer.docker) !== null && _g !== void 0 ? _g : false,
717
+ isUpdate: true,
718
+ excludeFiles: (_h = localSettings.excludeFiles) !== null && _h !== void 0 ? _h : [],
719
+ excludeFilePath: excludeFiles !== null && excludeFiles !== void 0 ? excludeFiles : [],
720
+ filePath: currentDir,
721
+ };
1010
722
  }
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",
723
+ else {
724
+ answer = await getAnswer();
725
+ }
726
+ if (answer === null) {
727
+ console.log(chalk.red("Installation cancelled."));
728
+ return;
729
+ }
730
+ const latestVersionOfCreatePrismaPhpApp = await fetchPackageVersion("create-prisma-php-app");
731
+ const isCreatePrismaPhpAppInstalled = getInstalledPackageVersion("create-prisma-php-app");
732
+ if (isCreatePrismaPhpAppInstalled) {
733
+ if (compareVersions(isCreatePrismaPhpAppInstalled, latestVersionOfCreatePrismaPhpApp) === -1) {
734
+ execSync(`npm uninstall -g create-prisma-php-app`, {
735
+ stdio: "inherit",
736
+ });
737
+ execSync(`npm install -g create-prisma-php-app`, {
738
+ stdio: "inherit",
739
+ });
740
+ }
741
+ }
742
+ else {
743
+ execSync("npm install -g create-prisma-php-app", { stdio: "inherit" });
744
+ }
745
+ const latestVersionOfBrowserSync = await fetchPackageVersion("browser-sync");
746
+ const isBrowserSyncInstalled = getInstalledPackageVersion("browser-sync");
747
+ if (isBrowserSyncInstalled) {
748
+ if (compareVersions(isBrowserSyncInstalled, latestVersionOfBrowserSync) ===
749
+ -1) {
750
+ execSync(`npm uninstall -g browser-sync`, {
751
+ stdio: "inherit",
752
+ });
753
+ execSync(`npm install -g browser-sync`, {
754
+ stdio: "inherit",
755
+ });
756
+ }
757
+ }
758
+ else {
759
+ execSync("npm install -g browser-sync", { stdio: "inherit" });
760
+ }
761
+ // Create the project directory
762
+ if (!projectName)
763
+ fs.mkdirSync(answer.projectName);
764
+ const currentDir = process.cwd();
765
+ let projectPath = projectName
766
+ ? currentDir
767
+ : path.join(currentDir, answer.projectName);
768
+ if (!projectName)
769
+ process.chdir(answer.projectName);
770
+ const dependencies = [
771
+ "typescript",
772
+ "@types/node",
773
+ "ts-node",
774
+ "http-proxy-middleware@^3.0.0",
775
+ "chalk",
1044
776
  ];
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",
777
+ if (answer.swaggerDocs) {
778
+ dependencies.push("swagger-jsdoc");
1103
779
  }
1104
- );
1105
- } else {
1106
- execSync(
1107
- `C:\\xampp\\php\\php.exe C:\\ProgramData\\ComposerSetup\\bin\\composer.phar install`,
1108
- {
1109
- stdio: "inherit",
780
+ if (!answer.backendOnly && !answer.swaggerDocs) {
781
+ dependencies.push("npm-run-all");
782
+ }
783
+ if (answer.tailwindcss) {
784
+ dependencies.push("tailwindcss", "autoprefixer", "postcss", "postcss-cli", "cssnano");
785
+ }
786
+ if (answer.websocket) {
787
+ dependencies.push("chokidar-cli");
1110
788
  }
1111
- );
789
+ if (answer.prisma) {
790
+ dependencies.push("prisma", "@prisma/client");
791
+ }
792
+ await installDependencies(projectPath, dependencies, true);
793
+ if (!projectName) {
794
+ execSync(`npx tsc --init`, { stdio: "inherit" });
795
+ }
796
+ if (answer.tailwindcss)
797
+ execSync(`npx tailwindcss init -p`, { stdio: "inherit" });
798
+ if (answer.prisma) {
799
+ if (!fs.existsSync(path.join(projectPath, "prisma")))
800
+ execSync(`npx prisma init`, { stdio: "inherit" });
801
+ }
802
+ await createDirectoryStructure(projectPath, answer);
803
+ const publicDirPath = path.join(projectPath, "public");
804
+ if (!fs.existsSync(publicDirPath)) {
805
+ fs.mkdirSync(publicDirPath);
806
+ }
807
+ if (updateAnswer === null || updateAnswer === void 0 ? void 0 : updateAnswer.isUpdate) {
808
+ const updateUninstallDependencies = [];
809
+ if (updateAnswer.backendOnly) {
810
+ nonBackendFiles.forEach((file) => {
811
+ const filePath = path.join(projectPath, "src", "app", file);
812
+ if (fs.existsSync(filePath)) {
813
+ fs.unlinkSync(filePath); // Delete each file if it exists
814
+ console.log(`${file} was deleted successfully.`);
815
+ }
816
+ else {
817
+ console.log(`${file} does not exist.`);
818
+ }
819
+ });
820
+ const backendOnlyFolders = ["js", "css"];
821
+ backendOnlyFolders.forEach((folder) => {
822
+ const folderPath = path.join(projectPath, "src", "app", folder);
823
+ if (fs.existsSync(folderPath)) {
824
+ fs.rmSync(folderPath, { recursive: true, force: true }); // Use fs.rmSync instead of fs.rmdirSync
825
+ console.log(`${folder} was deleted successfully.`);
826
+ }
827
+ else {
828
+ console.log(`${folder} does not exist.`);
829
+ }
830
+ });
831
+ }
832
+ if (!updateAnswer.swaggerDocs) {
833
+ const swaggerDocsFolder = path.join(projectPath, "src", "app", "swagger-docs");
834
+ if (fs.existsSync(swaggerDocsFolder)) {
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
+ });
907
+ }
908
+ else {
909
+ execSync(`C:\\xampp\\php\\php.exe C:\\ProgramData\\ComposerSetup\\bin\\composer.phar install`, {
910
+ stdio: "inherit",
911
+ });
912
+ }
913
+ console.log(`${chalk.green("Success!")} Prisma PHP project successfully created in ${answer.projectName}!`);
914
+ }
915
+ catch (error) {
916
+ console.error("Error while creating the project:", error);
917
+ process.exit(1);
1112
918
  }
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
- }
1122
919
  }
1123
920
  main();