create-prisma-php-app 1.22.5 → 1.22.7
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/dist/bootstrap.php +3 -5
- package/dist/index.js +38 -4
- package/dist/settings/bs-config.js +44 -40
- package/dist/settings/files-list.js +34 -34
- package/dist/settings/project-name.js +56 -48
- package/dist/settings/request-methods.php +1 -1
- package/dist/settings/restart-websocket.js +34 -27
- package/dist/settings/swagger-config.js +52 -66
- package/dist/settings/utils.js +13 -0
- package/dist/tsconfig.json +5 -5
- package/package.json +1 -1
package/dist/bootstrap.php
CHANGED
|
@@ -37,7 +37,7 @@ function determineContentToInclude()
|
|
|
37
37
|
* ================================================
|
|
38
38
|
*/
|
|
39
39
|
|
|
40
|
-
$isDirectAccessToPrivateRoute = preg_match('
|
|
40
|
+
$isDirectAccessToPrivateRoute = preg_match('/_/', $uri);
|
|
41
41
|
if ($isDirectAccessToPrivateRoute) {
|
|
42
42
|
$sameSiteFetch = false;
|
|
43
43
|
$serverFetchSite = $_SERVER['HTTP_SEC_FETCH_SITE'] ?? '';
|
|
@@ -335,9 +335,7 @@ function singleDynamicRoute($uriSegments, $routeSegments)
|
|
|
335
335
|
|
|
336
336
|
function checkForDuplicateRoutes()
|
|
337
337
|
{
|
|
338
|
-
if ($_ENV['APP_ENV'] !== 'development')
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
338
|
+
if ($_ENV['APP_ENV'] !== 'development') return;
|
|
341
339
|
|
|
342
340
|
global $_filesListRoutes;
|
|
343
341
|
$normalizedRoutesMap = [];
|
|
@@ -760,7 +758,7 @@ try {
|
|
|
760
758
|
$_isContentIncluded = true;
|
|
761
759
|
}
|
|
762
760
|
|
|
763
|
-
if (!empty($_contentToInclude)) {
|
|
761
|
+
if (!empty($_contentToInclude) && !empty($_fileToInclude)) {
|
|
764
762
|
if (!$_isParentLayout) {
|
|
765
763
|
ob_start();
|
|
766
764
|
require_once $_contentToInclude;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
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";import https from"https";const __filename=fileURLToPath(import.meta.url),__dirname=path.dirname(__filename);let updateAnswer=null;const nonBackendFiles=["favicon.ico","\\src\\app\\index.php","metadata.php","not-found.php"],dockerFiles=[".dockerignore","docker-compose.yml","Dockerfile","apache.conf"];function bsConfigUrls(e){const s=e.indexOf("\\htdocs\\");if(-1===s)return{bsTarget:"",bsPathRewrite:{}};const t=e.substring(0,s+"\\htdocs\\".length).replace(/\\/g,"\\\\"),n=e.replace(new RegExp(`^${t}`),"").replace(/\\/g,"/");let i=`http://localhost/${n}`;i=i.endsWith("/")?i.slice(0,-1):i;const c=i.replace(/(?<!:)(\/\/+)/g,"/"),o=n.replace(/\/\/+/g,"/");return{bsTarget:`${c}/`,bsPathRewrite:{"^/":`/${o.startsWith("/")?o.substring(1):o}/`}}}async function updatePackageJson(e,s){const t=path.join(e,"package.json");if(checkExcludeFiles(t))return;const n=JSON.parse(fs.readFileSync(t,"utf8"));n.scripts=Object.assign(Object.assign({},n.scripts),{projectName:"node settings/project-name.js"});let i=[];s.tailwindcss&&(n.scripts=Object.assign(Object.assign({},n.scripts),{tailwind:"postcss src/app/css/tailwind.css -o src/app/css/styles.css --watch"}),i.push("tailwind")),s.websocket&&(n.scripts=Object.assign(Object.assign({},n.scripts),{websocket:"node settings/restart-websocket.js"}),i.push("websocket")),s.docker&&(n.scripts=Object.assign(Object.assign({},n.scripts),{docker:"docker-compose up"}),i.push("docker")),s.swaggerDocs&&(n.scripts=Object.assign(Object.assign({},n.scripts),{"create-swagger-docs":"node settings/swagger-config.js"}),i.push("create-swagger-docs"));let c=Object.assign({},n.scripts);c.browserSync="node settings/bs-config.js",c.dev=`npm-run-all -p projectName browserSync ${i.join(" ")}`,n.scripts=c,n.type="module",s.prisma&&(n.prisma={seed:"node prisma/seed.js"}),fs.writeFileSync(t,JSON.stringify(n,null,2))}async function updateComposerJson(e,s){const t=path.join(e,"composer.json");if(checkExcludeFiles(t))return;let n;if(fs.existsSync(t)){{const e=fs.readFileSync(t,"utf8");n=JSON.parse(e)}s.websocket&&(n.require=Object.assign(Object.assign({},n.require),{"cboden/ratchet":"^0.4.4"})),s.prisma&&(n.require=Object.assign(Object.assign({},n.require),{"ramsey/uuid":"5.x-dev","hidehalo/nanoid-php":"1.x-dev"})),fs.writeFileSync(t,JSON.stringify(n,null,2))}}async function updateIndexJsForWebSocket(e,s){if(!s.websocket)return;const t=path.join(e,"src","app","js","index.js");if(checkExcludeFiles(t))return;let n=fs.readFileSync(t,"utf8");n+='\n// WebSocket initialization\nconst ws = new WebSocket("ws://localhost:8080");\n',fs.writeFileSync(t,n,"utf8")}async function createUpdateGitignoreFile(e,s){const t=path.join(e,".gitignore");if(checkExcludeFiles(t))return;let n="";s.forEach((e=>{n.includes(e)||(n+=`\n${e}`)})),n=n.trimStart(),fs.writeFileSync(t,n)}function copyRecursiveSync(e,s,t){var n;const i=fs.existsSync(e),c=i&&fs.statSync(e);if(i&&c&&c.isDirectory()){const i=s.toLowerCase();if(!t.websocket&&i.includes("src\\lib\\websocket"))return;if(!t.prisma&&i.includes("src\\lib\\prisma"))return;if(t.backendOnly&&i.includes("src\\app\\js")||t.backendOnly&&i.includes("src\\app\\css"))return;if(!t.swaggerDocs&&i.includes("src\\app\\swagger-docs"))return;const c=s.replace(/\\/g,"/");if(null===(n=null==updateAnswer?void 0:updateAnswer.excludeFilePath)||void 0===n?void 0:n.includes(c))return;fs.existsSync(s)||fs.mkdirSync(s,{recursive:!0}),fs.readdirSync(e).forEach((n=>{copyRecursiveSync(path.join(e,n),path.join(s,n),t)}))}else{if(checkExcludeFiles(s))return;if(!t.tailwindcss&&(s.includes("tailwind.css")||s.includes("styles.css")))return;if(!t.websocket&&(s.includes("restart-websocket.cjs")||s.includes("restart-websocket.bat")))return;if(!t.docker&&dockerFiles.some((e=>s.includes(e))))return;if(t.backendOnly&&nonBackendFiles.some((e=>s.includes(e))))return;if(!t.backendOnly&&s.includes("route.php"))return;if(!t.swaggerDocs&&s.includes("swagger-config.js"))return;fs.copyFileSync(e,s,0)}}async function executeCopy(e,s,t){s.forEach((({src:s,dest:n})=>{copyRecursiveSync(path.join(__dirname,s),path.join(e,n),t)}))}function createOrUpdateTailwindConfig(e){const s=path.join(e,"tailwind.config.js");if(checkExcludeFiles(s))return;let t=fs.readFileSync(s,"utf8");const n=["./src/**/*.{html,js,php}"].map((e=>` "${e}"`)).join(",\n");t=t.replace(/content: \[\],/g,`content: [\n${n}\n],`),fs.writeFileSync(s,t,{flag:"w"})}function modifyPostcssConfig(e){const s=path.join(e,"postcss.config.js");if(checkExcludeFiles(s))return;fs.writeFileSync(s,"export default {\n plugins: {\n tailwindcss: {},\n autoprefixer: {},\n cssnano: {},\n },\n};",{flag:"w"})}function modifyLayoutPHP(e,s){const t=path.join(e,"src","app","layout.php");if(!checkExcludeFiles(t))try{let e=fs.readFileSync(t,"utf8"),n="";s.backendOnly||(n='\n <link href="<?= $baseUrl; ?>/css/index.css" rel="stylesheet">\n <script src="<?= $baseUrl; ?>/js/index.js"><\/script>');let i="";s.backendOnly||(i=s.tailwindcss?` <link href="<?= $baseUrl; ?>/css/styles.css" rel="stylesheet"> ${n}`:` <script src="https://cdn.tailwindcss.com"><\/script> ${n}`);const c=i.length>0?"\n":"";e=e.replace("</head>",`${i}${c} \x3c!-- Dynamic Head --\x3e\n <?= implode("\\n", $mainLayoutHead); ?>\n</head>`),fs.writeFileSync(t,e,{flag:"w"})}catch(e){}}async function createOrUpdateEnvFile(e,s){const t=path.join(e,".env");checkExcludeFiles(t)||fs.writeFileSync(t,s,{flag:"w"})}function checkExcludeFiles(e){var s,t;return!!(null==updateAnswer?void 0:updateAnswer.isUpdate)&&(null!==(t=null===(s=null==updateAnswer?void 0:updateAnswer.excludeFilePath)||void 0===s?void 0:s.includes(e.replace(/\\/g,"/")))&&void 0!==t&&t)}async function createDirectoryStructure(e,s){const t=[{src:"/bootstrap.php",dest:"/bootstrap.php"},{src:"/.htaccess",dest:"/.htaccess"},{src:"/../composer.json",dest:"/composer.json"},{src:"/tsconfig.json",dest:"/tsconfig.json"}];s.tailwindcss&&t.push({src:"/postcss.config.js",dest:"/postcss.config.js"},{src:"/tailwind.config.js",dest:"/tailwind.config.js"});const n=[{src:"/settings",dest:"/settings"},{src:"/src",dest:"/src"}];s.backendOnly&&s.swaggerDocs&&n.push({src:"/swagger-docs-layout.php",dest:"/src/app/layout.php"}),s.prisma&&n.push({src:"/prisma",dest:"/prisma"}),s.docker&&n.push({src:"/.dockerignore",dest:"/.dockerignore"},{src:"/docker-compose.yml",dest:"/docker-compose.yml"},{src:"/Dockerfile",dest:"/Dockerfile"},{src:"/apache.conf",dest:"/apache.conf"}),t.forEach((({src:s,dest:t})=>{const n=path.join(__dirname,s),i=path.join(e,t);if(checkExcludeFiles(i))return;const c=fs.readFileSync(n,"utf8");fs.writeFileSync(i,c,{flag:"w"})})),await executeCopy(e,n,s),await updatePackageJson(e,s),await updateComposerJson(e,s),s.backendOnly||await updateIndexJsForWebSocket(e,s),s.tailwindcss&&(createOrUpdateTailwindConfig(e),modifyPostcssConfig(e)),(s.tailwindcss||!s.backendOnly||s.swaggerDocs)&&modifyLayoutPHP(e,s);const i='# Prisma PHP Auth Secret Key For development only - Change this in production\nAUTH_SECRET=uxsjXVPHN038DEYls2Kw0QUgBcXKUyrjv416nIFWPY4= \n \n# PHPMailer\n# SMTP_HOST=smtp.gmail.com or your SMTP host\n# SMTP_USERNAME=john.doe@gmail.com or your SMTP username\n# SMTP_PASSWORD=123456\n# SMTP_PORT=587 for TLS, 465 for SSL or your SMTP port\n# SMTP_ENCRYPTION=ssl or tls\n# MAIL_FROM=john.doe@gmail.com\n# MAIL_FROM_NAME="John Doe"\n\n# SHOW ERRORS - Set to true to show errors in the browser for development only - Change this in production to false\nSHOW_ERRORS=true\n\n# APP TIMEZONE - Set your application timezone - Default is "UTC"\nAPP_TIMEZONE="UTC"\n\n# APP ENV - Set your application environment - Default is "development" - Change this in production to "production"\nAPP_ENV=development';if(s.prisma){const s=`${'# Environment variables declared in this file are automatically made available to Prisma.\n# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema\n\n# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.\n# See the documentation for all the connection string options: https://pris.ly/d/connection-strings\n\nDATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"'}\n\n${i}`;await createOrUpdateEnvFile(e,s)}else await createOrUpdateEnvFile(e,i);await createUpdateGitignoreFile(e,["vendor",".env","node_modules"])}async function getAnswer(e={}){var s,t,n,i,c,o,a,r,l,p,d,u,g;const m=[];e.projectName||m.push({type:"text",name:"projectName",message:"What is your project named?",initial:"my-app"}),e.backendOnly||m.push({type:"toggle",name:"backendOnly",message:"Would you like to create a backend-only project?",initial:!1,active:"Yes",inactive:"No"});const f=()=>{process.exit(0)},h=await prompts(m,{onCancel:f}),y=[];h.backendOnly||e.backendOnly?(e.swaggerDocs||y.push({type:"toggle",name:"swaggerDocs",message:`Would you like to use ${chalk.blue("Swagger Docs")}?`,initial:!1,active:"Yes",inactive:"No"}),e.websocket||y.push({type:"toggle",name:"websocket",message:`Would you like to use ${chalk.blue("Websocket")}?`,initial:!0,active:"Yes",inactive:"No"}),e.prisma||y.push({type:"toggle",name:"prisma",message:`Would you like to use ${chalk.blue("Prisma PHP ORM")}?`,initial:!0,active:"Yes",inactive:"No"}),e.docker||y.push({type:"toggle",name:"docker",message:`Would you like to use ${chalk.blue("Docker")}?`,initial:!1,active:"Yes",inactive:"No"})):(e.swaggerDocs||y.push({type:"toggle",name:"swaggerDocs",message:`Would you like to use ${chalk.blue("Swagger Docs")}?`,initial:!1,active:"Yes",inactive:"No"}),e.tailwindcss||y.push({type:"toggle",name:"tailwindcss",message:`Would you like to use ${chalk.blue("Tailwind CSS")}?`,initial:!0,active:"Yes",inactive:"No"}),e.websocket||y.push({type:"toggle",name:"websocket",message:`Would you like to use ${chalk.blue("Websocket")}?`,initial:!0,active:"Yes",inactive:"No"}),e.prisma||y.push({type:"toggle",name:"prisma",message:`Would you like to use ${chalk.blue("Prisma PHP ORM")}?`,initial:!0,active:"Yes",inactive:"No"}),e.docker||y.push({type:"toggle",name:"docker",message:`Would you like to use ${chalk.blue("Docker")}?`,initial:!1,active:"Yes",inactive:"No"}));const w=await prompts(y,{onCancel:f});return{projectName:h.projectName?String(h.projectName).trim().replace(/ /g,"-"):null!==(s=e.projectName)&&void 0!==s?s:"my-app",backendOnly:null!==(n=null!==(t=h.backendOnly)&&void 0!==t?t:e.backendOnly)&&void 0!==n&&n,swaggerDocs:null!==(c=null!==(i=w.swaggerDocs)&&void 0!==i?i:e.swaggerDocs)&&void 0!==c&&c,tailwindcss:null!==(a=null!==(o=w.tailwindcss)&&void 0!==o?o:e.tailwindcss)&&void 0!==a&&a,websocket:null!==(l=null!==(r=w.websocket)&&void 0!==r?r:e.websocket)&&void 0!==l&&l,prisma:null!==(d=null!==(p=w.prisma)&&void 0!==p?p:e.prisma)&&void 0!==d&&d,docker:null!==(g=null!==(u=w.docker)&&void 0!==u?u:e.docker)&&void 0!==g&&g}}async function installDependencies(e,s,t=!1){fs.existsSync(path.join(e,"package.json"))||execSync("npm init -y",{stdio:"inherit",cwd:e}),s.forEach((e=>{}));const n=`npm install ${t?"--save-dev":""} ${s.join(" ")}`;execSync(n,{stdio:"inherit",cwd:e})}async function uninstallDependencies(e,s,t=!1){s.forEach((e=>{}));const n=`npm uninstall ${t?"--save-dev":"--save"} ${s.join(" ")}`;execSync(n,{stdio:"inherit",cwd:e})}function fetchPackageVersion(e){return new Promise(((s,t)=>{https.get(`https://registry.npmjs.org/${e}`,(e=>{let n="";e.on("data",(e=>n+=e)),e.on("end",(()=>{try{const e=JSON.parse(n);s(e["dist-tags"].latest)}catch(e){t(new Error("Failed to parse JSON response"))}}))})).on("error",(e=>t(e)))}))}const readJsonFile=e=>{const s=fs.readFileSync(e,"utf8");return JSON.parse(s)};function compareVersions(e,s){const t=e.split(".").map(Number),n=s.split(".").map(Number);for(let e=0;e<t.length;e++){if(t[e]>n[e])return 1;if(t[e]<n[e])return-1}return 0}function getInstalledPackageVersion(e){try{const s=execSync(`npm list -g ${e} --depth=0`).toString().match(new RegExp(`${e}@(\\d+\\.\\d+\\.\\d+)`));return s?s[1]:null}catch(e){return null}}
|
|
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";import https from"https";const __filename=fileURLToPath(import.meta.url),__dirname=path.dirname(__filename);let updateAnswer=null;const nonBackendFiles=["favicon.ico","\\src\\app\\index.php","metadata.php","not-found.php"],dockerFiles=[".dockerignore","docker-compose.yml","Dockerfile","apache.conf"];function bsConfigUrls(e){const s=e.indexOf("\\htdocs\\");if(-1===s)return{bsTarget:"",bsPathRewrite:{}};const t=e.substring(0,s+"\\htdocs\\".length).replace(/\\/g,"\\\\"),n=e.replace(new RegExp(`^${t}`),"").replace(/\\/g,"/");let i=`http://localhost/${n}`;i=i.endsWith("/")?i.slice(0,-1):i;const c=i.replace(/(?<!:)(\/\/+)/g,"/"),o=n.replace(/\/\/+/g,"/");return{bsTarget:`${c}/`,bsPathRewrite:{"^/":`/${o.startsWith("/")?o.substring(1):o}/`}}}async function updatePackageJson(e,s){const t=path.join(e,"package.json");if(checkExcludeFiles(t))return;const n=JSON.parse(fs.readFileSync(t,"utf8"));n.scripts=Object.assign(Object.assign({},n.scripts),{projectName:"node settings/project-name.js"});let i=[];s.tailwindcss&&(n.scripts=Object.assign(Object.assign({},n.scripts),{tailwind:"postcss src/app/css/tailwind.css -o src/app/css/styles.css --watch"}),i.push("tailwind")),s.websocket&&(n.scripts=Object.assign(Object.assign({},n.scripts),{websocket:"node settings/restart-websocket.js"}),i.push("websocket")),s.docker&&(n.scripts=Object.assign(Object.assign({},n.scripts),{docker:"docker-compose up"}),i.push("docker")),s.swaggerDocs&&(n.scripts=Object.assign(Object.assign({},n.scripts),{"create-swagger-docs":"node settings/swagger-config.js"}),i.push("create-swagger-docs"));let c=Object.assign({},n.scripts);c.browserSync="node settings/bs-config.js",c.dev=`npm-run-all -p projectName browserSync ${i.join(" ")}`,n.scripts=c,n.type="module",s.prisma&&(n.prisma={seed:"node prisma/seed.js"}),fs.writeFileSync(t,JSON.stringify(n,null,2))}async function updateComposerJson(e,s){const t=path.join(e,"composer.json");if(checkExcludeFiles(t))return;let n;if(fs.existsSync(t)){{const e=fs.readFileSync(t,"utf8");n=JSON.parse(e)}s.websocket&&(n.require=Object.assign(Object.assign({},n.require),{"cboden/ratchet":"^0.4.4"})),s.prisma&&(n.require=Object.assign(Object.assign({},n.require),{"ramsey/uuid":"5.x-dev","hidehalo/nanoid-php":"1.x-dev"})),fs.writeFileSync(t,JSON.stringify(n,null,2))}}async function updateIndexJsForWebSocket(e,s){if(!s.websocket)return;const t=path.join(e,"src","app","js","index.js");if(checkExcludeFiles(t))return;let n=fs.readFileSync(t,"utf8");n+='\n// WebSocket initialization\nconst ws = new WebSocket("ws://localhost:8080");\n',fs.writeFileSync(t,n,"utf8")}async function createUpdateGitignoreFile(e,s){const t=path.join(e,".gitignore");if(checkExcludeFiles(t))return;let n="";s.forEach((e=>{n.includes(e)||(n+=`\n${e}`)})),n=n.trimStart(),fs.writeFileSync(t,n)}function copyRecursiveSync(e,s,t){var n;const i=fs.existsSync(e),c=i&&fs.statSync(e);if(i&&c&&c.isDirectory()){const i=s.toLowerCase();if(!t.websocket&&i.includes("src\\lib\\websocket"))return;if(!t.prisma&&i.includes("src\\lib\\prisma"))return;if(t.backendOnly&&i.includes("src\\app\\js")||t.backendOnly&&i.includes("src\\app\\css"))return;if(!t.swaggerDocs&&i.includes("src\\app\\swagger-docs"))return;const c=s.replace(/\\/g,"/");if(null===(n=null==updateAnswer?void 0:updateAnswer.excludeFilePath)||void 0===n?void 0:n.includes(c))return;fs.existsSync(s)||fs.mkdirSync(s,{recursive:!0}),fs.readdirSync(e).forEach((n=>{copyRecursiveSync(path.join(e,n),path.join(s,n),t)}))}else{if(checkExcludeFiles(s))return;if(!t.tailwindcss&&(s.includes("tailwind.css")||s.includes("styles.css")))return;if(!t.websocket&&(s.includes("restart-websocket.js")||s.includes("restart-websocket.bat")))return;if(!t.docker&&dockerFiles.some((e=>s.includes(e))))return;if(t.backendOnly&&nonBackendFiles.some((e=>s.includes(e))))return;if(!t.backendOnly&&s.includes("route.php"))return;if(!t.swaggerDocs&&s.includes("swagger-config.js"))return;fs.copyFileSync(e,s,0)}}async function executeCopy(e,s,t){s.forEach((({src:s,dest:n})=>{copyRecursiveSync(path.join(__dirname,s),path.join(e,n),t)}))}function createOrUpdateTailwindConfig(e){const s=path.join(e,"tailwind.config.js");if(checkExcludeFiles(s))return;let t=fs.readFileSync(s,"utf8");const n=["./src/**/*.{html,js,php}"].map((e=>` "${e}"`)).join(",\n");t=t.replace(/content: \[\],/g,`content: [\n${n}\n],`),fs.writeFileSync(s,t,{flag:"w"})}function modifyPostcssConfig(e){const s=path.join(e,"postcss.config.js");if(checkExcludeFiles(s))return;fs.writeFileSync(s,"export default {\n plugins: {\n tailwindcss: {},\n autoprefixer: {},\n cssnano: {},\n },\n};",{flag:"w"})}function modifyLayoutPHP(e,s){const t=path.join(e,"src","app","layout.php");if(!checkExcludeFiles(t))try{let e=fs.readFileSync(t,"utf8"),n="";s.backendOnly||(n='\n <link href="<?= $baseUrl; ?>/css/index.css" rel="stylesheet">\n <script src="<?= $baseUrl; ?>/js/index.js"><\/script>');let i="";s.backendOnly||(i=s.tailwindcss?` <link href="<?= $baseUrl; ?>/css/styles.css" rel="stylesheet"> ${n}`:` <script src="https://cdn.tailwindcss.com"><\/script> ${n}`);const c=i.length>0?"\n":"";e=e.replace("</head>",`${i}${c} \x3c!-- Dynamic Head --\x3e\n <?= implode("\\n", $mainLayoutHead); ?>\n</head>`),fs.writeFileSync(t,e,{flag:"w"})}catch(e){}}async function createOrUpdateEnvFile(e,s){const t=path.join(e,".env");checkExcludeFiles(t)||fs.writeFileSync(t,s,{flag:"w"})}function checkExcludeFiles(e){var s,t;return!!(null==updateAnswer?void 0:updateAnswer.isUpdate)&&(null!==(t=null===(s=null==updateAnswer?void 0:updateAnswer.excludeFilePath)||void 0===s?void 0:s.includes(e.replace(/\\/g,"/")))&&void 0!==t&&t)}async function createDirectoryStructure(e,s){const t=[{src:"/bootstrap.php",dest:"/bootstrap.php"},{src:"/.htaccess",dest:"/.htaccess"},{src:"/../composer.json",dest:"/composer.json"},{src:"/tsconfig.json",dest:"/tsconfig.json"}];s.tailwindcss&&t.push({src:"/postcss.config.js",dest:"/postcss.config.js"},{src:"/tailwind.config.js",dest:"/tailwind.config.js"});const n=[{src:"/settings",dest:"/settings"},{src:"/src",dest:"/src"}];s.backendOnly&&s.swaggerDocs&&n.push({src:"/swagger-docs-layout.php",dest:"/src/app/layout.php"}),s.prisma&&n.push({src:"/prisma",dest:"/prisma"}),s.docker&&n.push({src:"/.dockerignore",dest:"/.dockerignore"},{src:"/docker-compose.yml",dest:"/docker-compose.yml"},{src:"/Dockerfile",dest:"/Dockerfile"},{src:"/apache.conf",dest:"/apache.conf"}),t.forEach((({src:s,dest:t})=>{const n=path.join(__dirname,s),i=path.join(e,t);if(checkExcludeFiles(i))return;const c=fs.readFileSync(n,"utf8");fs.writeFileSync(i,c,{flag:"w"})})),await executeCopy(e,n,s),await updatePackageJson(e,s),await updateComposerJson(e,s),s.backendOnly||await updateIndexJsForWebSocket(e,s),s.tailwindcss&&(createOrUpdateTailwindConfig(e),modifyPostcssConfig(e)),(s.tailwindcss||!s.backendOnly||s.swaggerDocs)&&modifyLayoutPHP(e,s);const i='# Prisma PHP Auth Secret Key For development only - Change this in production\nAUTH_SECRET=uxsjXVPHN038DEYls2Kw0QUgBcXKUyrjv416nIFWPY4= \n \n# PHPMailer\n# SMTP_HOST=smtp.gmail.com or your SMTP host\n# SMTP_USERNAME=john.doe@gmail.com or your SMTP username\n# SMTP_PASSWORD=123456\n# SMTP_PORT=587 for TLS, 465 for SSL or your SMTP port\n# SMTP_ENCRYPTION=ssl or tls\n# MAIL_FROM=john.doe@gmail.com\n# MAIL_FROM_NAME="John Doe"\n\n# SHOW ERRORS - Set to true to show errors in the browser for development only - Change this in production to false\nSHOW_ERRORS=true\n\n# APP TIMEZONE - Set your application timezone - Default is "UTC"\nAPP_TIMEZONE="UTC"\n\n# APP ENV - Set your application environment - Default is "development" - Change this in production to "production"\nAPP_ENV=development';if(s.prisma){const s=`${'# Environment variables declared in this file are automatically made available to Prisma.\n# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema\n\n# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.\n# See the documentation for all the connection string options: https://pris.ly/d/connection-strings\n\nDATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"'}\n\n${i}`;await createOrUpdateEnvFile(e,s)}else await createOrUpdateEnvFile(e,i);await createUpdateGitignoreFile(e,["vendor",".env","node_modules"])}async function getAnswer(e={}){var s,t,n,i,c,o,a,r,l,p,d,u,g;const m=[];e.projectName||m.push({type:"text",name:"projectName",message:"What is your project named?",initial:"my-app"}),e.backendOnly||m.push({type:"toggle",name:"backendOnly",message:"Would you like to create a backend-only project?",initial:!1,active:"Yes",inactive:"No"});const f=()=>{process.exit(0)},h=await prompts(m,{onCancel:f}),y=[];h.backendOnly||e.backendOnly?(e.swaggerDocs||y.push({type:"toggle",name:"swaggerDocs",message:`Would you like to use ${chalk.blue("Swagger Docs")}?`,initial:!1,active:"Yes",inactive:"No"}),e.websocket||y.push({type:"toggle",name:"websocket",message:`Would you like to use ${chalk.blue("Websocket")}?`,initial:!0,active:"Yes",inactive:"No"}),e.prisma||y.push({type:"toggle",name:"prisma",message:`Would you like to use ${chalk.blue("Prisma PHP ORM")}?`,initial:!0,active:"Yes",inactive:"No"}),e.docker||y.push({type:"toggle",name:"docker",message:`Would you like to use ${chalk.blue("Docker")}?`,initial:!1,active:"Yes",inactive:"No"})):(e.swaggerDocs||y.push({type:"toggle",name:"swaggerDocs",message:`Would you like to use ${chalk.blue("Swagger Docs")}?`,initial:!1,active:"Yes",inactive:"No"}),e.tailwindcss||y.push({type:"toggle",name:"tailwindcss",message:`Would you like to use ${chalk.blue("Tailwind CSS")}?`,initial:!0,active:"Yes",inactive:"No"}),e.websocket||y.push({type:"toggle",name:"websocket",message:`Would you like to use ${chalk.blue("Websocket")}?`,initial:!0,active:"Yes",inactive:"No"}),e.prisma||y.push({type:"toggle",name:"prisma",message:`Would you like to use ${chalk.blue("Prisma PHP ORM")}?`,initial:!0,active:"Yes",inactive:"No"}),e.docker||y.push({type:"toggle",name:"docker",message:`Would you like to use ${chalk.blue("Docker")}?`,initial:!1,active:"Yes",inactive:"No"}));const k=await prompts(y,{onCancel:f});return{projectName:h.projectName?String(h.projectName).trim().replace(/ /g,"-"):null!==(s=e.projectName)&&void 0!==s?s:"my-app",backendOnly:null!==(n=null!==(t=h.backendOnly)&&void 0!==t?t:e.backendOnly)&&void 0!==n&&n,swaggerDocs:null!==(c=null!==(i=k.swaggerDocs)&&void 0!==i?i:e.swaggerDocs)&&void 0!==c&&c,tailwindcss:null!==(a=null!==(o=k.tailwindcss)&&void 0!==o?o:e.tailwindcss)&&void 0!==a&&a,websocket:null!==(l=null!==(r=k.websocket)&&void 0!==r?r:e.websocket)&&void 0!==l&&l,prisma:null!==(d=null!==(p=k.prisma)&&void 0!==p?p:e.prisma)&&void 0!==d&&d,docker:null!==(g=null!==(u=k.docker)&&void 0!==u?u:e.docker)&&void 0!==g&&g}}async function uninstallDependencies(e,s,t=!1){s.forEach((e=>{}));const n=`npm uninstall ${t?"--save-dev":"--save"} ${s.join(" ")}`;execSync(n,{stdio:"inherit",cwd:e})}function fetchPackageVersion(e){return new Promise(((s,t)=>{https.get(`https://registry.npmjs.org/${e}`,(e=>{let n="";e.on("data",(e=>n+=e)),e.on("end",(()=>{try{const e=JSON.parse(n);s(e["dist-tags"].latest)}catch(e){t(new Error("Failed to parse JSON response"))}}))})).on("error",(e=>t(e)))}))}const readJsonFile=e=>{const s=fs.readFileSync(e,"utf8");return JSON.parse(s)};function compareVersions(e,s){const t=e.split(".").map(Number),n=s.split(".").map(Number);for(let e=0;e<t.length;e++){if(t[e]>n[e])return 1;if(t[e]<n[e])return-1}return 0}function getInstalledPackageVersion(e){try{const s=execSync(`npm list -g ${e} --depth=0`).toString().match(new RegExp(`${e}@(\\d+\\.\\d+\\.\\d+)`));return s?s[1]:null}catch(e){return null}}
|
|
3
|
+
/**
|
|
4
|
+
* Install dependencies in the specified directory.
|
|
5
|
+
* @param {string} baseDir - The base directory where to install the dependencies.
|
|
6
|
+
* @param {string[]} dependencies - The list of dependencies to install.
|
|
7
|
+
* @param {boolean} [isDev=false] - Whether to install the dependencies as devDependencies.
|
|
8
|
+
*/
|
|
9
|
+
async function installDependencies(baseDir, dependencies, isDev = false) {
|
|
10
|
+
console.log("Initializing new Node.js project...");
|
|
11
|
+
// Initialize a package.json if it doesn't exist
|
|
12
|
+
if (!fs.existsSync(path.join(baseDir, "package.json")))
|
|
13
|
+
execSync("npm init -y", {
|
|
14
|
+
stdio: "inherit",
|
|
15
|
+
cwd: baseDir,
|
|
16
|
+
});
|
|
17
|
+
// Log the dependencies being installed
|
|
18
|
+
console.log(
|
|
19
|
+
`${
|
|
20
|
+
isDev ? "Installing development dependencies" : "Installing dependencies"
|
|
21
|
+
}:`
|
|
22
|
+
);
|
|
23
|
+
dependencies.forEach((dep) => console.log(`- ${chalk.blue(dep)}`));
|
|
24
|
+
// Prepare the npm install command with the appropriate flag for dev dependencies
|
|
25
|
+
const npmInstallCommand = `npm install ${
|
|
26
|
+
isDev ? "--save-dev" : ""
|
|
27
|
+
} ${dependencies.join(" ")}`;
|
|
28
|
+
// Execute the npm install command
|
|
29
|
+
execSync(npmInstallCommand, {
|
|
30
|
+
stdio: "inherit",
|
|
31
|
+
cwd: baseDir,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
3
34
|
async function main() {
|
|
4
35
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
5
36
|
try {
|
|
@@ -323,7 +354,6 @@ async function main() {
|
|
|
323
354
|
websocket: answer.websocket,
|
|
324
355
|
prisma: answer.prisma,
|
|
325
356
|
docker: answer.docker,
|
|
326
|
-
ngrok: false,
|
|
327
357
|
version: latestVersionOfCreatePrismaPhpApp,
|
|
328
358
|
excludeFiles:
|
|
329
359
|
(_j =
|
|
@@ -357,11 +387,15 @@ async function main() {
|
|
|
357
387
|
}
|
|
358
388
|
);
|
|
359
389
|
}
|
|
390
|
+
console.log("\n=========================\n");
|
|
360
391
|
console.log(
|
|
361
|
-
`${chalk.green(
|
|
392
|
+
`${chalk.green(
|
|
393
|
+
"Success!"
|
|
394
|
+
)} Prisma PHP project successfully created in ${chalk.green(
|
|
362
395
|
answer.projectName
|
|
363
|
-
}!`
|
|
396
|
+
)}!`
|
|
364
397
|
);
|
|
398
|
+
console.log("\n=========================");
|
|
365
399
|
} catch (error) {
|
|
366
400
|
console.error("Error while creating the project:", error);
|
|
367
401
|
process.exit(1);
|
|
@@ -1,48 +1,47 @@
|
|
|
1
1
|
import { createProxyMiddleware } from "http-proxy-middleware";
|
|
2
|
-
import {
|
|
2
|
+
import { writeFileSync } from "fs";
|
|
3
3
|
import chokidar from "chokidar";
|
|
4
4
|
import browserSync from "browser-sync";
|
|
5
|
-
|
|
5
|
+
import prismaPhpConfig from "../prisma-php.json";
|
|
6
6
|
import { generateFileListJson } from "./files-list.js";
|
|
7
|
-
import { join
|
|
8
|
-
import {
|
|
9
|
-
const
|
|
10
|
-
const __dirname = dirname(__filename);
|
|
7
|
+
import { join } from "path";
|
|
8
|
+
import { getFileMeta } from "./utils.js";
|
|
9
|
+
const { __dirname } = getFileMeta();
|
|
11
10
|
const bs = browserSync.create();
|
|
12
|
-
const prismaPhpConfig = JSON.parse(readFileSync(join(__dirname, "..", "prisma-php.json")).toString("utf-8"));
|
|
13
11
|
// Watch for file changes (create, delete, save)
|
|
14
12
|
const watcher = chokidar.watch("src/app/**/*", {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
ignored: /(^|[\/\\])\../, // Ignore dotfiles
|
|
14
|
+
persistent: true,
|
|
15
|
+
usePolling: true,
|
|
16
|
+
interval: 1000,
|
|
19
17
|
});
|
|
20
18
|
// Perform specific actions for file events
|
|
21
19
|
watcher
|
|
22
|
-
|
|
20
|
+
.on("add", () => {
|
|
23
21
|
generateFileListJson();
|
|
24
|
-
})
|
|
25
|
-
|
|
22
|
+
})
|
|
23
|
+
.on("change", () => {
|
|
26
24
|
generateFileListJson();
|
|
27
|
-
})
|
|
28
|
-
|
|
25
|
+
})
|
|
26
|
+
.on("unlink", () => {
|
|
29
27
|
generateFileListJson();
|
|
30
|
-
});
|
|
28
|
+
});
|
|
31
29
|
// BrowserSync initialization
|
|
32
|
-
bs.init(
|
|
30
|
+
bs.init(
|
|
31
|
+
{
|
|
33
32
|
proxy: "http://localhost:3000",
|
|
34
33
|
middleware: [
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
34
|
+
(_, res, next) => {
|
|
35
|
+
res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
|
|
36
|
+
res.setHeader("Pragma", "no-cache");
|
|
37
|
+
res.setHeader("Expires", "0");
|
|
38
|
+
next();
|
|
39
|
+
},
|
|
40
|
+
createProxyMiddleware({
|
|
41
|
+
target: prismaPhpConfig.bsTarget,
|
|
42
|
+
changeOrigin: true,
|
|
43
|
+
pathRewrite: {},
|
|
44
|
+
}),
|
|
46
45
|
],
|
|
47
46
|
files: "src/**/*.*",
|
|
48
47
|
notify: false,
|
|
@@ -50,13 +49,14 @@ bs.init({
|
|
|
50
49
|
ghostMode: false,
|
|
51
50
|
codeSync: true, // Disable synchronization of code changes across clients
|
|
52
51
|
watchOptions: {
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
usePolling: true,
|
|
53
|
+
interval: 1000,
|
|
55
54
|
},
|
|
56
|
-
},
|
|
55
|
+
},
|
|
56
|
+
(err, bsInstance) => {
|
|
57
57
|
if (err) {
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
console.error("BrowserSync failed to start:", err);
|
|
59
|
+
return;
|
|
60
60
|
}
|
|
61
61
|
// Retrieve the active URLs from the BrowserSync instance
|
|
62
62
|
const options = bsInstance.getOption("urls");
|
|
@@ -66,10 +66,14 @@ bs.init({
|
|
|
66
66
|
const uiExternalUrl = options.get("ui-external");
|
|
67
67
|
// Construct the URLs dynamically
|
|
68
68
|
const urls = {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
local: localUrl,
|
|
70
|
+
external: externalUrl,
|
|
71
|
+
ui: uiUrl,
|
|
72
|
+
uiExternal: uiExternalUrl,
|
|
73
73
|
};
|
|
74
|
-
writeFileSync(
|
|
75
|
-
|
|
74
|
+
writeFileSync(
|
|
75
|
+
join(__dirname, "bs-config.json"),
|
|
76
|
+
JSON.stringify(urls, null, 2)
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
);
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { join, sep, relative
|
|
3
|
-
import {
|
|
4
|
-
const
|
|
5
|
-
const __dirname = dirname(__filename);
|
|
1
|
+
import { existsSync, readdirSync, statSync, writeFileSync } from "fs";
|
|
2
|
+
import { join, sep, relative } from "path";
|
|
3
|
+
import { getFileMeta } from "./utils.js";
|
|
4
|
+
const { __dirname } = getFileMeta();
|
|
6
5
|
// Define the directory and JSON file paths correctly
|
|
7
6
|
const dirPath = "src/app"; // Directory path
|
|
8
7
|
const jsonFilePath = "settings/files-list.json"; // Path to the JSON file
|
|
9
8
|
// Function to get all files in the directory
|
|
10
9
|
const getAllFiles = (dirPath) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
const files = [];
|
|
11
|
+
// Check if directory exists before reading
|
|
12
|
+
if (!existsSync(dirPath)) {
|
|
13
|
+
console.error(`Directory not found: ${dirPath}`);
|
|
14
|
+
return files; // Return an empty array if the directory doesn't exist
|
|
15
|
+
}
|
|
16
|
+
const items = readdirSync(dirPath);
|
|
17
|
+
items.forEach((item) => {
|
|
18
|
+
const fullPath = join(dirPath, item);
|
|
19
|
+
if (statSync(fullPath).isDirectory()) {
|
|
20
|
+
files.push(...getAllFiles(fullPath)); // Recursive call for subdirectories
|
|
21
|
+
} else {
|
|
22
|
+
// Generate the relative path and ensure it starts with ./src
|
|
23
|
+
const relativePath = `.${sep}${relative(
|
|
24
|
+
join(__dirname, ".."),
|
|
25
|
+
fullPath
|
|
26
|
+
)}`;
|
|
27
|
+
// Replace only the root backslashes with forward slashes and leave inner ones
|
|
28
|
+
files.push(relativePath.replace(/\\/g, "/").replace(/^\.\.\//, ""));
|
|
16
29
|
}
|
|
17
|
-
|
|
18
|
-
|
|
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;
|
|
30
|
+
});
|
|
31
|
+
return files;
|
|
31
32
|
};
|
|
32
33
|
// Function to generate the files-list.json
|
|
33
|
-
export const generateFileListJson = () => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
34
|
+
export const generateFileListJson = async () => {
|
|
35
|
+
const files = getAllFiles(dirPath);
|
|
36
|
+
// If files exist, generate JSON file
|
|
37
|
+
if (files.length > 0) {
|
|
38
|
+
writeFileSync(jsonFilePath, JSON.stringify(files, null, 2));
|
|
39
|
+
// console.log(`File list has been saved to: ${jsonFilePath}`);
|
|
40
|
+
} else {
|
|
41
|
+
console.error("No files found to save in the JSON file.");
|
|
42
|
+
}
|
|
43
43
|
};
|
|
@@ -1,58 +1,66 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { writeFile } from "fs";
|
|
2
2
|
import { join, basename, dirname, normalize, sep } from "path";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const __dirname = dirname(__filename);
|
|
7
|
-
const prismaPhpConfig = JSON.parse(readFileSync(join(__dirname, "..", "prisma-php.json")).toString("utf-8"));
|
|
3
|
+
import prismaPhpConfig from "../prisma-php.json";
|
|
4
|
+
import { getFileMeta } from "./utils.js";
|
|
5
|
+
const { __dirname } = getFileMeta();
|
|
8
6
|
const newProjectName = basename(join(__dirname, ".."));
|
|
9
7
|
// Function to update the project name and paths in the JSON config
|
|
10
8
|
function updateProjectNameInConfig(filePath, newProjectName) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
9
|
+
const filePathDir = dirname(filePath);
|
|
10
|
+
// Update the projectName directly in the imported config
|
|
11
|
+
prismaPhpConfig.projectName = newProjectName;
|
|
12
|
+
// Update other paths
|
|
13
|
+
prismaPhpConfig.projectRootPath = filePathDir;
|
|
14
|
+
const targetPath = getTargetPath(filePathDir, prismaPhpConfig.phpEnvironment);
|
|
15
|
+
prismaPhpConfig.bsTarget = `http://localhost${targetPath}`;
|
|
16
|
+
prismaPhpConfig.bsPathRewrite["^/"] = targetPath;
|
|
17
|
+
// Save the updated config back to the JSON file
|
|
18
|
+
writeFile(
|
|
19
|
+
filePath,
|
|
20
|
+
JSON.stringify(prismaPhpConfig, null, 2),
|
|
21
|
+
"utf8",
|
|
22
|
+
(err) => {
|
|
23
|
+
if (err) {
|
|
24
|
+
console.error("Error writing the updated JSON file:", err);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
console.log(
|
|
28
|
+
"The project name, PHP path, and other paths have been updated successfully."
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
);
|
|
27
32
|
}
|
|
28
33
|
// Function to determine the target path for browser-sync
|
|
29
34
|
function getTargetPath(fullPath, environment) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
35
|
+
const normalizedPath = normalize(fullPath);
|
|
36
|
+
const webDirectories = {
|
|
37
|
+
XAMPP: join("htdocs"),
|
|
38
|
+
WAMP: join("www"),
|
|
39
|
+
MAMP: join("htdocs"),
|
|
40
|
+
LAMP: join("var", "www", "html"),
|
|
41
|
+
LEMP: join("usr", "share", "nginx", "html"),
|
|
42
|
+
AMPPS: join("www"),
|
|
43
|
+
UniformServer: join("www"),
|
|
44
|
+
EasyPHP: join("data", "localweb"),
|
|
45
|
+
};
|
|
46
|
+
const webDir = webDirectories[environment.toUpperCase()];
|
|
47
|
+
if (!webDir) {
|
|
48
|
+
throw new Error(`Unsupported environment: ${environment}`);
|
|
49
|
+
}
|
|
50
|
+
const indexOfWebDir = normalizedPath
|
|
51
|
+
.toLowerCase()
|
|
52
|
+
.indexOf(normalize(webDir).toLowerCase());
|
|
53
|
+
if (indexOfWebDir === -1) {
|
|
54
|
+
throw new Error(`Web directory not found in path: ${webDir}`);
|
|
55
|
+
}
|
|
56
|
+
const startIndex = indexOfWebDir + webDir.length;
|
|
57
|
+
const subPath = normalizedPath.slice(startIndex);
|
|
58
|
+
const safeSeparatorRegex = new RegExp(
|
|
59
|
+
sep.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&"),
|
|
60
|
+
"g"
|
|
61
|
+
);
|
|
62
|
+
const finalPath = subPath.replace(safeSeparatorRegex, "/") + "/";
|
|
63
|
+
return finalPath;
|
|
56
64
|
}
|
|
57
65
|
// Path to your JSON configuration file (for saving changes)
|
|
58
66
|
const configFilePath = join(__dirname, "..", "prisma-php.json");
|
|
@@ -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 =
|
|
89
|
+
$baseUrl = '/src/app';
|
|
90
90
|
/**
|
|
91
91
|
* @var string $documentUrl - The document URL of the request.
|
|
92
92
|
*/
|
|
@@ -1,40 +1,47 @@
|
|
|
1
1
|
import { spawn } from "child_process";
|
|
2
|
-
import
|
|
2
|
+
import { join } from "path";
|
|
3
3
|
import chokidar from "chokidar";
|
|
4
|
-
import {
|
|
5
|
-
const
|
|
6
|
-
const __dirname = dirname(__filename);
|
|
4
|
+
import { getFileMeta } from "./utils.js";
|
|
5
|
+
const { __dirname } = getFileMeta();
|
|
7
6
|
// Define paths
|
|
8
7
|
const phpPath = "php"; // Adjust if necessary to include the full path to PHP
|
|
9
|
-
const serverScriptPath =
|
|
8
|
+
const serverScriptPath = join(
|
|
9
|
+
__dirname,
|
|
10
|
+
"..",
|
|
11
|
+
"src",
|
|
12
|
+
"Lib",
|
|
13
|
+
"Websocket",
|
|
14
|
+
"server.php"
|
|
15
|
+
);
|
|
10
16
|
// Hold the server process
|
|
11
17
|
let serverProcess = null;
|
|
12
18
|
const restartServer = () => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
// Start a new WebSocket server process
|
|
26
|
+
console.log("Starting WebSocket server...");
|
|
27
|
+
serverProcess = spawn(phpPath, [serverScriptPath]);
|
|
28
|
+
serverProcess.stdout?.on("data", (data) => {
|
|
29
|
+
console.log(`WebSocket Server: ${data.toString()}`);
|
|
30
|
+
});
|
|
31
|
+
serverProcess.stderr?.on("data", (data) => {
|
|
32
|
+
console.error(`WebSocket Server Error: ${data.toString()}`);
|
|
33
|
+
});
|
|
34
|
+
serverProcess.on("close", (code) => {
|
|
35
|
+
console.log(`WebSocket server process exited with code ${code}`);
|
|
36
|
+
});
|
|
31
37
|
};
|
|
32
38
|
// Initial start
|
|
33
39
|
restartServer();
|
|
34
40
|
// Watch for changes and restart the server
|
|
35
41
|
chokidar
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
42
|
+
.watch(join(__dirname, "..", "src", "Lib", "Websocket", "**", "*"))
|
|
43
|
+
.on("change", (path) => {
|
|
44
|
+
const fileChanged = path.split("\\").pop();
|
|
45
|
+
console.log(`File changed: src/Lib/Websocket/${fileChanged}`);
|
|
39
46
|
restartServer();
|
|
40
|
-
});
|
|
47
|
+
});
|
|
@@ -1,75 +1,61 @@
|
|
|
1
1
|
import swaggerJsdoc from "swagger-jsdoc";
|
|
2
|
-
import { writeFileSync
|
|
3
|
-
import {
|
|
4
|
-
import { join, dirname } from "path";
|
|
2
|
+
import { writeFileSync } from "fs";
|
|
3
|
+
import { join } from "path";
|
|
5
4
|
import chalk from "chalk";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 = {
|
|
5
|
+
import { getFileMeta } from "./utils.js";
|
|
6
|
+
import bsConnectionInfo from "./bs-config.json";
|
|
7
|
+
const { __dirname } = getFileMeta();
|
|
8
|
+
export async function swaggerConfig() {
|
|
9
|
+
const outputPath = join(
|
|
10
|
+
__dirname,
|
|
11
|
+
"../src/app/swagger-docs/apis/pphp-swagger.json"
|
|
12
|
+
);
|
|
13
|
+
const options = {
|
|
32
14
|
definition: {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
15
|
+
openapi: "3.0.0",
|
|
16
|
+
info: {
|
|
17
|
+
title: "Prisma PHP API Documentation",
|
|
18
|
+
version: "1.0.0",
|
|
19
|
+
description: "API documentation for the Prisma PHP project",
|
|
20
|
+
},
|
|
21
|
+
servers: [
|
|
22
|
+
{
|
|
23
|
+
url: bsConnectionInfo.local, // For Development
|
|
24
|
+
description: "Development Server",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
url: "your-production-domain", // For Production
|
|
28
|
+
description: "Production Server",
|
|
38
29
|
},
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
},
|
|
48
|
-
],
|
|
49
|
-
components: {
|
|
50
|
-
securitySchemes: {
|
|
51
|
-
bearerAuth: {
|
|
52
|
-
type: "http",
|
|
53
|
-
scheme: "bearer",
|
|
54
|
-
bearerFormat: "JWT",
|
|
55
|
-
},
|
|
56
|
-
},
|
|
30
|
+
],
|
|
31
|
+
components: {
|
|
32
|
+
securitySchemes: {
|
|
33
|
+
bearerAuth: {
|
|
34
|
+
type: "http",
|
|
35
|
+
scheme: "bearer",
|
|
36
|
+
bearerFormat: "JWT",
|
|
37
|
+
},
|
|
57
38
|
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
39
|
+
},
|
|
40
|
+
security: [
|
|
41
|
+
{
|
|
42
|
+
bearerAuth: [],
|
|
43
|
+
},
|
|
44
|
+
],
|
|
63
45
|
},
|
|
64
|
-
apis: [join(__dirname, "../src/app/swagger-docs/apis/**/*.
|
|
65
|
-
};
|
|
66
|
-
// Generate the Swagger specification
|
|
67
|
-
const swaggerSpec = JSON.stringify(swaggerJsdoc(options), null, 2);
|
|
68
|
-
// Always generate the swagger.json file
|
|
69
|
-
try {
|
|
46
|
+
apis: [join(__dirname, "../src/app/swagger-docs/apis/**/*.js")], // Adjust to match JavaScript file paths
|
|
47
|
+
};
|
|
48
|
+
// Generate the Swagger specification
|
|
49
|
+
const swaggerSpec = JSON.stringify(swaggerJsdoc(options), null, 2);
|
|
50
|
+
// Always generate the swagger.json file
|
|
51
|
+
try {
|
|
70
52
|
writeFileSync(outputPath, swaggerSpec, "utf-8");
|
|
71
|
-
console.log(
|
|
72
|
-
|
|
73
|
-
|
|
53
|
+
console.log(
|
|
54
|
+
`Swagger JSON has been generated and saved to ${chalk.blue(
|
|
55
|
+
"src/app/swagger-docs/pphp-swagger.json"
|
|
56
|
+
)}`
|
|
57
|
+
);
|
|
58
|
+
} catch (error) {
|
|
74
59
|
console.error("Error saving Swagger JSON:", error);
|
|
60
|
+
}
|
|
75
61
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { fileURLToPath } from "url";
|
|
2
|
+
import { dirname } from "path";
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves the file metadata including the filename and directory name.
|
|
5
|
+
*
|
|
6
|
+
* @param importMetaUrl - The URL of the module's import.meta.url.
|
|
7
|
+
* @returns An object containing the filename (`__filename`) and directory name (`__dirname`).
|
|
8
|
+
*/
|
|
9
|
+
export function getFileMeta() {
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = dirname(__filename);
|
|
12
|
+
return { __filename, __dirname };
|
|
13
|
+
}
|
package/dist/tsconfig.json
CHANGED
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
26
26
|
|
|
27
27
|
/* Modules */
|
|
28
|
-
"module": "
|
|
28
|
+
"module": "ESNext" /* Specify what module code is generated. */,
|
|
29
29
|
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
30
|
-
|
|
30
|
+
"moduleResolution": "Node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
31
31
|
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
32
32
|
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
33
33
|
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
|
75
75
|
|
|
76
76
|
/* Interop Constraints */
|
|
77
|
-
|
|
77
|
+
"isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
78
78
|
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
79
79
|
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
80
80
|
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
|
@@ -91,8 +91,8 @@
|
|
|
91
91
|
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
92
92
|
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
93
93
|
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
"noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
95
|
+
"noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
96
96
|
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
97
97
|
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
98
98
|
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|