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