create-prisma-php-app 5.1.0-alpha.2 → 5.1.0-alpha.21

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.
@@ -0,0 +1,205 @@
1
+ import { execFile, spawn } from "node:child_process";
2
+ import { mkdir, readFile, readFileSync, rm, rmSync, writeFile } from "node:fs";
3
+ import { promisify } from "node:util";
4
+ import { dirname, join } from "node:path";
5
+ import process from "node:process";
6
+
7
+ const mode: "watch" | "build" = process.argv[2] === "watch" ? "watch" : "build";
8
+ const watcherPidFile = join(process.cwd(), ".pp", "postcss-watch.pid");
9
+ const mkdirAsync = promisify(mkdir);
10
+ const readFileAsync = promisify(readFile);
11
+ const rmAsync = promisify(rm);
12
+ const writeFileAsync = promisify(writeFile);
13
+
14
+ const args: string[] = [
15
+ "--max-old-space-size=6144",
16
+ "./node_modules/postcss-cli/index.js",
17
+ "src/app/globals.css",
18
+ "-o",
19
+ "public/css/styles.css",
20
+ ];
21
+
22
+ if (mode === "watch") {
23
+ args.push("--watch");
24
+ }
25
+
26
+ function isValidPid(value: string): boolean {
27
+ return /^\d+$/.test(value.trim());
28
+ }
29
+
30
+ function isProcessRunning(pid: number): boolean {
31
+ try {
32
+ process.kill(pid, 0);
33
+ return true;
34
+ } catch {
35
+ return false;
36
+ }
37
+ }
38
+
39
+ function killWindowsProcessTree(pid: number): Promise<void> {
40
+ return new Promise((resolve) => {
41
+ const killer = execFile("taskkill", ["/F", "/T", "/PID", String(pid)], () =>
42
+ resolve(),
43
+ );
44
+
45
+ killer.on("error", () => resolve());
46
+ });
47
+ }
48
+
49
+ async function killProcessTree(pid: number): Promise<void> {
50
+ if (process.platform === "win32") {
51
+ await killWindowsProcessTree(pid);
52
+ return;
53
+ }
54
+
55
+ try {
56
+ process.kill(pid, "SIGTERM");
57
+ } catch {
58
+ return;
59
+ }
60
+ }
61
+
62
+ async function ensurePidDirectory(): Promise<void> {
63
+ await mkdirAsync(dirname(watcherPidFile), { recursive: true });
64
+ }
65
+
66
+ async function clearPidFile(): Promise<void> {
67
+ try {
68
+ const storedPid = (await readFileAsync(watcherPidFile, "utf8")).trim();
69
+ if (storedPid === String(process.pid)) {
70
+ await rmAsync(watcherPidFile, { force: true });
71
+ }
72
+ } catch {}
73
+ }
74
+
75
+ function clearPidFileSync(): void {
76
+ try {
77
+ const storedPid = readFileSync(watcherPidFile, "utf8").trim();
78
+ if (storedPid === String(process.pid)) {
79
+ rmSync(watcherPidFile, { force: true });
80
+ }
81
+ } catch {}
82
+ }
83
+
84
+ async function cleanupStaleWatcher(): Promise<void> {
85
+ if (mode !== "watch") {
86
+ return;
87
+ }
88
+
89
+ await ensurePidDirectory();
90
+
91
+ let storedPid = "";
92
+
93
+ try {
94
+ storedPid = (await readFileAsync(watcherPidFile, "utf8")).trim();
95
+ } catch {
96
+ return;
97
+ }
98
+
99
+ if (!isValidPid(storedPid)) {
100
+ await rmAsync(watcherPidFile, { force: true });
101
+ return;
102
+ }
103
+
104
+ const pid = Number(storedPid);
105
+
106
+ if (pid === process.pid) {
107
+ return;
108
+ }
109
+
110
+ if (!isProcessRunning(pid)) {
111
+ await rmAsync(watcherPidFile, { force: true });
112
+ return;
113
+ }
114
+
115
+ console.warn(
116
+ `[tailwind] Found stale PostCSS watcher (PID ${pid}), stopping it before restart.`,
117
+ );
118
+ await killProcessTree(pid);
119
+ await rmAsync(watcherPidFile, { force: true });
120
+ }
121
+
122
+ async function writePidFile(): Promise<void> {
123
+ if (mode !== "watch") {
124
+ return;
125
+ }
126
+
127
+ await ensurePidDirectory();
128
+ await writeFileAsync(watcherPidFile, `${process.pid}\n`, "utf8");
129
+ }
130
+
131
+ await cleanupStaleWatcher();
132
+ await writePidFile();
133
+
134
+ const child = spawn(process.execPath, args, {
135
+ stdio: "inherit",
136
+ windowsHide: true,
137
+ env: {
138
+ ...process.env,
139
+ PP_POSTCSS_MODE: mode,
140
+ },
141
+ });
142
+
143
+ let shuttingDown = false;
144
+
145
+ child.on("error", (error) => {
146
+ console.error(error);
147
+ void shutdown(1);
148
+ });
149
+
150
+ async function shutdown(exitCode: number): Promise<void> {
151
+ if (shuttingDown) {
152
+ return;
153
+ }
154
+
155
+ shuttingDown = true;
156
+
157
+ if (child.pid && child.exitCode === null && !child.killed) {
158
+ await killProcessTree(child.pid);
159
+ }
160
+
161
+ await clearPidFile();
162
+ process.exit(exitCode);
163
+ }
164
+
165
+ child.on("exit", async (code, signal) => {
166
+ await clearPidFile();
167
+
168
+ if (shuttingDown) {
169
+ process.exit(code ?? 0);
170
+ return;
171
+ }
172
+
173
+ if (signal) {
174
+ try {
175
+ process.kill(process.pid, signal);
176
+ } catch {
177
+ process.exit(1);
178
+ }
179
+ return;
180
+ }
181
+
182
+ process.exit(code ?? 0);
183
+ });
184
+
185
+ process.once("SIGINT", () => {
186
+ void shutdown(0);
187
+ });
188
+
189
+ process.once("SIGTERM", () => {
190
+ void shutdown(0);
191
+ });
192
+
193
+ process.once("uncaughtException", (error) => {
194
+ console.error(error);
195
+ void shutdown(1);
196
+ });
197
+
198
+ process.once("unhandledRejection", (reason) => {
199
+ console.error(reason);
200
+ void shutdown(1);
201
+ });
202
+
203
+ process.once("exit", () => {
204
+ clearPidFileSync();
205
+ });
@@ -1,4 +1,6 @@
1
- @import "tailwindcss";
1
+ @import "tailwindcss" source(none);
2
+ @source "../";
3
+ @source "../../ts";
2
4
 
3
5
  :root {
4
6
  --background: #ffffff;
@@ -15,7 +15,7 @@ MainLayout::$description = !empty(MainLayout::$description) ? MainLayout::$descr
15
15
  <!-- Dynamic Header Scripts -->
16
16
  </head>
17
17
 
18
- <body pp-spa="true" style="opacity:0;pointer-events:none;user-select:none;transition:opacity .18s ease-out;">
18
+ <body style="opacity:0;pointer-events:none;user-select:none;transition:opacity .18s ease-out;">
19
19
  <?= MainLayout::$children; ?>
20
20
  <!-- Dynamic Footer Scripts -->
21
21
  </body>
package/dist/ts/main.ts CHANGED
@@ -11,17 +11,14 @@ import "/js/pp-reactive-v2.js";
11
11
 
12
12
  // createGlobalSingleton("myCustomFunction", myCustomFunction);
13
13
 
14
-
15
14
  // Imports goes here --End
16
15
 
17
16
  const pp = (globalThis as any).pp;
18
17
 
19
18
  if (document.readyState !== "loading") {
20
- pp?.mount?.();
19
+ pp?.mount?.();
21
20
  } else {
22
- document.addEventListener(
23
- "DOMContentLoaded",
24
- () => pp?.mount?.(),
25
- { once: true },
26
- );
27
- }
21
+ document.addEventListener("DOMContentLoaded", () => pp?.mount?.(), {
22
+ once: true,
23
+ });
24
+ }
@@ -0,0 +1,13 @@
1
+ import { twMerge } from "tailwind-merge";
2
+
3
+ export type MergeableClassName = string | false | null | undefined;
4
+
5
+ export function mergeTailwindClasses(
6
+ ...classNames: MergeableClassName[]
7
+ ): string {
8
+ return twMerge(
9
+ classNames
10
+ .filter((className): className is string => Boolean(className))
11
+ .join(" "),
12
+ );
13
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "5.1.0-alpha.2",
3
+ "version": "5.1.0-alpha.21",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",