create-prisma-php-app 1.22.506 → 1.22.508

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,75 @@
1
+ import { createProxyMiddleware } from "http-proxy-middleware";
2
+ import { readFileSync, writeFileSync } from "fs";
3
+ import chokidar from "chokidar";
4
+ import browserSync from "browser-sync";
5
+ // import prismaPhpConfig from "../prisma-php.json" assert { type: "json" };
6
+ import { generateFileListJson } from "./files-list.js";
7
+ import { join, dirname } from "path";
8
+ import { fileURLToPath } from "url";
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = dirname(__filename);
11
+ const bs = browserSync.create();
12
+ const prismaPhpConfig = JSON.parse(readFileSync(join(__dirname, "..", "prisma-php.json")).toString("utf-8"));
13
+ // Watch for file changes (create, delete, save)
14
+ const watcher = chokidar.watch("src/app/**/*", {
15
+ ignored: /(^|[\/\\])\../, // Ignore dotfiles
16
+ persistent: true,
17
+ usePolling: true,
18
+ interval: 1000,
19
+ });
20
+ // Perform specific actions for file events
21
+ watcher
22
+ .on("add", (path) => {
23
+ generateFileListJson();
24
+ })
25
+ .on("change", (path) => {
26
+ generateFileListJson();
27
+ })
28
+ .on("unlink", (path) => {
29
+ generateFileListJson();
30
+ });
31
+ // BrowserSync initialization
32
+ bs.init({
33
+ proxy: "http://localhost:3000",
34
+ middleware: [
35
+ (req, res, next) => {
36
+ res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
37
+ res.setHeader("Pragma", "no-cache");
38
+ res.setHeader("Expires", "0");
39
+ next();
40
+ },
41
+ createProxyMiddleware({
42
+ target: prismaPhpConfig.bsTarget,
43
+ changeOrigin: true,
44
+ pathRewrite: prismaPhpConfig.ngrok ? {} : prismaPhpConfig.bsPathRewrite,
45
+ }),
46
+ ],
47
+ files: "src/**/*.*",
48
+ notify: false,
49
+ open: false,
50
+ ghostMode: false,
51
+ codeSync: true, // Disable synchronization of code changes across clients
52
+ watchOptions: {
53
+ usePolling: true,
54
+ interval: 1000,
55
+ },
56
+ }, (err, bsInstance) => {
57
+ if (err) {
58
+ console.error("BrowserSync failed to start:", err);
59
+ return;
60
+ }
61
+ // Retrieve the active URLs from the BrowserSync instance
62
+ const options = bsInstance.getOption("urls");
63
+ const localUrl = options.get("local");
64
+ const externalUrl = options.get("external");
65
+ const uiUrl = options.get("ui");
66
+ const uiExternalUrl = options.get("ui-external");
67
+ // Construct the URLs dynamically
68
+ const urls = {
69
+ local: localUrl,
70
+ external: externalUrl,
71
+ ui: uiUrl,
72
+ uiExternal: uiExternalUrl,
73
+ };
74
+ writeFileSync(join(__dirname, "bs-config.json"), JSON.stringify(urls, null, 2));
75
+ });
@@ -0,0 +1,43 @@
1
+ import fs from "fs";
2
+ import { join, sep, relative, dirname } from "path";
3
+ import { fileURLToPath } from "url";
4
+ const __filename = fileURLToPath(import.meta.url);
5
+ const __dirname = dirname(__filename);
6
+ // Define the directory and JSON file paths correctly
7
+ const dirPath = "src/app"; // Directory path
8
+ const jsonFilePath = "settings/files-list.json"; // Path to the JSON file
9
+ // Function to get all files in the directory
10
+ const getAllFiles = (dirPath) => {
11
+ const files = [];
12
+ // Check if directory exists before reading
13
+ if (!fs.existsSync(dirPath)) {
14
+ console.error(`Directory not found: ${dirPath}`);
15
+ return files; // Return an empty array if the directory doesn't exist
16
+ }
17
+ const items = fs.readdirSync(dirPath);
18
+ items.forEach((item) => {
19
+ const fullPath = join(dirPath, item);
20
+ if (fs.statSync(fullPath).isDirectory()) {
21
+ files.push(...getAllFiles(fullPath)); // Recursive call for subdirectories
22
+ }
23
+ else {
24
+ // Generate the relative path and ensure it starts with ./src
25
+ const relativePath = `.${sep}${relative(join(__dirname, ".."), fullPath)}`;
26
+ // Replace only the root backslashes with forward slashes and leave inner ones
27
+ files.push(relativePath.replace(/\\/g, "/").replace(/^\.\.\//, ""));
28
+ }
29
+ });
30
+ return files;
31
+ };
32
+ // Function to generate the files-list.json
33
+ export const generateFileListJson = () => {
34
+ const files = getAllFiles(dirPath);
35
+ // If files exist, generate JSON file
36
+ if (files.length > 0) {
37
+ fs.writeFileSync(jsonFilePath, JSON.stringify(files, null, 2));
38
+ // console.log(`File list has been saved to: ${jsonFilePath}`);
39
+ }
40
+ else {
41
+ console.error("No files found to save in the JSON file.");
42
+ }
43
+ };
@@ -0,0 +1,60 @@
1
+ import fs, { readFileSync } from "fs";
2
+ import { join, basename, dirname, normalize, sep } from "path";
3
+ import { fileURLToPath } from "url";
4
+ // import prismaPhpConfig from "../prisma-php.json" assert { type: "json" };
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = dirname(__filename);
7
+ const prismaPhpConfig = JSON.parse(readFileSync(join(__dirname, "..", "prisma-php.json")).toString("utf-8"));
8
+ const newProjectName = basename(join(__dirname, ".."));
9
+ // Function to update the project name and paths in the JSON config
10
+ function updateProjectNameInConfig(filePath, newProjectName) {
11
+ const filePathDir = dirname(filePath);
12
+ // Update the projectName directly in the imported config
13
+ prismaPhpConfig.projectName = newProjectName;
14
+ // Update other paths
15
+ prismaPhpConfig.projectRootPath = filePathDir;
16
+ const targetPath = getTargetPath(filePathDir, prismaPhpConfig.phpEnvironment);
17
+ prismaPhpConfig.bsTarget = `http://localhost${targetPath}`;
18
+ prismaPhpConfig.bsPathRewrite["^/"] = targetPath;
19
+ // Save the updated config back to the JSON file
20
+ fs.writeFile(filePath, JSON.stringify(prismaPhpConfig, null, 2), "utf8", (err) => {
21
+ if (err) {
22
+ console.error("Error writing the updated JSON file:", err);
23
+ return;
24
+ }
25
+ console.log("The project name, PHP path, and other paths have been updated successfully.");
26
+ });
27
+ }
28
+ // Function to determine the target path for browser-sync
29
+ function getTargetPath(fullPath, environment) {
30
+ const normalizedPath = normalize(fullPath);
31
+ const webDirectories = {
32
+ XAMPP: join("htdocs"),
33
+ WAMP: join("www"),
34
+ MAMP: join("htdocs"),
35
+ LAMP: join("var", "www", "html"),
36
+ LEMP: join("usr", "share", "nginx", "html"),
37
+ AMPPS: join("www"),
38
+ UniformServer: join("www"),
39
+ EasyPHP: join("data", "localweb"),
40
+ };
41
+ const webDir = webDirectories[environment.toUpperCase()];
42
+ if (!webDir) {
43
+ throw new Error(`Unsupported environment: ${environment}`);
44
+ }
45
+ const indexOfWebDir = normalizedPath
46
+ .toLowerCase()
47
+ .indexOf(normalize(webDir).toLowerCase());
48
+ if (indexOfWebDir === -1) {
49
+ throw new Error(`Web directory not found in path: ${webDir}`);
50
+ }
51
+ const startIndex = indexOfWebDir + webDir.length;
52
+ const subPath = normalizedPath.slice(startIndex);
53
+ const safeSeparatorRegex = new RegExp(sep.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&"), "g");
54
+ const finalPath = subPath.replace(safeSeparatorRegex, "/") + "/";
55
+ return finalPath;
56
+ }
57
+ // Path to your JSON configuration file (for saving changes)
58
+ const configFilePath = join(__dirname, "..", "prisma-php.json");
59
+ // Run the function with your config file path and the new project name
60
+ updateProjectNameInConfig(configFilePath, newProjectName);
@@ -86,7 +86,7 @@ $scriptName = dirname($_SERVER['SCRIPT_NAME']);
86
86
  /**
87
87
  * @var string $baseUrl - The base URL of the request.
88
88
  */
89
- $baseUrl = $protocol . $domainName . "$scriptName/src/app";
89
+ $baseUrl = $_prismaPHPSettings['ngrok'] ? 'src/app' : $protocol . $domainName . "$scriptName/src/app";
90
90
  /**
91
91
  * @var string $documentUrl - The document URL of the request.
92
92
  */
@@ -0,0 +1,40 @@
1
+ import { spawn } from "child_process";
2
+ import path, { dirname } from "path";
3
+ import chokidar from "chokidar";
4
+ import { fileURLToPath } from "url";
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = dirname(__filename);
7
+ // Define paths
8
+ const phpPath = "php"; // Adjust if necessary to include the full path to PHP
9
+ const serverScriptPath = path.join(__dirname, "..", "src", "Lib", "Websocket", "server.php");
10
+ // Hold the server process
11
+ let serverProcess = null;
12
+ const restartServer = () => {
13
+ // If a server process already exists, kill it
14
+ if (serverProcess) {
15
+ console.log("Stopping WebSocket server...");
16
+ serverProcess.kill("SIGINT"); // Adjust the signal as necessary for your environment
17
+ serverProcess = null;
18
+ }
19
+ // Start a new WebSocket server process
20
+ console.log("Starting WebSocket server...");
21
+ serverProcess = spawn(phpPath, [serverScriptPath]);
22
+ serverProcess.stdout?.on("data", (data) => {
23
+ console.log(`WebSocket Server: ${data.toString()}`);
24
+ });
25
+ serverProcess.stderr?.on("data", (data) => {
26
+ console.error(`WebSocket Server Error: ${data.toString()}`);
27
+ });
28
+ serverProcess.on("close", (code) => {
29
+ console.log(`WebSocket server process exited with code ${code}`);
30
+ });
31
+ };
32
+ // Initial start
33
+ restartServer();
34
+ // Watch for changes and restart the server
35
+ chokidar
36
+ .watch(path.join(__dirname, "..", "src", "Lib", "Websocket", "**", "*"))
37
+ .on("change", (path) => {
38
+ console.log(`File changed: ${path}`);
39
+ restartServer();
40
+ });
@@ -0,0 +1,75 @@
1
+ import swaggerJsdoc from "swagger-jsdoc";
2
+ import { writeFileSync, readFileSync, existsSync } from "fs";
3
+ import { fileURLToPath } from "url";
4
+ import { join, dirname } from "path";
5
+ import chalk from "chalk";
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = dirname(__filename);
8
+ // Define the output path for the swagger.json file
9
+ const outputPath = join(__dirname, "../src/app/swagger-docs/apis/pphp-swagger.json");
10
+ const bsConnectionInfo = join(__dirname, "bs-config.json");
11
+ // Default connection info
12
+ const defaultConnectionInfo = {
13
+ local: "http://localhost:3000",
14
+ external: "http://192.168.1.5:3000",
15
+ ui: "http://localhost:3001",
16
+ uiExternal: "http://192.168.1.5:3001",
17
+ };
18
+ let jsonData = defaultConnectionInfo;
19
+ if (existsSync(bsConnectionInfo)) {
20
+ try {
21
+ const data = readFileSync(bsConnectionInfo, "utf8");
22
+ jsonData = JSON.parse(data);
23
+ }
24
+ catch (error) {
25
+ console.error("Error parsing bs-output.json:", error);
26
+ }
27
+ }
28
+ else {
29
+ console.warn("bs-output.json not found, using default connection info.");
30
+ }
31
+ const options = {
32
+ definition: {
33
+ openapi: "3.0.0",
34
+ info: {
35
+ title: "Prisma PHP API Documentation",
36
+ version: "1.0.0",
37
+ description: "API documentation for the Prisma PHP project",
38
+ },
39
+ servers: [
40
+ {
41
+ url: jsonData.local, // For Development
42
+ description: "Development Server",
43
+ },
44
+ {
45
+ url: "your-production-domain", // For Production
46
+ description: "Production Server",
47
+ },
48
+ ],
49
+ components: {
50
+ securitySchemes: {
51
+ bearerAuth: {
52
+ type: "http",
53
+ scheme: "bearer",
54
+ bearerFormat: "JWT",
55
+ },
56
+ },
57
+ },
58
+ security: [
59
+ {
60
+ bearerAuth: [],
61
+ },
62
+ ],
63
+ },
64
+ apis: [join(__dirname, "../src/app/swagger-docs/apis/**/*.ts")], // Adjust to match TypeScript file paths
65
+ };
66
+ // Generate the Swagger specification
67
+ const swaggerSpec = JSON.stringify(swaggerJsdoc(options), null, 2);
68
+ // Always generate the swagger.json file
69
+ try {
70
+ writeFileSync(outputPath, swaggerSpec, "utf-8");
71
+ console.log(`Swagger JSON has been generated and saved to ${chalk.blue("src/app/swagger-docs/pphp-swagger.json")}`);
72
+ }
73
+ catch (error) {
74
+ console.error("Error saving Swagger JSON:", error);
75
+ }
@@ -106,6 +106,6 @@
106
106
  // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
107
107
  "skipLibCheck": true /* Skip type checking all .d.ts files. */
108
108
  },
109
- "include": ["src/**/*.ts", "settings/**/*.ts"],
109
+ "include": ["**/*.ts"],
110
110
  "exclude": ["node_modules", "vendor"]
111
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "1.22.506",
3
+ "version": "1.22.508",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -1,9 +0,0 @@
1
- module.exports = {
2
- proxy: "http://localhost",
3
- serveStatic: ["src/app"],
4
- files: "src/**/*.*",
5
- notify: false,
6
- open: false,
7
- ghostMode: false,
8
- codeSync: true, // Disable synchronization of code changes across clients
9
- };
@@ -1,61 +0,0 @@
1
- import { readdirSync, statSync, existsSync, writeFileSync } from "fs";
2
- import path, { dirname } from "path";
3
- import { fileURLToPath } from "url";
4
-
5
- // Define __dirname equivalent in ES modules
6
- const __filename = fileURLToPath(import.meta.url);
7
- const __dirname = dirname(__filename);
8
-
9
- const dirPath = path.join(__dirname, "..", "src", "app");
10
- const jsonFilePath = path.join(__dirname, "files-list.json");
11
-
12
- // Function to get all files in the directory
13
- const getAllFiles = (dirPath) => {
14
- const files = [];
15
-
16
- // Check if directory exists before reading
17
- if (!existsSync(dirPath)) {
18
- console.error(`Directory not found: ${dirPath}`);
19
- return files; // Return an empty array if the directory doesn't exist
20
- }
21
-
22
- const items = readdirSync(dirPath);
23
- items.forEach((item) => {
24
- const fullPath = path.join(dirPath, item);
25
- if (statSync(fullPath).isDirectory()) {
26
- files.push(...getAllFiles(fullPath)); // Recursive call for subdirectories
27
- } else {
28
- // Generate the relative path and ensure it starts with ./src
29
- const relativePath = `.${path.sep}${path.relative(
30
- path.join(__dirname, ".."),
31
- fullPath
32
- )}`;
33
- // Replace only the root backslashes with forward slashes and leave inner ones
34
- files.push(relativePath.replace(/\\/g, "\\").replace(/^\.\.\//, ""));
35
- }
36
- });
37
-
38
- return files;
39
- };
40
-
41
- // Function to generate the files-list.json
42
- const generateFileListJson = () => {
43
- const files = getAllFiles(dirPath);
44
-
45
- // If files exist, generate JSON file
46
- if (files.length > 0) {
47
- writeFileSync(jsonFilePath, JSON.stringify(files, null, 2));
48
- console.log(
49
- `File list has been saved to: settings/files-list.json`
50
- );
51
- } else {
52
- console.error("No files found to save in the JSON file.");
53
- }
54
- };
55
-
56
- // Main function
57
- async function processDirectory() {
58
- generateFileListJson();
59
- }
60
-
61
- processDirectory();
@@ -1,83 +0,0 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
-
4
- // Path to your JSON configuration file
5
- const configFilePath = path.join(__dirname, "..", "prisma-php.json");
6
-
7
- // Use the parent directory name as the new project name
8
- const newProjectName = path.basename(path.join(__dirname, ".."));
9
-
10
- // Function to update the project name and paths in the JSON config
11
- function updateProjectNameInConfig(filePath, newProjectName) {
12
- const filePathDir = path.dirname(filePath);
13
- fs.readFile(filePath, "utf8", (err, data) => {
14
- if (err) {
15
- console.error("Error reading the JSON file:", err);
16
- return;
17
- }
18
-
19
- let config = JSON.parse(data);
20
-
21
- // Update the projectName
22
- config.projectName = newProjectName;
23
-
24
- // Update other paths
25
- config.projectRootPath = filePathDir;
26
-
27
- const targetPath = getTargetPath(filePathDir, config.phpEnvironment);
28
-
29
- config.bsTarget = `http://localhost${targetPath}`;
30
- config.bsPathRewrite["^/"] = targetPath;
31
-
32
- // Save the updated config back to the JSON file
33
- fs.writeFile(filePath, JSON.stringify(config, null, 2), "utf8", (err) => {
34
- if (err) {
35
- console.error("Error writing the updated JSON file:", err);
36
- return;
37
- }
38
- console.log(
39
- "The project name, PHP path, and other paths have been updated successfully."
40
- );
41
- });
42
- });
43
- }
44
-
45
- // Function to determine the target path for browser-sync
46
- function getTargetPath(fullPath, environment) {
47
- const normalizedPath = path.normalize(fullPath);
48
- const webDirectories = {
49
- XAMPP: path.join("htdocs"),
50
- WAMP: path.join("www"),
51
- MAMP: path.join("htdocs"),
52
- LAMP: path.join("var", "www", "html"),
53
- LEMP: path.join("usr", "share", "nginx", "html"),
54
- AMPPS: path.join("www"),
55
- UniformServer: path.join("www"),
56
- EasyPHP: path.join("data", "localweb"),
57
- };
58
-
59
- const webDir = webDirectories[environment.toUpperCase()];
60
- if (!webDir) {
61
- throw new Error(`Unsupported environment: ${environment}`);
62
- }
63
-
64
- const indexOfWebDir = normalizedPath
65
- .toLowerCase()
66
- .indexOf(path.normalize(webDir).toLowerCase());
67
- if (indexOfWebDir === -1) {
68
- throw new Error(`Web directory not found in path: ${webDir}`);
69
- }
70
-
71
- const startIndex = indexOfWebDir + webDir.length;
72
- const subPath = normalizedPath.slice(startIndex);
73
- const safeSeparatorRegex = new RegExp(
74
- path.sep.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&"),
75
- "g"
76
- );
77
- const finalPath = subPath.replace(safeSeparatorRegex, "/") + "/";
78
-
79
- return finalPath;
80
- }
81
-
82
- // Run the function with your config file path and the new project name
83
- updateProjectNameInConfig(configFilePath, newProjectName);
@@ -1,53 +0,0 @@
1
- const { spawn } = require("child_process");
2
- const path = require("path");
3
-
4
- // Define paths
5
- const phpPath = "php"; // Adjust if necessary to include the full path to PHP
6
- const serverScriptPath = path.join(
7
- __dirname,
8
- "..",
9
- "src",
10
- "Lib",
11
- "Websocket",
12
- "server.php"
13
- );
14
-
15
- // Hold the server process
16
- let serverProcess = null;
17
-
18
- const restartServer = () => {
19
- // If a server process already exists, kill it
20
- if (serverProcess) {
21
- console.log("Stopping WebSocket server...");
22
- serverProcess.kill("SIGINT"); // Adjust the signal as necessary for your environment
23
- serverProcess = null;
24
- }
25
-
26
- // Start a new WebSocket server process
27
- console.log("Starting WebSocket server...");
28
- serverProcess = spawn(phpPath, [serverScriptPath]);
29
-
30
- serverProcess.stdout.on("data", (data) => {
31
- console.log(`WebSocket Server: ${data}`);
32
- });
33
-
34
- serverProcess.stderr.on("data", (data) => {
35
- console.error(`WebSocket Server Error: ${data}`);
36
- });
37
-
38
- serverProcess.on("close", (code) => {
39
- console.log(`WebSocket server process exited with code ${code}`);
40
- });
41
- };
42
-
43
- // Initial start
44
- restartServer();
45
-
46
- // Watch for changes and restart the server
47
- const chokidar = require("chokidar");
48
- chokidar
49
- .watch(path.join(__dirname, "..", "src", "Lib", "Websocket", "**", "*"))
50
- .on("change", (event, path) => {
51
- console.log(`${event}: ${path}`);
52
- restartServer();
53
- });