create-prisma-php-app 4.0.0-alpha.72 → 4.0.0-alpha.74

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/index.js +165 -50
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -39,11 +39,25 @@ async function installNpmDependencies(baseDir, dependencies, isDev = false) {
39
39
  function getComposerCmd() {
40
40
  try {
41
41
  execSync("composer --version", { stdio: "ignore" });
42
+ console.log("✓ Using global composer command");
42
43
  return { cmd: "composer", baseArgs: [] };
43
44
  } catch {
45
+ const phpPath = "C:\\xampp\\php\\php.exe";
46
+ const composerPath = "C:\\ProgramData\\ComposerSetup\\bin\\composer.phar";
47
+ // Check if PHP exists
48
+ if (!fs.existsSync(phpPath)) {
49
+ console.error(`✗ PHP not found at ${phpPath}`);
50
+ throw new Error(`PHP executable not found at ${phpPath}`);
51
+ }
52
+ // Check if Composer phar exists
53
+ if (!fs.existsSync(composerPath)) {
54
+ console.error(`✗ Composer not found at ${composerPath}`);
55
+ throw new Error(`Composer phar not found at ${composerPath}`);
56
+ }
57
+ console.log("✓ Using XAMPP PHP with Composer phar");
44
58
  return {
45
- cmd: "C:\\xampp\\php\\php.exe",
46
- baseArgs: ["C:\\ProgramData\\ComposerSetup\\bin\\composer.phar"],
59
+ cmd: phpPath,
60
+ baseArgs: [composerPath],
47
61
  };
48
62
  }
49
63
  }
@@ -59,9 +73,17 @@ export async function installComposerDependencies(baseDir, dependencies) {
59
73
  )
60
74
  );
61
75
  /* ------------------------------------------------------------------ */
62
- /* 1. Try composer init (quietly fall back if it fails) */
76
+ /* 1. Ensure base directory exists */
77
+ /* ------------------------------------------------------------------ */
78
+ if (!fs.existsSync(baseDir)) {
79
+ console.log(`Creating base directory: ${baseDir}`);
80
+ fs.mkdirSync(baseDir, { recursive: true });
81
+ }
82
+ /* ------------------------------------------------------------------ */
83
+ /* 2. Create composer.json directly (more reliable) */
63
84
  /* ------------------------------------------------------------------ */
64
85
  if (!existsAlready) {
86
+ // Try composer init first, but don't rely on it
65
87
  const initArgs = [
66
88
  ...baseArgs,
67
89
  "init",
@@ -75,82 +97,175 @@ export async function installComposerDependencies(baseDir, dependencies) {
75
97
  "--version",
76
98
  "1.0.0",
77
99
  ];
78
- const res = spawnSync(cmd, initArgs, { cwd: baseDir });
79
- if (res.status !== 0) {
80
- // Silent fallback: no logs, just write a minimal composer.json
100
+ console.log(`Attempting composer init...`);
101
+ const res = spawnSync(cmd, initArgs, {
102
+ cwd: baseDir,
103
+ stdio: ["ignore", "pipe", "pipe"],
104
+ encoding: "utf8",
105
+ });
106
+ // Check if composer.json was actually created
107
+ const composerJsonCreated = fs.existsSync(composerJsonPath);
108
+ if (res.status === 0 && composerJsonCreated) {
109
+ console.log("✓ Composer init successful and composer.json created");
110
+ } else {
111
+ if (res.status !== 0) {
112
+ console.log(`Composer init failed with status ${res.status}`);
113
+ if (res.stderr) console.log(`Stderr: ${res.stderr}`);
114
+ } else {
115
+ console.log(
116
+ `Composer init reported success but didn't create composer.json`
117
+ );
118
+ }
119
+ // Always create composer.json manually
120
+ console.log("Creating composer.json manually...");
121
+ const defaultComposerJson = {
122
+ name: "tsnc/prisma-php-app",
123
+ type: "project",
124
+ version: "1.0.0",
125
+ require: {
126
+ php: "^8.2",
127
+ },
128
+ autoload: {
129
+ "psr-4": {
130
+ "": "src/",
131
+ },
132
+ },
133
+ };
81
134
  try {
82
- const defaultComposerJson = {
83
- name: "tsnc/prisma-php-app",
84
- type: "project",
85
- version: "1.0.0",
86
- require: { php: "^8.2" },
87
- autoload: { "psr-4": { "": "src/" } },
88
- };
135
+ // Ensure we're writing to the correct absolute path
136
+ const absoluteComposerPath = path.resolve(baseDir, "composer.json");
137
+ console.log(`Writing composer.json to: ${absoluteComposerPath}`);
89
138
  fs.writeFileSync(
90
- composerJsonPath,
91
- JSON.stringify(defaultComposerJson, null, 2)
139
+ absoluteComposerPath,
140
+ JSON.stringify(defaultComposerJson, null, 2),
141
+ { encoding: "utf8" }
92
142
  );
93
- console.log("Created fallback composer.json");
143
+ // Verify the file was actually created
144
+ if (fs.existsSync(absoluteComposerPath)) {
145
+ console.log(`✓ Successfully created composer.json`);
146
+ } else {
147
+ throw new Error(
148
+ "File creation appeared to succeed but file doesn't exist"
149
+ );
150
+ }
94
151
  } catch (writeError) {
95
- console.error("Failed to create fallback composer.json:", writeError);
96
- throw writeError;
152
+ console.error(`✗ Failed to create composer.json:`, writeError);
153
+ // Additional debugging
154
+ console.error(`Base directory: ${baseDir}`);
155
+ console.error(`Absolute base directory: ${path.resolve(baseDir)}`);
156
+ console.error(`Target file path: ${composerJsonPath}`);
157
+ console.error(
158
+ `Absolute target file path: ${path.resolve(composerJsonPath)}`
159
+ );
160
+ console.error(`Current working directory: ${process.cwd()}`);
161
+ console.error(`Base directory exists: ${fs.existsSync(baseDir)}`);
162
+ if (fs.existsSync(baseDir)) {
163
+ try {
164
+ const stats = fs.statSync(baseDir);
165
+ console.error(`Base directory is writable: ${stats.isDirectory()}`);
166
+ } catch (statError) {
167
+ console.error(`Cannot stat base directory: ${statError}`);
168
+ }
169
+ }
170
+ throw new Error(`Cannot create composer.json: ${writeError}`);
97
171
  }
98
172
  }
99
173
  }
100
- /* 2. Ensure PSR-4 autoload entry ---------------------------------- */
101
- // Add safety check before reading
102
- if (!fs.existsSync(composerJsonPath)) {
103
- console.error(`composer.json not found at ${composerJsonPath}`);
104
- throw new Error("Failed to create or find composer.json");
174
+ /* ------------------------------------------------------------------ */
175
+ /* 3. Final verification that composer.json exists */
176
+ /* ------------------------------------------------------------------ */
177
+ const finalComposerPath = path.resolve(baseDir, "composer.json");
178
+ if (!fs.existsSync(finalComposerPath)) {
179
+ console.error(`✗ composer.json still not found at ${finalComposerPath}`);
180
+ console.error(`Directory contents:`, fs.readdirSync(baseDir));
181
+ throw new Error(
182
+ "Failed to create composer.json - file does not exist after all attempts"
183
+ );
105
184
  }
185
+ /* ------------------------------------------------------------------ */
186
+ /* 4. Read and update composer.json */
187
+ /* ------------------------------------------------------------------ */
106
188
  let json;
107
189
  try {
108
- json = JSON.parse(fs.readFileSync(composerJsonPath, "utf8"));
190
+ const jsonContent = fs.readFileSync(finalComposerPath, "utf8");
191
+ console.log("✓ Successfully read composer.json");
192
+ json = JSON.parse(jsonContent);
109
193
  } catch (readError) {
110
- console.error("Failed to read composer.json:", readError);
111
- throw readError;
194
+ console.error("Failed to read/parse composer.json:", readError);
195
+ throw new Error(`Cannot read composer.json: ${readError}`);
112
196
  }
197
+ // Ensure PSR-4 autoload entry
113
198
  json.autoload ??= {};
114
199
  json.autoload["psr-4"] ??= {};
115
200
  json.autoload["psr-4"][""] ??= "src/";
116
201
  try {
117
- fs.writeFileSync(composerJsonPath, JSON.stringify(json, null, 2));
202
+ fs.writeFileSync(finalComposerPath, JSON.stringify(json, null, 2));
203
+ console.log("✓ Updated composer.json with PSR-4 autoload");
118
204
  } catch (writeError) {
119
- console.error("Failed to update composer.json:", writeError);
205
+ console.error("Failed to update composer.json:", writeError);
120
206
  throw writeError;
121
207
  }
122
- /* 3. Install dependencies ----------------------------------------- */
208
+ /* ------------------------------------------------------------------ */
209
+ /* 5. Install dependencies */
210
+ /* ------------------------------------------------------------------ */
123
211
  if (dependencies.length) {
124
212
  console.log("Installing Composer dependencies:");
125
213
  dependencies.forEach((d) => console.log(`- ${chalk.blue(d)}`));
126
- execSync(
127
- `${cmd} ${[
214
+ try {
215
+ const requireCmd = `${cmd} ${[
128
216
  ...baseArgs,
129
217
  "require",
130
218
  "--no-interaction",
131
219
  ...dependencies,
132
- ].join(" ")}`,
133
- { stdio: "inherit", cwd: baseDir }
134
- );
220
+ ].join(" ")}`;
221
+ console.log(`Executing: ${requireCmd}`);
222
+ console.log(`Working directory: ${baseDir}`);
223
+ execSync(requireCmd, {
224
+ stdio: "inherit",
225
+ cwd: baseDir,
226
+ // Ensure the working directory is correct
227
+ env: { ...process.env },
228
+ });
229
+ console.log("✓ Composer dependencies installed");
230
+ } catch (installError) {
231
+ console.error("✗ Failed to install composer dependencies:", installError);
232
+ throw installError;
233
+ }
135
234
  }
136
- /* 4. Refresh lock when updating ----------------------------------- */
235
+ /* ------------------------------------------------------------------ */
236
+ /* 6. Refresh lock when updating */
237
+ /* ------------------------------------------------------------------ */
137
238
  if (existsAlready) {
138
- execSync(
139
- `${cmd} ${[
140
- ...baseArgs,
141
- "update",
142
- "--lock",
143
- "--no-install",
144
- "--no-interaction",
145
- ].join(" ")}`,
146
- { stdio: "inherit", cwd: baseDir }
147
- );
239
+ try {
240
+ execSync(
241
+ `${cmd} ${[
242
+ ...baseArgs,
243
+ "update",
244
+ "--lock",
245
+ "--no-install",
246
+ "--no-interaction",
247
+ ].join(" ")}`,
248
+ { stdio: "inherit", cwd: baseDir }
249
+ );
250
+ console.log("✓ Composer lock updated");
251
+ } catch (updateError) {
252
+ console.error("✗ Failed to update composer lock:", updateError);
253
+ throw updateError;
254
+ }
255
+ }
256
+ /* ------------------------------------------------------------------ */
257
+ /* 7. Regenerate autoloader */
258
+ /* ------------------------------------------------------------------ */
259
+ try {
260
+ execSync(`${cmd} ${[...baseArgs, "dump-autoload", "--quiet"].join(" ")}`, {
261
+ stdio: "inherit",
262
+ cwd: baseDir,
263
+ });
264
+ console.log("✓ Composer autoloader regenerated");
265
+ } catch (autoloadError) {
266
+ console.error("✗ Failed to regenerate autoloader:", autoloadError);
267
+ throw autoloadError;
148
268
  }
149
- /* 5. Regenerate autoloader ---------------------------------------- */
150
- execSync(`${cmd} ${[...baseArgs, "dump-autoload", "--quiet"].join(" ")}`, {
151
- stdio: "inherit",
152
- cwd: baseDir,
153
- });
154
269
  }
155
270
  const npmPinnedVersions = {
156
271
  "@tailwindcss/postcss": "^4.1.12",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "4.0.0-alpha.72",
3
+ "version": "4.0.0-alpha.74",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",