create-prisma-php-app 4.0.0-alpha.13 → 4.0.0-alpha.15
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 +57 -40
- 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,36 +58,41 @@ 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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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, { cwd: baseDir });
|
|
75
|
+
if (res.status !== 0) {
|
|
76
|
+
console.error(
|
|
77
|
+
chalk.yellow("⚠ composer init devolvió un código ≠ 0. Salida:")
|
|
78
|
+
);
|
|
79
|
+
if (res.stderr) console.error(res.stderr.toString());
|
|
80
|
+
if (res.error) console.error(res.error.message);
|
|
81
|
+
console.log(
|
|
82
|
+
chalk.yellow(
|
|
83
|
+
"Continuaré creando un composer.json mínimo para no detener la instalación…"
|
|
84
|
+
)
|
|
85
|
+
);
|
|
86
|
+
/* Escribimos un composer.json básico */
|
|
81
87
|
fs.writeFileSync(
|
|
82
88
|
composerJsonPath,
|
|
83
89
|
JSON.stringify(
|
|
84
90
|
{
|
|
85
91
|
name: "tsnc/prisma-php-app",
|
|
86
|
-
require: { php: "^8.2" },
|
|
87
|
-
autoload: { "psr-4": { "": "src/" } },
|
|
88
92
|
type: "project",
|
|
89
93
|
version: "1.0.0",
|
|
94
|
+
require: { php: "^8.2" },
|
|
95
|
+
autoload: { "psr-4": { "": "src/" } },
|
|
90
96
|
},
|
|
91
97
|
null,
|
|
92
98
|
2
|
|
@@ -95,7 +101,7 @@ export async function installComposerDependencies(baseDir, dependencies) {
|
|
|
95
101
|
}
|
|
96
102
|
}
|
|
97
103
|
/* ------------------------------------------------------------------ */
|
|
98
|
-
/* 2. Garantizar autoload PSR-4
|
|
104
|
+
/* 2. Garantizar autoload PSR-4 */
|
|
99
105
|
/* ------------------------------------------------------------------ */
|
|
100
106
|
const json = JSON.parse(fs.readFileSync(composerJsonPath, "utf8"));
|
|
101
107
|
json.autoload ??= {};
|
|
@@ -107,25 +113,36 @@ export async function installComposerDependencies(baseDir, dependencies) {
|
|
|
107
113
|
/* ------------------------------------------------------------------ */
|
|
108
114
|
if (dependencies.length) {
|
|
109
115
|
console.log("Installing Composer dependencies:");
|
|
110
|
-
dependencies.forEach((
|
|
111
|
-
execSync(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
116
|
+
dependencies.forEach((d) => console.log(`- ${chalk.blue(d)}`));
|
|
117
|
+
execSync(
|
|
118
|
+
`${cmd} ${[
|
|
119
|
+
...baseArgs,
|
|
120
|
+
"require",
|
|
121
|
+
"--no-interaction",
|
|
122
|
+
...dependencies,
|
|
123
|
+
].join(" ")}`,
|
|
124
|
+
{ stdio: "inherit", cwd: baseDir }
|
|
125
|
+
);
|
|
115
126
|
}
|
|
116
127
|
/* ------------------------------------------------------------------ */
|
|
117
128
|
/* 4. Refrescar lock (solo modo update) */
|
|
118
129
|
/* ------------------------------------------------------------------ */
|
|
119
130
|
if (existsAlready) {
|
|
120
|
-
execSync(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
131
|
+
execSync(
|
|
132
|
+
`${cmd} ${[
|
|
133
|
+
...baseArgs,
|
|
134
|
+
"update",
|
|
135
|
+
"--lock",
|
|
136
|
+
"--no-install",
|
|
137
|
+
"--no-interaction",
|
|
138
|
+
].join(" ")}`,
|
|
139
|
+
{ stdio: "inherit", cwd: baseDir }
|
|
140
|
+
);
|
|
124
141
|
}
|
|
125
142
|
/* ------------------------------------------------------------------ */
|
|
126
143
|
/* 5. Regenerar autoloader */
|
|
127
144
|
/* ------------------------------------------------------------------ */
|
|
128
|
-
execSync(`${
|
|
145
|
+
execSync(`${cmd} ${[...baseArgs, "dump-autoload", "--quiet"].join(" ")}`, {
|
|
129
146
|
stdio: "inherit",
|
|
130
147
|
cwd: baseDir,
|
|
131
148
|
});
|