prisma-client-php 2.3.6 → 3.0.0

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 CHANGED
@@ -1,45 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import chalk from "chalk";
3
- import fs from "fs";
4
- import path from "path";
5
- import { pathToFileURL } from "url";
6
- import { getFileMeta } from "./utils.js";
7
- const { __dirname } = getFileMeta();
8
- const args = process.argv.slice(2);
9
- const commandsToExecute = {
10
- generate: "generate",
11
- init: "init",
12
- };
13
- const executeFile = async (fileName, extraArgs = []) => {
14
- const filePath = path.join(__dirname, fileName);
15
- if (!fs.existsSync(filePath)) {
16
- console.error(chalk.red(`File '${fileName}' not found.`));
17
- process.exit(1);
18
- }
19
- try {
20
- const module = await import(pathToFileURL(filePath).toString());
21
- if (module.default) {
22
- module.default(extraArgs); // Pass extraArgs (even if empty)
23
- }
24
- } catch (error) {
25
- console.error("Error executing file:", error);
26
- }
27
- };
28
- const main = async () => {
29
- if (args.length === 0) {
30
- console.log("No command provided.");
31
- return;
32
- }
33
- const commandName = args[0]; // First argument is the command (e.g., "init" or "generate")
34
- const extraArgs = args.slice(1); // Capture any additional arguments (e.g., "--prisma-php")
35
- if (commandsToExecute.generate === commandName) {
36
- await executeFile("generate.js", extraArgs);
37
- } else if (commandsToExecute.init === commandName) {
38
- await executeFile("init.js", extraArgs);
39
- } else {
40
- console.log(chalk.red("Invalid command. Use: npx ppo generate"));
41
- }
42
- };
43
- main().catch((error) => {
44
- console.error("Unhandled error in main function:", error);
45
- });
2
+ import chalk from"chalk";import fs from"fs";import path from"path";import{pathToFileURL}from"url";import{getFileMeta}from"./utils.js";const{__dirname}=getFileMeta(),args=process.argv.slice(2),commandsToExecute={generate:"generate",init:"init"},executeFile=async(e,o=[])=>{const t=path.join(__dirname,e);fs.existsSync(t)||(console.error(chalk.red(`File '${e}' not found.`)),process.exit(1));try{const e=await import(pathToFileURL(t).toString());e.default&&e.default(o)}catch(e){console.error("Error executing file:",e)}},main=async()=>{if(0===args.length)return void console.log("No command provided.");const e=args[0],o=args.slice(1);commandsToExecute.generate===e?await executeFile("generate.js",o):commandsToExecute.init===e?await executeFile("init.js",o):console.log(chalk.red("Invalid command. Use: npx ppo generate"))};main().catch(e=>{console.error("Unhandled error in main function:",e)});
package/dist/init.js CHANGED
@@ -1,240 +1 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { execSync } from "child_process";
4
- import { getFileMeta } from "./utils.js";
5
- import chalk from "chalk";
6
- const { __dirname } = getFileMeta();
7
- let projectSettings = null;
8
- function checkExcludeFiles(destPath) {
9
- return (
10
- projectSettings?.excludeFilePath?.includes(destPath.replace(/\\/g, "/")) ??
11
- false
12
- );
13
- }
14
- /**
15
- * Recursively copies all files and folders from `src` to `dest`,
16
- * overwriting existing files if they already exist.
17
- *
18
- * The `base` parameter represents the original root of the copy.
19
- * It is used for computing a relative path for cleaner logging.
20
- */
21
- function copyRecursiveSync(src, dest, base = src, isPrismaPHP = false) {
22
- if (!fs.existsSync(src)) {
23
- console.error(`Source folder does not exist: ${src}`);
24
- return;
25
- }
26
- if (!fs.existsSync(dest)) {
27
- fs.mkdirSync(dest, { recursive: true });
28
- }
29
- const entries = fs.readdirSync(src, { withFileTypes: true });
30
- for (const entry of entries) {
31
- const srcPath = path.join(src, entry.name);
32
- const destPath = path.join(dest, entry.name);
33
- const relative = path.relative(base, srcPath);
34
- const display = path.join(path.basename(base), relative);
35
- if (checkExcludeFiles(destPath)) return;
36
- // **Normalize Path to Avoid Issues on Windows**
37
- const relativePath = path.relative(__dirname, srcPath);
38
- const validatorFile = path.normalize("src/Lib/Validator.php");
39
- // **Skip Validator.php when isPrismaPHP is true**
40
- if (isPrismaPHP && relativePath === validatorFile) {
41
- console.log(`Skipping file: ${display}`);
42
- continue;
43
- }
44
- if (entry.isDirectory()) {
45
- copyRecursiveSync(srcPath, destPath, base, isPrismaPHP);
46
- } else {
47
- // Copy the file (this will overwrite if it exists)
48
- fs.copyFileSync(srcPath, destPath);
49
- console.log(`Copied file: ${display}`);
50
- }
51
- }
52
- }
53
- // Configuration for directories to copy (copying the whole directory recursively)
54
- const directoriesToCopy = [
55
- {
56
- srcFolder: path.join(__dirname, "src"),
57
- destFolder: path.join(process.cwd(), "src"),
58
- },
59
- {
60
- srcFolder: path.join(__dirname, "settings"),
61
- destFolder: path.join(process.cwd(), "settings"),
62
- },
63
- {
64
- srcFolder: path.join(__dirname, "prisma"),
65
- destFolder: path.join(process.cwd(), "prisma"),
66
- },
67
- ];
68
- function installNpmDependencies(isPrismaPHP) {
69
- const currentDir = process.cwd();
70
- const packageJsonPath = path.join(currentDir, "package.json");
71
- let packageJson;
72
- if (fs.existsSync(packageJsonPath)) {
73
- const packageJsonContent = fs.readFileSync(packageJsonPath, "utf8");
74
- packageJson = JSON.parse(packageJsonContent);
75
- if (!isPrismaPHP) {
76
- packageJson.type = "module";
77
- }
78
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
79
- } else {
80
- console.error("package.json does not exist.");
81
- return;
82
- }
83
- let npmDependencies = [
84
- npmPkg("prisma"),
85
- npmPkg("@prisma/client"),
86
- npmPkg("@prisma/internals"),
87
- ];
88
- if (!isPrismaPHP) {
89
- npmDependencies.push(
90
- npmPkg("tsx"),
91
- npmPkg("typescript"),
92
- npmPkg("@types/node")
93
- );
94
- }
95
- const packagesStr = npmDependencies.join(" ");
96
- try {
97
- console.log(`Installing packages: ${packagesStr}`);
98
- execSync(`npm install --save-dev ${packagesStr}`, {
99
- stdio: "inherit",
100
- cwd: currentDir,
101
- });
102
- if (!isPrismaPHP) {
103
- execSync("npx tsc --init", {
104
- stdio: "inherit",
105
- cwd: currentDir,
106
- });
107
- }
108
- console.log("Packages installed successfully.");
109
- } catch (error) {
110
- console.error("Error installing packages:", error);
111
- }
112
- }
113
- /**
114
- * Runs the `npx prisma init` command to initialize Prisma.
115
- * If the prisma folder already exists, the command is skipped.
116
- */
117
- function initPrisma() {
118
- const currentDir = process.cwd();
119
- const prismaFolderPath = path.join(currentDir, "prisma");
120
- if (fs.existsSync(prismaFolderPath)) {
121
- console.warn("Prisma folder already exists. Skipping prisma init.");
122
- return;
123
- }
124
- try {
125
- console.log("Initializing Prisma...");
126
- execSync(`npx prisma init`, {
127
- stdio: "inherit",
128
- cwd: currentDir,
129
- });
130
- console.log("Prisma initialized successfully.");
131
- } catch (error) {
132
- console.error("Error initializing Prisma:", error);
133
- }
134
- }
135
- async function installComposerDependencies(isPrismaPHP) {
136
- const currentDir = process.cwd();
137
- const composerJsonPath = path.join(currentDir, "composer.json");
138
- if (!fs.existsSync(composerJsonPath)) {
139
- console.error("composer.json does not exist.");
140
- return;
141
- }
142
- let composerDependencies = [composerPkg("calicastle/cuid")];
143
- if (isPrismaPHP) {
144
- const configPath = path.join(currentDir, "prisma-php.json");
145
- if (fs.existsSync(configPath)) {
146
- const localSettings = readJsonFile(configPath);
147
- let excludeFiles = [];
148
- localSettings.excludeFiles?.map((file) => {
149
- const filePath = path.join(currentDir, file);
150
- if (fs.existsSync(filePath))
151
- excludeFiles.push(filePath.replace(/\\/g, "/"));
152
- });
153
- projectSettings = {
154
- ...localSettings,
155
- excludeFiles: localSettings.excludeFiles ?? [],
156
- excludeFilePath: excludeFiles ?? [],
157
- };
158
- }
159
- } else {
160
- composerDependencies.push(
161
- composerPkg("ezyang/htmlpurifier"),
162
- composerPkg("symfony/uid"),
163
- composerPkg("brick/math"),
164
- composerPkg("tsnc/prisma-php")
165
- );
166
- }
167
- try {
168
- // Log the dependencies being installed
169
- console.log("Installing Composer dependencies:");
170
- composerDependencies.forEach((dep) => console.log(`- ${chalk.blue(dep)}`));
171
- // Prepare the composer require command
172
- const composerRequireCommand = `C:\\xampp\\php\\php.exe C:\\ProgramData\\ComposerSetup\\bin\\composer.phar require ${composerDependencies.join(
173
- " "
174
- )}`;
175
- // Execute the composer require command
176
- execSync(composerRequireCommand, {
177
- stdio: "inherit",
178
- cwd: currentDir,
179
- });
180
- } catch (error) {
181
- console.error("Error installing Composer dependencies:", error);
182
- }
183
- }
184
- const readJsonFile = (filePath) => {
185
- const jsonData = fs.readFileSync(filePath, "utf8");
186
- return JSON.parse(jsonData);
187
- };
188
- const npmPinnedVersions = {
189
- prisma: "^6.14.0",
190
- "@prisma/client": "^6.14.0",
191
- "@prisma/internals": "^6.14.0",
192
- tsx: "^4.20.5",
193
- typescript: "^5.9.2",
194
- "@types/node": "^24.3.0",
195
- };
196
- function npmPkg(name) {
197
- return npmPinnedVersions[name] ? `${name}@${npmPinnedVersions[name]}` : name;
198
- }
199
- const composerPinnedVersions = {
200
- "ezyang/htmlpurifier": "^4.18.0",
201
- "calicastle/cuid": "^2.0.0",
202
- "symfony/uid": "^7.2.0",
203
- "brick/math": "^0.13.1",
204
- "tsnc/prisma-php": "^1.0.0",
205
- };
206
- function composerPkg(name) {
207
- return composerPinnedVersions[name]
208
- ? `${name}:${composerPinnedVersions[name]}`
209
- : name;
210
- }
211
- async function main() {
212
- const isPrismaPHP = process.argv.includes("--prisma-php");
213
- installNpmDependencies(isPrismaPHP);
214
- installComposerDependencies(isPrismaPHP);
215
- initPrisma();
216
- directoriesToCopy.forEach((config) => {
217
- copyRecursiveSync(
218
- config.srcFolder,
219
- config.destFolder,
220
- config.srcFolder,
221
- isPrismaPHP
222
- );
223
- });
224
- function copyFileVerbose(src, dest) {
225
- if (!fs.existsSync(src)) {
226
- console.warn(`File not found (skip): ${src}`);
227
- return;
228
- }
229
- fs.copyFileSync(src, dest);
230
- console.log(`Copied file: ${path.basename(src)}`);
231
- }
232
- const prismaConfigSrc = path.join(__dirname, "prisma.config.ts");
233
- const prismaConfigDest = path.join(process.cwd(), "prisma.config.ts");
234
- copyFileVerbose(prismaConfigSrc, prismaConfigDest);
235
- console.log("Finished copying directories.");
236
- }
237
- // Run the main function
238
- main().catch((error) => {
239
- console.error("Error during execution:", error);
240
- });
1
+ import fs from"fs";import path from"path";import{execSync}from"child_process";import{getFileMeta}from"./utils.js";import chalk from"chalk";const{__dirname}=getFileMeta();let projectSettings=null;function checkExcludeFiles(e){return projectSettings?.excludeFilePath?.includes(e.replace(/\\/g,"/"))??!1}function copyRecursiveSync(e,s,n=e,i=!1){if(!fs.existsSync(e))return void console.error(`Source folder does not exist: ${e}`);fs.existsSync(s)||fs.mkdirSync(s,{recursive:!0});const o=fs.readdirSync(e,{withFileTypes:!0});for(const r of o){const o=path.join(e,r.name),c=path.join(s,r.name),t=path.relative(n,o),p=path.join(path.basename(n),t);if(checkExcludeFiles(c))return;const a=path.relative(__dirname,o),l=path.normalize("src/Lib/Validator.php");i&&a===l?console.log(`Skipping file: ${p}`):r.isDirectory()?copyRecursiveSync(o,c,n,i):(fs.copyFileSync(o,c),console.log(`Copied file: ${p}`))}}const directoriesToCopy=[{srcFolder:path.join(__dirname,"src"),destFolder:path.join(process.cwd(),"src")},{srcFolder:path.join(__dirname,"settings"),destFolder:path.join(process.cwd(),"settings")},{srcFolder:path.join(__dirname,"prisma"),destFolder:path.join(process.cwd(),"prisma")}];function installNpmDependencies(e){const s=process.cwd(),n=path.join(s,"package.json");let i;if(!fs.existsSync(n))return void console.error("package.json does not exist.");{const s=fs.readFileSync(n,"utf8");i=JSON.parse(s),e||(i.type="module"),fs.writeFileSync(n,JSON.stringify(i,null,2))}let o=[npmPkg("prisma"),npmPkg("@prisma/client"),npmPkg("@prisma/internals")];e||o.push(npmPkg("tsx"),npmPkg("typescript"),npmPkg("@types/node"));const r=o.join(" ");try{console.log(`Installing packages: ${r}`),execSync(`npm install --save-dev ${r}`,{stdio:"inherit",cwd:s}),e||execSync("npx tsc --init",{stdio:"inherit",cwd:s}),console.log("Packages installed successfully.")}catch(e){console.error("Error installing packages:",e)}}function initPrisma(){const e=process.cwd(),s=path.join(e,"prisma");if(fs.existsSync(s))console.warn("Prisma folder already exists. Skipping prisma init.");else try{console.log("Initializing Prisma..."),execSync("npx prisma init",{stdio:"inherit",cwd:e}),console.log("Prisma initialized successfully.")}catch(e){console.error("Error initializing Prisma:",e)}}async function installComposerDependencies(e){const s=process.cwd(),n=path.join(s,"composer.json");if(!fs.existsSync(n))return void console.error("composer.json does not exist.");let i=[composerPkg("calicastle/cuid")];if(e){const e=path.join(s,"prisma-php.json");if(fs.existsSync(e)){const n=readJsonFile(e);let i=[];n.excludeFiles?.map(e=>{const n=path.join(s,e);fs.existsSync(n)&&i.push(n.replace(/\\/g,"/"))}),projectSettings={...n,excludeFiles:n.excludeFiles??[],excludeFilePath:i??[]}}}else i.push(composerPkg("symfony/uid"),composerPkg("brick/math"),composerPkg("tsnc/prisma-php"));try{console.log("Installing Composer dependencies:"),i.forEach(e=>console.log(`- ${chalk.blue(e)}`));const e=`C:\\xampp\\php\\php.exe C:\\ProgramData\\ComposerSetup\\bin\\composer.phar require ${i.join(" ")}`;execSync(e,{stdio:"inherit",cwd:s})}catch(e){console.error("Error installing Composer dependencies:",e)}}const readJsonFile=e=>{const s=fs.readFileSync(e,"utf8");return JSON.parse(s)},npmPinnedVersions={prisma:"^6.18.0","@prisma/client":"^6.18.0","@prisma/internals":"^6.18.0",tsx:"^4.20.6",typescript:"^5.9.3","@types/node":"^24.9.2"};function npmPkg(e){return npmPinnedVersions[e]?`${e}@${npmPinnedVersions[e]}`:e}const composerPinnedVersions={"calicastle/cuid":"^2.0.0","symfony/uid":"^7.3.1","brick/math":"^0.14.0","tsnc/prisma-php":"^1.0.0"};function composerPkg(e){return composerPinnedVersions[e]?`${e}:${composerPinnedVersions[e]}`:e}async function main(){const e=process.argv.includes("--prisma-php");installNpmDependencies(e),installComposerDependencies(e),initPrisma(),directoriesToCopy.forEach(s=>{copyRecursiveSync(s.srcFolder,s.destFolder,s.srcFolder,e)});const s=path.join(__dirname,"prisma.config.ts"),n=path.join(process.cwd(),"prisma.config.ts");var i,o;i=s,o=n,fs.existsSync(i)?(fs.copyFileSync(i,o),console.log(`Copied file: ${path.basename(i)}`)):console.warn(`File not found (skip): ${i}`),console.log("Finished copying directories.")}main().catch(e=>{console.error("Error during execution:",e)});