create-prisma-php-app 1.0.1 → 1.0.2

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 CHANGED
@@ -21,6 +21,14 @@ Installation Steps:
21
21
  1. Open your terminal.
22
22
  2. Run the command:
23
23
 
24
+ - Install `create-prisma-php-app` globally:
25
+
26
+ ```bash
27
+ npm install -g create-prisma-php-app
28
+ ```
29
+
30
+ - Create a new Prisma-PHP project: in the desired directory, run the command:
31
+
24
32
  ```bash
25
33
  npx create-prisma-php-app
26
34
  ```
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
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 e=path.join(i,"package.json"),s=JSON.parse(fs.readFileSync(e,"utf8"));s.scripts=Object.assign(Object.assign({},s.scripts),{postinstall:"prisma generate"}),s.type="module",s.prisma={seed:"node prisma/seed.js"},fs.writeFileSync(e,JSON.stringify(s,null,2))}async function createUpdateGitignoreFile(i,e){const s=path.join(i,".gitignore");let t="";fs.existsSync(s)&&(t=fs.readFileSync(s,"utf8")),e.forEach((i=>{t.includes(i)||(t+=`\n${i}`)})),t=t.trimStart(),fs.writeFileSync(s,t)}function copyRecursiveSync(i,e){const s=fs.existsSync(i),t=s&&fs.statSync(i);s&&t&&t.isDirectory()?(fs.mkdirSync(e,{recursive:!0}),fs.readdirSync(i).forEach((s=>copyRecursiveSync(path.join(i,s),path.join(e,s))))):fs.copyFileSync(i,e)}async function executeCopy(i,e){e.forEach((({srcDir:e,destDir:s})=>{copyRecursiveSync(path.join(__dirname,e),path.join(i,s))}))}function modifyTailwindConfig(i){const e=path.join(i,"tailwind.config.js");let s=fs.readFileSync(e,"utf8");const t=["./public/**/*.php","./public/**/*.html"].map((i=>` "${i}"`)).join(",\n");s=s.replace(/content: \[\],/g,`content: [\n${t}\n ],`),fs.writeFileSync(e,s,"utf8")}function modifyIndexPHP(i,e){const s=path.join(i,"public","index.php");try{let i=fs.readFileSync(s,"utf8");const t=e?' <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>",`${t}\n</head>`),fs.writeFileSync(s,i,"utf8")}catch(i){}}async function createDirectoryStructure(i,e){await updatePackageJson(i);const s=[{srcDir:"/settings",destDir:"/settings"},{srcDir:"/node_modules/prisma-client-php",destDir:"/node_modules/prisma-client-php"},{srcDir:"/prisma",destDir:"/prisma"},{srcDir:"/src",destDir:"/src"},{srcDir:"/../vendor",destDir:"/vendor"}];e.tailwindcss&&s.push({srcDir:"/public/css/",destDir:"/public/css/"}),s.push({srcDir:"/public/assets/",destDir:"/public/assets/"}),await executeCopy(i,s),[{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:e,dest:s})=>{const t=path.join(__dirname,e),c=path.join(i,s),n=fs.readFileSync(t,"utf8");fs.writeFileSync(c,n)})),e.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"}],e=()=>!1;try{const s=await prompts(i,{onCancel:e});return 0===Object.keys(s).length?null:{projectName:String(s.projectName).trim().replace(/ /g,"-"),tailwindcss:s.tailwindcss}}catch(i){return null}}async function installDependencies(i,e){execSync("npm init -y",{stdio:"inherit",cwd:i}),e.forEach((i=>{})),execSync(`npm install ${e.join(" ")}`,{stdio:"inherit",cwd:i})}async function main(){try{const i=await getAnswer();if(null===i)return;fs.mkdirSync(i.projectName);const e=path.join(process.cwd(),i.projectName);process.chdir(i.projectName);const s=["prisma","@prisma/client","typescript","@types/node","ts-node"];i.tailwindcss&&s.push("tailwindcss","autoprefixer","postcss"),await installDependencies(e,s),execSync("npx prisma init",{stdio:"inherit"}),execSync("npx tsc --init",{stdio:"inherit"}),i.tailwindcss&&execSync("npx tailwindcss init -p",{stdio:"inherit"}),await createDirectoryStructure(e,i),i.tailwindcss&&execSync("npx tailwindcss -i ./public/css/tailwind.css -o ./public/css/styles.css --minify",{stdio:"inherit"});const t=path.join(e,"settings","project-settings.js"),c=`export const projectSettings = {\n PROJECT_NAME: "${i.projectName}",\n PROJECT_ROOT_PATH: "${e.replace(/\\/g,"\\\\")}",\n PHP_ROOT_PATH_EXE: "D:\\\\xampp\\\\php\\\\php.exe",\n PHP_GENERATE_CLASS_PATH: "src/app/classes/prisma",\n };`;fs.writeFileSync(t,c)}catch(i){process.exit(1)}}main();
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  import*as fs from"fs";import{exec}from"child_process";import path from"path";import{pathToFileURL}from"url";import CryptoJS from"crypto-js";const args=process.argv.slice(2),getSecretKey=e=>{const t=fs.readFileSync(`${e}/key.enc`,"utf8");if(t.length<400)throw new Error("File content is less than 400 characters.");return t.substring(299,349)},decryptData=(e,t)=>CryptoJS.AES.decrypt(e,t).toString(CryptoJS.enc.Utf8),executePHP=e=>{exec(e,((e,t,r)=>{}))},main=async()=>{if("generate"===args[0]&&"class"===args[1])try{const e=process.cwd(),t=pathToFileURL(path.join(e,"settings","project-settings.js")),r=(await import(t.href)).projectSettings,c=r.PHP_GENERATE_CLASS_PATH,s=`${r.PROJECT_ROOT_PATH}/node_modules/prisma-client-php`,n=r.PROJECT_ROOT_PATH?`${s}/index.run.php`:`${s}/dist/prisma-client-php/index.run.php`,i=`${s}/index.enc`,p=getSecretKey(s),o=fs.readFileSync(i,{encoding:"utf8"}),a=decryptData(o,p);fs.writeFileSync(`${s}/index.run.php`,a);const h=`${r.PHP_ROOT_PATH_EXE} ${n} ${c}`;executePHP(h)}catch(e){}};main().catch((e=>{}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",