create-prisma-php-app 1.6.9 → 1.6.11

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.
Files changed (2) hide show
  1. package/dist/index.js +151 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,2 +1,152 @@
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.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?[]:[{type:"text",name:"projectName",message:"What is your project named?",initial:"my-app"}],...e.projectName?[]:[{type:"toggle",name:"tailwindcss",message:`Would you like to use ${chalk.blue("Tailwind CSS")}?`,initial:!0,active:"Yes",inactive:"No"}],...e.projectName?[]:[{type:"toggle",name:"websocket",message:`Would you like to use ${chalk.blue("Websocket")}?`,initial:!0,active:"Yes",inactive:"No"}]],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){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)))}))}async function main(){try{const e=process.argv.slice(2);let t=e[0],s=null;if(t){let n=e.includes("--tailwind"),i=e.includes("--websocket");const c={projectName:t,tailwindcss:n,websocket:i},r=await getAnswer(c);t=r.projectName,n=n||r.tailwindcss,i=i||r.websocket,s={projectName:t,tailwindcss:n,websocket:i}}else s=await getAnswer();if(null===s)return;execSync("npm install -g create-prisma-php-app@alpha-update-command",{stdio:"inherit"}),execSync("npm install -g browser-sync",{stdio:"inherit"}),t||fs.mkdirSync(s.projectName);const n=path.join(process.cwd(),s.projectName);t||process.chdir(s.projectName);const i=["prisma","@prisma/client","typescript","@types/node","ts-node","http-proxy-middleware"];s.tailwindcss&&i.push("tailwindcss","autoprefixer","postcss","postcss-cli","cssnano"),s.websocket&&i.push("chokidar-cli"),(s.tailwindcss||s.websocket)&&i.push("npm-run-all"),await installDependencies(n,i,!0),execSync("npx prisma init",{stdio:"inherit"}),execSync("npx tsc --init",{stdio:"inherit"}),s.tailwindcss&&execSync("npx tailwindcss init -p",{stdio:"inherit"});const c={PROJECT_NAME:s.projectName,PROJECT_ROOT_PATH:n.replace(/\\/g,"\\\\"),PHP_ROOT_PATH_EXE:"D:\\\\xampp\\\\php\\\\php.exe",PHP_GENERATE_CLASS_PATH:"src/lib/prisma/classes"};await createDirectoryStructure(n,s,c);const r=path.join(n,"settings","project-settings.js"),o=`export const projectSettings = {\n PROJECT_NAME: "${s.projectName}",\n PROJECT_ROOT_PATH: "${n.replace(/\\/g,"\\\\")}",\n PHP_ROOT_PATH_EXE: "D:\\\\xampp\\\\php\\\\php.exe",\n PHP_GENERATE_CLASS_PATH: "src/lib/prisma/classes",\n };`;if(fs.writeFileSync(r,o),fs.mkdirSync(path.join(n,"public")),!s.tailwindcss){const e=path.join(n,"src","app","css");["tailwind.css","styles.css"].forEach((t=>{const s=path.join(e,t);fs.existsSync(s)&&fs.unlinkSync(s)}))}if(!s.websocket){const e=path.join(n,"src","lib","websocket");fs.existsSync(e)&&fs.rmSync(e,{recursive:!0,force:!0});const t=path.join(n,"settings");["restartWebsocket.cjs","restart_websocket.bat"].forEach((e=>{const s=path.join(t,e);fs.existsSync(s)&&fs.unlinkSync(s)}))}const a=await fetchPackageVersion("create-prisma-php-app"),p={projectName:s.projectName,tailwindcss:s.tailwindcss,websocket:s.websocket,version:a};fs.writeFileSync(path.join(n,"prisma-php.json"),JSON.stringify(p,null,2))}catch(e){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";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 r=`http://localhost/${i}`;r=r.endsWith("/")?r.slice(0,-1):r;const c=r.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 "${c}",\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")),r=configureBrowserSyncCommand(e,t);i.scripts=Object.assign(Object.assign({},i.scripts),{postinstall:"prisma generate"});let c=[];s.tailwindcss&&(i.scripts=Object.assign(Object.assign({},i.scripts),{tailwind:"postcss ./src/app/css/tailwind.css -o ./src/app/css/styles.css --watch"}),c.push("tailwind")),s.websocket&&(i.scripts=Object.assign(Object.assign({},i.scripts),{websocket:"node ./settings/restartWebsocket.cjs"}),c.push("websocket"));const o=Object.assign({},i.scripts);c.length>0&&(o["browser-sync"]=r),o.dev=c.length>0?`npm-run-all --parallel browser-sync ${c.join(" ")}`:r,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.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),r=fs.readFileSync(n,"utf8");fs.writeFileSync(i,r)})),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?[]:[{type:"text",name:"projectName",message:"What is your project named?",initial:"my-app"}],...e.projectName?[]:[{type:"toggle",name:"tailwindcss",message:`Would you like to use ${chalk.blue("Tailwind CSS")}?`,initial:!0,active:"Yes",inactive:"No"}],...e.projectName?[]:[{type:"toggle",name:"websocket",message:`Would you like to use ${chalk.blue("Websocket")}?`,initial:!0,active:"Yes",inactive:"No"}]],r=()=>!1;try{const c=await prompts(i,{onCancel:r});return 0===Object.keys(c).length?null:{projectName:c.projectName?String(c.projectName).trim().replace(/ /g,"-"):null!==(t=e.projectName)&&void 0!==t?t:"my-app",tailwindcss:null!==(s=c.tailwindcss)&&void 0!==s?s:e.tailwindcss,websocket:null!==(n=c.websocket)&&void 0!==n?n:e.websocket}}catch(e){return null}}async function installDependencies(e,t,s=!1){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
+ async function main() {
4
+ try {
5
+ const args = process.argv.slice(2);
6
+ let projectName = args[0];
7
+ console.log("🚀 ~ main ~ projectName:", projectName);
8
+ let answer = null;
9
+ if (projectName) {
10
+ let useTailwind = args.includes("--tailwind");
11
+ let useWebsocket = args.includes("--websocket");
12
+ const predefinedAnswers = {
13
+ projectName,
14
+ tailwindcss: useTailwind,
15
+ websocket: useWebsocket,
16
+ };
17
+ const response = (await getAnswer(predefinedAnswers));
18
+ projectName = response.projectName;
19
+ useTailwind = useTailwind || response.tailwindcss;
20
+ useWebsocket = useWebsocket || response.websocket;
21
+ answer = {
22
+ projectName,
23
+ tailwindcss: useTailwind,
24
+ websocket: useWebsocket,
25
+ };
26
+ }
27
+ else {
28
+ answer = await getAnswer();
29
+ }
30
+ if (answer === null) {
31
+ console.log(chalk.red("Installation cancelled."));
32
+ return;
33
+ }
34
+ // execSync(`npm install -g create-prisma-php-app`, { stdio: "inherit" }); // TODO: Uncomment this line before publishing the package
35
+ execSync(`npm install -g create-prisma-php-app@alpha-update-command`, {
36
+ stdio: "inherit",
37
+ }); // TODO: Uncomment this line before publishing the package
38
+ // Support for browser-sync
39
+ execSync(`npm install -g browser-sync`, { stdio: "inherit" });
40
+ // Create the project directory
41
+ if (!projectName)
42
+ fs.mkdirSync(answer.projectName);
43
+ const projectPath = path.join(process.cwd(), answer.projectName);
44
+ console.log("🚀 ~ main ~ projectPath:", projectPath)
45
+ process.chdir(answer.projectName);
46
+ const dependencies = [
47
+ "prisma",
48
+ "@prisma/client",
49
+ "typescript",
50
+ "@types/node",
51
+ "ts-node",
52
+ "http-proxy-middleware",
53
+ ];
54
+ if (answer.tailwindcss) {
55
+ dependencies.push("tailwindcss", "autoprefixer", "postcss", "postcss-cli", "cssnano");
56
+ }
57
+ if (answer.websocket) {
58
+ dependencies.push("chokidar-cli");
59
+ }
60
+ if (answer.tailwindcss || answer.websocket) {
61
+ dependencies.push("npm-run-all");
62
+ }
63
+ await installDependencies(projectPath, dependencies, true);
64
+ execSync(`npx prisma init`, { stdio: "inherit" });
65
+ execSync(`npx tsc --init`, { stdio: "inherit" });
66
+ if (answer.tailwindcss) {
67
+ execSync(`npx tailwindcss init -p`, { stdio: "inherit" });
68
+ }
69
+ const projectSettings = {
70
+ PROJECT_NAME: answer.projectName,
71
+ PROJECT_ROOT_PATH: projectPath.replace(/\\/g, "\\\\"),
72
+ PHP_ROOT_PATH_EXE: "D:\\\\xampp\\\\php\\\\php.exe",
73
+ PHP_GENERATE_CLASS_PATH: "src/lib/prisma/classes",
74
+ };
75
+ await createDirectoryStructure(projectPath, answer, projectSettings);
76
+ // if (answer.tailwindcss) {
77
+ // execSync(
78
+ // `npx tailwindcss -i ./src/app/css/tailwind.css -o ./src/app/css/styles.css --minify`,
79
+ // { stdio: "inherit" }
80
+ // );
81
+ // }
82
+ // execSync(`composer install`, { stdio: "inherit" });
83
+ // execSync(`composer dump-autoload`, { stdio: "inherit" });
84
+ // Create settings file
85
+ const settingsPath = path.join(projectPath, "settings", "project-settings.js");
86
+ const settingsCode = `export const projectSettings = {
87
+ PROJECT_NAME: "${answer.projectName}",
88
+ PROJECT_ROOT_PATH: "${projectPath.replace(/\\/g, "\\\\")}",
89
+ PHP_ROOT_PATH_EXE: "D:\\\\xampp\\\\php\\\\php.exe",
90
+ PHP_GENERATE_CLASS_PATH: "src/lib/prisma/classes",
91
+ };`;
92
+ fs.writeFileSync(settingsPath, settingsCode);
93
+ // Create public directory
94
+ fs.mkdirSync(path.join(projectPath, "public"));
95
+ // Update css if tailwindcss is not chosen by the user
96
+ if (!answer.tailwindcss) {
97
+ // delete specific files of tailwindcss if not chosen
98
+ const cssPath = path.join(projectPath, "src", "app", "css");
99
+ const tailwindFiles = ["tailwind.css", "styles.css"];
100
+ tailwindFiles.forEach((file) => {
101
+ const filePath = path.join(cssPath, file);
102
+ if (fs.existsSync(filePath)) {
103
+ fs.unlinkSync(filePath); // Delete each file if it exists
104
+ console.log(`${file} was deleted successfully.`);
105
+ }
106
+ else {
107
+ console.log(`${file} does not exist.`);
108
+ }
109
+ });
110
+ }
111
+ // Update websocket if not chosen by the user
112
+ if (!answer.websocket) {
113
+ const wsPath = path.join(projectPath, "src", "lib", "websocket");
114
+ // Check if the websocket directory exists
115
+ if (fs.existsSync(wsPath)) {
116
+ // Use fs.rmSync with recursive option set to true to delete the directory and its contents
117
+ fs.rmSync(wsPath, { recursive: true, force: true }); // force option is not necessary but can be used to ensure deletion
118
+ console.log("Websocket directory was deleted successfully.");
119
+ }
120
+ else {
121
+ console.log("Websocket directory does not exist.");
122
+ }
123
+ // Update settings directory if websocket is not chosen
124
+ const settingsPath = path.join(projectPath, "settings");
125
+ const websocketFiles = ["restartWebsocket.cjs", "restart_websocket.bat"];
126
+ websocketFiles.forEach((file) => {
127
+ const filePath = path.join(settingsPath, file);
128
+ if (fs.existsSync(filePath)) {
129
+ fs.unlinkSync(filePath); // Delete each file if it exists
130
+ console.log(`${file} was deleted successfully.`);
131
+ }
132
+ else {
133
+ console.log(`${file} does not exist.`);
134
+ }
135
+ });
136
+ }
137
+ const version = await fetchPackageVersion("create-prisma-php-app");
138
+ const prismaPhpConfig = {
139
+ projectName: answer.projectName,
140
+ tailwindcss: answer.tailwindcss,
141
+ websocket: answer.websocket,
142
+ version,
143
+ };
144
+ fs.writeFileSync(path.join(projectPath, "prisma-php.json"), JSON.stringify(prismaPhpConfig, null, 2));
145
+ console.log(`${chalk.green("Success!")} Prisma PHP project successfully created in ${answer.projectName}!`);
146
+ }
147
+ catch (error) {
148
+ console.error("Error while creating the project:", error);
149
+ process.exit(1);
150
+ }
151
+ }
152
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "1.6.9",
3
+ "version": "1.6.11",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",