create-prisma-php-app 2.3.34 → 2.3.35

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.
@@ -36,7 +36,25 @@ const handleFileChange = async () => {
36
36
  // Optionally, run the component check on each PHP file.
37
37
  const phpFiles = await getAllPhpFiles(SRC_DIR + "/app");
38
38
  for (const file of phpFiles) {
39
- const fileImports = await analyzeImportsInFile(file);
39
+ const rawFileImports = await analyzeImportsInFile(file);
40
+ // Convert Record<string, string> to Record<string, { className: string; filePath: string; importer?: string }[]>
41
+ const fileImports: Record<
42
+ string,
43
+ | { className: string; filePath: string; importer?: string }[]
44
+ | { className: string; filePath: string; importer?: string }
45
+ > = {};
46
+ for (const key in rawFileImports) {
47
+ if (typeof rawFileImports[key] === "string") {
48
+ fileImports[key] = [
49
+ {
50
+ className: key,
51
+ filePath: rawFileImports[key],
52
+ },
53
+ ];
54
+ } else {
55
+ fileImports[key] = rawFileImports[key];
56
+ }
57
+ }
40
58
  await checkComponentImports(file, fileImports);
41
59
  }
42
60
  };
@@ -11,59 +11,99 @@ import {
11
11
  updateComponentImports,
12
12
  } from "./class-imports";
13
13
  import { checkComponentImports } from "./component-import-checker";
14
+ import prismaPhpConfigJson from "../prisma-php.json";
15
+ import { exec as execCb } from "child_process";
16
+ import { promisify } from "util";
14
17
 
18
+ const exec = promisify(execCb);
15
19
  const { __dirname } = getFileMeta();
16
20
 
17
21
  (async () => {
18
22
  console.log("📦 Generating files for production...");
19
23
 
20
- // Run all watchers logic ONCE
24
+ // 1) Run all watchers logic ONCE
21
25
  await generateFileListJson();
22
26
  await updateAllClassLogs();
23
27
  await updateComponentImports();
24
28
 
25
- const phpFiles = await getAllPhpFiles(SRC_DIR + "/app");
26
- for (const file of phpFiles) {
27
- const fileImports = await analyzeImportsInFile(file);
28
- await checkComponentImports(file, fileImports);
29
- }
30
-
31
- // Start BrowserSync just to extract URLs (and shut down immediately)
32
- const bs = browserSync.create();
33
- bs.init(
34
- {
35
- proxy: "http://localhost:3000",
36
- middleware: [],
37
- notify: false,
38
- open: false,
39
- ghostMode: false,
40
- codeSync: false,
41
- watchOptions: {
42
- usePolling: true,
43
- interval: 1000,
29
+ // 2) Start BrowserSync to extract URLs (and shut down immediately)
30
+ await new Promise<void>((resolve, reject) => {
31
+ const bs = browserSync.create();
32
+ bs.init(
33
+ {
34
+ proxy: "http://localhost:3000",
35
+ middleware: [],
36
+ notify: false,
37
+ open: false,
38
+ ghostMode: false,
39
+ codeSync: false,
40
+ watchOptions: {
41
+ usePolling: true,
42
+ interval: 1000,
43
+ },
44
44
  },
45
- },
46
- (err, bsInstance) => {
47
- if (err) {
48
- console.error("❌ BrowserSync failed:", err);
49
- process.exit(1);
45
+ (err, bsInstance) => {
46
+ if (err) {
47
+ console.error("❌ BrowserSync failed:", err);
48
+ process.exit(1);
49
+ return reject(err);
50
+ }
51
+
52
+ const options = bsInstance.getOption("urls");
53
+ const urls = {
54
+ local: options.get("local"),
55
+ external: options.get("external"),
56
+ ui: options.get("ui"),
57
+ uiExternal: options.get("ui-external"),
58
+ };
59
+
60
+ writeFileSync(
61
+ join(__dirname, "bs-config.json"),
62
+ JSON.stringify(urls, null, 2)
63
+ );
64
+
65
+ console.log("✅ BrowserSync URLs extracted; shutting down.");
66
+ bs.exit();
67
+ resolve();
50
68
  }
69
+ );
70
+ });
71
+
72
+ // 3) Run `npx ppo generate` and wait for it to finish
73
+ if (prismaPhpConfigJson.prisma) {
74
+ try {
75
+ console.log("🚀 Running `npx ppo generate`...");
76
+ const { stdout, stderr } = await exec("npx ppo generate");
77
+ if (stderr) console.error(stderr);
78
+ console.log(`stdout:\n${stdout}`);
79
+ } catch (error: any) {
80
+ console.error(`Error executing ppo generate: ${error.message}`);
81
+ process.exit(1);
82
+ }
83
+ }
51
84
 
52
- const options = bsInstance.getOption("urls");
53
- const urls = {
54
- local: options.get("local"),
55
- external: options.get("external"),
56
- ui: options.get("ui"),
57
- uiExternal: options.get("ui-external"),
58
- };
85
+ // 4) Process all PHP files for component-import checks
86
+ const phpFiles = await getAllPhpFiles(join(SRC_DIR, "app"));
87
+ for (const file of phpFiles) {
88
+ const rawFileImports = await analyzeImportsInFile(file);
59
89
 
60
- writeFileSync(
61
- join(__dirname, "bs-config.json"),
62
- JSON.stringify(urls, null, 2)
63
- );
90
+ // Normalize imports into array-of-objects format
91
+ const fileImports: Record<
92
+ string,
93
+ { className: string; filePath: string; importer?: string }[]
94
+ > = {};
64
95
 
65
- console.log("✅ Generating files for production completed.");
66
- bs.exit(); // Shut down immediately
96
+ for (const key in rawFileImports) {
97
+ const val = rawFileImports[key];
98
+ if (typeof val === "string") {
99
+ fileImports[key] = [{ className: key, filePath: val }];
100
+ } else {
101
+ fileImports[key] = val;
102
+ }
67
103
  }
68
- );
104
+
105
+ await checkComponentImports(file, fileImports);
106
+ }
107
+
108
+ console.log("✅ Generating files for production completed.");
69
109
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "2.3.34",
3
+ "version": "2.3.35",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",