create-prisma-php-app 1.6.56 → 1.6.58

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
@@ -73,6 +73,8 @@ function configureBrowserSyncCommand(baseDir, projectSettings) {
73
73
  }
74
74
  async function updatePackageJson(baseDir, projectSettings, answer) {
75
75
  const packageJsonPath = path.join(baseDir, "package.json");
76
+ if (checkExcludeFiles(packageJsonPath))
77
+ return;
76
78
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
77
79
  // Use the new function to configure the Browser Sync command
78
80
  const browserSyncCommand = configureBrowserSyncCommand(baseDir, projectSettings);
@@ -109,6 +111,8 @@ async function updateComposerJson(baseDir, answer) {
109
111
  if (!answer.websocket)
110
112
  return;
111
113
  const composerJsonPath = path.join(baseDir, "composer.json");
114
+ if (checkExcludeFiles(composerJsonPath))
115
+ return;
112
116
  let composerJson;
113
117
  // Check if the composer.json file exists
114
118
  if (fs.existsSync(composerJsonPath)) {
@@ -133,6 +137,8 @@ async function updateIndexJsForWebSocket(baseDir, answer) {
133
137
  return;
134
138
  }
135
139
  const indexPath = path.join(baseDir, "src", "app", "js", "index.js");
140
+ if (checkExcludeFiles(indexPath))
141
+ return;
136
142
  let indexContent = fs.readFileSync(indexPath, "utf8");
137
143
  // WebSocket initialization code to be appended
138
144
  const webSocketCode = `
@@ -147,6 +153,8 @@ const ws = new WebSocket("ws://localhost:8080");
147
153
  // This function updates the .gitignore file
148
154
  async function createUpdateGitignoreFile(baseDir, additions) {
149
155
  const gitignorePath = path.join(baseDir, ".gitignore");
156
+ if (checkExcludeFiles(gitignorePath))
157
+ return;
150
158
  // Check if the .gitignore file exists, create if it doesn't
151
159
  let gitignoreContent = "";
152
160
  if (fs.existsSync(gitignorePath)) {
@@ -163,7 +171,6 @@ async function createUpdateGitignoreFile(baseDir, additions) {
163
171
  }
164
172
  // Recursive copy function
165
173
  function copyRecursiveSync(src, dest) {
166
- var _a;
167
174
  console.log("🚀 ~ copyRecursiveSync ~ dest:", dest);
168
175
  console.log("🚀 ~ copyRecursiveSync ~ src:", src);
169
176
  const exists = fs.existsSync(src);
@@ -176,10 +183,8 @@ function copyRecursiveSync(src, dest) {
176
183
  });
177
184
  }
178
185
  else {
179
- if ((_a = updateAnswer === null || updateAnswer === void 0 ? void 0 : updateAnswer.excludeFiles) === null || _a === void 0 ? void 0 : _a.includes(dest.replace(/\\/g, "/"))) {
180
- console.log(`Skipping file: ${src}`);
186
+ if (checkExcludeFiles(dest))
181
187
  return;
182
- }
183
188
  fs.copyFileSync(src, dest, 0);
184
189
  }
185
190
  }
@@ -194,6 +199,8 @@ async function executeCopy(baseDir, directoriesToCopy) {
194
199
  function createOrUpdateTailwindConfig(baseDir) {
195
200
  console.log("🚀 ~ createOrUpdateTailwindConfig ~ baseDir:", baseDir);
196
201
  const filePath = path.join(baseDir, "tailwind.config.js");
202
+ if (checkExcludeFiles(filePath))
203
+ return;
197
204
  const newContent = [
198
205
  "./src/app/**/*.{html,js,php}",
199
206
  // Add more paths as needed
@@ -209,6 +216,8 @@ function createOrUpdateTailwindConfig(baseDir) {
209
216
  }
210
217
  function modifyPostcssConfig(baseDir) {
211
218
  const filePath = path.join(baseDir, "postcss.config.js");
219
+ if (checkExcludeFiles(filePath))
220
+ return;
212
221
  const newContent = `export default {
213
222
  plugins: {
214
223
  tailwindcss: {},
@@ -219,10 +228,12 @@ function modifyPostcssConfig(baseDir) {
219
228
  fs.writeFileSync(filePath, newContent, { flag: "w" });
220
229
  console.log(chalk.green("postcss.config.js updated successfully."));
221
230
  }
222
- function modifyIndexPHP(baseDir, useTailwind) {
223
- const indexPath = path.join(baseDir, "src", "app", "layout.php");
231
+ function modifyLayoutPHP(baseDir, useTailwind) {
232
+ const layoutPath = path.join(baseDir, "src", "app", "layout.php");
233
+ if (checkExcludeFiles(layoutPath))
234
+ return;
224
235
  try {
225
- let indexContent = fs.readFileSync(indexPath, "utf8");
236
+ let indexContent = fs.readFileSync(layoutPath, "utf8");
226
237
  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>`;
227
238
  // Tailwind CSS link or CDN script
228
239
  const tailwindLink = useTailwind
@@ -230,7 +241,7 @@ function modifyIndexPHP(baseDir, useTailwind) {
230
241
  : ` <script src="https://cdn.tailwindcss.com"></script> ${stylesAndLinks}`;
231
242
  // Insert before the closing </head> tag
232
243
  indexContent = indexContent.replace("</head>", `${tailwindLink}\n</head>`);
233
- fs.writeFileSync(indexPath, indexContent, { flag: "w" });
244
+ fs.writeFileSync(layoutPath, indexContent, { flag: "w" });
234
245
  console.log(chalk.green(`index.php modified successfully for ${useTailwind ? "local Tailwind CSS" : "Tailwind CSS CDN"}.`));
235
246
  }
236
247
  catch (error) {
@@ -240,6 +251,8 @@ function modifyIndexPHP(baseDir, useTailwind) {
240
251
  // This function updates or creates the .env file
241
252
  async function createOrUpdateEnvFile(baseDir, content) {
242
253
  const envPath = path.join(baseDir, ".env");
254
+ if (checkExcludeFiles(envPath))
255
+ return;
243
256
  let envContent = fs.existsSync(envPath)
244
257
  ? fs.readFileSync(envPath, "utf8")
245
258
  : "";
@@ -249,6 +262,10 @@ async function createOrUpdateEnvFile(baseDir, content) {
249
262
  fs.writeFileSync(envPath, envContent, { flag: "w" });
250
263
  }
251
264
  }
265
+ function checkExcludeFiles(destPath) {
266
+ var _a, _b;
267
+ return ((_b = (_a = updateAnswer === null || updateAnswer === void 0 ? void 0 : updateAnswer.excludeFiles) === null || _a === void 0 ? void 0 : _a.includes(destPath.replace(/\\/g, "/"))) !== null && _b !== void 0 ? _b : false);
268
+ }
252
269
  async function createDirectoryStructure(baseDir, answer, projectSettings) {
253
270
  console.log("🚀 ~ baseDir:", baseDir);
254
271
  console.log("🚀 ~ answer:", answer);
@@ -294,6 +311,8 @@ async function createDirectoryStructure(baseDir, answer, projectSettings) {
294
311
  filesToCopy.forEach(({ src, dest }) => {
295
312
  const sourcePath = path.join(__dirname, src);
296
313
  const destPath = path.join(baseDir, dest);
314
+ if (checkExcludeFiles(destPath))
315
+ return;
297
316
  const code = fs.readFileSync(sourcePath, "utf8");
298
317
  fs.writeFileSync(destPath, code, { flag: "w" });
299
318
  });
@@ -303,11 +322,11 @@ async function createDirectoryStructure(baseDir, answer, projectSettings) {
303
322
  await updateIndexJsForWebSocket(baseDir, answer);
304
323
  if (answer.tailwindcss) {
305
324
  createOrUpdateTailwindConfig(baseDir);
306
- modifyIndexPHP(baseDir, true);
325
+ modifyLayoutPHP(baseDir, true);
307
326
  modifyPostcssConfig(baseDir);
308
327
  }
309
328
  else {
310
- modifyIndexPHP(baseDir, false);
329
+ modifyLayoutPHP(baseDir, false);
311
330
  }
312
331
  const envContent = `# PHPMailer
313
332
  SMTP_HOST=
@@ -9,88 +9,100 @@ const __filename = fileURLToPath(import.meta.url);
9
9
  const __dirname = path.dirname(__filename);
10
10
  const args = process.argv.slice(2);
11
11
  const readJsonFile = (filePath) => {
12
- const jsonData = fs.readFileSync(filePath, "utf8");
13
- return JSON.parse(jsonData);
12
+ const jsonData = fs.readFileSync(filePath, "utf8");
13
+ return JSON.parse(jsonData);
14
14
  };
15
15
  const executeCommand = (command, args = [], options = {}) => {
16
- return new Promise((resolve, reject) => {
17
- const process = spawn(command, args, Object.assign({ stdio: "inherit", shell: true }, options));
18
- process.on("error", (error) => {
19
- console.error(`Execution error: ${error.message}`);
20
- reject(error);
21
- });
22
- process.on("close", (code) => {
23
- if (code === 0) {
24
- resolve();
25
- }
26
- else {
27
- reject(new Error(`Process exited with code ${code}`));
28
- }
29
- });
16
+ return new Promise((resolve, reject) => {
17
+ const process = spawn(
18
+ command,
19
+ args,
20
+ Object.assign({ stdio: "inherit", shell: true }, options)
21
+ );
22
+ process.on("error", (error) => {
23
+ console.error(`Execution error: ${error.message}`);
24
+ reject(error);
30
25
  });
26
+ process.on("close", (code) => {
27
+ if (code === 0) {
28
+ resolve();
29
+ } else {
30
+ reject(new Error(`Process exited with code ${code}`));
31
+ }
32
+ });
33
+ });
31
34
  };
32
35
  async function getAnswer() {
33
- const questions = [
34
- {
35
- type: "toggle",
36
- name: "shouldProceed",
37
- message: `This command will update the ${chalk.blue("create-prisma-php-app")} package and overwrite all default files. ${chalk.blue("Do you want to proceed")}?`,
38
- initial: false,
39
- active: "Yes",
40
- inactive: "No",
41
- },
42
- ];
43
- const onCancel = () => {
44
- console.log(chalk.red("Operation cancelled by the user."));
45
- process.exit(0);
46
- };
47
- const response = await prompts(questions, { onCancel });
48
- if (Object.keys(response).length === 0) {
49
- return null;
50
- }
51
- return response;
36
+ const questions = [
37
+ {
38
+ type: "toggle",
39
+ name: "shouldProceed",
40
+ message: `This command will update the ${chalk.blue(
41
+ "create-prisma-php-app"
42
+ )} package and overwrite all default files. ${chalk.blue(
43
+ "Do you want to proceed"
44
+ )}?`,
45
+ initial: false,
46
+ active: "Yes",
47
+ inactive: "No",
48
+ },
49
+ ];
50
+ const onCancel = () => {
51
+ console.log(chalk.red("Operation cancelled by the user."));
52
+ process.exit(0);
53
+ };
54
+ const response = await prompts(questions, { onCancel });
55
+ if (Object.keys(response).length === 0) {
56
+ return null;
57
+ }
58
+ return response;
52
59
  }
53
60
  const main = async () => {
54
- if (args.length > 0 && args[0] === "update") {
55
- try {
56
- const answer = await getAnswer();
57
- if (!(answer === null || answer === void 0 ? void 0 : answer.shouldProceed)) {
58
- console.log(chalk.red("Operation cancelled by the user."));
59
- return;
60
- }
61
- const currentDir = process.cwd();
62
- const configPath = path.join(currentDir, "prisma-php.json");
63
- if (!fs.existsSync(configPath)) {
64
- console.error(chalk.red("The configuration file 'prisma-php.json' was not found in the current directory."));
65
- return;
66
- }
67
- const localSettings = readJsonFile(configPath);
68
- const commandArgs = [localSettings.projectName];
69
- if (localSettings.tailwindcss)
70
- commandArgs.push("--tailwindcss");
71
- if (localSettings.websocket)
72
- commandArgs.push("--websocket");
73
- console.log("Executing command...\n");
74
- await executeCommand("npx", [
75
- "create-prisma-php-app@alpha-update-command",
76
- ...commandArgs,
77
- ]);
78
- }
79
- catch (error) {
80
- if (error instanceof Error) {
81
- if (error.message.includes("no such file or directory")) {
82
- console.error(chalk.red("The configuration file 'prisma-php.json' was not found in the current directory."));
83
- }
84
- }
85
- else {
86
- console.error("Error in script execution:", error);
87
- }
61
+ if (args.length > 0 && args[0] === "update") {
62
+ try {
63
+ const answer = await getAnswer();
64
+ if (
65
+ !(answer === null || answer === void 0 ? void 0 : answer.shouldProceed)
66
+ ) {
67
+ console.log(chalk.red("Operation cancelled by the user."));
68
+ return;
69
+ }
70
+ const currentDir = process.cwd();
71
+ const configPath = path.join(currentDir, "prisma-php.json");
72
+ if (!fs.existsSync(configPath)) {
73
+ console.error(
74
+ chalk.red(
75
+ "The configuration file 'prisma-php.json' was not found in the current directory."
76
+ )
77
+ );
78
+ return;
79
+ }
80
+ const localSettings = readJsonFile(configPath);
81
+ const commandArgs = [localSettings.projectName];
82
+ if (localSettings.tailwindcss) commandArgs.push("--tailwindcss");
83
+ if (localSettings.websocket) commandArgs.push("--websocket");
84
+ console.log("Executing command...\n");
85
+ await executeCommand("npx", [
86
+ "create-prisma-php-app@alpha-update-command",
87
+ ...commandArgs,
88
+ ]);
89
+ } catch (error) {
90
+ if (error instanceof Error) {
91
+ if (error.message.includes("no such file or directory")) {
92
+ console.error(
93
+ chalk.red(
94
+ "The configuration file 'prisma-php.json' was not found in the current directory."
95
+ )
96
+ );
88
97
  }
98
+ } else {
99
+ console.error("Error in script execution:", error);
100
+ }
89
101
  }
90
- else {
91
- console.log("Command not recognized.");
92
- }
102
+ } else {
103
+ console.log("Command not recognized.");
104
+ }
93
105
  };
94
106
  main().catch((error) => {
95
- console.error("Unhandled error in main function:", error);
107
+ console.error("Unhandled error in main function:", error);
96
108
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "1.6.56",
3
+ "version": "1.6.58",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",