create-prisma-php-app 1.2.2 → 1.2.3
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.
- package/README.md +16 -10
- package/dist/index.js +1 -1
- package/dist/settings/bs-config.cjs +1 -0
- package/dist/src/app/api/api.php +3 -3
- package/dist/src/app/layout.php +49 -34
- package/dist/src/app/not-found.php +11 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -147,20 +147,20 @@ PrismaPHPProject
|
|
|
147
147
|
│ ├── schema.prisma # Main Prisma schema file
|
|
148
148
|
│ └── seed.js # Database seeding script
|
|
149
149
|
├── public # Publicly accessible files
|
|
150
|
-
│
|
|
151
|
-
│ ├── css # CSS files
|
|
152
|
-
│ ├── js # JavaScript files
|
|
153
|
-
│ └── assets # Static assets like images, fonts
|
|
150
|
+
│ └── [...]
|
|
154
151
|
├── src # Source code
|
|
155
|
-
│ ├──
|
|
156
|
-
│ │ ├──
|
|
157
|
-
│ │ ├──
|
|
158
|
-
│ │ ├──
|
|
159
|
-
│ │ ├──
|
|
160
|
-
│ │
|
|
152
|
+
│ ├── app # Core application code
|
|
153
|
+
│ │ ├── api # API endpoints and logic
|
|
154
|
+
│ │ ├── assets # Static assets (images, fonts, etc.)
|
|
155
|
+
│ │ ├── css # CSS stylesheets
|
|
156
|
+
│ │ ├── favicon # Favicon files
|
|
157
|
+
│ │ ├── index.php # Main application entry point
|
|
158
|
+
│ │ ├── layout.php # Main application layout
|
|
159
|
+
│ │ └── [...] # Other application files (/users, /dashboard, etc.)
|
|
161
160
|
│ ├── Lib # Utility functions and libraries
|
|
162
161
|
│ └── [...]
|
|
163
162
|
├── settings # Configuration files
|
|
163
|
+
│ ├── bs-config.cjs # BrowserSync configuration
|
|
164
164
|
│ ├── paths.php # Path settings
|
|
165
165
|
│ └── project-settings.js # Project settings
|
|
166
166
|
├── vendor # Composer dependencies
|
|
@@ -192,6 +192,12 @@ For a better development experience, consider installing the following Visual St
|
|
|
192
192
|
- [PHP Debug](https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug)
|
|
193
193
|
- [Tailwind CSS IntelliSense](https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss)
|
|
194
194
|
|
|
195
|
+
## Video Tutorial
|
|
196
|
+
|
|
197
|
+
For a step-by-step guide on how to use `create-prisma-php-app`, watch the following video:
|
|
198
|
+
|
|
199
|
+
[Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM](https://www.youtube.com/playlist?list=PLS-62wu4j8sS0Ia7ZkWHQ41W85Ice85PA)
|
|
200
|
+
|
|
195
201
|
## Contributing
|
|
196
202
|
|
|
197
203
|
Contributions to `create-prisma-php-app` are welcome. If you have any suggestions, bug reports, or pull requests, feel free to open an issue or submit a pull request on the repository.
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{execSync}from"child_process";import fs from"fs";import{fileURLToPath}from"url";import path from"path";import chalk from"chalk";import prompts from"prompts";const __filename=fileURLToPath(import.meta.url),__dirname=path.dirname(__filename);function configureBrowserSyncCommand(
|
|
2
|
+
import{execSync}from"child_process";import fs from"fs";import{fileURLToPath}from"url";import path from"path";import chalk from"chalk";import prompts from"prompts";const __filename=fileURLToPath(import.meta.url),__dirname=path.dirname(__filename);function configureBrowserSyncCommand(e,t){const s=t.PROJECT_ROOT_PATH.indexOf("\\htdocs\\");if(-1===s)return"";const i=t.PROJECT_ROOT_PATH.substring(0,s+"\\htdocs\\".length).replace(/\\/g,"\\\\");let n=`http://localhost/${t.PROJECT_ROOT_PATH.replace(new RegExp(`^${i}`),"").replace(/\\/g,"/")}`;n=n.endsWith("/")?n.slice(0,-1):n;const c=n.replace(/(?<!:)(\/\/+)/g,"/"),r=c.replace("http://localhost",""),a=`\n const { createProxyMiddleware } = require("http-proxy-middleware");\n\n module.exports = {\n // Use the 'middleware' option to create a proxy that masks the deep URL.\n middleware: [\n // This middleware intercepts requests to the root and proxies them to the deep path.\n createProxyMiddleware("/", {\n target:\n "${c}",\n changeOrigin: true,\n pathRewrite: {\n "^/": "${r}", // Rewrite the path.\n },\n }),\n ],\n proxy: "http://localhost:3000", // Proxy the BrowserSync server.\n serveStatic: ["src/app"], // Serve static files from this directory.\n notify: false,\n };`,o=path.join(e,"settings","bs-config.cjs");return fs.writeFileSync(o,a,"utf8"),"browser-sync start --config settings/bs-config.cjs"}async function updatePackageJson(e,t,s){const i=path.join(e,"package.json"),n=JSON.parse(fs.readFileSync(i,"utf8")),c=configureBrowserSyncCommand(e,t);n.scripts=Object.assign(Object.assign({},n.scripts),{postinstall:"prisma generate"}),s.tailwindcss?n.scripts=Object.assign(Object.assign({},n.scripts),{tailwind:"tailwindcss -i ./src/app/css/tailwind.css -o ./src/app/css/styles.css --minify --watch","browser-sync":c,dev:"npm-run-all --parallel browser-sync tailwind"}):n.scripts=Object.assign(Object.assign({},n.scripts),{dev:c}),n.type="module",n.prisma={seed:"node prisma/seed.js"},fs.writeFileSync(i,JSON.stringify(n,null,2))}async function createUpdateGitignoreFile(e,t){const s=path.join(e,".gitignore");let i="";fs.existsSync(s)&&(i=fs.readFileSync(s,"utf8")),t.forEach((e=>{i.includes(e)||(i+=`\n${e}`)})),i=i.trimStart(),fs.writeFileSync(s,i)}function copyRecursiveSync(e,t){const s=fs.existsSync(e),i=s&&fs.statSync(e);s&&i&&i.isDirectory()?(fs.mkdirSync(t,{recursive:!0}),fs.readdirSync(e).forEach((s=>copyRecursiveSync(path.join(e,s),path.join(t,s))))):fs.copyFileSync(e,t)}async function executeCopy(e,t){t.forEach((({srcDir:t,destDir:s})=>{copyRecursiveSync(path.join(__dirname,t),path.join(e,s))}))}function modifyTailwindConfig(e){const t=path.join(e,"tailwind.config.js");let s=fs.readFileSync(t,"utf8");const i=["./src/app/**/*.{php,html,js}"].map((e=>` "${e}"`)).join(",\n");s=s.replace(/content: \[\],/g,`content: [\n${i}\n],`),fs.writeFileSync(t,s,"utf8")}function modifyIndexPHP(e,t){const s=path.join(e,"src","app","layout.php");try{let i=fs.readFileSync(s,"utf8");const n=t?' <link href="<?php echo $baseUrl; ?>css/styles.css" rel="stylesheet">':' <script src="https://cdn.tailwindcss.com"><\/script>';if(i=i.replace("</head>",`${n}\n</head>`),fs.writeFileSync(s,i,"utf8"),!t){const t=path.join(e,"src","app","css");fs.rm(t,{recursive:!0},(e=>{if(e)throw e}))}}catch(e){}}async function createDirectoryStructure(e,t,s){await executeCopy(e,[{srcDir:"/settings",destDir:"/settings"},{srcDir:"/prisma",destDir:"/prisma"},{srcDir:"/public",destDir:"/public"},{srcDir:"/src",destDir:"/src"},{srcDir:"/../vendor",destDir:"/vendor"}]),await updatePackageJson(e,s,t),[{src:"/bootstrap.php",dest:"/bootstrap.php"},{src:"/.htaccess",dest:"/.htaccess"},{src:"/../composer.json",dest:"/composer.json"},{src:"/../composer.lock",dest:"/composer.lock"}].forEach((({src:t,dest:s})=>{const i=path.join(__dirname,t),n=path.join(e,s),c=fs.readFileSync(i,"utf8");fs.writeFileSync(n,c)})),t.tailwindcss?(modifyTailwindConfig(e),modifyIndexPHP(e,!0)):modifyIndexPHP(e,!1)}async function getAnswer(){const e=[{type:"text",name:"projectName",message:"What is your project named?",initial:"my-app"},{type:"toggle",name:"tailwindcss",message:`Would you like to use ${chalk.blue("Tailwind CSS")}?`,initial:!0,active:"Yes",inactive:"No"}],t=()=>!1;try{const s=await prompts(e,{onCancel:t});return 0===Object.keys(s).length?null:{projectName:String(s.projectName).trim().replace(/ /g,"-"),tailwindcss:s.tailwindcss}}catch(e){return null}}async function installDependencies(e,t,s=!1){execSync("npm init -y",{stdio:"inherit",cwd:e}),t.forEach((e=>{}));const i=`npm install ${s?"--save-dev":""} ${t.join(" ")}`;execSync(i,{stdio:"inherit",cwd:e})}async function main(){try{const e=await getAnswer();if(null===e)return;execSync("npm install -g create-prisma-php-app",{stdio:"inherit"}),execSync("npm install -g browser-sync",{stdio:"inherit"}),fs.mkdirSync(e.projectName);const t=path.join(process.cwd(),e.projectName);process.chdir(e.projectName);const s=["prisma","@prisma/client","typescript","@types/node","ts-node","http-proxy-middleware"];e.tailwindcss&&s.push("npm-run-all","tailwindcss","autoprefixer","postcss"),await installDependencies(t,s,!0),execSync("npx prisma init",{stdio:"inherit"}),execSync("npx tsc --init",{stdio:"inherit"}),e.tailwindcss&&execSync("npx tailwindcss init -p",{stdio:"inherit"});const i={PROJECT_NAME:e.projectName,PROJECT_ROOT_PATH:t.replace(/\\/g,"\\\\"),PHP_ROOT_PATH_EXE:"D:\\\\xampp\\\\php\\\\php.exe",PHP_GENERATE_CLASS_PATH:"src/lib/prisma/classes"};await createDirectoryStructure(t,e,i),e.tailwindcss&&execSync("npx tailwindcss -i ./src/app/css/tailwind.css -o ./src/app/css/styles.css --minify",{stdio:"inherit"});const n=path.join(t,"settings","project-settings.js"),c=`export const projectSettings = {\n PROJECT_NAME: "${e.projectName}",\n PROJECT_ROOT_PATH: "${t.replace(/\\/g,"\\\\")}",\n PHP_ROOT_PATH_EXE: "D:\\\\xampp\\\\php\\\\php.exe",\n PHP_GENERATE_CLASS_PATH: "src/lib/prisma/classes",\n };`;fs.writeFileSync(n,c)}catch(e){process.exit(1)}}main();
|
package/dist/src/app/api/api.php
CHANGED
|
@@ -17,7 +17,7 @@ if (empty($_SERVER["HTTP_X_REQUESTED_WITH"]) || $_SERVER["HTTP_X_REQUESTED_WITH"
|
|
|
17
17
|
// Retrieve class name, method name, and params from POST data
|
|
18
18
|
$className = $_POST["className"] ?? "";
|
|
19
19
|
$methodName = $_POST["methodName"] ?? "";
|
|
20
|
-
$paramsJson = $_POST["params"] ??
|
|
20
|
+
$paramsJson = $_POST["params"] ?? "";
|
|
21
21
|
|
|
22
22
|
$params = null; // Initialize params as null
|
|
23
23
|
|
|
@@ -48,7 +48,7 @@ if (!method_exists($instance, $methodName)) {
|
|
|
48
48
|
|
|
49
49
|
try {
|
|
50
50
|
// Call the method with params if they are provided and decoded; otherwise, call without params
|
|
51
|
-
$result = $params !== null ?
|
|
51
|
+
$result = $params !== null ? callUserMethodWithParams($instance, $methodName, $params) : $instance->$methodName();
|
|
52
52
|
// Encode and return the result as JSON
|
|
53
53
|
echo json_encode(['result' => $result instanceof \stdClass ? (array)$result : $result]);
|
|
54
54
|
} catch (\ArgumentCountError | \Exception $e) {
|
|
@@ -56,7 +56,7 @@ try {
|
|
|
56
56
|
echo json_encode(['error' => "Error: " . $e->getMessage()]);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
function
|
|
59
|
+
function callUserMethodWithParams($instance, $methodName, $params)
|
|
60
60
|
{
|
|
61
61
|
// Determine how to call the method based on the presence of specific keys in $params
|
|
62
62
|
if (isset($params['identifier'], $params['data'])) {
|
package/dist/src/app/layout.php
CHANGED
|
@@ -1,8 +1,47 @@
|
|
|
1
1
|
<?php
|
|
2
|
-
|
|
2
|
+
// Require necessary files and initiate any PHP logic before outputting HTML.
|
|
3
3
|
require_once "../../bootstrap.php";
|
|
4
|
-
includeIndexFileFromUri();
|
|
5
4
|
|
|
5
|
+
// Define the function at the top.
|
|
6
|
+
function determineContentToInclude()
|
|
7
|
+
{
|
|
8
|
+
$subject = $_SERVER["SCRIPT_NAME"];
|
|
9
|
+
preg_match("/^(.*)\/src\/app\//", $subject, $matches);
|
|
10
|
+
|
|
11
|
+
// Normalize the request URI by removing the query string.
|
|
12
|
+
$requestUri = explode('?', $_SERVER['REQUEST_URI'], 2)[0];
|
|
13
|
+
$requestUri = rtrim($requestUri, '/'); // Remove trailing slash if any.
|
|
14
|
+
// Replace the base part of the URI.
|
|
15
|
+
$requestUri = str_replace($matches[1], '', $requestUri);
|
|
16
|
+
$uri = trim($requestUri, '/');
|
|
17
|
+
$baseDir = __DIR__;
|
|
18
|
+
$includePath = ''; // Initialize with empty string.
|
|
19
|
+
|
|
20
|
+
if ($uri) {
|
|
21
|
+
$path = $baseDir . '/' . $uri . '.php'; // Attempt to resolve to a specific PHP file.
|
|
22
|
+
if (file_exists($path)) {
|
|
23
|
+
$includePath = $path;
|
|
24
|
+
} else {
|
|
25
|
+
$path = $baseDir . '/' . $uri . '/index.php'; // Fallback to index.php in the directory.
|
|
26
|
+
if (file_exists($path)) {
|
|
27
|
+
$includePath = $path;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
// Default route handling, e.g., when the URI is empty.
|
|
32
|
+
$includePath = $baseDir . '/index.php';
|
|
33
|
+
}
|
|
34
|
+
return $includePath;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Dynamically calculate the base URL
|
|
38
|
+
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
|
|
39
|
+
$domainName = $_SERVER['HTTP_HOST'];
|
|
40
|
+
$scriptPath = dirname($_SERVER['SCRIPT_NAME']);
|
|
41
|
+
$baseUrl = $protocol . $domainName . rtrim($scriptPath, '/') . '/';
|
|
42
|
+
|
|
43
|
+
// Determine which content to include based on the current URI.
|
|
44
|
+
$contentToInclude = determineContentToInclude();
|
|
6
45
|
?>
|
|
7
46
|
|
|
8
47
|
<!DOCTYPE html>
|
|
@@ -13,44 +52,20 @@ includeIndexFileFromUri();
|
|
|
13
52
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
14
53
|
<meta name="description" content="Generated by create Prisma PHP App">
|
|
15
54
|
<title>Create Prisma PHP App</title>
|
|
16
|
-
<link rel="shortcut icon" href="
|
|
55
|
+
<link rel="shortcut icon" href="<?php echo $baseUrl; ?>favicon.ico" type="image/x-icon">
|
|
17
56
|
</head>
|
|
18
57
|
|
|
19
58
|
<body>
|
|
20
59
|
<?php
|
|
21
|
-
|
|
22
|
-
{
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
// Replace the base part of the URI
|
|
28
|
-
$requestUri = str_replace($matches[1], '', $requestUri);
|
|
29
|
-
$uri = trim($requestUri, '/');
|
|
30
|
-
$baseDir = __DIR__;
|
|
31
|
-
// Check if the request is for a specific file or directory
|
|
32
|
-
if ($uri) {
|
|
33
|
-
// Inside includeIndexFileFromUri function
|
|
34
|
-
$path = $baseDir . '/' . $uri . '.php'; // Resolve to a specific PHP file
|
|
35
|
-
if (file_exists($path)) {
|
|
36
|
-
error_log("Including path: " . $path); // Add logging
|
|
37
|
-
require_once $path;
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
$path = $baseDir . '/' . $uri . '/index.php'; // Fallback to index.php in the directory
|
|
41
|
-
if (file_exists($path)) {
|
|
42
|
-
require_once $path;
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
} else {
|
|
46
|
-
// Default route handling, e.g., when the URI is empty
|
|
47
|
-
require_once $baseDir . '/index.php';
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
// If none of the above, show 404 Not Found
|
|
51
|
-
echo "404 Not Found or redirect to a default page.";
|
|
60
|
+
// Include the determined content within the body.
|
|
61
|
+
if (!empty($contentToInclude)) {
|
|
62
|
+
require_once $contentToInclude;
|
|
63
|
+
} else {
|
|
64
|
+
// If no content is determined, show a 404 message or redirect.
|
|
65
|
+
require_once "not-found.php";
|
|
52
66
|
}
|
|
53
67
|
?>
|
|
68
|
+
<!-- Additional HTML content can go here. -->
|
|
54
69
|
</body>
|
|
55
70
|
|
|
56
71
|
</html>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<div class="flex flex-col min-h-[100vh] items-center justify-center space-y-4 text-center">
|
|
2
|
+
<div class="space-y-2">
|
|
3
|
+
<h1 class="text-4xl font-bold tracking-tighter sm:text-5xl md:text-6xl">404 Not Found</h1>
|
|
4
|
+
<p class="max-w-[600px] text-gray-500 md:text-xl/relaxed lg:text-base/relaxed xl:text-xl/relaxed dark:text-gray-400">
|
|
5
|
+
Sorry, we couldn't find the page you're looking for.
|
|
6
|
+
</p>
|
|
7
|
+
</div>
|
|
8
|
+
<a class="inline-flex h-10 items-center justify-center rounded-md border border-gray-200 bg-white px-8 text-sm font-medium shadow-sm transition-colors hover:bg-gray-100 hover:text-gray-900 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-gray-950 disabled:pointer-events-none disabled:opacity-50 dark:border-gray-800 dark:bg-gray-950 dark:hover:bg-gray-800 dark:hover:text-gray-50 dark:focus-visible:ring-gray-300" href="#">
|
|
9
|
+
Go to Homepage
|
|
10
|
+
</a>
|
|
11
|
+
</div>
|