create-prisma-php-app 1.6.22 → 1.6.24
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/dist/prisma-php.js +11 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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);function configureBrowserSyncCommand(e,t){const s=t.PROJECT_ROOT_PATH.indexOf("\\htdocs\\");if(-1===s)return"";const n=t.PROJECT_ROOT_PATH.substring(0,s+"\\htdocs\\".length).replace(/\\/g,"\\\\"),i=t.PROJECT_ROOT_PATH.replace(new RegExp(`^${n}`),"").replace(/\\/g,"/");let c=`http://localhost/${i}`;c=c.endsWith("/")?c.slice(0,-1):c;const r=c.replace(/(?<!:)(\/\/+)/g,"/"),o=i.replace(/\/\/+/g,"/"),a=`\n const { createProxyMiddleware } = require("http-proxy-middleware");\n\n module.exports = {\n // First middleware: Set Cache-Control headers\n function (req, res, next) {\n res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");\n res.setHeader("Pragma", "no-cache");\n res.setHeader("Expires", "0");\n next();\n },\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 "${r}",\n changeOrigin: true,\n pathRewrite: {\n "^/": "/${o.startsWith("/")?o.substring(1):o}", // 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 files: "src/**/*.*",\n notify: false,\n open: false,\n ghostMode: false,\n };`,p=path.join(e,"settings","bs-config.cjs");return fs.writeFileSync(p,a,"utf8"),"browser-sync start --config settings/bs-config.cjs"}async function updatePackageJson(e,t,s){const n=path.join(e,"package.json"),i=JSON.parse(fs.readFileSync(n,"utf8")),c=configureBrowserSyncCommand(e,t);i.scripts=Object.assign(Object.assign({},i.scripts),{postinstall:"prisma generate"});let r=[];s.tailwindcss&&(i.scripts=Object.assign(Object.assign({},i.scripts),{tailwind:"postcss ./src/app/css/tailwind.css -o ./src/app/css/styles.css --watch"}),r.push("tailwind")),s.websocket&&(i.scripts=Object.assign(Object.assign({},i.scripts),{websocket:"node ./settings/restartWebsocket.cjs"}),r.push("websocket"));const o=Object.assign({},i.scripts);r.length>0&&(o["browser-sync"]=c),o.dev=r.length>0?`npm-run-all --parallel browser-sync ${r.join(" ")}`:c,i.scripts=o,i.type="module",i.prisma={seed:"node prisma/seed.js"},fs.writeFileSync(n,JSON.stringify(i,null,2))}async function updateComposerJson(e,t){if(!t.websocket)return;const s=path.join(e,"composer.json");let n;if(fs.existsSync(s)){{const e=fs.readFileSync(s,"utf8");n=JSON.parse(e)}t.websocket&&(n.require=Object.assign(Object.assign({},n.require),{"cboden/ratchet":"^0.4.4"})),fs.writeFileSync(s,JSON.stringify(n,null,2))}}async function updateIndexJsForWebSocket(e,t){if(!t.websocket)return;const s=path.join(e,"src","app","js","index.js");let n=fs.readFileSync(s,"utf8");n+='\n// WebSocket initialization\nconst ws = new WebSocket("ws://localhost:8080");\n',fs.writeFileSync(s,n,"utf8")}async function createUpdateGitignoreFile(e,t){const s=path.join(e,".gitignore");let n="";fs.existsSync(s)&&(n=fs.readFileSync(s,"utf8")),t.forEach((e=>{n.includes(e)||(n+=`\n${e}`)})),n=n.trimStart(),fs.writeFileSync(s,n)}function copyRecursiveSync(e,t){const s=fs.existsSync(e),n=s&&fs.statSync(e);s&&n&&n.isDirectory()?(fs.existsSync(t)&&fs.rmSync(t,{recursive:!0,force:!0}),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 n=["./src/app/**/*.{html,js,php}"].map((e=>` "${e}"`)).join(",\n");s=s.replace(/content: \[\],/g,`content: [\n${n}\n],`),fs.writeFileSync(t,s,"utf8")}function modifyPostcssConfig(e){const t=path.join(e,"postcss.config.js");fs.writeFileSync(t,"export default {\n plugins: {\n tailwindcss: {},\n autoprefixer: {},\n cssnano: {},\n },\n};","utf8")}function modifyIndexPHP(e,t){const s=path.join(e,"src","app","layout.php");try{let e=fs.readFileSync(s,"utf8");const n='\n <link href="<?php echo $baseUrl; ?>css/index.css" rel="stylesheet">\n <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">\n <script src="<?php echo $baseUrl; ?>js/index.js"><\/script>',i=t?` <link href="<?php echo $baseUrl; ?>css/styles.css" rel="stylesheet"> ${n}`:` <script src="https://cdn.tailwindcss.com"><\/script> ${n}`;e=e.replace("</head>",`${i}\n</head>`),fs.writeFileSync(s,e,"utf8")}catch(e){}}async function updateOrCreateEnvFile(e,t){const s=path.join(e,".env");let n=fs.existsSync(s)?fs.readFileSync(s,"utf8"):"";n+=`${""!==n?"\n\n":""}${t}`,fs.writeFileSync(s,n)}async function createDirectoryStructure(e,t,s){[{src:"/bootstrap.php",dest:"/bootstrap.php"},{src:"/.htaccess",dest:"/.htaccess"},{src:"/../composer.json",dest:"/composer.json"}].forEach((({src:t,dest:s})=>{const n=path.join(__dirname,t),i=path.join(e,s),c=fs.readFileSync(n,"utf8");fs.writeFileSync(i,c)})),await executeCopy(e,[{srcDir:"/settings",destDir:"/settings"},{srcDir:"/prisma",destDir:"/prisma"},{srcDir:"/src",destDir:"/src"},{srcDir:"/../vendor",destDir:"/vendor"}]),await updatePackageJson(e,s,t),await updateComposerJson(e,t),await updateIndexJsForWebSocket(e,t),t.tailwindcss?(modifyTailwindConfig(e),modifyIndexPHP(e,!0),modifyPostcssConfig(e)):modifyIndexPHP(e,!1);await updateOrCreateEnvFile(e,'# PHPMailer\nSMTP_HOST=\nSMTP_USERNAME=\nSMTP_PASSWORD=\nSMTP_PORT=\nSMTP_ENCRYPTION=ssl\nMAIL_FROM=\nMAIL_FROM_NAME=""'),await createUpdateGitignoreFile(e,["vendor"])}async function getAnswer(e={}){var t,s,n;const i=[];e.projectName||i.push({type:"text",name:"projectName",message:"What is your project named?",initial:"my-app"}),e.tailwindcss||i.push({type:"toggle",name:"tailwindcss",message:`Would you like to use ${chalk.blue("Tailwind CSS")}?`,initial:!0,active:"Yes",inactive:"No"}),e.websocket||i.push({type:"toggle",name:"websocket",message:`Would you like to use ${chalk.blue("Websocket")}?`,initial:!0,active:"Yes",inactive:"No"});const c=()=>!1;try{const r=await prompts(i,{onCancel:c});return 0===Object.keys(r).length?null:{projectName:r.projectName?String(r.projectName).trim().replace(/ /g,"-"):null!==(t=e.projectName)&&void 0!==t?t:"my-app",tailwindcss:null!==(s=r.tailwindcss)&&void 0!==s?s:e.tailwindcss,websocket:null!==(n=r.websocket)&&void 0!==n?n:e.websocket}}catch(e){return null}}async function installDependencies(e,t,s=!1){fs.existsSync(path.join(e,"package.json"))||execSync("npm init -y",{stdio:"inherit",cwd:e}),t.forEach((e=>{}));const n=`npm install ${s?"--save-dev":""} ${t.join(" ")}`;execSync(n,{stdio:"inherit",cwd:e})}function fetchPackageVersion(e){return new Promise(((t,s)=>{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);t(e["dist-tags"].latest)}catch(e){s(new Error("Failed to parse JSON response"))}}))})).on("error",(e=>s(e)))}))}
|
|
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);function configureBrowserSyncCommand(e,t){const s=t.PROJECT_ROOT_PATH.indexOf("\\htdocs\\");if(-1===s)return"";const n=t.PROJECT_ROOT_PATH.substring(0,s+"\\htdocs\\".length).replace(/\\/g,"\\\\"),i=t.PROJECT_ROOT_PATH.replace(new RegExp(`^${n}`),"").replace(/\\/g,"/");let c=`http://localhost/${i}`;c=c.endsWith("/")?c.slice(0,-1):c;const r=c.replace(/(?<!:)(\/\/+)/g,"/"),o=i.replace(/\/\/+/g,"/"),a=`\n const { createProxyMiddleware } = require("http-proxy-middleware");\n\n module.exports = {\n // First middleware: Set Cache-Control headers\n function (req, res, next) {\n res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");\n res.setHeader("Pragma", "no-cache");\n res.setHeader("Expires", "0");\n next();\n },\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 "${r}",\n changeOrigin: true,\n pathRewrite: {\n "^/": "/${o.startsWith("/")?o.substring(1):o}", // 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 files: "src/**/*.*",\n notify: false,\n open: false,\n ghostMode: false,\n };`,p=path.join(e,"settings","bs-config.cjs");return fs.writeFileSync(p,a,"utf8"),"browser-sync start --config settings/bs-config.cjs"}async function updatePackageJson(e,t,s){const n=path.join(e,"package.json"),i=JSON.parse(fs.readFileSync(n,"utf8")),c=configureBrowserSyncCommand(e,t);i.scripts=Object.assign(Object.assign({},i.scripts),{postinstall:"prisma generate"});let r=[];s.tailwindcss&&(i.scripts=Object.assign(Object.assign({},i.scripts),{tailwind:"postcss ./src/app/css/tailwind.css -o ./src/app/css/styles.css --watch"}),r.push("tailwind")),s.websocket&&(i.scripts=Object.assign(Object.assign({},i.scripts),{websocket:"node ./settings/restartWebsocket.cjs"}),r.push("websocket"));const o=Object.assign({},i.scripts);r.length>0&&(o["browser-sync"]=c),o.dev=r.length>0?`npm-run-all --parallel browser-sync ${r.join(" ")}`:c,i.scripts=o,i.type="module",i.prisma={seed:"node prisma/seed.js"},fs.writeFileSync(n,JSON.stringify(i,null,2))}async function updateComposerJson(e,t){if(!t.websocket)return;const s=path.join(e,"composer.json");let n;if(fs.existsSync(s)){{const e=fs.readFileSync(s,"utf8");n=JSON.parse(e)}t.websocket&&(n.require=Object.assign(Object.assign({},n.require),{"cboden/ratchet":"^0.4.4"})),fs.writeFileSync(s,JSON.stringify(n,null,2))}}async function updateIndexJsForWebSocket(e,t){if(!t.websocket)return;const s=path.join(e,"src","app","js","index.js");let n=fs.readFileSync(s,"utf8");n+='\n// WebSocket initialization\nconst ws = new WebSocket("ws://localhost:8080");\n',fs.writeFileSync(s,n,"utf8")}async function createUpdateGitignoreFile(e,t){const s=path.join(e,".gitignore");let n="";fs.existsSync(s)&&(n=fs.readFileSync(s,"utf8")),t.forEach((e=>{n.includes(e)||(n+=`\n${e}`)})),n=n.trimStart(),fs.writeFileSync(s,n)}function copyRecursiveSync(e,t){const s=fs.existsSync(e),n=s&&fs.statSync(e);s&&n&&n.isDirectory()?(fs.existsSync(t)&&fs.rmSync(t,{recursive:!0,force:!0}),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 n=["./src/app/**/*.{html,js,php}"].map((e=>` "${e}"`)).join(",\n");s=s.replace(/content: \[\],/g,`content: [\n${n}\n],`),fs.writeFileSync(t,s,"utf8")}function modifyPostcssConfig(e){const t=path.join(e,"postcss.config.js");fs.writeFileSync(t,"export default {\n plugins: {\n tailwindcss: {},\n autoprefixer: {},\n cssnano: {},\n },\n};","utf8")}function modifyIndexPHP(e,t){const s=path.join(e,"src","app","layout.php");try{let e=fs.readFileSync(s,"utf8");const n='\n <link href="<?php echo $baseUrl; ?>css/index.css" rel="stylesheet">\n <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">\n <script src="<?php echo $baseUrl; ?>js/index.js"><\/script>',i=t?` <link href="<?php echo $baseUrl; ?>css/styles.css" rel="stylesheet"> ${n}`:` <script src="https://cdn.tailwindcss.com"><\/script> ${n}`;e=e.replace("</head>",`${i}\n</head>`),fs.writeFileSync(s,e,"utf8")}catch(e){}}async function updateOrCreateEnvFile(e,t){const s=path.join(e,".env");let n=fs.existsSync(s)?fs.readFileSync(s,"utf8"):"";n+=`${""!==n?"\n\n":""}${t}`,fs.writeFileSync(s,n)}async function createDirectoryStructure(e,t,s){[{src:"/bootstrap.php",dest:"/bootstrap.php"},{src:"/.htaccess",dest:"/.htaccess"},{src:"/../composer.json",dest:"/composer.json"}].forEach((({src:t,dest:s})=>{const n=path.join(__dirname,t),i=path.join(e,s),c=fs.readFileSync(n,"utf8");fs.writeFileSync(i,c,{flag:"w"})})),await executeCopy(e,[{srcDir:"/settings",destDir:"/settings"},{srcDir:"/prisma",destDir:"/prisma"},{srcDir:"/src",destDir:"/src"},{srcDir:"/../vendor",destDir:"/vendor"}]),await updatePackageJson(e,s,t),await updateComposerJson(e,t),await updateIndexJsForWebSocket(e,t),t.tailwindcss?(modifyTailwindConfig(e),modifyIndexPHP(e,!0),modifyPostcssConfig(e)):modifyIndexPHP(e,!1);await updateOrCreateEnvFile(e,'# PHPMailer\nSMTP_HOST=\nSMTP_USERNAME=\nSMTP_PASSWORD=\nSMTP_PORT=\nSMTP_ENCRYPTION=ssl\nMAIL_FROM=\nMAIL_FROM_NAME=""'),await createUpdateGitignoreFile(e,["vendor"])}async function getAnswer(e={}){var t,s,n;const i=[];e.projectName||i.push({type:"text",name:"projectName",message:"What is your project named?",initial:"my-app"}),e.tailwindcss||i.push({type:"toggle",name:"tailwindcss",message:`Would you like to use ${chalk.blue("Tailwind CSS")}?`,initial:!0,active:"Yes",inactive:"No"}),e.websocket||i.push({type:"toggle",name:"websocket",message:`Would you like to use ${chalk.blue("Websocket")}?`,initial:!0,active:"Yes",inactive:"No"});const c=()=>!1;try{const r=await prompts(i,{onCancel:c});return 0===Object.keys(r).length?null:{projectName:r.projectName?String(r.projectName).trim().replace(/ /g,"-"):null!==(t=e.projectName)&&void 0!==t?t:"my-app",tailwindcss:null!==(s=r.tailwindcss)&&void 0!==s?s:e.tailwindcss,websocket:null!==(n=r.websocket)&&void 0!==n?n:e.websocket}}catch(e){return null}}async function installDependencies(e,t,s=!1){fs.existsSync(path.join(e,"package.json"))||execSync("npm init -y",{stdio:"inherit",cwd:e}),t.forEach((e=>{}));const n=`npm install ${s?"--save-dev":""} ${t.join(" ")}`;execSync(n,{stdio:"inherit",cwd:e})}function fetchPackageVersion(e){return new Promise(((t,s)=>{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);t(e["dist-tags"].latest)}catch(e){s(new Error("Failed to parse JSON response"))}}))})).on("error",(e=>s(e)))}))}
|
|
3
3
|
async function main() {
|
|
4
4
|
try {
|
|
5
5
|
const args = process.argv.slice(2);
|
package/dist/prisma-php.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{spawn}from"child_process";import fs from"fs";import path from"path";import{fileURLToPath}from"url";const __filename=fileURLToPath(import.meta.url),__dirname=path.dirname(__filename),args=process.argv.slice(2),readJsonFile=
|
|
2
|
+
import{spawn}from"child_process";import fs from"fs";import path from"path";import prompts from"prompts";import{fileURLToPath}from"url";const __filename=fileURLToPath(import.meta.url),__dirname=path.dirname(__filename),args=process.argv.slice(2),readJsonFile=r=>{const e=fs.readFileSync(r,"utf8");return JSON.parse(e)},executeCommand=(r,e=[],o={})=>new Promise(((s,t)=>{const i=spawn(r,e,Object.assign({stdio:"inherit",shell:!0},o));i.on("error",(r=>{t(r)})),i.on("close",(r=>{0===r?s():t(new Error(`Process exited with code ${r}`))}))}));
|
|
3
3
|
const main = async () => {
|
|
4
4
|
if (args.length > 0 && args[0] === "update") {
|
|
5
5
|
try {
|
|
6
|
+
const shouldProceed = await prompts({
|
|
7
|
+
type: "confirm",
|
|
8
|
+
name: "value",
|
|
9
|
+
message: "This will overwrite existing files and directories. Do you want to continue?",
|
|
10
|
+
initial: false,
|
|
11
|
+
});
|
|
12
|
+
if (!shouldProceed.value) {
|
|
13
|
+
console.log("Operation cancelled by the user.");
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
6
16
|
const currentDir = process.cwd();
|
|
7
17
|
const configPath = path.join(currentDir, "prisma-php.json");
|
|
8
18
|
const localSettings = readJsonFile(configPath);
|