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

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 +123 -46
  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,7 +73,14 @@ 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. Try composer init (with better error handling) */
63
84
  /* ------------------------------------------------------------------ */
64
85
  if (!existsAlready) {
65
86
  const initArgs = [
@@ -75,82 +96,138 @@ export async function installComposerDependencies(baseDir, dependencies) {
75
96
  "--version",
76
97
  "1.0.0",
77
98
  ];
78
- const res = spawnSync(cmd, initArgs, { cwd: baseDir });
99
+ console.log(`Executing: ${cmd} ${initArgs.join(" ")}`);
100
+ console.log(`Working directory: ${baseDir}`);
101
+ const res = spawnSync(cmd, initArgs, {
102
+ cwd: baseDir,
103
+ stdio: ["ignore", "pipe", "pipe"], // Capture output for debugging
104
+ encoding: "utf8",
105
+ });
79
106
  if (res.status !== 0) {
80
- // Silent fallback: no logs, just write a minimal composer.json
107
+ console.log(`Composer init failed with status ${res.status}`);
108
+ if (res.stderr) {
109
+ console.log(`Composer stderr: ${res.stderr}`);
110
+ }
111
+ if (res.stdout) {
112
+ console.log(`Composer stdout: ${res.stdout}`);
113
+ }
114
+ // Create fallback composer.json
115
+ console.log("Creating fallback composer.json...");
116
+ const defaultComposerJson = {
117
+ name: "tsnc/prisma-php-app",
118
+ type: "project",
119
+ version: "1.0.0",
120
+ require: { php: "^8.2" },
121
+ autoload: { "psr-4": { "": "src/" } },
122
+ };
81
123
  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
- };
89
124
  fs.writeFileSync(
90
125
  composerJsonPath,
91
- JSON.stringify(defaultComposerJson, null, 2)
126
+ JSON.stringify(defaultComposerJson, null, 2),
127
+ { encoding: "utf8" }
92
128
  );
93
- console.log("Created fallback composer.json");
129
+ console.log(`✓ Created fallback composer.json at ${composerJsonPath}`);
94
130
  } catch (writeError) {
95
- console.error("Failed to create fallback composer.json:", writeError);
96
- throw writeError;
131
+ console.error(`✗ Failed to create fallback composer.json:`, writeError);
132
+ console.error(`Attempted to write to: ${composerJsonPath}`);
133
+ console.error(`Base directory exists: ${fs.existsSync(baseDir)}`);
134
+ console.error(
135
+ `Base directory stats:`,
136
+ fs.existsSync(baseDir) ? fs.statSync(baseDir) : "N/A"
137
+ );
138
+ throw new Error(`Cannot create composer.json: ${writeError}`);
97
139
  }
140
+ } else {
141
+ console.log("✓ Composer init successful");
98
142
  }
99
143
  }
100
- /* 2. Ensure PSR-4 autoload entry ---------------------------------- */
101
- // Add safety check before reading
144
+ /* ------------------------------------------------------------------ */
145
+ /* 3. Verify composer.json exists before proceeding */
146
+ /* ------------------------------------------------------------------ */
102
147
  if (!fs.existsSync(composerJsonPath)) {
103
- console.error(`composer.json not found at ${composerJsonPath}`);
104
- throw new Error("Failed to create or find composer.json");
148
+ console.error(`✗ composer.json still not found at ${composerJsonPath}`);
149
+ console.error(`Directory contents:`, fs.readdirSync(baseDir));
150
+ throw new Error(
151
+ "Failed to create composer.json - file does not exist after init/fallback"
152
+ );
105
153
  }
154
+ /* ------------------------------------------------------------------ */
155
+ /* 4. Ensure PSR-4 autoload entry */
156
+ /* ------------------------------------------------------------------ */
106
157
  let json;
107
158
  try {
108
- json = JSON.parse(fs.readFileSync(composerJsonPath, "utf8"));
159
+ const jsonContent = fs.readFileSync(composerJsonPath, "utf8");
160
+ console.log("✓ Successfully read composer.json");
161
+ json = JSON.parse(jsonContent);
109
162
  } catch (readError) {
110
- console.error("Failed to read composer.json:", readError);
111
- throw readError;
163
+ console.error("Failed to read/parse composer.json:", readError);
164
+ throw new Error(`Cannot read composer.json: ${readError}`);
112
165
  }
113
166
  json.autoload ??= {};
114
167
  json.autoload["psr-4"] ??= {};
115
168
  json.autoload["psr-4"][""] ??= "src/";
116
169
  try {
117
170
  fs.writeFileSync(composerJsonPath, JSON.stringify(json, null, 2));
171
+ console.log("✓ Updated composer.json with PSR-4 autoload");
118
172
  } catch (writeError) {
119
- console.error("Failed to update composer.json:", writeError);
173
+ console.error("Failed to update composer.json:", writeError);
120
174
  throw writeError;
121
175
  }
122
- /* 3. Install dependencies ----------------------------------------- */
176
+ /* ------------------------------------------------------------------ */
177
+ /* 5. Install dependencies */
178
+ /* ------------------------------------------------------------------ */
123
179
  if (dependencies.length) {
124
180
  console.log("Installing Composer dependencies:");
125
181
  dependencies.forEach((d) => console.log(`- ${chalk.blue(d)}`));
126
- execSync(
127
- `${cmd} ${[
182
+ try {
183
+ const requireCmd = `${cmd} ${[
128
184
  ...baseArgs,
129
185
  "require",
130
186
  "--no-interaction",
131
187
  ...dependencies,
132
- ].join(" ")}`,
133
- { stdio: "inherit", cwd: baseDir }
134
- );
188
+ ].join(" ")}`;
189
+ console.log(`Executing: ${requireCmd}`);
190
+ execSync(requireCmd, { stdio: "inherit", cwd: baseDir });
191
+ console.log("✓ Composer dependencies installed");
192
+ } catch (installError) {
193
+ console.error("✗ Failed to install composer dependencies:", installError);
194
+ throw installError;
195
+ }
135
196
  }
136
- /* 4. Refresh lock when updating ----------------------------------- */
197
+ /* ------------------------------------------------------------------ */
198
+ /* 6. Refresh lock when updating */
199
+ /* ------------------------------------------------------------------ */
137
200
  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
- );
201
+ try {
202
+ execSync(
203
+ `${cmd} ${[
204
+ ...baseArgs,
205
+ "update",
206
+ "--lock",
207
+ "--no-install",
208
+ "--no-interaction",
209
+ ].join(" ")}`,
210
+ { stdio: "inherit", cwd: baseDir }
211
+ );
212
+ console.log("✓ Composer lock updated");
213
+ } catch (updateError) {
214
+ console.error("✗ Failed to update composer lock:", updateError);
215
+ throw updateError;
216
+ }
217
+ }
218
+ /* ------------------------------------------------------------------ */
219
+ /* 7. Regenerate autoloader */
220
+ /* ------------------------------------------------------------------ */
221
+ try {
222
+ execSync(`${cmd} ${[...baseArgs, "dump-autoload", "--quiet"].join(" ")}`, {
223
+ stdio: "inherit",
224
+ cwd: baseDir,
225
+ });
226
+ console.log("✓ Composer autoloader regenerated");
227
+ } catch (autoloadError) {
228
+ console.error("✗ Failed to regenerate autoloader:", autoloadError);
229
+ throw autoloadError;
148
230
  }
149
- /* 5. Regenerate autoloader ---------------------------------------- */
150
- execSync(`${cmd} ${[...baseArgs, "dump-autoload", "--quiet"].join(" ")}`, {
151
- stdio: "inherit",
152
- cwd: baseDir,
153
- });
154
231
  }
155
232
  const npmPinnedVersions = {
156
233
  "@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.73",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",