prisma-client-php 0.0.30 → 0.0.31

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.
Files changed (2) hide show
  1. package/dist/init.js +90 -71
  2. package/package.json +1 -1
package/dist/init.js CHANGED
@@ -2,6 +2,7 @@ import fs from "fs";
2
2
  import path from "path";
3
3
  import { execSync } from "child_process";
4
4
  import { getFileMeta } from "./utils.js";
5
+ import chalk from "chalk";
5
6
  const { __dirname } = getFileMeta();
6
7
  let projectSettings = null;
7
8
  function checkExcludeFiles(destPath) {
@@ -64,29 +65,44 @@ const directoriesToCopy = [
64
65
  destFolder: path.join(process.cwd(), "prisma"),
65
66
  },
66
67
  ];
67
- /**
68
- * Installs specified packages using npm in the current working directory.
69
- */
70
- function installPackages(isPrismaPHP) {
71
- const packages = [
72
- "prisma@^6.5.0",
73
- "@prisma/client@^6.5.0",
74
- "@prisma/internals@^6.5.0",
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
+ packageJson.prisma = {
76
+ seed: "tsx prisma/seed.ts",
77
+ };
78
+ } else {
79
+ console.error("package.json does not exist.");
80
+ return;
81
+ }
82
+ let npmDependencies = [
83
+ npmPkg("prisma"),
84
+ npmPkg("@prisma/client"),
85
+ npmPkg("@prisma/internals"),
75
86
  ];
76
87
  if (!isPrismaPHP) {
77
- packages.push("tsx@^4.19.3", "typescript@^5.8.2", "@types/node@^22.13.10");
88
+ npmDependencies.push(
89
+ npmPkg("tsx"),
90
+ npmPkg("typescript"),
91
+ npmPkg("@types/node")
92
+ );
93
+ packageJson.type = "module";
78
94
  }
79
- const packagesStr = packages.join(" ");
95
+ const packagesStr = npmDependencies.join(" ");
80
96
  try {
81
97
  console.log(`Installing packages: ${packagesStr}`);
82
98
  execSync(`npm install --save-dev ${packagesStr}`, {
83
99
  stdio: "inherit",
84
- cwd: process.cwd(),
100
+ cwd: currentDir,
85
101
  });
86
102
  if (!isPrismaPHP) {
87
103
  execSync("npx tsc --init", {
88
104
  stdio: "inherit",
89
- cwd: process.cwd(),
105
+ cwd: currentDir,
90
106
  });
91
107
  }
92
108
  console.log("Packages installed successfully.");
@@ -99,7 +115,8 @@ function installPackages(isPrismaPHP) {
99
115
  * If the prisma folder already exists, the command is skipped.
100
116
  */
101
117
  function initPrisma() {
102
- const prismaFolderPath = path.join(process.cwd(), "prisma");
118
+ const currentDir = process.cwd();
119
+ const prismaFolderPath = path.join(currentDir, "prisma");
103
120
  if (fs.existsSync(prismaFolderPath)) {
104
121
  console.warn("Prisma folder already exists. Skipping prisma init.");
105
122
  return;
@@ -108,18 +125,16 @@ function initPrisma() {
108
125
  console.log("Initializing Prisma...");
109
126
  execSync(`npx prisma init`, {
110
127
  stdio: "inherit",
111
- cwd: process.cwd(),
128
+ cwd: currentDir,
112
129
  });
113
130
  console.log("Prisma initialized successfully.");
114
131
  } catch (error) {
115
132
  console.error("Error initializing Prisma:", error);
116
133
  }
117
134
  }
118
- /**
119
- * Updates the composer.json file by adding "calicastle/cuid": "^2.0.0" to its require section.
120
- */
121
- async function updateComposerJson(baseDir) {
122
- const composerJsonPath = path.join(baseDir, "composer.json");
135
+ async function installComposerDependencies(isPrismaPHP) {
136
+ const currentDir = process.cwd();
137
+ const composerJsonPath = path.join(currentDir, "composer.json");
123
138
  let composerJson;
124
139
  if (fs.existsSync(composerJsonPath)) {
125
140
  const composerJsonContent = fs.readFileSync(composerJsonPath, "utf8");
@@ -128,51 +143,9 @@ async function updateComposerJson(baseDir) {
128
143
  console.error("composer.json does not exist.");
129
144
  return;
130
145
  }
131
- composerJson.require = {
132
- ...composerJson.require,
133
- "calicastle/cuid": "^2.0.0",
134
- };
135
- fs.writeFileSync(composerJsonPath, JSON.stringify(composerJson, null, 2));
136
- console.log("composer.json updated successfully.");
137
- }
138
- /**
139
- * Installs the specified Composer packages using the require command.
140
- */
141
- function runComposerInstall(packages) {
142
- if (packages.length === 0) {
143
- console.warn("No Composer packages specified for installation.");
144
- return;
145
- }
146
- const packageList = packages.join(" ");
147
- try {
148
- console.log(`Installing Composer packages: ${packageList}...`);
149
- execSync(
150
- `C:\\xampp\\php\\php.exe C:\\ProgramData\\ComposerSetup\\bin\\composer.phar require ${packageList}`,
151
- {
152
- stdio: "inherit",
153
- }
154
- );
155
- console.log("Composer packages installed successfully.");
156
- } catch (error) {
157
- console.error("Error installing Composer packages:", error);
158
- }
159
- }
160
- const readJsonFile = (filePath) => {
161
- const jsonData = fs.readFileSync(filePath, "utf8");
162
- return JSON.parse(jsonData);
163
- };
164
- /**
165
- * Main execution flow.
166
- *
167
- * If the flag "--prisma-php" is passed, it will update composer.json.
168
- * Otherwise, it will run Composer install to install the package.
169
- * Then, it proceeds with npm package installation, Prisma initialization, and file copying.
170
- */
171
- async function main() {
172
- const isPrismaPHP = process.argv.includes("--prisma-php");
173
- const currentDir = process.cwd();
174
- const configPath = path.join(currentDir, "prisma-php.json");
146
+ let composerDependencies = [];
175
147
  if (isPrismaPHP) {
148
+ const configPath = path.join(currentDir, "prisma-php.json");
176
149
  if (fs.existsSync(configPath)) {
177
150
  const localSettings = readJsonFile(configPath);
178
151
  let excludeFiles = [];
@@ -186,17 +159,63 @@ async function main() {
186
159
  excludeFiles: localSettings.excludeFiles ?? [],
187
160
  excludeFilePath: excludeFiles ?? [],
188
161
  };
162
+ composerDependencies.push(composerPkg("calicastle/cuid"));
189
163
  }
190
- await updateComposerJson(currentDir);
191
164
  } else {
192
- runComposerInstall([
193
- "ezyang/htmlpurifier:^4.18.0",
194
- "calicastle/cuid:^2.0.0",
195
- "symfony/uid:^7.2.0",
196
- "brick/math:^0.13.0",
197
- ]);
165
+ composerDependencies.push(
166
+ composerPkg("ezyang/htmlpurifier"),
167
+ composerPkg("calicastle/cuid"),
168
+ composerPkg("symfony/uid"),
169
+ composerPkg("brick/math")
170
+ );
171
+ }
172
+ try {
173
+ // Log the dependencies being installed
174
+ console.log("Installing Composer dependencies:");
175
+ composerDependencies.forEach((dep) => console.log(`- ${chalk.blue(dep)}`));
176
+ // Prepare the composer require command
177
+ const composerRequireCommand = `C:\\xampp\\php\\php.exe C:\\ProgramData\\ComposerSetup\\bin\\composer.phar require ${composerDependencies.join(
178
+ " "
179
+ )}`;
180
+ // Execute the composer require command
181
+ execSync(composerRequireCommand, {
182
+ stdio: "inherit",
183
+ cwd: currentDir,
184
+ });
185
+ } catch (error) {
186
+ console.error("Error installing Composer dependencies:", error);
198
187
  }
199
- installPackages(isPrismaPHP);
188
+ fs.writeFileSync(composerJsonPath, JSON.stringify(composerJson, null, 2));
189
+ console.log("composer.json updated successfully.");
190
+ }
191
+ const readJsonFile = (filePath) => {
192
+ const jsonData = fs.readFileSync(filePath, "utf8");
193
+ return JSON.parse(jsonData);
194
+ };
195
+ const npmPinnedVersions = {
196
+ prisma: "^6.5.0",
197
+ "@prisma/client": "^6.5.0",
198
+ "@prisma/internals": "^6.5.0",
199
+ tsx: "^4.19.3",
200
+ typescript: "^5.8.2",
201
+ "@types/node": "^22.13.11",
202
+ };
203
+ function npmPkg(name) {
204
+ return npmPinnedVersions[name] ? `${name}@${npmPinnedVersions[name]}` : name;
205
+ }
206
+ const composerPinnedVersions = {
207
+ "ezyang/htmlpurifier": "^4.18.0",
208
+ "calicastle/cuid": "^2.0.0",
209
+ "symfony/uid": "^7.2.0",
210
+ "brick/math": "^0.13.0",
211
+ };
212
+ function composerPkg(name) {
213
+ return composerPinnedVersions[name] ?? name;
214
+ }
215
+ async function main() {
216
+ const isPrismaPHP = process.argv.includes("--prisma-php");
217
+ installNpmDependencies(isPrismaPHP);
218
+ installComposerDependencies(isPrismaPHP);
200
219
  initPrisma();
201
220
  directoriesToCopy.forEach((config) => {
202
221
  copyRecursiveSync(
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "prisma-client-php",
3
3
  "description": "Prisma Client PHP is an auto-generated query builder that enables type-safe database access in PHP.",
4
- "version": "0.0.30",
4
+ "version": "0.0.31",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "scripts": {