prisma-client-php 2.3.6 → 3.0.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/generate.js CHANGED
@@ -1,57 +1 @@
1
- import*as fs from"fs";import{exec}from"child_process";import path from"path";import CryptoJS from"crypto-js";import chalk from"chalk";import{getFileMeta}from"./utils.js";const{__dirname:__dirname}=getFileMeta(),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(754,799)},decryptData=(t,r)=>CryptoJS.AES.decrypt(t,r).toString(CryptoJS.enc.Utf8);
2
- const executePHP = (command) => {
3
- exec(command, (error, stdout, stderr) => {
4
- if (error) {
5
- if (stderr?.trim()) console.error(stderr);
6
- console.error(`Execution error: ${error.message}`);
7
- return;
8
- }
9
- if (stderr?.trim()) {
10
- const filtered = stderr
11
- .split(/\r?\n/)
12
- .filter(
13
- (line) =>
14
- line.trim() &&
15
- !/Loaded Prisma config from/i.test(line) &&
16
- !/Prisma config detected, skipping environment variable loading/i.test(
17
- line
18
- )
19
- )
20
- .join("\n");
21
- if (filtered) console.warn(filtered);
22
- }
23
- if (stdout.includes("Result: Prisma schema is valid.")) {
24
- console.log(chalk.blue(stdout));
25
- } else if (stdout.trim()) {
26
- console.log(`Standard output...\n${stdout}`);
27
- }
28
- });
29
- };
30
- const main = async () => {
31
- try {
32
- const currentDir = process.cwd();
33
- const settingsPath = path.join(currentDir, "prisma-php.json");
34
- // Read the JSON file's content as a string
35
- const settingsContent = fs.readFileSync(settingsPath, { encoding: "utf8" });
36
- // Parse the string to get the JSON object
37
- const projectSettings = JSON.parse(settingsContent);
38
- const phpGenerateClassPath =
39
- projectSettings.phpGenerateClassPath ?? "src/Lib/Prisma/Classes";
40
- const phpFile = `${__dirname}/index.php`;
41
- const encryptedFilePath = `${__dirname}/index.enc`;
42
- const secretKey = getSecretKey();
43
- const encryptedData = fs.readFileSync(encryptedFilePath, {
44
- encoding: "utf8",
45
- });
46
- const decryptedData = decryptData(encryptedData, secretKey);
47
- fs.writeFileSync(`${__dirname}/index.php`, decryptedData);
48
- const command = `${projectSettings.phpRootPathExe} ${phpFile} ${phpGenerateClassPath}`;
49
- console.log("Executing command...\n");
50
- executePHP(command);
51
- } catch (error) {
52
- console.error("Error in script execution:", error);
53
- }
54
- };
55
- main().catch((error) => {
56
- console.error("Unhandled error in main function:", error);
57
- });
1
+ import*as fs from"fs";import{exec}from"child_process";import path from"path";import CryptoJS from"crypto-js";import chalk from"chalk";import{getFileMeta}from"./utils.js";const{__dirname}=getFileMeta(),getSecretKey=()=>{const e=fs.readFileSync(`${__dirname}/key.enc`,"utf8");if(e.length<400)throw new Error("File content is less than 400 characters.");return e.substring(754,799)},decryptData=(e,r)=>CryptoJS.AES.decrypt(e,r).toString(CryptoJS.enc.Utf8),executePHP=e=>{exec(e,(e,r,t)=>{if(e)return t?.trim()&&console.error(t),void console.error(`Execution error: ${e.message}`);if(t?.trim()){const e=t.split(/\r?\n/).filter(e=>e.trim()&&!/Loaded Prisma config from/i.test(e)&&!/Prisma config detected, skipping environment variable loading/i.test(e)).join("\n");e&&console.warn(e)}r.includes("Result: Prisma schema is valid.")?console.log(chalk.blue(r)):r.trim()&&console.log(`Standard output...\n${r}`)})},main=async()=>{try{const e=process.cwd(),r=path.join(e,"prisma-php.json"),t=fs.readFileSync(r,{encoding:"utf8"}),n=JSON.parse(t),o=n.phpGenerateClassPath??"src/Lib/Prisma/Classes",i=`${__dirname}/index.php`,c=`${__dirname}/index.enc`,s=getSecretKey(),a=fs.readFileSync(c,{encoding:"utf8"}),l=decryptData(a,s);fs.writeFileSync(`${__dirname}/index.php`,l);const m=`${n.phpRootPathExe} ${i} ${o}`;console.log("Executing command...\n"),executePHP(m)}catch(e){console.error("Error in script execution:",e)}};main().catch(e=>{console.error("Unhandled error in main function:",e)});