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.
Files changed (2) hide show
  1. package/dist/index.js +45 -37
  2. 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
- async function composerBin() {
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 windowsPhar;
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 composer = await composerBin();
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 init = spawnSync(
61
- composer,
62
- [
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
- { stdio: "inherit", cwd: baseDir }
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 sin borrar mapeos previos */
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((dep) => console.log(`- ${chalk.blue(dep)}`));
111
- execSync(`${composer} require --no-interaction ${dependencies.join(" ")}`, {
112
- stdio: "inherit",
113
- cwd: baseDir,
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(`${composer} update --lock --no-install --no-interaction`, {
121
- stdio: "inherit",
122
- cwd: baseDir,
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(`${composer} dump-autoload --quiet`, {
136
+ execSync(`${cmd} ${[...baseArgs, "dump-autoload", "--quiet"].join(" ")}`, {
129
137
  stdio: "inherit",
130
138
  cwd: baseDir,
131
139
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "4.0.0-alpha.13",
3
+ "version": "4.0.0-alpha.14",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",