create-prisma-php-app 1.9.8 → 1.9.11
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/prisma-php.js
CHANGED
|
@@ -1,80 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
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=
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
const answer = await getAnswer();
|
|
17
|
-
if (
|
|
18
|
-
!(answer === null || answer === void 0 ? void 0 : answer.shouldProceed)
|
|
19
|
-
) {
|
|
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=r=>{const e=fs.readFileSync(r,"utf8");return JSON.parse(e)},executeCommand=(r,e=[],o={})=>new Promise(((s,t)=>{const i=spawn(r,e,Object.assign({stdio:"inherit",shell:!0},o));i.on("error",(r=>{t(r)})),i.on("close",(r=>{0===r?s():t(new Error(`Process exited with code ${r}`))}))}));
|
|
3
|
+
async function getAnswer() {
|
|
4
|
+
const questions = [
|
|
5
|
+
{
|
|
6
|
+
type: "toggle",
|
|
7
|
+
name: "shouldProceed",
|
|
8
|
+
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")}?`,
|
|
9
|
+
initial: false,
|
|
10
|
+
active: "Yes",
|
|
11
|
+
inactive: "No",
|
|
12
|
+
},
|
|
13
|
+
];
|
|
14
|
+
const onCancel = () => {
|
|
20
15
|
console.log(chalk.red("Operation cancelled by the user."));
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
console.error(
|
|
27
|
-
chalk.red(
|
|
28
|
-
"The configuration file 'prisma-php.json' was not found in the current directory."
|
|
29
|
-
)
|
|
30
|
-
);
|
|
31
|
-
return;
|
|
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
|
-
);
|
|
50
|
-
}
|
|
51
|
-
} else {
|
|
52
|
-
console.error("Error in script execution:", error);
|
|
53
|
-
}
|
|
16
|
+
process.exit(0);
|
|
17
|
+
};
|
|
18
|
+
const response = await prompts(questions, { onCancel });
|
|
19
|
+
if (Object.keys(response).length === 0) {
|
|
20
|
+
return null;
|
|
54
21
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
22
|
+
return response;
|
|
23
|
+
}
|
|
24
|
+
const commandsToExecute = {
|
|
25
|
+
generateClass: "npx php generate class",
|
|
26
|
+
update: "npx php update project",
|
|
77
27
|
};
|
|
78
|
-
main().catch((
|
|
79
|
-
console.error("Unhandled error in main function:", error);
|
|
80
|
-
});
|
|
28
|
+
const main=async()=>{if(0===args.length)return;const s=`npx php ${args.join(" ")}`;if(Object.values(commandsToExecute).includes(s)){if(s===commandsToExecute.update)try{const s=await getAnswer();if(!(null==s?void 0:s.shouldProceed))return;const e=process.cwd(),n=path.join(e,"prisma-php.json");if(!fs.existsSync(n))return;const t=readJsonFile(n),a=[t.projectName];t.tailwindcss&&a.push("--tailwindcss"),t.websocket&&a.push("--websocket"),t.prisma&&a.push("--prisma"),await executeCommand("npx",["create-prisma-php-app@latest",...a])}catch(s){s instanceof Error&&s.message.includes("no such file or directory")}if(s===commandsToExecute.generateClass)try{const s=process.cwd(),e=path.join(s,"prisma-php.json");if(!fs.existsSync(e))return;if(!readJsonFile(e).prisma)return;const n=path.join(__dirname,"prisma-client-php","index.js");if(!fs.existsSync(n))return;await executeCommand("node",[n])}catch(s){}}};main().catch((s=>{}));
|
|
@@ -115,7 +115,7 @@ abstract class Utility
|
|
|
115
115
|
$relation = $field['decorators']['relation'] ?? null;
|
|
116
116
|
$inverseRelation = $field['decorators']['inverseRelation'] ?? null;
|
|
117
117
|
|
|
118
|
-
if (isset($relation['name']) && $relation['name'] == $key || isset($inverseRelation['
|
|
118
|
+
if (isset($relation['name']) && $relation['name'] == $key || isset($inverseRelation['fromField']) && $inverseRelation['fromField'] == $key) $isRelatedModel = true;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
if ($isRelatedModel) continue;
|