create-prisma-php-app 1.6.64 → 1.7.1
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 +1 -659
- package/dist/prisma-client-php/index.enc +1 -1
- package/dist/prisma-client-php/index.js +2 -49
- package/dist/prisma-php.js +70 -113
- package/dist/src/app/index.php +1 -1
- package/package.json +2 -2
|
@@ -1,21 +1,4 @@
|
|
|
1
|
-
import
|
|
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
|
-
};
|
|
1
|
+
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),getSecretKey=()=>{const t=fs.readFileSync(`${__dirname}/key.enc`,"utf8");if(t.length<400)throw new Error("File content is less than 400 characters.");return t.substring(247,289)},decryptData=(t,r)=>CryptoJS.AES.decrypt(t,r).toString(CryptoJS.enc.Utf8);
|
|
19
2
|
const executePHP = (command) => {
|
|
20
3
|
exec(command, (error, stdout, stderr) => {
|
|
21
4
|
if (error) {
|
|
@@ -29,34 +12,4 @@ const executePHP = (command) => {
|
|
|
29
12
|
console.log(`Standard output...\n${stdout}`);
|
|
30
13
|
});
|
|
31
14
|
};
|
|
32
|
-
const main
|
|
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
|
-
});
|
|
15
|
+
const main=async()=>{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=>{}));
|
package/dist/prisma-php.js
CHANGED
|
@@ -1,123 +1,80 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import chalk from "chalk";
|
|
3
|
-
import { spawn } from "child_process";
|
|
4
|
-
import fs from "fs";
|
|
5
|
-
import path from "path";
|
|
6
|
-
import prompts from "prompts";
|
|
7
|
-
import { fileURLToPath } from "url";
|
|
8
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
-
const __dirname = path.dirname(__filename);
|
|
10
|
-
const args = process.argv.slice(2);
|
|
11
|
-
const readJsonFile = (filePath) => {
|
|
12
|
-
const jsonData = fs.readFileSync(filePath, "utf8");
|
|
13
|
-
return JSON.parse(jsonData);
|
|
14
|
-
};
|
|
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
|
-
});
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
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;
|
|
52
|
-
}
|
|
53
|
-
const commandsToExecute = {
|
|
54
|
-
generateClass: "npx pphp generate class",
|
|
55
|
-
update: "npx pphp update",
|
|
56
|
-
};
|
|
2
|
+
import chalk from"chalk";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=e=>{const t=fs.readFileSync(e,"utf8");return JSON.parse(t)},executeCommand=(e,t=[],o={})=>new Promise(((r,a)=>{const s=spawn(e,t,Object.assign({stdio:"inherit",shell:!0},o));s.on("error",(e=>{a(e)})),s.on("close",(e=>{0===e?r():a(new Error(`Process exited with code ${e}`))}))}));async function getAnswer(){const e=[{type:"toggle",name:"shouldProceed",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")}?`,initial:!1,active:"Yes",inactive:"No"}],t=await prompts(e,{onCancel:()=>{process.exit(0)}});return 0===Object.keys(t).length?null:t}const commandsToExecute={generateClass:"npx php generate class",update:"npx php update project"};
|
|
57
3
|
const main = async () => {
|
|
58
|
-
|
|
59
|
-
|
|
4
|
+
if (args.length === 0) {
|
|
5
|
+
console.log("No command provided.");
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const formattedCommand = `npx php ${args.join(" ")}`;
|
|
9
|
+
const commandsArray = Object.values(commandsToExecute);
|
|
10
|
+
if (!commandsArray.includes(formattedCommand)) {
|
|
11
|
+
console.log("Command not recognized or not allowed.");
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (formattedCommand === commandsToExecute.update) {
|
|
15
|
+
try {
|
|
16
|
+
const answer = await getAnswer();
|
|
17
|
+
if (
|
|
18
|
+
!(answer === null || answer === void 0 ? void 0 : answer.shouldProceed)
|
|
19
|
+
) {
|
|
20
|
+
console.log(chalk.red("Operation cancelled by the user."));
|
|
60
21
|
return;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
22
|
+
}
|
|
23
|
+
const currentDir = process.cwd();
|
|
24
|
+
const configPath = path.join(currentDir, "prisma-php.json");
|
|
25
|
+
if (!fs.existsSync(configPath)) {
|
|
26
|
+
console.error(
|
|
27
|
+
chalk.red(
|
|
28
|
+
"The configuration file 'prisma-php.json' was not found in the current directory."
|
|
29
|
+
)
|
|
30
|
+
);
|
|
68
31
|
return;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
}
|
|
32
|
+
}
|
|
33
|
+
const localSettings = readJsonFile(configPath);
|
|
34
|
+
const commandArgs = [localSettings.projectName];
|
|
35
|
+
if (localSettings.tailwindcss) commandArgs.push("--tailwindcss");
|
|
36
|
+
if (localSettings.websocket) commandArgs.push("--websocket");
|
|
37
|
+
console.log("Executing command...\n");
|
|
38
|
+
await executeCommand("npx", [
|
|
39
|
+
"create-prisma-php-app@latest",
|
|
40
|
+
...commandArgs,
|
|
41
|
+
]);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (error instanceof Error) {
|
|
44
|
+
if (error.message.includes("no such file or directory")) {
|
|
45
|
+
console.error(
|
|
46
|
+
chalk.red(
|
|
47
|
+
"The configuration file 'prisma-php.json' was not found in the current directory."
|
|
48
|
+
)
|
|
49
|
+
);
|
|
104
50
|
}
|
|
51
|
+
} else {
|
|
52
|
+
console.error("Error in script execution:", error);
|
|
53
|
+
}
|
|
105
54
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
55
|
+
}
|
|
56
|
+
if (formattedCommand === commandsToExecute.generateClass) {
|
|
57
|
+
try {
|
|
58
|
+
const prismaClientPath = path.join(
|
|
59
|
+
__dirname,
|
|
60
|
+
"prisma-client-php",
|
|
61
|
+
"index.js"
|
|
62
|
+
);
|
|
63
|
+
if (!fs.existsSync(prismaClientPath)) {
|
|
64
|
+
console.error(
|
|
65
|
+
chalk.red(
|
|
66
|
+
"The prisma-client-php/index.js file was not found in the current directory."
|
|
67
|
+
)
|
|
68
|
+
);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
console.log("Executing command...\n");
|
|
72
|
+
await executeCommand("node", [prismaClientPath]);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.error("Error in script execution:", error);
|
|
119
75
|
}
|
|
76
|
+
}
|
|
120
77
|
};
|
|
121
78
|
main().catch((error) => {
|
|
122
|
-
|
|
79
|
+
console.error("Unhandled error in main function:", error);
|
|
123
80
|
});
|
package/dist/src/app/index.php
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
<div class="px-4 md:px-6">
|
|
23
23
|
<div class="flex flex-col items-center space-y-4 text-center">
|
|
24
24
|
<h1 class="text-3xl font-bold tracking-tighter sm:text-4xl md:text-5xl lg:text-6xl/none flex items-center gap-3 justify-center">
|
|
25
|
-
Welcome to Prisma PHP <img class="h-20 w-20" src="<?= $baseUrl ?>assets/images/prisma-php.png" alt="Prisma PHP">
|
|
25
|
+
Welcome to Prisma PHP <img class="h-20 w-20 hidden sm:block" src="<?= $baseUrl ?>assets/images/prisma-php.png" alt="Prisma PHP">
|
|
26
26
|
</h1>
|
|
27
27
|
<p class="mx-auto max-w-[700px] text-gray-500 md:text-xl dark:text-gray-400">
|
|
28
28
|
The Next Generation ORM for PHP
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-prisma-php-app",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"bin": {
|
|
13
13
|
"create-prisma-php-app": "dist/index.js",
|
|
14
|
-
"
|
|
14
|
+
"php": "dist/prisma-php.js"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|