create-prisma-php-app 4.4.0 → 4.4.1

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.
@@ -13,7 +13,7 @@ const newProjectName = basename(join(__dirname, ".."));
13
13
 
14
14
  function updateProjectNameInConfig(
15
15
  filePath: string,
16
- newProjectName: string
16
+ newProjectName: string,
17
17
  ): void {
18
18
  const filePathDir = dirname(filePath);
19
19
 
@@ -23,7 +23,7 @@ function updateProjectNameInConfig(
23
23
 
24
24
  const targetPath = getTargetPath(
25
25
  filePathDir,
26
- prismaPhpConfigJson.phpEnvironment
26
+ prismaPhpConfigJson.phpEnvironment,
27
27
  );
28
28
 
29
29
  prismaPhpConfigJson.bsTarget = `http://localhost${targetPath}`;
@@ -39,59 +39,84 @@ function updateProjectNameInConfig(
39
39
  return;
40
40
  }
41
41
  console.log(
42
- "The project name, PHP path, and other paths have been updated successfully."
42
+ "The project name, PHP path, and other paths have been updated successfully.",
43
43
  );
44
- }
44
+ },
45
45
  );
46
46
  }
47
47
 
48
48
  function getTargetPath(fullPath: string, environment: string): string {
49
49
  const normalizedPath = normalize(fullPath);
50
50
 
51
- if (process.env.CI === "true") {
51
+ // ---- CI / Railway / Docker safe-guards ----
52
+ // GitHub Actions etc.
53
+ if (process.env.CI === "true") return "/";
54
+
55
+ // Railway commonly exposes these (not guaranteed, but helpful)
56
+ if (process.env.RAILWAY_ENVIRONMENT || process.env.RAILWAY_PROJECT_ID)
57
+ return "/";
58
+
59
+ // Docker/containers: your app root is usually /app
60
+ // If you're not inside an AMP stack folder, don't crash.
61
+ const lower = normalizedPath.toLowerCase();
62
+ if (
63
+ lower === "/app" ||
64
+ lower.startsWith("/app" + sep) ||
65
+ lower.startsWith("/app/")
66
+ ) {
52
67
  return "/";
53
68
  }
54
69
 
55
- const webDirectories: { [key: string]: string } = {
70
+ // ---- Local AMP detection map (your original logic) ----
71
+ const webDirectories: Record<string, string> = {
56
72
  XAMPP: join("htdocs"),
57
73
  WAMP: join("www"),
58
74
  MAMP: join("htdocs"),
59
75
  LAMP: join("var", "www", "html"),
60
76
  LEMP: join("usr", "share", "nginx", "html"),
61
77
  AMPPS: join("www"),
62
- UniformServer: join("www"),
63
- EasyPHP: join("data", "localweb"),
78
+ UNIFORMSERVER: join("www"),
79
+ EASYPHP: join("data", "localweb"),
64
80
  };
65
81
 
66
- const webDir = webDirectories[environment.toUpperCase()];
67
- if (!webDir) {
68
- throw new Error(`Unsupported environment: ${environment}`);
69
- }
82
+ const envKey = (environment || "").toUpperCase();
83
+ const webDir = webDirectories[envKey];
70
84
 
71
- const indexOfWebDir = normalizedPath
72
- .toLowerCase()
73
- .indexOf(normalize(webDir).toLowerCase());
74
- if (indexOfWebDir === -1) {
75
- throw new Error(`Web directory not found in path: ${webDir}`);
76
- }
85
+ // If phpEnvironment is missing/unknown, don't crash in non-local contexts.
86
+ if (!webDir) return "/";
77
87
 
78
- const startIndex = indexOfWebDir + webDir.length;
88
+ const webDirNorm = normalize(webDir).toLowerCase();
89
+ const idx = lower.indexOf(webDirNorm);
90
+
91
+ // If we can't find htdocs/www/etc, fall back instead of throwing.
92
+ if (idx === -1) return "/";
93
+
94
+ const startIndex = idx + webDir.length;
79
95
  const subPath = normalizedPath.slice(startIndex);
96
+
80
97
  const safeSeparatorRegex = new RegExp(
81
98
  sep.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&"),
82
- "g"
99
+ "g",
83
100
  );
84
- const finalPath = subPath.replace(safeSeparatorRegex, "/") + "/";
85
101
 
86
- return finalPath;
102
+ const finalPath = (subPath.replace(safeSeparatorRegex, "/") || "/") + "/";
103
+
104
+ // Ensure it starts with "/"
105
+ return finalPath.startsWith("/") ? finalPath : `/${finalPath}`;
87
106
  }
88
107
 
89
108
  const configFilePath = join(__dirname, "..", "prisma-php.json");
90
109
 
91
- updateProjectNameInConfig(configFilePath, newProjectName);
110
+ const isLocal =
111
+ !process.env.CI &&
112
+ !process.env.RAILWAY_ENVIRONMENT &&
113
+ !process.env.RAILWAY_PROJECT_ID;
114
+ if (isLocal) {
115
+ updateProjectNameInConfig(configFilePath, newProjectName);
116
+ }
92
117
 
93
118
  export const deleteFilesIfExist = async (
94
- filePaths: string[]
119
+ filePaths: string[],
95
120
  ): Promise<void> => {
96
121
  for (const filePath of filePaths) {
97
122
  try {
@@ -113,7 +138,7 @@ export const deleteFilesIfExist = async (
113
138
  };
114
139
 
115
140
  export async function deleteDirectoriesIfExist(
116
- dirPaths: string[]
141
+ dirPaths: string[],
117
142
  ): Promise<void> {
118
143
  for (const dirPath of dirPaths) {
119
144
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "4.4.0",
3
+ "version": "4.4.1",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",