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.
- package/dist/index.js +2 -0
- package/dist/prisma-client-php/index.enc +1 -1
- package/dist/prisma-client-php/index.js +49 -3
- package/dist/prisma-php.js +98 -83
- package/package.json +2 -3
|
@@ -1,5 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
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
|
|
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
|
+
});
|
package/dist/prisma-php.js
CHANGED
|
@@ -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
|
-
|
|
13
|
-
|
|
12
|
+
const jsonData = fs.readFileSync(filePath, "utf8");
|
|
13
|
+
return JSON.parse(jsonData);
|
|
14
14
|
};
|
|
15
15
|
const executeCommand = (command, args = [], options = {}) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
62
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
-
"
|
|
15
|
-
"prisma-php": "dist/prisma-php.js"
|
|
14
|
+
"pphp": "dist/prisma-php.js"
|
|
16
15
|
},
|
|
17
16
|
"repository": {
|
|
18
17
|
"type": "git",
|