create-prisma-php-app 1.1.8 → 1.1.10
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/index.js +1 -1
- package/package.json +1 -1
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(e){const i="
|
|
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=e.PROJECT_ROOT_PATH.indexOf("\\htdocs\\");if(-1===i)return"";const s=e.PROJECT_ROOT_PATH.substring(0,i+"\\htdocs\\".length).replace(/\\/g,"\\\\"),t=`http://localhost/${e.PROJECT_ROOT_PATH.replace(new RegExp(`^${s}`),"").replace(/\\/g,"/")}`;return`browser-sync start --proxy ${(t.endsWith("/")?t.slice(0,-1):t).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();
|