create-prisma-php-app 1.1.5 → 1.1.6

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,25 @@
1
+ # Contributing to create-prisma-php-app
2
+
3
+ We welcome contributions from the community! Here's how you can contribute:
4
+
5
+ ## Reporting Issues
6
+
7
+ - Use GitHub Issues to report bugs or suggest features.
8
+ - Before submitting an issue, please search existing issues to avoid duplicates.
9
+
10
+ ## Pull Requests
11
+
12
+ - Fork the repository and create your branch from `master`.
13
+ - If you've added code that should be tested, add tests.
14
+ - Ensure your code lints and follows the coding conventions used throughout the project.
15
+ - Write clear, concise commit messages.
16
+
17
+ ## Code of Conduct
18
+
19
+ This project and everyone participating in it are governed by the [Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code.
20
+
21
+ ## Questions or Suggestions
22
+
23
+ Feel free to contact us via [GitHub Discussions](https://github.com/TheSteelNinjaCode) or our Discord server (link) for questions, discussions, or suggestions.
24
+
25
+ Thank you for contributing to create-prisma-php-app!
package/README.md CHANGED
@@ -14,6 +14,14 @@ Ensure your system is equipped with:
14
14
  - XAMPP: (or any PHP 7.4+ environment) [Download XAMPP](https://www.apachefriends.org/download.html)
15
15
  - Composer: Version 2.x or higher [Download Composer](https://getcomposer.org/download/)
16
16
 
17
+ ## Verifying Prerequisites
18
+
19
+ To verify your installations, run the following commands in your terminal:
20
+
21
+ - Node.js: `node -v`
22
+ - PHP: `php -v`
23
+ - Composer: `composer --version`
24
+
17
25
  ## Installation
18
26
 
19
27
  Installation Steps:
@@ -43,13 +51,48 @@ composer install
43
51
 
44
52
  ### PHP and Composer Dependencies
45
53
 
46
- - `vlucas/phpdotenv`: For environment variable management.
47
- - `ramsey/uuid`, `hidehalo/nanoid-php`, `firebase/php-jwt`: For unique ID generation and JWT handling.
54
+ - `vlucas/phpdotenv`: Allows your project to load environment variables from a `.env` file, making configuration management easier and more secure.
55
+ - `ramsey/uuid`, `hidehalo/nanoid-php`: Provide robust solutions for generating unique identifiers in your application.
56
+ - `firebase/php-jwt`: Facilitates working with JSON Web Tokens (JWT) for secure authentication.
48
57
 
49
58
  ### Tailwind CSS Support (Optional)
50
59
 
51
60
  - `tailwindcss`, `postcss`, `autoprefixer`: Enhance your front-end with Tailwind's utility-first CSS framework.
52
61
 
62
+ ### browser-sync support (Optional)
63
+
64
+ - `browser-sync`: For live reloading and synchronized browser testing.
65
+
66
+ The package will include `browser-sync` for live reloading and synchronized browser testing. This feature is optional and can be removed if not needed.
67
+
68
+ ## Usage
69
+
70
+ ```bash
71
+ npm run dev
72
+ ```
73
+
74
+ If you get an "Error" like this:
75
+
76
+ ```bash
77
+ browser-sync : File C:\Users\Username\AppData\Roaming\npm\browser-sync.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies
78
+ at https:/go.microsoft.com/fwlink/?LinkID=135170.
79
+ At line:1 char:1
80
+ + browser-sync start --proxy localhost:3000 --files "public/**/*"
81
+ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
82
+ + CategoryInfo : SecurityError: (:) [], PSSecurityException
83
+ + FullyQualifiedErrorId : UnauthorizedAccess
84
+ ```
85
+
86
+ ### Solution
87
+
88
+ Run the following command in PowerShell as an administrator:
89
+
90
+ ```bash
91
+ Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
92
+ "OR"
93
+ Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
94
+ ```
95
+
53
96
  ## Prisma Command
54
97
 
55
98
  | Command | Description |
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);async function updatePackageJson(i){const t=path.join(i,"package.json"),e=JSON.parse(fs.readFileSync(t,"utf8"));e.scripts=Object.assign(Object.assign({},e.scripts),{postinstall:"prisma generate"}),e.type="module",e.prisma={seed:"node prisma/seed.js"},fs.writeFileSync(t,JSON.stringify(e,null,2))}async function createUpdateGitignoreFile(i,t){const e=path.join(i,".gitignore");let s="";fs.existsSync(e)&&(s=fs.readFileSync(e,"utf8")),t.forEach((i=>{s.includes(i)||(s+=`\n${i}`)})),s=s.trimStart(),fs.writeFileSync(e,s)}function copyRecursiveSync(i,t){const e=fs.existsSync(i),s=e&&fs.statSync(i);e&&s&&s.isDirectory()?(fs.mkdirSync(t,{recursive:!0}),fs.readdirSync(i).forEach((e=>copyRecursiveSync(path.join(i,e),path.join(t,e))))):fs.copyFileSync(i,t)}async function executeCopy(i,t){t.forEach((({srcDir:t,destDir:e})=>{copyRecursiveSync(path.join(__dirname,t),path.join(i,e))}))}function modifyTailwindConfig(i){const t=path.join(i,"tailwind.config.js");let e=fs.readFileSync(t,"utf8");const s=["./public/**/*.php","./public/**/*.html"].map((i=>` "${i}"`)).join(",\n");e=e.replace(/content: \[\],/g,`content: [\n${s}\n ],`),fs.writeFileSync(t,e,"utf8")}function modifyIndexPHP(i,t){const e=path.join(i,"public","index.php");try{let i=fs.readFileSync(e,"utf8");const s=t?' <link href="css/styles.css" rel="stylesheet"> \x3c!-- Stylesheet link to the tailwind compiled css --\x3e':' <script src="https://cdn.tailwindcss.com"><\/script>';i=i.replace("</head>",`${s}\n</head>`),fs.writeFileSync(e,i,"utf8")}catch(i){}}async function createDirectoryStructure(i,t){await updatePackageJson(i);const e=[{srcDir:"/settings",destDir:"/settings"},{srcDir:"/prisma",destDir:"/prisma"},{srcDir:"/src",destDir:"/src"},{srcDir:"/../vendor",destDir:"/vendor"}];t.tailwindcss&&e.push({srcDir:"/public/css/",destDir:"/public/css/"}),e.push({srcDir:"/public/assets/",destDir:"/public/assets/"}),await executeCopy(i,e),[{src:"/public/favicon.ico",dest:"/public/favicon.ico"},{src:"/public/index.php",dest:"/public/index.php"},{src:"/bootstrap.php",dest:"/bootstrap.php"},{src:"/../composer.json",dest:"/composer.json"},{src:"/../composer.lock",dest:"/composer.lock"}].forEach((({src:t,dest:e})=>{const s=path.join(__dirname,t),c=path.join(i,e),n=fs.readFileSync(s,"utf8");fs.writeFileSync(c,n)})),t.tailwindcss?(modifyTailwindConfig(i),modifyIndexPHP(i,!0)):modifyIndexPHP(i,!1)}async function getAnswer(){const i=[{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 e=await prompts(i,{onCancel:t});return 0===Object.keys(e).length?null:{projectName:String(e.projectName).trim().replace(/ /g,"-"),tailwindcss:e.tailwindcss}}catch(i){return null}}async function installDependencies(i,t){execSync("npm init -y",{stdio:"inherit",cwd:i}),t.forEach((i=>{})),execSync(`npm install ${t.join(" ")}`,{stdio:"inherit",cwd:i})}async function main(){try{const i=await getAnswer();if(null===i)return;execSync("npm install -g create-prisma-php-app",{stdio:"inherit"}),fs.mkdirSync(i.projectName);const t=path.join(process.cwd(),i.projectName);process.chdir(i.projectName);const e=["prisma","@prisma/client","typescript","@types/node","ts-node"];i.tailwindcss&&e.push("tailwindcss","autoprefixer","postcss"),await installDependencies(t,e),execSync("npx prisma init",{stdio:"inherit"}),execSync("npx tsc --init",{stdio:"inherit"}),i.tailwindcss&&execSync("npx tailwindcss init -p",{stdio:"inherit"}),await createDirectoryStructure(t,i),i.tailwindcss&&execSync("npx tailwindcss -i ./public/css/tailwind.css -o ./public/css/styles.css --minify",{stdio:"inherit"});const s=path.join(t,"settings","project-settings.js"),c=`export const projectSettings = {\n PROJECT_NAME: "${i.projectName}",\n PROJECT_ROOT_PATH: "${t.replace(/\\/g,"\\\\")}",\n PHP_ROOT_PATH_EXE: "D:\\\\xampp\\\\php\\\\php.exe",\n PHP_GENERATE_CLASS_PATH: "src/app/classes/prisma",\n };`;fs.writeFileSync(s,c)}catch(i){process.exit(1)}}main();
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){const i="D:\\\\xampp\\\\htdocs\\\\".replace(/\\/g,"\\\\");return`browser-sync start --proxy ${`http://localhost/${e.PROJECT_ROOT_PATH.replace(new RegExp(`^${i}`),"").replace(/\\/g,"/")}`}/public --files public/css/**/*.css, public/**/*.html, public/**/*.php`}async function updatePackageJson(e,i){const s=path.join(e,"package.json"),t=JSON.parse(fs.readFileSync(s,"utf8")),c=configureBrowserSyncCommand(i);t.scripts=Object.assign(Object.assign({},t.scripts),{postinstall:"prisma generate",dev:c}),t.type="module",t.prisma={seed:"node prisma/seed.js"},fs.writeFileSync(s,JSON.stringify(t,null,2))}async function createUpdateGitignoreFile(e,i){const s=path.join(e,".gitignore");let t="";fs.existsSync(s)&&(t=fs.readFileSync(s,"utf8")),i.forEach((e=>{t.includes(e)||(t+=`\n${e}`)})),t=t.trimStart(),fs.writeFileSync(s,t)}function copyRecursiveSync(e,i){const s=fs.existsSync(e),t=s&&fs.statSync(e);s&&t&&t.isDirectory()?(fs.mkdirSync(i,{recursive:!0}),fs.readdirSync(e).forEach((s=>copyRecursiveSync(path.join(e,s),path.join(i,s))))):fs.copyFileSync(e,i)}async function executeCopy(e,i){i.forEach((({srcDir:i,destDir:s})=>{copyRecursiveSync(path.join(__dirname,i),path.join(e,s))}))}function modifyTailwindConfig(e){const i=path.join(e,"tailwind.config.js");let s=fs.readFileSync(i,"utf8");const t=["./public/**/*.php","./public/**/*.html"].map((e=>` "${e}"`)).join(",\n");s=s.replace(/content: \[\],/g,`content: [\n${t}\n ],`),fs.writeFileSync(i,s,"utf8")}function modifyIndexPHP(e,i){const s=path.join(e,"public","index.php");try{let e=fs.readFileSync(s,"utf8");const t=i?' <link href="css/styles.css" rel="stylesheet"> \x3c!-- Stylesheet link to the tailwind compiled css --\x3e':' <script src="https://cdn.tailwindcss.com"><\/script>';e=e.replace("</head>",`${t}\n</head>`),fs.writeFileSync(s,e,"utf8")}catch(e){}}async function createDirectoryStructure(e,i,s){await updatePackageJson(e,s);const t=[{srcDir:"/settings",destDir:"/settings"},{srcDir:"/prisma",destDir:"/prisma"},{srcDir:"/src",destDir:"/src"},{srcDir:"/../vendor",destDir:"/vendor"}];i.tailwindcss&&t.push({srcDir:"/public/css/",destDir:"/public/css/"}),t.push({srcDir:"/public/assets/",destDir:"/public/assets/"}),await executeCopy(e,t),[{src:"/public/favicon.ico",dest:"/public/favicon.ico"},{src:"/public/index.php",dest:"/public/index.php"},{src:"/bootstrap.php",dest:"/bootstrap.php"},{src:"/../composer.json",dest:"/composer.json"},{src:"/../composer.lock",dest:"/composer.lock"}].forEach((({src:i,dest:s})=>{const t=path.join(__dirname,i),c=path.join(e,s),n=fs.readFileSync(t,"utf8");fs.writeFileSync(c,n)})),i.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"}],i=()=>!1;try{const s=await prompts(e,{onCancel:i});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,i){execSync("npm init -y",{stdio:"inherit",cwd:e}),i.forEach((e=>{})),execSync(`npm install ${i.join(" ")}`,{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 i=path.join(process.cwd(),e.projectName);process.chdir(e.projectName);const s=["prisma","@prisma/client","typescript","@types/node","ts-node"];e.tailwindcss&&s.push("tailwindcss","autoprefixer","postcss"),await installDependencies(i,s),execSync("npx prisma init",{stdio:"inherit"}),execSync("npx tsc --init",{stdio:"inherit"}),e.tailwindcss&&execSync("npx tailwindcss init -p",{stdio:"inherit"});const t={PROJECT_NAME:e.projectName,PROJECT_ROOT_PATH:i.replace(/\\/g,"\\\\"),PHP_ROOT_PATH_EXE:"D:\\\\xampp\\\\php\\\\php.exe",PHP_GENERATE_CLASS_PATH:"src/app/classes/prisma"};await createDirectoryStructure(i,e,t),e.tailwindcss&&execSync("npx tailwindcss -i ./public/css/tailwind.css -o ./public/css/styles.css --minify",{stdio:"inherit"});const c=path.join(i,"settings","project-settings.js"),n=`export const projectSettings = {\n PROJECT_NAME: "${e.projectName}",\n PROJECT_ROOT_PATH: "${i.replace(/\\/g,"\\\\")}",\n PHP_ROOT_PATH_EXE: "D:\\\\xampp\\\\php\\\\php.exe",\n PHP_GENERATE_CLASS_PATH: "src/app/classes/prisma",\n };`;fs.writeFileSync(c,n)}catch(e){process.exit(1)}}main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",