create-prisma-php-app 1.6.60 → 1.6.63

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
@@ -264,7 +264,9 @@ async function createOrUpdateEnvFile(baseDir, content) {
264
264
  }
265
265
  function checkExcludeFiles(destPath) {
266
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);
267
+ if (!(updateAnswer === null || updateAnswer === void 0 ? void 0 : updateAnswer.isUpdate))
268
+ return false;
269
+ 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);
268
270
  }
269
271
  async function createDirectoryStructure(baseDir, answer, projectSettings) {
270
272
  console.log("🚀 ~ baseDir:", baseDir);
@@ -485,7 +487,7 @@ async function main() {
485
487
  const filePath = path.join(currentDir, file);
486
488
  console.log("🚀 ~ localSettings.excludeFiles?.map ~ filePath:", filePath);
487
489
  if (fs.existsSync(filePath))
488
- excludeFiles.push(filePath);
490
+ excludeFiles.push(filePath.replace(/\\/g, "/"));
489
491
  });
490
492
  updateAnswer = {
491
493
  projectName,
@@ -493,6 +495,7 @@ async function main() {
493
495
  websocket: (_c = answer === null || answer === void 0 ? void 0 : answer.websocket) !== null && _c !== void 0 ? _c : false,
494
496
  isUpdate: true,
495
497
  excludeFiles: (_d = localSettings.excludeFiles) !== null && _d !== void 0 ? _d : [],
498
+ excludeFilePath: excludeFiles !== null && excludeFiles !== void 0 ? excludeFiles : [],
496
499
  filePath: currentDir,
497
500
  };
498
501
  console.log("🚀 ~ main ~ answer:", answer);
@@ -9,100 +9,117 @@ 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(
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);
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
+ });
25
30
  });
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
- });
34
31
  };
35
32
  async function getAnswer() {
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;
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;
59
52
  }
53
+ const commandsToExecute = ["npx pphp generate class", "npx pphp update"];
60
54
  const main = async () => {
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."));
55
+ if (args.length === 0) {
56
+ console.log("No command provided.");
68
57
  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
- );
58
+ }
59
+ const formattedCommand = `npx pphp ${args.join(" ")}`;
60
+ if (!commandsToExecute.includes(formattedCommand)) {
61
+ console.log("Command not recognized or not allowed.");
78
62
  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
- );
63
+ }
64
+ if (args[0] === "update") {
65
+ try {
66
+ const answer = await getAnswer();
67
+ if (!(answer === null || answer === void 0 ? void 0 : answer.shouldProceed)) {
68
+ console.log(chalk.red("Operation cancelled by the user."));
69
+ return;
70
+ }
71
+ const currentDir = process.cwd();
72
+ const configPath = path.join(currentDir, "prisma-php.json");
73
+ if (!fs.existsSync(configPath)) {
74
+ console.error(chalk.red("The configuration file 'prisma-php.json' was not found in the current directory."));
75
+ return;
76
+ }
77
+ const localSettings = readJsonFile(configPath);
78
+ const commandArgs = [localSettings.projectName];
79
+ if (localSettings.tailwindcss)
80
+ commandArgs.push("--tailwindcss");
81
+ if (localSettings.websocket)
82
+ commandArgs.push("--websocket");
83
+ console.log("Executing command...\n");
84
+ await executeCommand("npx", [
85
+ "create-prisma-php-app@alpha-update-command",
86
+ ...commandArgs,
87
+ ]);
88
+ }
89
+ catch (error) {
90
+ if (error instanceof Error) {
91
+ if (error.message.includes("no such file or directory")) {
92
+ console.error(chalk.red("The configuration file 'prisma-php.json' was not found in the current directory."));
93
+ }
94
+ }
95
+ else {
96
+ console.error("Error in script execution:", error);
97
+ }
97
98
  }
98
- } else {
99
- console.error("Error in script execution:", error);
100
- }
101
99
  }
102
- } else {
103
- console.log("Command not recognized.");
104
- }
100
+ else if (args[0] === "generate" && args[1] === "class") {
101
+ const executeGenerateCommand = async () => {
102
+ try {
103
+ const currentDir = process.cwd();
104
+ const prismaClientPath = path.join(currentDir, "prisma-client-php", "index.js");
105
+ if (!fs.existsSync(prismaClientPath)) {
106
+ console.error(chalk.red("The prisma-client-php/index.js file was not found in the current directory."));
107
+ return;
108
+ }
109
+ console.log("Executing command...\n");
110
+ await executeCommand("node", [prismaClientPath]);
111
+ }
112
+ catch (error) {
113
+ console.error("Error in script execution:", error);
114
+ }
115
+ };
116
+ // Call the executeGenerateCommand function
117
+ await executeGenerateCommand();
118
+ }
119
+ else {
120
+ console.log("Command not recognized.");
121
+ }
105
122
  };
106
123
  main().catch((error) => {
107
- console.error("Unhandled error in main function:", error);
124
+ console.error("Unhandled error in main function:", error);
108
125
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "1.6.60",
3
+ "version": "1.6.63",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -11,8 +11,7 @@
11
11
  },
12
12
  "bin": {
13
13
  "create-prisma-php-app": "dist/index.js",
14
- "php": "dist/prisma-client-php/index.js",
15
- "prisma-php": "dist/prisma-php.js"
14
+ "pphp": "dist/prisma-php.js"
16
15
  },
17
16
  "repository": {
18
17
  "type": "git",