create-prisma-php-app 1.6.61 → 1.6.64

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.
@@ -1,5 +1,21 @@
1
- #!/usr/bin/env node
2
- import*as fs from"fs";import{exec}from"child_process";import path from"path";import{fileURLToPath,pathToFileURL}from"url";import CryptoJS from"crypto-js";const __filename=fileURLToPath(import.meta.url),__dirname=path.dirname(__filename),args=process.argv.slice(2),getSecretKey=()=>{const r=fs.readFileSync(`${__dirname}/key.enc`,"utf8");if(r.length<400)throw new Error("File content is less than 400 characters.");return r.substring(247,289)},decryptData=(r,t)=>CryptoJS.AES.decrypt(r,t).toString(CryptoJS.enc.Utf8);
1
+ import * as fs from "fs";
2
+ import { exec } from "child_process";
3
+ import path from "path";
4
+ import { fileURLToPath, pathToFileURL } from "url";
5
+ import CryptoJS from "crypto-js";
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
8
+ const getSecretKey = () => {
9
+ const data = fs.readFileSync(`${__dirname}/key.enc`, "utf8");
10
+ if (data.length < 400) {
11
+ throw new Error("File content is less than 400 characters.");
12
+ }
13
+ return data.substring(247, 289);
14
+ };
15
+ const decryptData = (encryptedData, secretKey) => {
16
+ const bytes = CryptoJS.AES.decrypt(encryptedData, secretKey);
17
+ return bytes.toString(CryptoJS.enc.Utf8);
18
+ };
3
19
  const executePHP = (command) => {
4
20
  exec(command, (error, stdout, stderr) => {
5
21
  if (error) {
@@ -13,4 +29,34 @@ const executePHP = (command) => {
13
29
  console.log(`Standard output...\n${stdout}`);
14
30
  });
15
31
  };
16
- const main=async()=>{if("generate"===args[0]&&"class"===args[1])try{const e=process.cwd(),t=pathToFileURL(path.join(e,"settings","project-settings.js")),n=(await import(t.href)).projectSettings,c=n.PHP_GENERATE_CLASS_PATH,i=`${__dirname}/index.php`,a=`${__dirname}/index.enc`,s=getSecretKey(),r=fs.readFileSync(a,{encoding:"utf8"}),_=decryptData(r,s);fs.writeFileSync(`${__dirname}/index.php`,_);const p=`${n.PHP_ROOT_PATH_EXE} ${i} ${c}`;executePHP(p)}catch(e){}};main().catch((e=>{}));
32
+ const main = async () => {
33
+ try {
34
+ const currentDir = process.cwd();
35
+ console.log("🚀 ~ main ~ currentDir:", currentDir);
36
+ console.log("🚀 ~ __dirname:", __dirname);
37
+ const settingsURL = pathToFileURL(
38
+ path.join(currentDir, "settings", "project-settings.js")
39
+ );
40
+ const localSettings = await import(settingsURL.href);
41
+ const projectSettings = localSettings.projectSettings;
42
+ console.log("🚀 ~ main ~ projectSettings:", projectSettings);
43
+ const phpGenerateClassPath = projectSettings.PHP_GENERATE_CLASS_PATH;
44
+ const phpFile = `${__dirname}/index.php`;
45
+ console.log("🚀 ~ main ~ phpFile:", phpFile);
46
+ const encryptedFilePath = `${__dirname}/index.enc`;
47
+ const secretKey = getSecretKey();
48
+ const encryptedData = fs.readFileSync(encryptedFilePath, {
49
+ encoding: "utf8",
50
+ });
51
+ const decryptedData = decryptData(encryptedData, secretKey);
52
+ fs.writeFileSync(`${__dirname}/index.php`, decryptedData);
53
+ const command = `${projectSettings.PHP_ROOT_PATH_EXE} ${phpFile} ${phpGenerateClassPath}`;
54
+ console.log("Executing command...\n");
55
+ executePHP(command);
56
+ } catch (error) {
57
+ console.error("Error in script execution:", error);
58
+ }
59
+ };
60
+ main().catch((error) => {
61
+ console.error("Unhandled error in main function:", error);
62
+ });
@@ -9,100 +9,115 @@ 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 = {
54
+ generateClass: "npx pphp generate class",
55
+ update: "npx pphp update",
56
+ };
60
57
  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."));
58
+ if (args.length === 0) {
59
+ console.log("No command provided.");
68
60
  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
- );
61
+ }
62
+ const formattedCommand = `npx pphp ${args.join(" ")}`;
63
+ console.log("🚀 ~ main ~ formattedCommand:", formattedCommand);
64
+ const commandsArray = Object.values(commandsToExecute);
65
+ console.log("🚀 ~ main ~ commandsToExecute:", commandsArray);
66
+ if (!commandsArray.includes(formattedCommand)) {
67
+ console.log("Command not recognized or not allowed.");
78
68
  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
- );
69
+ }
70
+ if (formattedCommand === commandsToExecute.update) {
71
+ try {
72
+ const answer = await getAnswer();
73
+ if (!(answer === null || answer === void 0 ? void 0 : answer.shouldProceed)) {
74
+ console.log(chalk.red("Operation cancelled by the user."));
75
+ return;
76
+ }
77
+ const currentDir = process.cwd();
78
+ const configPath = path.join(currentDir, "prisma-php.json");
79
+ if (!fs.existsSync(configPath)) {
80
+ console.error(chalk.red("The configuration file 'prisma-php.json' was not found in the current directory."));
81
+ return;
82
+ }
83
+ const localSettings = readJsonFile(configPath);
84
+ const commandArgs = [localSettings.projectName];
85
+ if (localSettings.tailwindcss)
86
+ commandArgs.push("--tailwindcss");
87
+ if (localSettings.websocket)
88
+ commandArgs.push("--websocket");
89
+ console.log("Executing command...\n");
90
+ await executeCommand("npx", [
91
+ "create-prisma-php-app@alpha-update-command",
92
+ ...commandArgs,
93
+ ]);
94
+ }
95
+ catch (error) {
96
+ if (error instanceof Error) {
97
+ if (error.message.includes("no such file or directory")) {
98
+ console.error(chalk.red("The configuration file 'prisma-php.json' was not found in the current directory."));
99
+ }
100
+ }
101
+ else {
102
+ console.error("Error in script execution:", error);
103
+ }
104
+ }
105
+ }
106
+ if (formattedCommand === commandsToExecute.generateClass) {
107
+ try {
108
+ const prismaClientPath = path.join(__dirname, "prisma-client-php", "index.js");
109
+ if (!fs.existsSync(prismaClientPath)) {
110
+ console.error(chalk.red("The prisma-client-php/index.js file was not found in the current directory."));
111
+ return;
112
+ }
113
+ console.log("Executing command...\n");
114
+ await executeCommand("node", [prismaClientPath]);
115
+ }
116
+ catch (error) {
117
+ console.error("Error in script execution:", error);
97
118
  }
98
- } else {
99
- console.error("Error in script execution:", error);
100
- }
101
119
  }
102
- } else {
103
- console.log("Command not recognized.");
104
- }
105
120
  };
106
121
  main().catch((error) => {
107
- console.error("Unhandled error in main function:", error);
122
+ console.error("Unhandled error in main function:", error);
108
123
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "1.6.61",
3
+ "version": "1.6.64",
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",