create-prisma-php-app 1.6.30 → 1.6.31

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 CHANGED
@@ -9,32 +9,40 @@ import https from "https";
9
9
  const __filename = fileURLToPath(import.meta.url);
10
10
  const __dirname = path.dirname(__filename);
11
11
  function configureBrowserSyncCommand(baseDir, projectSettings) {
12
- // Identify the base path dynamically up to and including 'htdocs'
13
- const htdocsIndex = projectSettings.PROJECT_ROOT_PATH.indexOf("\\htdocs\\");
14
- if (htdocsIndex === -1) {
15
- console.error("Invalid PROJECT_ROOT_PATH. The path does not contain \\htdocs\\");
16
- return ""; // Return an empty string or handle the error as appropriate
17
- }
18
- // Extract the path up to and including 'htdocs\\'
19
- const basePathToRemove = projectSettings.PROJECT_ROOT_PATH.substring(0, htdocsIndex + "\\htdocs\\".length);
20
- // Escape backslashes for the regex pattern
21
- const escapedBasePathToRemove = basePathToRemove.replace(/\\/g, "\\\\");
22
- // Remove the base path and replace backslashes with forward slashes for URL compatibility
23
- const relativeWebPath = projectSettings.PROJECT_ROOT_PATH.replace(new RegExp(`^${escapedBasePathToRemove}`), "").replace(/\\/g, "/");
24
- // Construct the Browser Sync command with the correct proxy URL, being careful not to affect the protocol part
25
- let proxyUrl = `http://localhost/${relativeWebPath}`;
26
- // Ensure the proxy URL does not end with a slash before appending '/public'
27
- proxyUrl = proxyUrl.endsWith("/") ? proxyUrl.slice(0, -1) : proxyUrl;
28
- // Clean the URL by replacing "//" with "/" but not affecting "http://"
29
- // We replace instances of "//" that are not preceded by ":"
30
- const cleanUrl = proxyUrl.replace(/(?<!:)(\/\/+)/g, "/");
31
- const cleanRelativeWebPath = relativeWebPath.replace(/\/\/+/g, "/");
32
- // Correct the relativeWebPath to ensure it does not start with a "/"
33
- const adjustedRelativeWebPath = cleanRelativeWebPath.startsWith("/")
34
- ? cleanRelativeWebPath.substring(1)
35
- : cleanRelativeWebPath;
36
- // TypeScript content to write
37
- const bsConfigTsContent = `
12
+ // Identify the base path dynamically up to and including 'htdocs'
13
+ const htdocsIndex = projectSettings.PROJECT_ROOT_PATH.indexOf("\\htdocs\\");
14
+ if (htdocsIndex === -1) {
15
+ console.error(
16
+ "Invalid PROJECT_ROOT_PATH. The path does not contain \\htdocs\\"
17
+ );
18
+ return ""; // Return an empty string or handle the error as appropriate
19
+ }
20
+ // Extract the path up to and including 'htdocs\\'
21
+ const basePathToRemove = projectSettings.PROJECT_ROOT_PATH.substring(
22
+ 0,
23
+ htdocsIndex + "\\htdocs\\".length
24
+ );
25
+ // Escape backslashes for the regex pattern
26
+ const escapedBasePathToRemove = basePathToRemove.replace(/\\/g, "\\\\");
27
+ // Remove the base path and replace backslashes with forward slashes for URL compatibility
28
+ const relativeWebPath = projectSettings.PROJECT_ROOT_PATH.replace(
29
+ new RegExp(`^${escapedBasePathToRemove}`),
30
+ ""
31
+ ).replace(/\\/g, "/");
32
+ // Construct the Browser Sync command with the correct proxy URL, being careful not to affect the protocol part
33
+ let proxyUrl = `http://localhost/${relativeWebPath}`;
34
+ // Ensure the proxy URL does not end with a slash before appending '/public'
35
+ proxyUrl = proxyUrl.endsWith("/") ? proxyUrl.slice(0, -1) : proxyUrl;
36
+ // Clean the URL by replacing "//" with "/" but not affecting "http://"
37
+ // We replace instances of "//" that are not preceded by ":"
38
+ const cleanUrl = proxyUrl.replace(/(?<!:)(\/\/+)/g, "/");
39
+ const cleanRelativeWebPath = relativeWebPath.replace(/\/\/+/g, "/");
40
+ // Correct the relativeWebPath to ensure it does not start with a "/"
41
+ const adjustedRelativeWebPath = cleanRelativeWebPath.startsWith("/")
42
+ ? cleanRelativeWebPath.substring(1)
43
+ : cleanRelativeWebPath;
44
+ // TypeScript content to write
45
+ const bsConfigTsContent = `
38
46
  const { createProxyMiddleware } = require("http-proxy-middleware");
39
47
 
40
48
  module.exports = {
@@ -64,237 +72,261 @@ function configureBrowserSyncCommand(baseDir, projectSettings) {
64
72
  open: false,
65
73
  ghostMode: false,
66
74
  };`;
67
- // Determine the path and write the bs-config.js
68
- const bsConfigPath = path.join(baseDir, "settings", "bs-config.cjs");
69
- fs.writeFileSync(bsConfigPath, bsConfigTsContent, "utf8");
70
- // Return the Browser Sync command string, using the cleaned URL
71
- return `browser-sync start --config settings/bs-config.cjs`;
75
+ // Determine the path and write the bs-config.js
76
+ const bsConfigPath = path.join(baseDir, "settings", "bs-config.cjs");
77
+ fs.writeFileSync(bsConfigPath, bsConfigTsContent, "utf8");
78
+ // Return the Browser Sync command string, using the cleaned URL
79
+ return `browser-sync start --config settings/bs-config.cjs`;
72
80
  }
73
81
  async function updatePackageJson(baseDir, projectSettings, answer) {
74
- const packageJsonPath = path.join(baseDir, "package.json");
75
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
76
- // Use the new function to configure the Browser Sync command
77
- const browserSyncCommand = configureBrowserSyncCommand(baseDir, projectSettings);
78
- packageJson.scripts = Object.assign(Object.assign({}, packageJson.scripts), { postinstall: "prisma generate" });
79
- let answersToInclude = [];
80
- if (answer.tailwindcss) {
81
- packageJson.scripts = Object.assign(Object.assign({}, packageJson.scripts), { tailwind: "postcss ./src/app/css/tailwind.css -o ./src/app/css/styles.css --watch" });
82
- answersToInclude.push("tailwind");
83
- }
84
- if (answer.websocket) {
85
- packageJson.scripts = Object.assign(Object.assign({}, packageJson.scripts), { websocket: "node ./settings/restartWebsocket.cjs" });
86
- answersToInclude.push("websocket");
87
- }
88
- // Initialize with existing scripts
89
- const updatedScripts = Object.assign({}, packageJson.scripts);
90
- // Conditionally add "browser-sync" command
91
- if (answersToInclude.length > 0) {
92
- updatedScripts["browser-sync"] = browserSyncCommand;
93
- }
94
- // Conditionally set the "dev" command
95
- updatedScripts.dev =
96
- answersToInclude.length > 0
97
- ? `npm-run-all --parallel browser-sync ${answersToInclude.join(" ")}`
98
- : browserSyncCommand;
99
- // Finally, assign the updated scripts back to packageJson
100
- packageJson.scripts = updatedScripts;
101
- packageJson.type = "module";
102
- packageJson.prisma = {
103
- seed: "node prisma/seed.js",
104
- };
105
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
82
+ const packageJsonPath = path.join(baseDir, "package.json");
83
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
84
+ // Use the new function to configure the Browser Sync command
85
+ const browserSyncCommand = configureBrowserSyncCommand(
86
+ baseDir,
87
+ projectSettings
88
+ );
89
+ packageJson.scripts = Object.assign(Object.assign({}, packageJson.scripts), {
90
+ postinstall: "prisma generate",
91
+ });
92
+ let answersToInclude = [];
93
+ if (answer.tailwindcss) {
94
+ packageJson.scripts = Object.assign(
95
+ Object.assign({}, packageJson.scripts),
96
+ {
97
+ tailwind:
98
+ "postcss ./src/app/css/tailwind.css -o ./src/app/css/styles.css --watch",
99
+ }
100
+ );
101
+ answersToInclude.push("tailwind");
102
+ }
103
+ if (answer.websocket) {
104
+ packageJson.scripts = Object.assign(
105
+ Object.assign({}, packageJson.scripts),
106
+ { websocket: "node ./settings/restartWebsocket.cjs" }
107
+ );
108
+ answersToInclude.push("websocket");
109
+ }
110
+ // Initialize with existing scripts
111
+ const updatedScripts = Object.assign({}, packageJson.scripts);
112
+ // Conditionally add "browser-sync" command
113
+ if (answersToInclude.length > 0) {
114
+ updatedScripts["browser-sync"] = browserSyncCommand;
115
+ }
116
+ // Conditionally set the "dev" command
117
+ updatedScripts.dev =
118
+ answersToInclude.length > 0
119
+ ? `npm-run-all --parallel browser-sync ${answersToInclude.join(" ")}`
120
+ : browserSyncCommand;
121
+ // Finally, assign the updated scripts back to packageJson
122
+ packageJson.scripts = updatedScripts;
123
+ packageJson.type = "module";
124
+ packageJson.prisma = {
125
+ seed: "node prisma/seed.js",
126
+ };
127
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
106
128
  }
107
129
  async function updateComposerJson(baseDir, answer) {
108
- if (!answer.websocket)
109
- return;
110
- const composerJsonPath = path.join(baseDir, "composer.json");
111
- let composerJson;
112
- // Check if the composer.json file exists
113
- if (fs.existsSync(composerJsonPath)) {
114
- // Read the current composer.json content
115
- const composerJsonContent = fs.readFileSync(composerJsonPath, "utf8");
116
- composerJson = JSON.parse(composerJsonContent);
117
- }
118
- else {
119
- console.error("composer.json does not exist.");
120
- return;
121
- }
122
- // Conditionally add WebSocket dependency
123
- if (answer.websocket) {
124
- composerJson.require = Object.assign(Object.assign({}, composerJson.require), { "cboden/ratchet": "^0.4.4" });
125
- }
126
- // Write the modified composer.json back to the file
127
- fs.writeFileSync(composerJsonPath, JSON.stringify(composerJson, null, 2));
128
- console.log("composer.json updated successfully.");
130
+ if (!answer.websocket) return;
131
+ const composerJsonPath = path.join(baseDir, "composer.json");
132
+ let composerJson;
133
+ // Check if the composer.json file exists
134
+ if (fs.existsSync(composerJsonPath)) {
135
+ // Read the current composer.json content
136
+ const composerJsonContent = fs.readFileSync(composerJsonPath, "utf8");
137
+ composerJson = JSON.parse(composerJsonContent);
138
+ } else {
139
+ console.error("composer.json does not exist.");
140
+ return;
141
+ }
142
+ // Conditionally add WebSocket dependency
143
+ if (answer.websocket) {
144
+ composerJson.require = Object.assign(
145
+ Object.assign({}, composerJson.require),
146
+ { "cboden/ratchet": "^0.4.4" }
147
+ );
148
+ }
149
+ // Write the modified composer.json back to the file
150
+ fs.writeFileSync(composerJsonPath, JSON.stringify(composerJson, null, 2));
151
+ console.log("composer.json updated successfully.");
129
152
  }
130
153
  async function updateIndexJsForWebSocket(baseDir, answer) {
131
- if (!answer.websocket) {
132
- return;
133
- }
134
- const indexPath = path.join(baseDir, "src", "app", "js", "index.js");
135
- let indexContent = fs.readFileSync(indexPath, "utf8");
136
- // WebSocket initialization code to be appended
137
- const webSocketCode = `
154
+ if (!answer.websocket) {
155
+ return;
156
+ }
157
+ const indexPath = path.join(baseDir, "src", "app", "js", "index.js");
158
+ let indexContent = fs.readFileSync(indexPath, "utf8");
159
+ // WebSocket initialization code to be appended
160
+ const webSocketCode = `
138
161
  // WebSocket initialization
139
162
  const ws = new WebSocket("ws://localhost:8080");
140
163
  `;
141
- // Append WebSocket code if user chose to use WebSocket
142
- indexContent += webSocketCode;
143
- fs.writeFileSync(indexPath, indexContent, "utf8");
144
- console.log("WebSocket code added to index.js successfully.");
164
+ // Append WebSocket code if user chose to use WebSocket
165
+ indexContent += webSocketCode;
166
+ fs.writeFileSync(indexPath, indexContent, "utf8");
167
+ console.log("WebSocket code added to index.js successfully.");
145
168
  }
146
169
  // This function updates the .gitignore file
147
170
  async function createUpdateGitignoreFile(baseDir, additions) {
148
- const gitignorePath = path.join(baseDir, ".gitignore");
149
- // Check if the .gitignore file exists, create if it doesn't
150
- let gitignoreContent = "";
151
- if (fs.existsSync(gitignorePath)) {
152
- gitignoreContent = fs.readFileSync(gitignorePath, "utf8");
171
+ const gitignorePath = path.join(baseDir, ".gitignore");
172
+ // Check if the .gitignore file exists, create if it doesn't
173
+ let gitignoreContent = "";
174
+ if (fs.existsSync(gitignorePath)) {
175
+ gitignoreContent = fs.readFileSync(gitignorePath, "utf8");
176
+ }
177
+ additions.forEach((addition) => {
178
+ if (!gitignoreContent.includes(addition)) {
179
+ gitignoreContent += `\n${addition}`;
153
180
  }
154
- additions.forEach((addition) => {
155
- if (!gitignoreContent.includes(addition)) {
156
- gitignoreContent += `\n${addition}`;
157
- }
158
- });
159
- // Ensure there's no leading newline if the file was just created
160
- gitignoreContent = gitignoreContent.trimStart();
161
- fs.writeFileSync(gitignorePath, gitignoreContent);
181
+ });
182
+ // Ensure there's no leading newline if the file was just created
183
+ gitignoreContent = gitignoreContent.trimStart();
184
+ fs.writeFileSync(gitignorePath, gitignoreContent);
162
185
  }
163
186
  // Recursive copy function
164
187
  function copyRecursiveSync(src, dest) {
165
- const exists = fs.existsSync(src);
166
- const stats = exists && fs.statSync(src);
167
- const isDirectory = exists && stats && stats.isDirectory();
168
- console.log("🚀 ~ copyRecursiveSync ~ isDirectory:", isDirectory);
169
- if (isDirectory) {
170
- if (fs.existsSync(dest)) {
171
- fs.rmSync(dest, { recursive: true, force: true }); // Remove the directory if it exists
172
- }
173
- fs.mkdirSync(dest, { recursive: true }); // Recreate the directory
174
- fs.readdirSync(src).forEach((childItemName) => {
175
- copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName));
176
- });
177
- }
178
- else {
179
- fs.copyFileSync(src, dest); // This line ensures files are overwritten
188
+ const exists = fs.existsSync(src);
189
+ const stats = exists && fs.statSync(src);
190
+ const isDirectory = exists && stats && stats.isDirectory();
191
+ console.log("🚀 ~ copyRecursiveSync ~ isDirectory:", isDirectory);
192
+ if (isDirectory) {
193
+ if (fs.existsSync(dest)) {
194
+ fs.rmSync(dest, { recursive: true, force: true }); // Remove the directory if it exists
180
195
  }
196
+ fs.mkdirSync(dest, { recursive: true }); // Recreate the directory
197
+ fs.readdirSync(src).forEach((childItemName) => {
198
+ copyRecursiveSync(
199
+ path.join(src, childItemName),
200
+ path.join(dest, childItemName)
201
+ );
202
+ });
203
+ } else {
204
+ fs.copyFileSync(src, dest); // This line ensures files are overwritten
205
+ }
181
206
  }
182
207
  // Function to execute the recursive copy for entire directories
183
208
  async function executeCopy(baseDir, directoriesToCopy) {
184
- directoriesToCopy.forEach(({ srcDir, destDir }) => {
185
- const sourcePath = path.join(__dirname, srcDir);
186
- const destPath = path.join(baseDir, destDir);
187
- copyRecursiveSync(sourcePath, destPath);
188
- });
209
+ directoriesToCopy.forEach(({ srcDir, destDir }) => {
210
+ const sourcePath = path.join(__dirname, srcDir);
211
+ const destPath = path.join(baseDir, destDir);
212
+ copyRecursiveSync(sourcePath, destPath);
213
+ });
189
214
  }
190
215
  function modifyTailwindConfig(baseDir) {
191
- const filePath = path.join(baseDir, "tailwind.config.js");
192
- const newContent = [
193
- "./src/app/**/*.{html,js,php}",
194
- // Add more paths as needed
195
- ];
196
- let configData = fs.readFileSync(filePath, "utf8");
197
- const contentArrayString = newContent
198
- .map((item) => ` "${item}"`)
199
- .join(",\n");
200
- configData = configData.replace(/content: \[\],/g, `content: [\n${contentArrayString}\n],`);
201
- fs.writeFileSync(filePath, configData, "utf8");
202
- console.log(chalk.green("Tailwind configuration updated successfully."));
216
+ const filePath = path.join(baseDir, "tailwind.config.js");
217
+ const newContent = [
218
+ "./src/app/**/*.{html,js,php}",
219
+ // Add more paths as needed
220
+ ];
221
+ let configData = fs.readFileSync(filePath, "utf8");
222
+ const contentArrayString = newContent
223
+ .map((item) => ` "${item}"`)
224
+ .join(",\n");
225
+ configData = configData.replace(
226
+ /content: \[\],/g,
227
+ `content: [\n${contentArrayString}\n],`
228
+ );
229
+ fs.writeFileSync(filePath, configData, "utf8");
230
+ console.log(chalk.green("Tailwind configuration updated successfully."));
203
231
  }
204
232
  function modifyPostcssConfig(baseDir) {
205
- const filePath = path.join(baseDir, "postcss.config.js");
206
- const newContent = `export default {
233
+ const filePath = path.join(baseDir, "postcss.config.js");
234
+ const newContent = `export default {
207
235
  plugins: {
208
236
  tailwindcss: {},
209
237
  autoprefixer: {},
210
238
  cssnano: {},
211
239
  },
212
240
  };`;
213
- fs.writeFileSync(filePath, newContent, "utf8");
214
- console.log(chalk.green("postcss.config.js updated successfully."));
241
+ fs.writeFileSync(filePath, newContent, "utf8");
242
+ console.log(chalk.green("postcss.config.js updated successfully."));
215
243
  }
216
244
  function modifyIndexPHP(baseDir, useTailwind) {
217
- const indexPath = path.join(baseDir, "src", "app", "layout.php");
218
- try {
219
- let indexContent = fs.readFileSync(indexPath, "utf8");
220
- const stylesAndLinks = `\n <link href="<?php echo $baseUrl; ?>css/index.css" rel="stylesheet">\n <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">\n <script src="<?php echo $baseUrl; ?>js/index.js"></script>`;
221
- // Tailwind CSS link or CDN script
222
- const tailwindLink = useTailwind
223
- ? ` <link href="<?php echo $baseUrl; ?>css/styles.css" rel="stylesheet"> ${stylesAndLinks}`
224
- : ` <script src="https://cdn.tailwindcss.com"></script> ${stylesAndLinks}`;
225
- // Insert before the closing </head> tag
226
- indexContent = indexContent.replace("</head>", `${tailwindLink}\n</head>`);
227
- fs.writeFileSync(indexPath, indexContent, "utf8");
228
- console.log(chalk.green(`index.php modified successfully for ${useTailwind ? "local Tailwind CSS" : "Tailwind CSS CDN"}.`));
229
- }
230
- catch (error) {
231
- console.error(chalk.red("Error modifying index.php:"), error);
232
- }
245
+ const indexPath = path.join(baseDir, "src", "app", "layout.php");
246
+ try {
247
+ let indexContent = fs.readFileSync(indexPath, "utf8");
248
+ const stylesAndLinks = `\n <link href="<?php echo $baseUrl; ?>css/index.css" rel="stylesheet">\n <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">\n <script src="<?php echo $baseUrl; ?>js/index.js"></script>`;
249
+ // Tailwind CSS link or CDN script
250
+ const tailwindLink = useTailwind
251
+ ? ` <link href="<?php echo $baseUrl; ?>css/styles.css" rel="stylesheet"> ${stylesAndLinks}`
252
+ : ` <script src="https://cdn.tailwindcss.com"></script> ${stylesAndLinks}`;
253
+ // Insert before the closing </head> tag
254
+ indexContent = indexContent.replace("</head>", `${tailwindLink}\n</head>`);
255
+ fs.writeFileSync(indexPath, indexContent, "utf8");
256
+ console.log(
257
+ chalk.green(
258
+ `index.php modified successfully for ${
259
+ useTailwind ? "local Tailwind CSS" : "Tailwind CSS CDN"
260
+ }.`
261
+ )
262
+ );
263
+ } catch (error) {
264
+ console.error(chalk.red("Error modifying index.php:"), error);
265
+ }
233
266
  }
234
267
  // This function updates or creates the .env file
235
268
  async function updateOrCreateEnvFile(baseDir, content) {
236
- const envPath = path.join(baseDir, ".env");
237
- let envContent = fs.existsSync(envPath)
238
- ? fs.readFileSync(envPath, "utf8")
239
- : "";
240
- envContent += `${envContent !== "" ? "\n\n" : ""}${content}`;
241
- fs.writeFileSync(envPath, envContent);
269
+ const envPath = path.join(baseDir, ".env");
270
+ let envContent = fs.existsSync(envPath)
271
+ ? fs.readFileSync(envPath, "utf8")
272
+ : "";
273
+ envContent += `${envContent !== "" ? "\n\n" : ""}${content}`;
274
+ fs.writeFileSync(envPath, envContent);
242
275
  }
243
276
  async function createDirectoryStructure(baseDir, answer, projectSettings) {
244
- console.log("🚀 ~ baseDir:", baseDir);
245
- console.log("🚀 ~ answer:", answer);
246
- console.log("🚀 ~ projectSettings:", projectSettings);
247
- const filesToCopy = [
248
- { src: "/bootstrap.php", dest: "/bootstrap.php" },
249
- { src: "/.htaccess", dest: "/.htaccess" },
250
- { src: "/../composer.json", dest: "/composer.json" },
251
- ];
252
- // if (answer.websocket) {
253
- // filesToCopy.push({
254
- // src: "/../composer-websocket.lock",
255
- // dest: "/composer.lock",
256
- // });
257
- // } else {
258
- // filesToCopy.push({ src: "/../composer.lock", dest: "/composer.lock" });
259
- // }
260
- const directoriesToCopy = [
261
- {
262
- srcDir: "/settings",
263
- destDir: "/settings",
264
- },
265
- {
266
- srcDir: "/prisma",
267
- destDir: "/prisma",
268
- },
269
- {
270
- srcDir: "/src",
271
- destDir: "/src",
272
- },
273
- {
274
- srcDir: "/../vendor",
275
- destDir: "/vendor",
276
- },
277
- ];
278
- console.log("🚀 ~ directoriesToCopy:", directoriesToCopy);
279
- filesToCopy.forEach(({ src, dest }) => {
280
- const sourcePath = path.join(__dirname, src);
281
- const destPath = path.join(baseDir, dest);
282
- const code = fs.readFileSync(sourcePath, "utf8");
283
- fs.writeFileSync(destPath, code, { flag: "w" });
284
- });
285
- await executeCopy(baseDir, directoriesToCopy);
286
- await updatePackageJson(baseDir, projectSettings, answer);
287
- await updateComposerJson(baseDir, answer);
288
- await updateIndexJsForWebSocket(baseDir, answer);
289
- if (answer.tailwindcss) {
290
- modifyTailwindConfig(baseDir);
291
- modifyIndexPHP(baseDir, true);
292
- modifyPostcssConfig(baseDir);
293
- }
294
- else {
295
- modifyIndexPHP(baseDir, false);
296
- }
297
- const envContent = `# PHPMailer
277
+ console.log("🚀 ~ baseDir:", baseDir);
278
+ console.log("🚀 ~ answer:", answer);
279
+ console.log("🚀 ~ projectSettings:", projectSettings);
280
+ const filesToCopy = [
281
+ { src: "/bootstrap.php", dest: "/bootstrap.php" },
282
+ { src: "/.htaccess", dest: "/.htaccess" },
283
+ { src: "/../composer.json", dest: "/composer.json" },
284
+ ];
285
+ // if (answer.websocket) {
286
+ // filesToCopy.push({
287
+ // src: "/../composer-websocket.lock",
288
+ // dest: "/composer.lock",
289
+ // });
290
+ // } else {
291
+ // filesToCopy.push({ src: "/../composer.lock", dest: "/composer.lock" });
292
+ // }
293
+ const directoriesToCopy = [
294
+ {
295
+ srcDir: "/settings",
296
+ destDir: "/settings",
297
+ },
298
+ {
299
+ srcDir: "/prisma",
300
+ destDir: "/prisma",
301
+ },
302
+ {
303
+ srcDir: "/src",
304
+ destDir: "/src",
305
+ },
306
+ {
307
+ srcDir: "/../vendor",
308
+ destDir: "/vendor",
309
+ },
310
+ ];
311
+ console.log("🚀 ~ directoriesToCopy:", directoriesToCopy);
312
+ filesToCopy.forEach(({ src, dest }) => {
313
+ const sourcePath = path.join(__dirname, src);
314
+ const destPath = path.join(baseDir, dest);
315
+ const code = fs.readFileSync(sourcePath, "utf8");
316
+ fs.writeFileSync(destPath, code, { flag: "w" });
317
+ });
318
+ await executeCopy(baseDir, directoriesToCopy);
319
+ await updatePackageJson(baseDir, projectSettings, answer);
320
+ await updateComposerJson(baseDir, answer);
321
+ await updateIndexJsForWebSocket(baseDir, answer);
322
+ if (answer.tailwindcss) {
323
+ modifyTailwindConfig(baseDir);
324
+ modifyIndexPHP(baseDir, true);
325
+ modifyPostcssConfig(baseDir);
326
+ } else {
327
+ modifyIndexPHP(baseDir, false);
328
+ }
329
+ const envContent = `# PHPMailer
298
330
  SMTP_HOST=
299
331
  SMTP_USERNAME=
300
332
  SMTP_PASSWORD=
@@ -302,63 +334,70 @@ SMTP_PORT=
302
334
  SMTP_ENCRYPTION=ssl
303
335
  MAIL_FROM=
304
336
  MAIL_FROM_NAME=""`;
305
- await updateOrCreateEnvFile(baseDir, envContent);
306
- // Add vendor to .gitignore
307
- await createUpdateGitignoreFile(baseDir, ["vendor"]);
337
+ await updateOrCreateEnvFile(baseDir, envContent);
338
+ // Add vendor to .gitignore
339
+ await createUpdateGitignoreFile(baseDir, ["vendor"]);
308
340
  }
309
341
  async function getAnswer(predefinedAnswers = {}) {
310
- var _a, _b, _c;
311
- console.log("🚀 ~ predefinedAnswers:", predefinedAnswers);
312
- const questions = [];
313
- if (!predefinedAnswers.projectName) {
314
- questions.push({
315
- type: "text",
316
- name: "projectName",
317
- message: "What is your project named?",
318
- initial: "my-app",
319
- });
320
- }
321
- if (!predefinedAnswers.tailwindcss) {
322
- questions.push({
323
- type: "toggle",
324
- name: "tailwindcss",
325
- message: `Would you like to use ${chalk.blue("Tailwind CSS")}?`,
326
- initial: true,
327
- active: "Yes",
328
- inactive: "No",
329
- });
330
- }
331
- if (!predefinedAnswers.websocket) {
332
- questions.push({
333
- type: "toggle",
334
- name: "websocket",
335
- message: `Would you like to use ${chalk.blue("Websocket")}?`,
336
- initial: true,
337
- active: "Yes",
338
- inactive: "No",
339
- });
342
+ var _a, _b, _c;
343
+ console.log("🚀 ~ predefinedAnswers:", predefinedAnswers);
344
+ const questions = [];
345
+ if (!predefinedAnswers.projectName) {
346
+ questions.push({
347
+ type: "text",
348
+ name: "projectName",
349
+ message: "What is your project named?",
350
+ initial: "my-app",
351
+ });
352
+ }
353
+ if (!predefinedAnswers.tailwindcss) {
354
+ questions.push({
355
+ type: "toggle",
356
+ name: "tailwindcss",
357
+ message: `Would you like to use ${chalk.blue("Tailwind CSS")}?`,
358
+ initial: true,
359
+ active: "Yes",
360
+ inactive: "No",
361
+ });
362
+ }
363
+ if (!predefinedAnswers.websocket) {
364
+ questions.push({
365
+ type: "toggle",
366
+ name: "websocket",
367
+ message: `Would you like to use ${chalk.blue("Websocket")}?`,
368
+ initial: true,
369
+ active: "Yes",
370
+ inactive: "No",
371
+ });
372
+ }
373
+ console.log("🚀 ~ questions:", questions);
374
+ const onCancel = () => {
375
+ return false;
376
+ };
377
+ try {
378
+ const response = await prompts(questions, { onCancel });
379
+ if (Object.keys(response).length === 0) {
380
+ return null;
340
381
  }
341
- console.log("🚀 ~ questions:", questions);
342
- const onCancel = () => {
343
- return false;
382
+ return {
383
+ projectName: response.projectName
384
+ ? String(response.projectName).trim().replace(/ /g, "-")
385
+ : (_a = predefinedAnswers.projectName) !== null && _a !== void 0
386
+ ? _a
387
+ : "my-app",
388
+ tailwindcss:
389
+ (_b = response.tailwindcss) !== null && _b !== void 0
390
+ ? _b
391
+ : predefinedAnswers.tailwindcss,
392
+ websocket:
393
+ (_c = response.websocket) !== null && _c !== void 0
394
+ ? _c
395
+ : predefinedAnswers.websocket,
344
396
  };
345
- try {
346
- const response = await prompts(questions, { onCancel });
347
- if (Object.keys(response).length === 0) {
348
- return null;
349
- }
350
- return {
351
- projectName: response.projectName
352
- ? String(response.projectName).trim().replace(/ /g, "-")
353
- : (_a = predefinedAnswers.projectName) !== null && _a !== void 0 ? _a : "my-app",
354
- tailwindcss: (_b = response.tailwindcss) !== null && _b !== void 0 ? _b : predefinedAnswers.tailwindcss,
355
- websocket: (_c = response.websocket) !== null && _c !== void 0 ? _c : predefinedAnswers.websocket,
356
- };
357
- }
358
- catch (error) {
359
- console.error(chalk.red("Prompt error:"), error);
360
- return null;
361
- }
397
+ } catch (error) {
398
+ console.error(chalk.red("Prompt error:"), error);
399
+ return null;
400
+ }
362
401
  }
363
402
  /**
364
403
  * Install dependencies in the specified directory.
@@ -367,194 +406,206 @@ async function getAnswer(predefinedAnswers = {}) {
367
406
  * @param {boolean} [isDev=false] - Whether to install the dependencies as devDependencies.
368
407
  */
369
408
  async function installDependencies(baseDir, dependencies, isDev = false) {
370
- console.log("Initializing new Node.js project...");
371
- // Initialize a package.json if it doesn't exist
372
- if (!fs.existsSync(path.join(baseDir, "package.json")))
373
- execSync("npm init -y", {
374
- stdio: "inherit",
375
- cwd: baseDir,
376
- });
377
- // Log the dependencies being installed
378
- console.log(`${isDev ? "Installing development dependencies" : "Installing dependencies"}:`);
379
- dependencies.forEach((dep) => console.log(`- ${chalk.blue(dep)}`));
380
- // Prepare the npm install command with the appropriate flag for dev dependencies
381
- const npmInstallCommand = `npm install ${isDev ? "--save-dev" : ""} ${dependencies.join(" ")}`;
382
- // Execute the npm install command
383
- execSync(npmInstallCommand, {
384
- stdio: "inherit",
385
- cwd: baseDir,
409
+ console.log("Initializing new Node.js project...");
410
+ // Initialize a package.json if it doesn't exist
411
+ if (!fs.existsSync(path.join(baseDir, "package.json")))
412
+ execSync("npm init -y", {
413
+ stdio: "inherit",
414
+ cwd: baseDir,
386
415
  });
416
+ // Log the dependencies being installed
417
+ console.log(
418
+ `${
419
+ isDev ? "Installing development dependencies" : "Installing dependencies"
420
+ }:`
421
+ );
422
+ dependencies.forEach((dep) => console.log(`- ${chalk.blue(dep)}`));
423
+ // Prepare the npm install command with the appropriate flag for dev dependencies
424
+ const npmInstallCommand = `npm install ${
425
+ isDev ? "--save-dev" : ""
426
+ } ${dependencies.join(" ")}`;
427
+ // Execute the npm install command
428
+ execSync(npmInstallCommand, {
429
+ stdio: "inherit",
430
+ cwd: baseDir,
431
+ });
387
432
  }
388
433
  function fetchPackageVersion(packageName) {
389
- return new Promise((resolve, reject) => {
390
- https
391
- .get(`https://registry.npmjs.org/${packageName}`, (res) => {
392
- let data = "";
393
- res.on("data", (chunk) => (data += chunk));
394
- res.on("end", () => {
395
- try {
396
- const parsed = JSON.parse(data);
397
- resolve(parsed["dist-tags"].latest);
398
- }
399
- catch (error) {
400
- reject(new Error("Failed to parse JSON response"));
401
- }
402
- });
403
- })
404
- .on("error", (err) => reject(err));
405
- });
434
+ return new Promise((resolve, reject) => {
435
+ https
436
+ .get(`https://registry.npmjs.org/${packageName}`, (res) => {
437
+ let data = "";
438
+ res.on("data", (chunk) => (data += chunk));
439
+ res.on("end", () => {
440
+ try {
441
+ const parsed = JSON.parse(data);
442
+ resolve(parsed["dist-tags"].latest);
443
+ } catch (error) {
444
+ reject(new Error("Failed to parse JSON response"));
445
+ }
446
+ });
447
+ })
448
+ .on("error", (err) => reject(err));
449
+ });
406
450
  }
407
451
  async function main() {
408
- try {
409
- const args = process.argv.slice(2);
410
- let projectName = args[0];
411
- console.log("🚀 ~ main ~ projectName:", projectName);
412
- let answer = null;
413
- if (projectName) {
414
- let useTailwind = args.includes("--tailwind");
415
- let useWebsocket = args.includes("--websocket");
416
- const predefinedAnswers = {
417
- projectName,
418
- tailwindcss: useTailwind,
419
- websocket: useWebsocket,
420
- };
421
- answer = await getAnswer(predefinedAnswers);
422
- console.log("🚀 ~ main ~ answer:", answer);
423
- }
424
- else {
425
- answer = await getAnswer();
426
- }
427
- if (answer === null) {
428
- console.log(chalk.red("Installation cancelled."));
429
- return;
430
- }
431
- // execSync(`npm install -g create-prisma-php-app`, { stdio: "inherit" }); // TODO: Uncomment this line before publishing the package
432
- execSync(`npm install -g create-prisma-php-app@alpha-update-command`, {
433
- stdio: "inherit",
434
- }); // TODO: Uncomment this line before publishing the package
435
- // Support for browser-sync
436
- execSync(`npm install -g browser-sync`, { stdio: "inherit" });
437
- // Create the project directory
438
- if (!projectName)
439
- fs.mkdirSync(answer.projectName);
440
- const currentDir = process.cwd();
441
- console.log("🚀 ~ main ~ currentDir:", currentDir);
442
- let projectPath = projectName
443
- ? currentDir
444
- : path.join(currentDir, answer.projectName);
445
- console.log("🚀 ~ main ~ projectPath:", projectPath);
446
- if (!projectName)
447
- process.chdir(answer.projectName);
448
- const dependencies = [
449
- "prisma",
450
- "@prisma/client",
451
- "typescript",
452
- "@types/node",
453
- "ts-node",
454
- "http-proxy-middleware",
455
- ];
456
- if (answer.tailwindcss) {
457
- dependencies.push("tailwindcss", "autoprefixer", "postcss", "postcss-cli", "cssnano");
458
- }
459
- if (answer.websocket) {
460
- dependencies.push("chokidar-cli");
461
- }
462
- if (answer.tailwindcss || answer.websocket) {
463
- dependencies.push("npm-run-all");
464
- }
465
- await installDependencies(projectPath, dependencies, true);
466
- if (!projectName) {
467
- execSync(`npx prisma init`, { stdio: "inherit" });
468
- execSync(`npx tsc --init`, { stdio: "inherit" });
469
- }
470
- if (answer.tailwindcss) {
471
- execSync(`npx tailwindcss init -p`, { stdio: "inherit" });
472
- }
473
- const projectSettings = {
474
- PROJECT_NAME: answer.projectName,
475
- PROJECT_ROOT_PATH: projectPath.replace(/\\/g, "\\\\"),
476
- PHP_ROOT_PATH_EXE: "D:\\\\xampp\\\\php\\\\php.exe",
477
- PHP_GENERATE_CLASS_PATH: "src/lib/prisma/classes",
478
- };
479
- await createDirectoryStructure(projectPath, answer, projectSettings);
480
- // if (answer.tailwindcss) {
481
- // execSync(
482
- // `npx tailwindcss -i ./src/app/css/tailwind.css -o ./src/app/css/styles.css --minify`,
483
- // { stdio: "inherit" }
484
- // );
485
- // }
486
- // execSync(`composer install`, { stdio: "inherit" });
487
- // execSync(`composer dump-autoload`, { stdio: "inherit" });
488
- // Create settings file
489
- const settingsPath = path.join(projectPath, "settings", "project-settings.js");
490
- const settingsCode = `export const projectSettings = {
452
+ try {
453
+ const args = process.argv.slice(2);
454
+ let projectName = args[0];
455
+ console.log("🚀 ~ main ~ projectName:", projectName);
456
+ let answer = null;
457
+ if (projectName) {
458
+ let useTailwind = args.includes("--tailwind");
459
+ let useWebsocket = args.includes("--websocket");
460
+ const predefinedAnswers = {
461
+ projectName,
462
+ tailwindcss: useTailwind,
463
+ websocket: useWebsocket,
464
+ };
465
+ answer = await getAnswer(predefinedAnswers);
466
+ console.log("🚀 ~ main ~ answer:", answer);
467
+ } else {
468
+ answer = await getAnswer();
469
+ }
470
+ if (answer === null) {
471
+ console.log(chalk.red("Installation cancelled."));
472
+ return;
473
+ }
474
+ // execSync(`npm install -g create-prisma-php-app`, { stdio: "inherit" }); // TODO: Uncomment this line before publishing the package
475
+ execSync(`npm install -g create-prisma-php-app@alpha-update-command`, {
476
+ stdio: "inherit",
477
+ }); // TODO: Uncomment this line before publishing the package
478
+ // Support for browser-sync
479
+ execSync(`npm install -g browser-sync`, { stdio: "inherit" });
480
+ // Create the project directory
481
+ if (!projectName) fs.mkdirSync(answer.projectName);
482
+ const currentDir = process.cwd();
483
+ console.log("🚀 ~ main ~ currentDir:", currentDir);
484
+ let projectPath = projectName
485
+ ? currentDir
486
+ : path.join(currentDir, answer.projectName);
487
+ console.log("🚀 ~ main ~ projectPath:", projectPath);
488
+ if (!projectName) process.chdir(answer.projectName);
489
+ const dependencies = [
490
+ "prisma",
491
+ "@prisma/client",
492
+ "typescript",
493
+ "@types/node",
494
+ "ts-node",
495
+ "http-proxy-middleware",
496
+ ];
497
+ if (answer.tailwindcss) {
498
+ dependencies.push(
499
+ "tailwindcss",
500
+ "autoprefixer",
501
+ "postcss",
502
+ "postcss-cli",
503
+ "cssnano"
504
+ );
505
+ }
506
+ if (answer.websocket) {
507
+ dependencies.push("chokidar-cli");
508
+ }
509
+ if (answer.tailwindcss || answer.websocket) {
510
+ dependencies.push("npm-run-all");
511
+ }
512
+ await installDependencies(projectPath, dependencies, true);
513
+ if (!projectName) {
514
+ execSync(`npx prisma init`, { stdio: "inherit" });
515
+ execSync(`npx tsc --init`, { stdio: "inherit" });
516
+ }
517
+ if (answer.tailwindcss) {
518
+ execSync(`npx tailwindcss init -p`, { stdio: "inherit" });
519
+ }
520
+ const projectSettings = {
521
+ PROJECT_NAME: answer.projectName,
522
+ PROJECT_ROOT_PATH: projectPath.replace(/\\/g, "\\\\"),
523
+ PHP_ROOT_PATH_EXE: "D:\\\\xampp\\\\php\\\\php.exe",
524
+ PHP_GENERATE_CLASS_PATH: "src/lib/prisma/classes",
525
+ };
526
+ await createDirectoryStructure(projectPath, answer, projectSettings);
527
+ // if (answer.tailwindcss) {
528
+ // execSync(
529
+ // `npx tailwindcss -i ./src/app/css/tailwind.css -o ./src/app/css/styles.css --minify`,
530
+ // { stdio: "inherit" }
531
+ // );
532
+ // }
533
+ // execSync(`composer install`, { stdio: "inherit" });
534
+ // execSync(`composer dump-autoload`, { stdio: "inherit" });
535
+ // Create settings file
536
+ const settingsPath = path.join(
537
+ projectPath,
538
+ "settings",
539
+ "project-settings.js"
540
+ );
541
+ const settingsCode = `export const projectSettings = {
491
542
  PROJECT_NAME: "${answer.projectName}",
492
543
  PROJECT_ROOT_PATH: "${projectPath.replace(/\\/g, "\\\\")}",
493
544
  PHP_ROOT_PATH_EXE: "D:\\\\xampp\\\\php\\\\php.exe",
494
545
  PHP_GENERATE_CLASS_PATH: "src/lib/prisma/classes",
495
546
  };`;
496
- console.log("🚀 ~ main ~ settingsCode:", settingsCode);
497
- fs.writeFileSync(settingsPath, settingsCode, { flag: "w" });
498
- // Create public directory
499
- const publicDirPath = path.join(projectPath, "public");
500
- if (!fs.existsSync(publicDirPath)) {
501
- fs.mkdirSync(publicDirPath);
502
- }
503
- // Update css if tailwindcss is not chosen by the user
504
- if (!answer.tailwindcss) {
505
- // delete specific files of tailwindcss if not chosen
506
- const cssPath = path.join(projectPath, "src", "app", "css");
507
- const tailwindFiles = ["tailwind.css", "styles.css"];
508
- tailwindFiles.forEach((file) => {
509
- const filePath = path.join(cssPath, file);
510
- if (fs.existsSync(filePath)) {
511
- fs.unlinkSync(filePath); // Delete each file if it exists
512
- console.log(`${file} was deleted successfully.`);
513
- }
514
- else {
515
- console.log(`${file} does not exist.`);
516
- }
517
- });
518
- }
519
- // Update websocket if not chosen by the user
520
- if (!answer.websocket) {
521
- const wsPath = path.join(projectPath, "src", "lib", "websocket");
522
- // Check if the websocket directory exists
523
- if (fs.existsSync(wsPath)) {
524
- // Use fs.rmSync with recursive option set to true to delete the directory and its contents
525
- fs.rmSync(wsPath, { recursive: true, force: true }); // force option is not necessary but can be used to ensure deletion
526
- console.log("Websocket directory was deleted successfully.");
527
- }
528
- else {
529
- console.log("Websocket directory does not exist.");
530
- }
531
- // Update settings directory if websocket is not chosen
532
- const settingsPath = path.join(projectPath, "settings");
533
- const websocketFiles = ["restartWebsocket.cjs", "restart_websocket.bat"];
534
- websocketFiles.forEach((file) => {
535
- const filePath = path.join(settingsPath, file);
536
- if (fs.existsSync(filePath)) {
537
- fs.unlinkSync(filePath); // Delete each file if it exists
538
- console.log(`${file} was deleted successfully.`);
539
- }
540
- else {
541
- console.log(`${file} does not exist.`);
542
- }
543
- });
547
+ fs.writeFileSync(settingsPath, settingsCode, { flag: "w" });
548
+ const publicDirPath = path.join(projectPath, "public");
549
+ if (!fs.existsSync(publicDirPath)) {
550
+ fs.mkdirSync(publicDirPath);
551
+ }
552
+ if (!answer.tailwindcss) {
553
+ const cssPath = path.join(projectPath, "src", "app", "css");
554
+ const tailwindFiles = ["tailwind.css", "styles.css"];
555
+ tailwindFiles.forEach((file) => {
556
+ const filePath = path.join(cssPath, file);
557
+ if (fs.existsSync(filePath)) {
558
+ fs.unlinkSync(filePath); // Delete each file if it exists
559
+ console.log(`${file} was deleted successfully.`);
560
+ } else {
561
+ console.log(`${file} does not exist.`);
544
562
  }
545
- const version = await fetchPackageVersion("create-prisma-php-app");
546
- const prismaPhpConfig = {
547
- projectName: answer.projectName,
548
- tailwindcss: answer.tailwindcss,
549
- websocket: answer.websocket,
550
- version,
551
- };
552
- fs.writeFileSync(path.join(projectPath, "prisma-php.json"), JSON.stringify(prismaPhpConfig, null, 2), { flag: "w" });
553
- console.log(`${chalk.green("Success!")} Prisma PHP project successfully created in ${answer.projectName}!`);
563
+ });
554
564
  }
555
- catch (error) {
556
- console.error("Error while creating the project:", error);
557
- process.exit(1);
565
+ // Update websocket if not chosen by the user
566
+ if (!answer.websocket) {
567
+ const wsPath = path.join(projectPath, "src", "lib", "websocket");
568
+ // Check if the websocket directory exists
569
+ if (fs.existsSync(wsPath)) {
570
+ // Use fs.rmSync with recursive option set to true to delete the directory and its contents
571
+ fs.rmSync(wsPath, { recursive: true, force: true }); // force option is not necessary but can be used to ensure deletion
572
+ console.log("Websocket directory was deleted successfully.");
573
+ } else {
574
+ console.log("Websocket directory does not exist.");
575
+ }
576
+ // Update settings directory if websocket is not chosen
577
+ const settingsPath = path.join(projectPath, "settings");
578
+ const websocketFiles = ["restartWebsocket.cjs", "restart_websocket.bat"];
579
+ websocketFiles.forEach((file) => {
580
+ const filePath = path.join(settingsPath, file);
581
+ if (fs.existsSync(filePath)) {
582
+ fs.unlinkSync(filePath); // Delete each file if it exists
583
+ console.log(`${file} was deleted successfully.`);
584
+ } else {
585
+ console.log(`${file} does not exist.`);
586
+ }
587
+ });
558
588
  }
589
+ const version = await fetchPackageVersion("create-prisma-php-app");
590
+ const prismaPhpConfig = {
591
+ projectName: answer.projectName,
592
+ tailwindcss: answer.tailwindcss,
593
+ websocket: answer.websocket,
594
+ version,
595
+ };
596
+ fs.writeFileSync(
597
+ path.join(projectPath, "prisma-php.json"),
598
+ JSON.stringify(prismaPhpConfig, null, 2),
599
+ { flag: "w" }
600
+ );
601
+ console.log(
602
+ `${chalk.green("Success!")} Prisma PHP project successfully created in ${
603
+ answer.projectName
604
+ }!`
605
+ );
606
+ } catch (error) {
607
+ console.error("Error while creating the project:", error);
608
+ process.exit(1);
609
+ }
559
610
  }
560
611
  main();
@@ -1,5 +1,33 @@
1
1
  #!/usr/bin/env node
2
- import{spawn}from"child_process";import fs from"fs";import path from"path";import prompts from"prompts";import{fileURLToPath}from"url";const __filename=fileURLToPath(import.meta.url),__dirname=path.dirname(__filename),args=process.argv.slice(2),readJsonFile=r=>{const e=fs.readFileSync(r,"utf8");return JSON.parse(e)},executeCommand=(r,e=[],o={})=>new Promise(((s,t)=>{const i=spawn(r,e,Object.assign({stdio:"inherit",shell:!0},o));i.on("error",(r=>{t(r)})),i.on("close",(r=>{0===r?s():t(new Error(`Process exited with code ${r}`))}))}));
2
+ import { spawn } from "child_process";
3
+ import fs from "fs";
4
+ import path from "path";
5
+ import prompts from "prompts";
6
+ import { fileURLToPath } from "url";
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = path.dirname(__filename);
9
+ const args = process.argv.slice(2);
10
+ const readJsonFile = (filePath) => {
11
+ const jsonData = fs.readFileSync(filePath, "utf8");
12
+ return JSON.parse(jsonData);
13
+ };
14
+ const executeCommand = (command, args = [], options = {}) => {
15
+ return new Promise((resolve, reject) => {
16
+ const process = spawn(command, args, Object.assign({ stdio: "inherit", shell: true }, options));
17
+ process.on("error", (error) => {
18
+ console.error(`Execution error: ${error.message}`);
19
+ reject(error);
20
+ });
21
+ process.on("close", (code) => {
22
+ if (code === 0) {
23
+ resolve();
24
+ }
25
+ else {
26
+ reject(new Error(`Process exited with code ${code}`));
27
+ }
28
+ });
29
+ });
30
+ };
3
31
  const main = async () => {
4
32
  if (args.length > 0 && args[0] === "update") {
5
33
  try {
@@ -16,11 +44,13 @@ const main = async () => {
16
44
  const currentDir = process.cwd();
17
45
  const configPath = path.join(currentDir, "prisma-php.json");
18
46
  const localSettings = readJsonFile(configPath);
47
+ console.log("🚀 ~ main ~ localSettings:", localSettings);
19
48
  const commandArgs = [localSettings.projectName];
20
49
  if (localSettings.tailwindcss)
21
50
  commandArgs.push("--tailwindcss");
22
51
  if (localSettings.websocket)
23
52
  commandArgs.push("--websocket");
53
+ console.log("🚀 ~ main ~ commandArgs:", commandArgs);
24
54
  console.log("Executing command...\n");
25
55
  await executeCommand("npx", [
26
56
  "create-prisma-php-app@alpha-update-command",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "1.6.30",
3
+ "version": "1.6.31",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",