create-prisma-php-app 4.0.0-alpha.13 → 4.0.0-alpha.14
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 +45 -37
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -32,18 +32,19 @@ async function installNpmDependencies(baseDir, dependencies, isDev = false) {
|
|
|
32
32
|
cwd: baseDir,
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
const windowsPhar =
|
|
37
|
-
'"C:\\xampp\\php\\php.exe" "C:\\ProgramData\\ComposerSetup\\bin\\composer.phar"';
|
|
35
|
+
function getComposerCmd() {
|
|
38
36
|
try {
|
|
39
37
|
execSync("composer --version", { stdio: "ignore" });
|
|
40
|
-
return "composer";
|
|
38
|
+
return { cmd: "composer", baseArgs: [] };
|
|
41
39
|
} catch {
|
|
42
|
-
return
|
|
40
|
+
return {
|
|
41
|
+
cmd: "C:\\xampp\\php\\php.exe",
|
|
42
|
+
baseArgs: ["C:\\ProgramData\\ComposerSetup\\bin\\composer.phar"],
|
|
43
|
+
};
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
export async function installComposerDependencies(baseDir, dependencies) {
|
|
46
|
-
const
|
|
47
|
+
const { cmd, baseArgs } = getComposerCmd();
|
|
47
48
|
const composerJsonPath = path.join(baseDir, "composer.json");
|
|
48
49
|
const existsAlready = fs.existsSync(composerJsonPath);
|
|
49
50
|
console.log(
|
|
@@ -57,26 +58,22 @@ export async function installComposerDependencies(baseDir, dependencies) {
|
|
|
57
58
|
/* 1. Crear composer.json (solo si no existe) */
|
|
58
59
|
/* ------------------------------------------------------------------ */
|
|
59
60
|
if (!existsAlready) {
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (init.status !== 0) {
|
|
77
|
-
throw new Error("Composer init failed");
|
|
78
|
-
}
|
|
79
|
-
/* -- Última defensa: si composer.json no apareció, lo creamos mínimo */
|
|
61
|
+
const initArgs = [
|
|
62
|
+
...baseArgs,
|
|
63
|
+
"init",
|
|
64
|
+
"--no-interaction",
|
|
65
|
+
"--name",
|
|
66
|
+
"tsnc/prisma-php-app",
|
|
67
|
+
"--require",
|
|
68
|
+
"php:^8.2",
|
|
69
|
+
"--type",
|
|
70
|
+
"project",
|
|
71
|
+
"--version",
|
|
72
|
+
"1.0.0",
|
|
73
|
+
];
|
|
74
|
+
const res = spawnSync(cmd, initArgs, { stdio: "inherit", cwd: baseDir });
|
|
75
|
+
if (res.status !== 0) throw new Error("Composer init failed");
|
|
76
|
+
// Salvaguarda: crear composer.json mínimo si aún no existe
|
|
80
77
|
if (!fs.existsSync(composerJsonPath)) {
|
|
81
78
|
fs.writeFileSync(
|
|
82
79
|
composerJsonPath,
|
|
@@ -95,7 +92,7 @@ export async function installComposerDependencies(baseDir, dependencies) {
|
|
|
95
92
|
}
|
|
96
93
|
}
|
|
97
94
|
/* ------------------------------------------------------------------ */
|
|
98
|
-
/* 2. Garantizar autoload PSR-4
|
|
95
|
+
/* 2. Garantizar autoload PSR-4 */
|
|
99
96
|
/* ------------------------------------------------------------------ */
|
|
100
97
|
const json = JSON.parse(fs.readFileSync(composerJsonPath, "utf8"));
|
|
101
98
|
json.autoload ??= {};
|
|
@@ -107,25 +104,36 @@ export async function installComposerDependencies(baseDir, dependencies) {
|
|
|
107
104
|
/* ------------------------------------------------------------------ */
|
|
108
105
|
if (dependencies.length) {
|
|
109
106
|
console.log("Installing Composer dependencies:");
|
|
110
|
-
dependencies.forEach((
|
|
111
|
-
execSync(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
107
|
+
dependencies.forEach((d) => console.log(`- ${chalk.blue(d)}`));
|
|
108
|
+
execSync(
|
|
109
|
+
`${cmd} ${[
|
|
110
|
+
...baseArgs,
|
|
111
|
+
"require",
|
|
112
|
+
"--no-interaction",
|
|
113
|
+
...dependencies,
|
|
114
|
+
].join(" ")}`,
|
|
115
|
+
{ stdio: "inherit", cwd: baseDir }
|
|
116
|
+
);
|
|
115
117
|
}
|
|
116
118
|
/* ------------------------------------------------------------------ */
|
|
117
119
|
/* 4. Refrescar lock (solo modo update) */
|
|
118
120
|
/* ------------------------------------------------------------------ */
|
|
119
121
|
if (existsAlready) {
|
|
120
|
-
execSync(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
execSync(
|
|
123
|
+
`${cmd} ${[
|
|
124
|
+
...baseArgs,
|
|
125
|
+
"update",
|
|
126
|
+
"--lock",
|
|
127
|
+
"--no-install",
|
|
128
|
+
"--no-interaction",
|
|
129
|
+
].join(" ")}`,
|
|
130
|
+
{ stdio: "inherit", cwd: baseDir }
|
|
131
|
+
);
|
|
124
132
|
}
|
|
125
133
|
/* ------------------------------------------------------------------ */
|
|
126
134
|
/* 5. Regenerar autoloader */
|
|
127
135
|
/* ------------------------------------------------------------------ */
|
|
128
|
-
execSync(`${
|
|
136
|
+
execSync(`${cmd} ${[...baseArgs, "dump-autoload", "--quiet"].join(" ")}`, {
|
|
129
137
|
stdio: "inherit",
|
|
130
138
|
cwd: baseDir,
|
|
131
139
|
});
|