create-prisma-php-app 1.22.506 → 1.22.508

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 CHANGED
@@ -1,963 +1,370 @@
1
1
  #!/usr/bin/env node
2
- import { execSync } from "child_process";
3
- import fs from "fs";
4
- import { fileURLToPath } from "url";
5
- import path from "path";
6
- import chalk from "chalk";
7
- import prompts from "prompts";
8
- import https from "https";
9
- const __filename = fileURLToPath(import.meta.url);
10
- const __dirname = path.dirname(__filename);
11
- let updateAnswer = null;
12
- const nonBackendFiles = [
13
- "favicon.ico",
14
- "\\src\\app\\index.php",
15
- "metadata.php",
16
- "not-found.php",
17
- ];
18
- const dockerFiles = [
19
- ".dockerignore",
20
- "docker-compose.yml",
21
- "Dockerfile",
22
- "apache.conf",
23
- ];
24
- function bsConfigUrls(projectRootPath) {
25
- // Identify the base path dynamically up to and including 'htdocs'
26
- const htdocsIndex = projectRootPath.indexOf("\\htdocs\\");
27
- if (htdocsIndex === -1) {
28
- console.error("Invalid PROJECT_ROOT_PATH. The path does not contain \\htdocs\\");
29
- return {
30
- bsTarget: "",
31
- bsPathRewrite: {},
32
- };
33
- }
34
- // Extract the path up to and including 'htdocs\\'
35
- const basePathToRemove = projectRootPath.substring(0, htdocsIndex + "\\htdocs\\".length);
36
- // Escape backslashes for the regex pattern
37
- const escapedBasePathToRemove = basePathToRemove.replace(/\\/g, "\\\\");
38
- // Remove the base path and replace backslashes with forward slashes for URL compatibility
39
- const relativeWebPath = projectRootPath
40
- .replace(new RegExp(`^${escapedBasePathToRemove}`), "")
41
- .replace(/\\/g, "/");
42
- // Construct the Browser Sync command with the correct proxy URL, being careful not to affect the protocol part
43
- let proxyUrl = `http://localhost/${relativeWebPath}`;
44
- // Ensure the proxy URL does not end with a slash before appending '/public'
45
- proxyUrl = proxyUrl.endsWith("/") ? proxyUrl.slice(0, -1) : proxyUrl;
46
- // Clean the URL by replacing "//" with "/" but not affecting "http://"
47
- // We replace instances of "//" that are not preceded by ":"
48
- const cleanUrl = proxyUrl.replace(/(?<!:)(\/\/+)/g, "/");
49
- const cleanRelativeWebPath = relativeWebPath.replace(/\/\/+/g, "/");
50
- // Correct the relativeWebPath to ensure it does not start with a "/"
51
- const adjustedRelativeWebPath = cleanRelativeWebPath.startsWith("/")
52
- ? cleanRelativeWebPath.substring(1)
53
- : cleanRelativeWebPath;
54
- return {
55
- bsTarget: `${cleanUrl}/`,
56
- bsPathRewrite: {
57
- "^/": `/${adjustedRelativeWebPath}/`,
58
- },
59
- };
60
- }
61
- function configureBrowserSyncCommand(baseDir) {
62
- // TypeScript content to write
63
- const bsConfigTsContent = `const { createProxyMiddleware } = require("http-proxy-middleware");
64
- const fs = require("fs");
65
- const chokidar = require("chokidar");
66
- const { execSync } = require("child_process");
67
-
68
- const jsonData = fs.readFileSync("prisma-php.json", "utf8");
69
- const config = JSON.parse(jsonData);
70
-
71
- // Watch for file changes (create, delete, save)
72
- const watcher = chokidar.watch("src/**/*", {
73
- ignored: /(^|[\\/\\\\])\\\../,
74
- persistent: true,
75
- usePolling: true,
76
- interval: 1000,
77
- });
78
-
79
- watcher
80
- .on("add", async (path) => {
81
- execSync("node settings/files-list-config.js");
82
- })
83
- .on("change", async (path) => {
84
- execSync("node settings/files-list-config.js");
85
- })
86
- .on("unlink", async (path) => {
87
- execSync("node settings/files-list-config.js");
88
- });
89
-
90
- module.exports = {
91
- proxy: "http://localhost:3000",
92
- middleware: [
93
- (req, res, next) => {
94
- res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
95
- res.setHeader("Pragma", "no-cache");
96
- res.setHeader("Expires", "0");
97
- next();
98
- },
99
- createProxyMiddleware({
100
- target: config.bsTarget,
101
- changeOrigin: true,
102
- pathRewrite: config.bsPathRewrite,
103
- }),
104
- ],
105
- files: "src/**/*.*",
106
- notify: false,
107
- open: false,
108
- ghostMode: false,
109
- codeSync: true, // Disable synchronization of code changes across clients
110
- watchOptions: {
111
- usePolling: true,
112
- interval: 1000,
113
- },
114
- };`;
115
- // Determine the path and write the bs-config.js
116
- const bsConfigPath = path.join(baseDir, "settings", "bs-config.cjs");
117
- fs.writeFileSync(bsConfigPath, bsConfigTsContent, "utf8");
118
- // Return the Browser Sync command string, using the cleaned URL
119
- return `browser-sync start --config settings/bs-config.cjs`;
120
- }
121
- async function updatePackageJson(baseDir, answer) {
122
- const packageJsonPath = path.join(baseDir, "package.json");
123
- if (checkExcludeFiles(packageJsonPath))
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);let updateAnswer=null;const nonBackendFiles=["favicon.ico","\\src\\app\\index.php","metadata.php","not-found.php"],dockerFiles=[".dockerignore","docker-compose.yml","Dockerfile","apache.conf"];function bsConfigUrls(e){const s=e.indexOf("\\htdocs\\");if(-1===s)return{bsTarget:"",bsPathRewrite:{}};const t=e.substring(0,s+"\\htdocs\\".length).replace(/\\/g,"\\\\"),n=e.replace(new RegExp(`^${t}`),"").replace(/\\/g,"/");let i=`http://localhost/${n}`;i=i.endsWith("/")?i.slice(0,-1):i;const c=i.replace(/(?<!:)(\/\/+)/g,"/"),o=n.replace(/\/\/+/g,"/");return{bsTarget:`${c}/`,bsPathRewrite:{"^/":`/${o.startsWith("/")?o.substring(1):o}/`}}}async function updatePackageJson(e,s){const t=path.join(e,"package.json");if(checkExcludeFiles(t))return;const n=JSON.parse(fs.readFileSync(t,"utf8"));n.scripts=Object.assign(Object.assign({},n.scripts),{projectName:"node settings/project-name.js"});let i=[];s.tailwindcss&&(n.scripts=Object.assign(Object.assign({},n.scripts),{tailwind:"postcss src/app/css/tailwind.css -o src/app/css/styles.css --watch"}),i.push("tailwind")),s.websocket&&(n.scripts=Object.assign(Object.assign({},n.scripts),{websocket:"node settings/restart-websocket.js"}),i.push("websocket")),s.docker&&(n.scripts=Object.assign(Object.assign({},n.scripts),{docker:"docker-compose up"}),i.push("docker")),s.swaggerDocs&&(n.scripts=Object.assign(Object.assign({},n.scripts),{"create-swagger-docs":"node settings/swagger-config.js"}),i.push("create-swagger-docs"));let c=Object.assign({},n.scripts);c.browserSync="node settings/bs-config.js",c.dev=`npm-run-all -p projectName browserSync ${i.join(" ")}`,n.scripts=c,n.type="module",s.prisma&&(n.prisma={seed:"node prisma/seed.js"}),fs.writeFileSync(t,JSON.stringify(n,null,2))}async function updateComposerJson(e,s){const t=path.join(e,"composer.json");if(checkExcludeFiles(t))return;let n;if(fs.existsSync(t)){{const e=fs.readFileSync(t,"utf8");n=JSON.parse(e)}s.websocket&&(n.require=Object.assign(Object.assign({},n.require),{"cboden/ratchet":"^0.4.4"})),s.prisma&&(n.require=Object.assign(Object.assign({},n.require),{"ramsey/uuid":"5.x-dev","hidehalo/nanoid-php":"1.x-dev"})),fs.writeFileSync(t,JSON.stringify(n,null,2))}}async function updateIndexJsForWebSocket(e,s){if(!s.websocket)return;const t=path.join(e,"src","app","js","index.js");if(checkExcludeFiles(t))return;let n=fs.readFileSync(t,"utf8");n+='\n// WebSocket initialization\nconst ws = new WebSocket("ws://localhost:8080");\n',fs.writeFileSync(t,n,"utf8")}async function createUpdateGitignoreFile(e,s){const t=path.join(e,".gitignore");if(checkExcludeFiles(t))return;let n="";s.forEach((e=>{n.includes(e)||(n+=`\n${e}`)})),n=n.trimStart(),fs.writeFileSync(t,n)}function copyRecursiveSync(e,s,t){var n;const i=fs.existsSync(e),c=i&&fs.statSync(e);if(i&&c&&c.isDirectory()){const i=s.toLowerCase();if(!t.websocket&&i.includes("src\\lib\\websocket"))return;if(!t.prisma&&i.includes("src\\lib\\prisma"))return;if(t.backendOnly&&i.includes("src\\app\\js")||t.backendOnly&&i.includes("src\\app\\css"))return;if(!t.swaggerDocs&&i.includes("src\\app\\swagger-docs"))return;const c=s.replace(/\\/g,"/");if(null===(n=null==updateAnswer?void 0:updateAnswer.excludeFilePath)||void 0===n?void 0:n.includes(c))return;fs.existsSync(s)||fs.mkdirSync(s,{recursive:!0}),fs.readdirSync(e).forEach((n=>{copyRecursiveSync(path.join(e,n),path.join(s,n),t)}))}else{if(checkExcludeFiles(s))return;if(!t.tailwindcss&&(s.includes("tailwind.css")||s.includes("styles.css")))return;if(!t.websocket&&(s.includes("restart-websocket.cjs")||s.includes("restart-websocket.bat")))return;if(!t.docker&&dockerFiles.some((e=>s.includes(e))))return;if(t.backendOnly&&nonBackendFiles.some((e=>s.includes(e))))return;if(!t.backendOnly&&s.includes("route.php"))return;if(!t.swaggerDocs&&s.includes("swagger-config.js"))return;fs.copyFileSync(e,s,0)}}async function executeCopy(e,s,t){s.forEach((({src:s,dest:n})=>{copyRecursiveSync(path.join(__dirname,s),path.join(e,n),t)}))}function createOrUpdateTailwindConfig(e){const s=path.join(e,"tailwind.config.js");if(checkExcludeFiles(s))return;let t=fs.readFileSync(s,"utf8");const n=["./src/**/*.{html,js,php}"].map((e=>` "${e}"`)).join(",\n");t=t.replace(/content: \[\],/g,`content: [\n${n}\n],`),fs.writeFileSync(s,t,{flag:"w"})}function modifyPostcssConfig(e){const s=path.join(e,"postcss.config.js");if(checkExcludeFiles(s))return;fs.writeFileSync(s,"export default {\n plugins: {\n tailwindcss: {},\n autoprefixer: {},\n cssnano: {},\n },\n};",{flag:"w"})}function modifyLayoutPHP(e,s){const t=path.join(e,"src","app","layout.php");if(!checkExcludeFiles(t))try{let e=fs.readFileSync(t,"utf8"),n="";s.backendOnly||(n='\n <link href="<?= $baseUrl; ?>/css/index.css" rel="stylesheet">\n <script src="<?= $baseUrl; ?>/js/index.js"><\/script>');let i="";s.backendOnly||(i=s.tailwindcss?` <link href="<?= $baseUrl; ?>/css/styles.css" rel="stylesheet"> ${n}`:` <script src="https://cdn.tailwindcss.com"><\/script> ${n}`);const c=i.length>0?"\n":"";e=e.replace("</head>",`${i}${c} \x3c!-- Dynamic Head --\x3e\n <?= implode("\\n", $mainLayoutHead); ?>\n</head>`),fs.writeFileSync(t,e,{flag:"w"})}catch(e){}}async function createOrUpdateEnvFile(e,s){const t=path.join(e,".env");checkExcludeFiles(t)||fs.writeFileSync(t,s,{flag:"w"})}function checkExcludeFiles(e){var s,t;return!!(null==updateAnswer?void 0:updateAnswer.isUpdate)&&(null!==(t=null===(s=null==updateAnswer?void 0:updateAnswer.excludeFilePath)||void 0===s?void 0:s.includes(e.replace(/\\/g,"/")))&&void 0!==t&&t)}async function createDirectoryStructure(e,s){const t=[{src:"/bootstrap.php",dest:"/bootstrap.php"},{src:"/.htaccess",dest:"/.htaccess"},{src:"/../composer.json",dest:"/composer.json"},{src:"/tsconfig.json",dest:"/tsconfig.json"}];s.tailwindcss&&t.push({src:"/postcss.config.js",dest:"/postcss.config.js"},{src:"/tailwind.config.js",dest:"/tailwind.config.js"});const n=[{src:"/settings",dest:"/settings"},{src:"/src",dest:"/src"}];s.backendOnly&&s.swaggerDocs&&n.push({src:"/swagger-docs-layout.php",dest:"/src/app/layout.php"}),s.prisma&&n.push({src:"/prisma",dest:"/prisma"}),s.docker&&n.push({src:"/.dockerignore",dest:"/.dockerignore"},{src:"/docker-compose.yml",dest:"/docker-compose.yml"},{src:"/Dockerfile",dest:"/Dockerfile"},{src:"/apache.conf",dest:"/apache.conf"}),t.forEach((({src:s,dest:t})=>{const n=path.join(__dirname,s),i=path.join(e,t);if(checkExcludeFiles(i))return;const c=fs.readFileSync(n,"utf8");fs.writeFileSync(i,c,{flag:"w"})})),await executeCopy(e,n,s),await updatePackageJson(e,s),await updateComposerJson(e,s),s.backendOnly||await updateIndexJsForWebSocket(e,s),s.tailwindcss&&(createOrUpdateTailwindConfig(e),modifyPostcssConfig(e)),(s.tailwindcss||!s.backendOnly||s.swaggerDocs)&&modifyLayoutPHP(e,s);const i='# Prisma PHP Auth Secret Key For development only - Change this in production\nAUTH_SECRET=uxsjXVPHN038DEYls2Kw0QUgBcXKUyrjv416nIFWPY4= \n \n# PHPMailer\n# SMTP_HOST=smtp.gmail.com or your SMTP host\n# SMTP_USERNAME=john.doe@gmail.com or your SMTP username\n# SMTP_PASSWORD=123456\n# SMTP_PORT=587 for TLS, 465 for SSL or your SMTP port\n# SMTP_ENCRYPTION=ssl or tls\n# MAIL_FROM=john.doe@gmail.com\n# MAIL_FROM_NAME="John Doe"\n\n# SHOW ERRORS - Set to true to show errors in the browser for development only - Change this in production to false\nSHOW_ERRORS=true\n\n# APP TIMEZONE - Set your application timezone - Default is "UTC"\nAPP_TIMEZONE="UTC"\n\n# APP ENV - Set your application environment - Default is "development" - Change this in production to "production"\nAPP_ENV=development';if(s.prisma){const s=`${'# Environment variables declared in this file are automatically made available to Prisma.\n# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema\n\n# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.\n# See the documentation for all the connection string options: https://pris.ly/d/connection-strings\n\nDATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"'}\n\n${i}`;await createOrUpdateEnvFile(e,s)}else await createOrUpdateEnvFile(e,i);await createUpdateGitignoreFile(e,["vendor",".env","node_modules"])}async function getAnswer(e={}){var s,t,n,i,c,o,a,r,l,p,d,u,g;const m=[];e.projectName||m.push({type:"text",name:"projectName",message:"What is your project named?",initial:"my-app"}),e.backendOnly||m.push({type:"toggle",name:"backendOnly",message:"Would you like to create a backend-only project?",initial:!1,active:"Yes",inactive:"No"});const f=()=>{process.exit(0)},h=await prompts(m,{onCancel:f}),y=[];h.backendOnly||e.backendOnly?(e.swaggerDocs||y.push({type:"toggle",name:"swaggerDocs",message:`Would you like to use ${chalk.blue("Swagger Docs")}?`,initial:!1,active:"Yes",inactive:"No"}),e.websocket||y.push({type:"toggle",name:"websocket",message:`Would you like to use ${chalk.blue("Websocket")}?`,initial:!0,active:"Yes",inactive:"No"}),e.prisma||y.push({type:"toggle",name:"prisma",message:`Would you like to use ${chalk.blue("Prisma PHP ORM")}?`,initial:!0,active:"Yes",inactive:"No"}),e.docker||y.push({type:"toggle",name:"docker",message:`Would you like to use ${chalk.blue("Docker")}?`,initial:!1,active:"Yes",inactive:"No"})):(e.swaggerDocs||y.push({type:"toggle",name:"swaggerDocs",message:`Would you like to use ${chalk.blue("Swagger Docs")}?`,initial:!1,active:"Yes",inactive:"No"}),e.tailwindcss||y.push({type:"toggle",name:"tailwindcss",message:`Would you like to use ${chalk.blue("Tailwind CSS")}?`,initial:!0,active:"Yes",inactive:"No"}),e.websocket||y.push({type:"toggle",name:"websocket",message:`Would you like to use ${chalk.blue("Websocket")}?`,initial:!0,active:"Yes",inactive:"No"}),e.prisma||y.push({type:"toggle",name:"prisma",message:`Would you like to use ${chalk.blue("Prisma PHP ORM")}?`,initial:!0,active:"Yes",inactive:"No"}),e.docker||y.push({type:"toggle",name:"docker",message:`Would you like to use ${chalk.blue("Docker")}?`,initial:!1,active:"Yes",inactive:"No"}));const w=await prompts(y,{onCancel:f});return{projectName:h.projectName?String(h.projectName).trim().replace(/ /g,"-"):null!==(s=e.projectName)&&void 0!==s?s:"my-app",backendOnly:null!==(n=null!==(t=h.backendOnly)&&void 0!==t?t:e.backendOnly)&&void 0!==n&&n,swaggerDocs:null!==(c=null!==(i=w.swaggerDocs)&&void 0!==i?i:e.swaggerDocs)&&void 0!==c&&c,tailwindcss:null!==(a=null!==(o=w.tailwindcss)&&void 0!==o?o:e.tailwindcss)&&void 0!==a&&a,websocket:null!==(l=null!==(r=w.websocket)&&void 0!==r?r:e.websocket)&&void 0!==l&&l,prisma:null!==(d=null!==(p=w.prisma)&&void 0!==p?p:e.prisma)&&void 0!==d&&d,docker:null!==(g=null!==(u=w.docker)&&void 0!==u?u:e.docker)&&void 0!==g&&g}}async function installDependencies(e,s,t=!1){fs.existsSync(path.join(e,"package.json"))||execSync("npm init -y",{stdio:"inherit",cwd:e}),s.forEach((e=>{}));const n=`npm install ${t?"--save-dev":""} ${s.join(" ")}`;execSync(n,{stdio:"inherit",cwd:e})}async function uninstallDependencies(e,s,t=!1){s.forEach((e=>{}));const n=`npm uninstall ${t?"--save-dev":"--save"} ${s.join(" ")}`;execSync(n,{stdio:"inherit",cwd:e})}function fetchPackageVersion(e){return new Promise(((s,t)=>{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);s(e["dist-tags"].latest)}catch(e){t(new Error("Failed to parse JSON response"))}}))})).on("error",(e=>t(e)))}))}const readJsonFile=e=>{const s=fs.readFileSync(e,"utf8");return JSON.parse(s)};function compareVersions(e,s){const t=e.split(".").map(Number),n=s.split(".").map(Number);for(let e=0;e<t.length;e++){if(t[e]>n[e])return 1;if(t[e]<n[e])return-1}return 0}function getInstalledPackageVersion(e){try{const s=execSync(`npm list -g ${e} --depth=0`).toString().match(new RegExp(`${e}@(\\d+\\.\\d+\\.\\d+)`));return s?s[1]:null}catch(e){return null}}
3
+ async function main() {
4
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
5
+ try {
6
+ const args = process.argv.slice(2);
7
+ let projectName = args[0];
8
+ let answer = null;
9
+ if (projectName) {
10
+ let useBackendOnly = args.includes("--backend-only");
11
+ let useSwaggerDocs = args.includes("--swagger-docs");
12
+ let useTailwind = args.includes("--tailwindcss");
13
+ let useWebsocket = args.includes("--websocket");
14
+ let usePrisma = args.includes("--prisma");
15
+ let useDocker = args.includes("--docker");
16
+ const predefinedAnswers = {
17
+ projectName,
18
+ backendOnly: useBackendOnly,
19
+ swaggerDocs: useSwaggerDocs,
20
+ tailwindcss: useTailwind,
21
+ websocket: useWebsocket,
22
+ prisma: usePrisma,
23
+ docker: useDocker,
24
+ };
25
+ answer = await getAnswer(predefinedAnswers);
26
+ if (answer === null) {
27
+ console.log(chalk.red("Installation cancelled."));
124
28
  return;
125
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
126
- // Use the new function to configure the Browser Sync command
127
- const browserSyncCommand = configureBrowserSyncCommand(baseDir);
128
- packageJson.scripts = Object.assign(Object.assign({}, packageJson.scripts), { projectName: "node settings/project-name.cjs" });
129
- let answersToInclude = [];
130
- if (answer.tailwindcss) {
131
- packageJson.scripts = Object.assign(Object.assign({}, packageJson.scripts), { tailwind: "postcss ./src/app/css/tailwind.css -o ./src/app/css/styles.css --watch" });
132
- answersToInclude.push("tailwind");
133
- }
134
- if (answer.websocket) {
135
- packageJson.scripts = Object.assign(Object.assign({}, packageJson.scripts), { websocket: "node ./settings/restart-websocket.cjs" });
136
- answersToInclude.push("websocket");
137
- }
138
- // if (answer.prisma) {
139
- // packageJson.scripts = {
140
- // ...packageJson.scripts,
141
- // postinstall: "prisma generate",
142
- // };
143
- // }
144
- if (answer.docker) {
145
- packageJson.scripts = Object.assign(Object.assign({}, packageJson.scripts), { docker: "docker-compose up" });
146
- answersToInclude.push("docker");
147
- }
29
+ }
30
+ const currentDir = process.cwd();
31
+ const configPath = path.join(currentDir, "prisma-php.json");
32
+ const localSettings = readJsonFile(configPath);
33
+ let excludeFiles = [];
34
+ (_a = localSettings.excludeFiles) === null || _a === void 0
35
+ ? void 0
36
+ : _a.map((file) => {
37
+ const filePath = path.join(currentDir, file);
38
+ if (fs.existsSync(filePath))
39
+ excludeFiles.push(filePath.replace(/\\/g, "/"));
40
+ });
41
+ updateAnswer = {
42
+ projectName,
43
+ backendOnly:
44
+ (_b =
45
+ answer === null || answer === void 0
46
+ ? void 0
47
+ : answer.backendOnly) !== null && _b !== void 0
48
+ ? _b
49
+ : false,
50
+ swaggerDocs:
51
+ (_c =
52
+ answer === null || answer === void 0
53
+ ? void 0
54
+ : answer.swaggerDocs) !== null && _c !== void 0
55
+ ? _c
56
+ : false,
57
+ tailwindcss:
58
+ (_d =
59
+ answer === null || answer === void 0
60
+ ? void 0
61
+ : answer.tailwindcss) !== null && _d !== void 0
62
+ ? _d
63
+ : false,
64
+ websocket:
65
+ (_e =
66
+ answer === null || answer === void 0
67
+ ? void 0
68
+ : answer.websocket) !== null && _e !== void 0
69
+ ? _e
70
+ : false,
71
+ prisma:
72
+ (_f =
73
+ answer === null || answer === void 0 ? void 0 : answer.prisma) !==
74
+ null && _f !== void 0
75
+ ? _f
76
+ : false,
77
+ docker:
78
+ (_g =
79
+ answer === null || answer === void 0 ? void 0 : answer.docker) !==
80
+ null && _g !== void 0
81
+ ? _g
82
+ : false,
83
+ isUpdate: true,
84
+ excludeFiles:
85
+ (_h = localSettings.excludeFiles) !== null && _h !== void 0 ? _h : [],
86
+ excludeFilePath:
87
+ excludeFiles !== null && excludeFiles !== void 0 ? excludeFiles : [],
88
+ filePath: currentDir,
89
+ };
90
+ } else {
91
+ answer = await getAnswer();
92
+ }
93
+ if (answer === null) {
94
+ console.warn(chalk.red("Installation cancelled."));
95
+ return;
96
+ }
97
+ const latestVersionOfCreatePrismaPhpApp = await fetchPackageVersion(
98
+ "create-prisma-php-app"
99
+ );
100
+ const isCreatePrismaPhpAppInstalled = getInstalledPackageVersion(
101
+ "create-prisma-php-app"
102
+ );
103
+ if (isCreatePrismaPhpAppInstalled) {
104
+ if (
105
+ compareVersions(
106
+ isCreatePrismaPhpAppInstalled,
107
+ latestVersionOfCreatePrismaPhpApp
108
+ ) === -1
109
+ ) {
110
+ execSync(`npm uninstall -g create-prisma-php-app`, {
111
+ stdio: "inherit",
112
+ });
113
+ execSync(`npm install -g create-prisma-php-app`, {
114
+ stdio: "inherit",
115
+ });
116
+ }
117
+ } else {
118
+ execSync("npm install -g create-prisma-php-app", { stdio: "inherit" });
119
+ }
120
+ // Create the project directory
121
+ if (!projectName) fs.mkdirSync(answer.projectName);
122
+ const currentDir = process.cwd();
123
+ let projectPath = projectName
124
+ ? currentDir
125
+ : path.join(currentDir, answer.projectName);
126
+ if (!projectName) process.chdir(answer.projectName);
127
+ const dependencies = [
128
+ "typescript",
129
+ "@types/node",
130
+ "ts-node",
131
+ "http-proxy-middleware",
132
+ "chalk",
133
+ "npm-run-all",
134
+ "browser-sync",
135
+ ];
148
136
  if (answer.swaggerDocs) {
149
- packageJson.scripts = Object.assign(Object.assign({}, packageJson.scripts), { "create-swagger-docs": "node settings/swagger-setup.js" });
150
- answersToInclude.push("create-swagger-docs");
151
- }
152
- // Initialize with existing scripts
153
- let updatedScripts = Object.assign({}, packageJson.scripts);
154
- // Conditionally add "browser-sync" command
155
- updatedScripts.browserSync = browserSyncCommand;
156
- updatedScripts.npmRunAll =
157
- answersToInclude.length > 0
158
- ? `npm-run-all -p ${answersToInclude.join(" ")}`
159
- : 'echo "No additional scripts to run"';
160
- updatedScripts.dev = `node settings/start-dev.js`;
161
- // Finally, assign the updated scripts back to packageJson
162
- packageJson.scripts = updatedScripts;
163
- packageJson.type = "module";
164
- if (answer.prisma)
165
- packageJson.prisma = {
166
- seed: "node prisma/seed.js",
167
- };
168
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
169
- }
170
- async function updateComposerJson(baseDir, answer) {
171
- const composerJsonPath = path.join(baseDir, "composer.json");
172
- if (checkExcludeFiles(composerJsonPath))
173
- return;
174
- let composerJson;
175
- // Check if the composer.json file exists
176
- if (fs.existsSync(composerJsonPath)) {
177
- // Read the current composer.json content
178
- const composerJsonContent = fs.readFileSync(composerJsonPath, "utf8");
179
- composerJson = JSON.parse(composerJsonContent);
137
+ dependencies.push("swagger-jsdoc");
180
138
  }
181
- else {
182
- console.error("composer.json does not exist.");
183
- return;
139
+ if (answer.tailwindcss) {
140
+ dependencies.push(
141
+ "tailwindcss",
142
+ "autoprefixer",
143
+ "postcss",
144
+ "postcss-cli",
145
+ "cssnano"
146
+ );
184
147
  }
185
- // Conditionally add WebSocket dependency
186
148
  if (answer.websocket) {
187
- composerJson.require = Object.assign(Object.assign({}, composerJson.require), { "cboden/ratchet": "^0.4.4" });
149
+ dependencies.push("chokidar-cli");
188
150
  }
189
151
  if (answer.prisma) {
190
- composerJson.require = Object.assign(Object.assign({}, composerJson.require), { "ramsey/uuid": "5.x-dev", "hidehalo/nanoid-php": "1.x-dev" });
152
+ dependencies.push("prisma", "@prisma/client");
191
153
  }
192
- // Write the modified composer.json back to the file
193
- fs.writeFileSync(composerJsonPath, JSON.stringify(composerJson, null, 2));
194
- console.log("composer.json updated successfully.");
195
- }
196
- async function updateIndexJsForWebSocket(baseDir, answer) {
197
- if (!answer.websocket) {
198
- return;
154
+ await installDependencies(projectPath, dependencies, true);
155
+ if (!projectName) {
156
+ execSync(`npx tsc --init`, { stdio: "inherit" });
199
157
  }
200
- const indexPath = path.join(baseDir, "src", "app", "js", "index.js");
201
- if (checkExcludeFiles(indexPath))
202
- return;
203
- let indexContent = fs.readFileSync(indexPath, "utf8");
204
- // WebSocket initialization code to be appended
205
- const webSocketCode = `
206
- // WebSocket initialization
207
- const ws = new WebSocket("ws://localhost:8080");
208
- `;
209
- // Append WebSocket code if user chose to use WebSocket
210
- indexContent += webSocketCode;
211
- fs.writeFileSync(indexPath, indexContent, "utf8");
212
- console.log("WebSocket code added to index.js successfully.");
213
- }
214
- // This function updates the .gitignore file
215
- async function createUpdateGitignoreFile(baseDir, additions) {
216
- const gitignorePath = path.join(baseDir, ".gitignore");
217
- if (checkExcludeFiles(gitignorePath))
218
- return;
219
- let gitignoreContent = "";
220
- additions.forEach((addition) => {
221
- if (!gitignoreContent.includes(addition)) {
222
- gitignoreContent += `\n${addition}`;
223
- }
224
- });
225
- // Ensure there's no leading newline if the file was just created
226
- gitignoreContent = gitignoreContent.trimStart();
227
- fs.writeFileSync(gitignorePath, gitignoreContent);
228
- }
229
- // Recursive copy function
230
- function copyRecursiveSync(src, dest, answer) {
231
- var _a;
232
- console.log("🚀 ~ copyRecursiveSync ~ dest:", dest);
233
- console.log("🚀 ~ copyRecursiveSync ~ src:", src);
234
- const exists = fs.existsSync(src);
235
- const stats = exists && fs.statSync(src);
236
- const isDirectory = exists && stats && stats.isDirectory();
237
- if (isDirectory) {
238
- const destLower = dest.toLowerCase();
239
- if (!answer.websocket && destLower.includes("src\\lib\\websocket"))
240
- return;
241
- if (!answer.prisma && destLower.includes("src\\lib\\prisma"))
242
- return;
243
- if ((answer.backendOnly && destLower.includes("src\\app\\js")) ||
244
- (answer.backendOnly && destLower.includes("src\\app\\css")))
245
- return;
246
- if (!answer.swaggerDocs && destLower.includes("src\\app\\swagger-docs"))
247
- return;
248
- const destModified = dest.replace(/\\/g, "/");
249
- if ((_a = updateAnswer === null || updateAnswer === void 0 ? void 0 : updateAnswer.excludeFilePath) === null || _a === void 0 ? void 0 : _a.includes(destModified))
250
- return;
251
- if (!fs.existsSync(dest))
252
- fs.mkdirSync(dest, { recursive: true });
253
- fs.readdirSync(src).forEach((childItemName) => {
254
- copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName), answer);
255
- });
256
- }
257
- else {
258
- if (checkExcludeFiles(dest))
259
- return;
260
- if (!answer.tailwindcss &&
261
- (dest.includes("tailwind.css") || dest.includes("styles.css")))
262
- return;
263
- if (!answer.websocket &&
264
- (dest.includes("restart-websocket.cjs") ||
265
- dest.includes("restart-websocket.bat")))
266
- return;
267
- if (!answer.docker && dockerFiles.some((file) => dest.includes(file))) {
268
- return;
269
- }
270
- if (answer.backendOnly &&
271
- nonBackendFiles.some((file) => dest.includes(file))) {
272
- return;
273
- }
274
- if (!answer.backendOnly && dest.includes("route.php"))
275
- return;
276
- if (!answer.swaggerDocs && dest.includes("swagger-setup.js")) {
277
- return;
278
- }
279
- fs.copyFileSync(src, dest, 0);
280
- }
281
- }
282
- // Function to execute the recursive copy for entire directories
283
- async function executeCopy(baseDir, directoriesToCopy, answer) {
284
- directoriesToCopy.forEach(({ srcDir, destDir }) => {
285
- const sourcePath = path.join(__dirname, srcDir);
286
- const destPath = path.join(baseDir, destDir);
287
- copyRecursiveSync(sourcePath, destPath, answer);
288
- });
289
- }
290
- function createOrUpdateTailwindConfig(baseDir) {
291
- console.log("🚀 ~ createOrUpdateTailwindConfig ~ baseDir:", baseDir);
292
- const filePath = path.join(baseDir, "tailwind.config.js");
293
- if (checkExcludeFiles(filePath))
294
- return;
295
- const newContent = [
296
- "./src/**/*.{html,js,php}",
297
- // Add more paths as needed
298
- ];
299
- let configData = fs.readFileSync(filePath, "utf8");
300
- console.log("🚀 ~ createOrUpdateTailwindConfig ~ configData:", configData);
301
- const contentArrayString = newContent
302
- .map((item) => ` "${item}"`)
303
- .join(",\n");
304
- configData = configData.replace(/content: \[\],/g, `content: [\n${contentArrayString}\n],`);
305
- fs.writeFileSync(filePath, configData, { flag: "w" });
306
- console.log(chalk.green("Tailwind configuration updated successfully."));
307
- }
308
- function modifyPostcssConfig(baseDir) {
309
- const filePath = path.join(baseDir, "postcss.config.js");
310
- if (checkExcludeFiles(filePath))
311
- return;
312
- const newContent = `export default {
313
- plugins: {
314
- tailwindcss: {},
315
- autoprefixer: {},
316
- cssnano: {},
317
- },
318
- };`;
319
- fs.writeFileSync(filePath, newContent, { flag: "w" });
320
- console.log(chalk.green("postcss.config.js updated successfully."));
321
- }
322
- function modifyLayoutPHP(baseDir, answer) {
323
- const layoutPath = path.join(baseDir, "src", "app", "layout.php");
324
- if (checkExcludeFiles(layoutPath))
325
- return;
326
- try {
327
- let indexContent = fs.readFileSync(layoutPath, "utf8");
328
- let stylesAndLinks = "";
329
- if (!answer.backendOnly) {
330
- stylesAndLinks = `\n <link href="<?= $baseUrl; ?>/css/index.css" rel="stylesheet">\n <script src="<?= $baseUrl; ?>/js/index.js"></script>`;
331
- }
332
- // Tailwind CSS link or CDN script
333
- let tailwindLink = "";
334
- if (!answer.backendOnly) {
335
- tailwindLink = answer.tailwindcss
336
- ? ` <link href="<?= $baseUrl; ?>/css/styles.css" rel="stylesheet"> ${stylesAndLinks}`
337
- : ` <script src="https://cdn.tailwindcss.com"></script> ${stylesAndLinks}`;
338
- }
339
- // Insert before the closing </head> tag
340
- const breakLine = tailwindLink.length > 0 ? "\n" : "";
341
- indexContent = indexContent.replace("</head>", `${tailwindLink}${breakLine} <!-- Dynamic Head -->
342
- <?= implode("\\n", $mainLayoutHead); ?>
343
- </head>`);
344
- fs.writeFileSync(layoutPath, indexContent, { flag: "w" });
345
- console.log(chalk.green(`layout.php modified successfully for ${answer.tailwindcss ? "local Tailwind CSS" : "Tailwind CSS CDN"}.`));
158
+ if (answer.tailwindcss)
159
+ execSync(`npx tailwindcss init -p`, { stdio: "inherit" });
160
+ if (answer.prisma) {
161
+ if (!fs.existsSync(path.join(projectPath, "prisma")))
162
+ execSync(`npx prisma init`, { stdio: "inherit" });
346
163
  }
347
- catch (error) {
348
- console.error(chalk.red("Error modifying layout.php:"), error);
164
+ await createDirectoryStructure(projectPath, answer);
165
+ const publicDirPath = path.join(projectPath, "public");
166
+ if (!fs.existsSync(publicDirPath)) {
167
+ fs.mkdirSync(publicDirPath);
349
168
  }
350
- }
351
- // This function updates or creates the .env file
352
- async function createOrUpdateEnvFile(baseDir, content) {
353
- const envPath = path.join(baseDir, ".env");
354
- if (checkExcludeFiles(envPath))
355
- return;
356
- console.log("🚀 ~ content:", content);
357
- fs.writeFileSync(envPath, content, { flag: "w" });
358
- }
359
- function checkExcludeFiles(destPath) {
360
- var _a, _b;
361
- if (!(updateAnswer === null || updateAnswer === void 0 ? void 0 : updateAnswer.isUpdate))
362
- return false;
363
- return ((_b = (_a = updateAnswer === null || updateAnswer === void 0 ? void 0 : updateAnswer.excludeFilePath) === null || _a === void 0 ? void 0 : _a.includes(destPath.replace(/\\/g, "/"))) !== null && _b !== void 0 ? _b : false);
364
- }
365
- async function createDirectoryStructure(baseDir, answer) {
366
- console.log("🚀 ~ baseDir:", baseDir);
367
- console.log("🚀 ~ answer:", answer);
368
- const filesToCopy = [
369
- { src: "/bootstrap.php", dest: "/bootstrap.php" },
370
- { src: "/.htaccess", dest: "/.htaccess" },
371
- { src: "/../composer.json", dest: "/composer.json" },
372
- ];
373
- if (updateAnswer === null || updateAnswer === void 0 ? void 0 : updateAnswer.isUpdate) {
374
- filesToCopy.push({ src: "/tsconfig.json", dest: "/tsconfig.json" });
375
- if (updateAnswer.tailwindcss) {
376
- filesToCopy.push({ src: "/postcss.config.js", dest: "/postcss.config.js" }, { src: "/tailwind.config.js", dest: "/tailwind.config.js" });
377
- }
378
- }
379
- const directoriesToCopy = [
380
- {
381
- srcDir: "/settings",
382
- destDir: "/settings",
383
- },
384
- {
385
- srcDir: "/src",
386
- destDir: "/src",
387
- },
388
- ];
389
- if (answer.backendOnly && answer.swaggerDocs) {
390
- directoriesToCopy.push({
391
- srcDir: "/swagger-docs-layout.php",
392
- destDir: "/src/app/layout.php",
169
+ if (answer.swaggerDocs) {
170
+ const swaggerDocsPath = path.join(
171
+ projectPath,
172
+ "src",
173
+ "app",
174
+ "swagger-docs"
175
+ );
176
+ // Check if the directory exists, if not, create it
177
+ if (!fs.existsSync(swaggerDocsPath)) {
178
+ fs.mkdirSync(swaggerDocsPath, { recursive: true }); // 'recursive: true' creates parent directories if they don't exist
179
+ }
180
+ // Clone the Git repository into the swagger-docs directory
181
+ execSync(
182
+ `git clone https://github.com/TheSteelNinjaCode/prisma-php-swagger-docs.git ${swaggerDocsPath}`,
183
+ { stdio: "inherit" }
184
+ );
185
+ }
186
+ if (
187
+ updateAnswer === null || updateAnswer === void 0
188
+ ? void 0
189
+ : updateAnswer.isUpdate
190
+ ) {
191
+ const updateUninstallDependencies = [];
192
+ if (updateAnswer.backendOnly) {
193
+ nonBackendFiles.forEach((file) => {
194
+ const filePath = path.join(projectPath, "src", "app", file);
195
+ if (fs.existsSync(filePath)) {
196
+ fs.unlinkSync(filePath); // Delete each file if it exists
197
+ console.log(`${file} was deleted successfully.`);
198
+ } else {
199
+ console.log(`${file} does not exist.`);
200
+ }
393
201
  });
394
- }
395
- if (answer.prisma) {
396
- directoriesToCopy.push({
397
- srcDir: "/prisma",
398
- destDir: "/prisma",
202
+ const backendOnlyFolders = ["js", "css"];
203
+ backendOnlyFolders.forEach((folder) => {
204
+ const folderPath = path.join(projectPath, "src", "app", folder);
205
+ if (fs.existsSync(folderPath)) {
206
+ fs.rmSync(folderPath, { recursive: true, force: true }); // Use fs.rmSync instead of fs.rmdirSync
207
+ console.log(`${folder} was deleted successfully.`);
208
+ } else {
209
+ console.log(`${folder} does not exist.`);
210
+ }
399
211
  });
400
- }
401
- if (answer.docker) {
402
- directoriesToCopy.push({ srcDir: "/.dockerignore", destDir: "/.dockerignore" }, { srcDir: "/docker-compose.yml", destDir: "/docker-compose.yml" }, { srcDir: "/Dockerfile", destDir: "/Dockerfile" }, { srcDir: "/apache.conf", destDir: "/apache.conf" });
403
- }
404
- console.log("🚀 ~ directoriesToCopy:", directoriesToCopy);
405
- filesToCopy.forEach(({ src, dest }) => {
406
- const sourcePath = path.join(__dirname, src);
407
- const destPath = path.join(baseDir, dest);
408
- if (checkExcludeFiles(destPath))
409
- return;
410
- const code = fs.readFileSync(sourcePath, "utf8");
411
- fs.writeFileSync(destPath, code, { flag: "w" });
412
- });
413
- await executeCopy(baseDir, directoriesToCopy, answer);
414
- await updatePackageJson(baseDir, answer);
415
- await updateComposerJson(baseDir, answer);
416
- if (!answer.backendOnly) {
417
- await updateIndexJsForWebSocket(baseDir, answer);
418
- }
419
- if (answer.tailwindcss) {
420
- createOrUpdateTailwindConfig(baseDir);
421
- modifyPostcssConfig(baseDir);
422
- }
423
- if (answer.tailwindcss || !answer.backendOnly || answer.swaggerDocs) {
424
- modifyLayoutPHP(baseDir, answer);
425
- }
426
- const prismaPHPEnvContent = `# Prisma PHP Auth Secret Key For development only - Change this in production
427
- AUTH_SECRET=uxsjXVPHN038DEYls2Kw0QUgBcXKUyrjv416nIFWPY4=
428
-
429
- # PHPMailer
430
- # SMTP_HOST=smtp.gmail.com or your SMTP host
431
- # SMTP_USERNAME=john.doe@gmail.com or your SMTP username
432
- # SMTP_PASSWORD=123456
433
- # SMTP_PORT=587 for TLS, 465 for SSL or your SMTP port
434
- # SMTP_ENCRYPTION=ssl or tls
435
- # MAIL_FROM=john.doe@gmail.com
436
- # MAIL_FROM_NAME="John Doe"
437
-
438
- # SHOW ERRORS - Set to true to show errors in the browser for development only - Change this in production to false
439
- SHOW_ERRORS=true
440
-
441
- # ChatGPT API Key
442
- # CHATGPT_API_KEY=sk-your-api-key
443
-
444
- # APP TIMEZONE - Set your application timezone - Default is "UTC"
445
- APP_TIMEZONE="UTC"
446
-
447
- # APP ENV - Set your application environment - Default is "development" - Change this in production to "production"
448
- APP_ENV=development`;
449
- if (answer.prisma) {
450
- const prismaEnvContent = `# Environment variables declared in this file are automatically made available to Prisma.
451
- # See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
452
-
453
- # Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
454
- # See the documentation for all the connection string options: https://pris.ly/d/connection-strings
455
-
456
- DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"`;
457
- const envContent = `${prismaEnvContent}\n\n${prismaPHPEnvContent}`;
458
- await createOrUpdateEnvFile(baseDir, envContent);
459
- }
460
- else {
461
- await createOrUpdateEnvFile(baseDir, prismaPHPEnvContent);
462
- }
463
- // Add vendor to .gitignore
464
- await createUpdateGitignoreFile(baseDir, ["vendor", ".env", "node_modules"]);
465
- }
466
- async function getAnswer(predefinedAnswers = {}) {
467
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
468
- console.log("🚀 ~ predefinedAnswers:", predefinedAnswers);
469
- const questionsArray = [];
470
- if (!predefinedAnswers.projectName) {
471
- questionsArray.push({
472
- type: "text",
473
- name: "projectName",
474
- message: "What is your project named?",
475
- initial: "my-app",
212
+ }
213
+ if (!updateAnswer.swaggerDocs) {
214
+ const swaggerDocsFolder = path.join(
215
+ projectPath,
216
+ "src",
217
+ "app",
218
+ "swagger-docs"
219
+ );
220
+ if (fs.existsSync(swaggerDocsFolder)) {
221
+ fs.rmSync(swaggerDocsFolder, { recursive: true, force: true }); // Use fs.rmSync instead of fs.rmdirSync
222
+ console.log(`swagger-docs was deleted successfully.`);
223
+ }
224
+ const swaggerFiles = ["swagger-setup.js"];
225
+ swaggerFiles.forEach((file) => {
226
+ const filePath = path.join(projectPath, "settings", file);
227
+ if (fs.existsSync(filePath)) {
228
+ fs.unlinkSync(filePath); // Delete each file if it exists
229
+ console.log(`${file} was deleted successfully.`);
230
+ } else {
231
+ console.log(`${file} does not exist.`);
232
+ }
476
233
  });
477
- }
478
- if (!predefinedAnswers.backendOnly) {
479
- questionsArray.push({
480
- type: "toggle",
481
- name: "backendOnly",
482
- message: "Would you like to create a backend-only project?",
483
- initial: false,
484
- active: "Yes",
485
- inactive: "No",
234
+ updateUninstallDependencies.push("swagger-jsdoc");
235
+ }
236
+ if (!updateAnswer.tailwindcss) {
237
+ const tailwindFiles = ["postcss.config.js", "tailwind.config.js"];
238
+ tailwindFiles.forEach((file) => {
239
+ const filePath = path.join(projectPath, file);
240
+ if (fs.existsSync(filePath)) {
241
+ fs.unlinkSync(filePath); // Delete each file if it exists
242
+ console.log(`${file} was deleted successfully.`);
243
+ } else {
244
+ console.log(`${file} does not exist.`);
245
+ }
486
246
  });
487
- }
488
- // Execute the initial questionsArray first
489
- const onCancel = () => {
490
- console.log(chalk.red("Operation cancelled by the user."));
491
- process.exit(0);
492
- };
493
- const initialResponse = await prompts(questionsArray, { onCancel });
494
- console.log("🚀 ~ initialResponse:", initialResponse);
495
- const nonBackendOnlyQuestionsArray = [];
496
- if (initialResponse.backendOnly || predefinedAnswers.backendOnly) {
497
- // If it's a backend-only project, skip Tailwind CSS, but ask other questions
498
- if (!predefinedAnswers.swaggerDocs) {
499
- nonBackendOnlyQuestionsArray.push({
500
- type: "toggle",
501
- name: "swaggerDocs",
502
- message: `Would you like to use ${chalk.blue("Swagger Docs")}?`,
503
- initial: false,
504
- active: "Yes",
505
- inactive: "No",
506
- });
507
- }
508
- if (!predefinedAnswers.websocket) {
509
- nonBackendOnlyQuestionsArray.push({
510
- type: "toggle",
511
- name: "websocket",
512
- message: `Would you like to use ${chalk.blue("Websocket")}?`,
513
- initial: true,
514
- active: "Yes",
515
- inactive: "No",
516
- });
517
- }
518
- if (!predefinedAnswers.prisma) {
519
- nonBackendOnlyQuestionsArray.push({
520
- type: "toggle",
521
- name: "prisma",
522
- message: `Would you like to use ${chalk.blue("Prisma PHP ORM")}?`,
523
- initial: true,
524
- active: "Yes",
525
- inactive: "No",
526
- });
527
- }
528
- if (!predefinedAnswers.docker) {
529
- nonBackendOnlyQuestionsArray.push({
530
- type: "toggle",
531
- name: "docker",
532
- message: `Would you like to use ${chalk.blue("Docker")}?`,
533
- initial: false,
534
- active: "Yes",
535
- inactive: "No",
536
- });
537
- }
538
- }
539
- else {
540
- // If it's not a backend-only project, ask Tailwind CSS as well
541
- if (!predefinedAnswers.swaggerDocs) {
542
- nonBackendOnlyQuestionsArray.push({
543
- type: "toggle",
544
- name: "swaggerDocs",
545
- message: `Would you like to use ${chalk.blue("Swagger Docs")}?`,
546
- initial: false,
547
- active: "Yes",
548
- inactive: "No",
549
- });
550
- }
551
- if (!predefinedAnswers.tailwindcss) {
552
- nonBackendOnlyQuestionsArray.push({
553
- type: "toggle",
554
- name: "tailwindcss",
555
- message: `Would you like to use ${chalk.blue("Tailwind CSS")}?`,
556
- initial: true,
557
- active: "Yes",
558
- inactive: "No",
559
- });
560
- }
561
- if (!predefinedAnswers.websocket) {
562
- nonBackendOnlyQuestionsArray.push({
563
- type: "toggle",
564
- name: "websocket",
565
- message: `Would you like to use ${chalk.blue("Websocket")}?`,
566
- initial: true,
567
- active: "Yes",
568
- inactive: "No",
569
- });
570
- }
571
- if (!predefinedAnswers.prisma) {
572
- nonBackendOnlyQuestionsArray.push({
573
- type: "toggle",
574
- name: "prisma",
575
- message: `Would you like to use ${chalk.blue("Prisma PHP ORM")}?`,
576
- initial: true,
577
- active: "Yes",
578
- inactive: "No",
579
- });
580
- }
581
- if (!predefinedAnswers.docker) {
582
- nonBackendOnlyQuestionsArray.push({
583
- type: "toggle",
584
- name: "docker",
585
- message: `Would you like to use ${chalk.blue("Docker")}?`,
586
- initial: false,
587
- active: "Yes",
588
- inactive: "No",
589
- });
590
- }
591
- }
592
- const nonBackendOnlyResponse = await prompts(nonBackendOnlyQuestionsArray, {
593
- onCancel,
594
- });
595
- console.log("🚀 ~ nonBackendOnlyResponse:", nonBackendOnlyResponse);
596
- return {
597
- projectName: initialResponse.projectName
598
- ? String(initialResponse.projectName).trim().replace(/ /g, "-")
599
- : (_a = predefinedAnswers.projectName) !== null && _a !== void 0 ? _a : "my-app",
600
- backendOnly: (_c = (_b = initialResponse.backendOnly) !== null && _b !== void 0 ? _b : predefinedAnswers.backendOnly) !== null && _c !== void 0 ? _c : false,
601
- swaggerDocs: (_e = (_d = nonBackendOnlyResponse.swaggerDocs) !== null && _d !== void 0 ? _d : predefinedAnswers.swaggerDocs) !== null && _e !== void 0 ? _e : false,
602
- tailwindcss: (_g = (_f = nonBackendOnlyResponse.tailwindcss) !== null && _f !== void 0 ? _f : predefinedAnswers.tailwindcss) !== null && _g !== void 0 ? _g : false,
603
- websocket: (_j = (_h = nonBackendOnlyResponse.websocket) !== null && _h !== void 0 ? _h : predefinedAnswers.websocket) !== null && _j !== void 0 ? _j : false,
604
- prisma: (_l = (_k = nonBackendOnlyResponse.prisma) !== null && _k !== void 0 ? _k : predefinedAnswers.prisma) !== null && _l !== void 0 ? _l : false,
605
- docker: (_o = (_m = nonBackendOnlyResponse.docker) !== null && _m !== void 0 ? _m : predefinedAnswers.docker) !== null && _o !== void 0 ? _o : false,
606
- };
607
- }
608
- /**
609
- * Install dependencies in the specified directory.
610
- * @param {string} baseDir - The base directory where to install the dependencies.
611
- * @param {string[]} dependencies - The list of dependencies to install.
612
- * @param {boolean} [isDev=false] - Whether to install the dependencies as devDependencies.
613
- */
614
- async function installDependencies(baseDir, dependencies, isDev = false) {
615
- console.log("Initializing new Node.js project...");
616
- // Initialize a package.json if it doesn't exist
617
- if (!fs.existsSync(path.join(baseDir, "package.json")))
618
- execSync("npm init -y", {
619
- stdio: "inherit",
620
- cwd: baseDir,
247
+ updateUninstallDependencies.push(
248
+ "tailwindcss",
249
+ "autoprefixer",
250
+ "postcss",
251
+ "postcss-cli",
252
+ "cssnano"
253
+ );
254
+ }
255
+ if (!updateAnswer.websocket) {
256
+ const websocketFiles = [
257
+ "restart-websocket.js",
258
+ "restart-websocket.bat",
259
+ ];
260
+ websocketFiles.forEach((file) => {
261
+ const filePath = path.join(projectPath, "settings", file);
262
+ if (fs.existsSync(filePath)) {
263
+ fs.unlinkSync(filePath); // Delete each file if it exists
264
+ console.log(`${file} was deleted successfully.`);
265
+ } else {
266
+ console.log(`${file} does not exist.`);
267
+ }
621
268
  });
622
- // Log the dependencies being installed
623
- console.log(`${isDev ? "Installing development dependencies" : "Installing dependencies"}:`);
624
- dependencies.forEach((dep) => console.log(`- ${chalk.blue(dep)}`));
625
- // Prepare the npm install command with the appropriate flag for dev dependencies
626
- const npmInstallCommand = `npm install ${isDev ? "--save-dev" : ""} ${dependencies.join(" ")}`;
627
- // Execute the npm install command
628
- execSync(npmInstallCommand, {
629
- stdio: "inherit",
630
- cwd: baseDir,
631
- });
632
- }
633
- async function uninstallDependencies(baseDir, dependencies, isDev = false) {
634
- console.log("Uninstalling dependencies:");
635
- dependencies.forEach((dep) => console.log(`- ${chalk.blue(dep)}`));
636
- // Prepare the npm uninstall command with the appropriate flag for dev dependencies
637
- const npmUninstallCommand = `npm uninstall ${isDev ? "--save-dev" : "--save"} ${dependencies.join(" ")}`;
638
- // Execute the npm uninstall command
639
- execSync(npmUninstallCommand, {
640
- stdio: "inherit",
641
- cwd: baseDir,
642
- });
643
- }
644
- function fetchPackageVersion(packageName) {
645
- return new Promise((resolve, reject) => {
646
- https
647
- .get(`https://registry.npmjs.org/${packageName}`, (res) => {
648
- let data = "";
649
- res.on("data", (chunk) => (data += chunk));
650
- res.on("end", () => {
651
- try {
652
- const parsed = JSON.parse(data);
653
- resolve(parsed["dist-tags"].latest);
654
- }
655
- catch (error) {
656
- reject(new Error("Failed to parse JSON response"));
657
- }
658
- });
659
- })
660
- .on("error", (err) => reject(err));
661
- });
662
- }
663
- const readJsonFile = (filePath) => {
664
- const jsonData = fs.readFileSync(filePath, "utf8");
665
- return JSON.parse(jsonData);
666
- };
667
- function compareVersions(installedVersion, currentVersion) {
668
- const installedVersionArray = installedVersion.split(".").map(Number);
669
- const currentVersionArray = currentVersion.split(".").map(Number);
670
- for (let i = 0; i < installedVersionArray.length; i++) {
671
- if (installedVersionArray[i] > currentVersionArray[i]) {
672
- return 1;
673
- }
674
- else if (installedVersionArray[i] < currentVersionArray[i]) {
675
- return -1;
676
- }
677
- }
678
- return 0;
679
- }
680
- function getInstalledPackageVersion(packageName) {
681
- try {
682
- const output = execSync(`npm list -g ${packageName} --depth=0`).toString();
683
- const versionMatch = output.match(new RegExp(`${packageName}@(\\d+\\.\\d+\\.\\d+)`));
684
- if (versionMatch) {
685
- return versionMatch[1];
686
- }
687
- else {
688
- console.error(`Package ${packageName} is not installed`);
689
- return null;
690
- }
691
- }
692
- catch (error) {
693
- console.error(error instanceof Error ? error.message : String(error));
694
- return null;
695
- }
696
- }
697
- async function main() {
698
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
699
- try {
700
- const args = process.argv.slice(2);
701
- let projectName = args[0];
702
- let answer = null;
703
- if (projectName) {
704
- let useBackendOnly = args.includes("--backend-only");
705
- let useSwaggerDocs = args.includes("--swagger-docs");
706
- let useTailwind = args.includes("--tailwindcss");
707
- let useWebsocket = args.includes("--websocket");
708
- let usePrisma = args.includes("--prisma");
709
- let useDocker = args.includes("--docker");
710
- const predefinedAnswers = {
711
- projectName,
712
- backendOnly: useBackendOnly,
713
- swaggerDocs: useSwaggerDocs,
714
- tailwindcss: useTailwind,
715
- websocket: useWebsocket,
716
- prisma: usePrisma,
717
- docker: useDocker,
718
- };
719
- console.log("🚀 ~ main ~ predefinedAnswers:", predefinedAnswers);
720
- answer = await getAnswer(predefinedAnswers);
721
- if (answer === null) {
722
- console.log(chalk.red("Installation cancelled."));
723
- return;
724
- }
725
- const currentDir = process.cwd();
726
- const configPath = path.join(currentDir, "prisma-php.json");
727
- const localSettings = readJsonFile(configPath);
728
- let excludeFiles = [];
729
- (_a = localSettings.excludeFiles) === null || _a === void 0 ? void 0 : _a.map((file) => {
730
- const filePath = path.join(currentDir, file);
731
- if (fs.existsSync(filePath))
732
- excludeFiles.push(filePath.replace(/\\/g, "/"));
733
- });
734
- updateAnswer = {
735
- projectName,
736
- backendOnly: (_b = answer === null || answer === void 0 ? void 0 : answer.backendOnly) !== null && _b !== void 0 ? _b : false,
737
- swaggerDocs: (_c = answer === null || answer === void 0 ? void 0 : answer.swaggerDocs) !== null && _c !== void 0 ? _c : false,
738
- tailwindcss: (_d = answer === null || answer === void 0 ? void 0 : answer.tailwindcss) !== null && _d !== void 0 ? _d : false,
739
- websocket: (_e = answer === null || answer === void 0 ? void 0 : answer.websocket) !== null && _e !== void 0 ? _e : false,
740
- prisma: (_f = answer === null || answer === void 0 ? void 0 : answer.prisma) !== null && _f !== void 0 ? _f : false,
741
- docker: (_g = answer === null || answer === void 0 ? void 0 : answer.docker) !== null && _g !== void 0 ? _g : false,
742
- isUpdate: true,
743
- excludeFiles: (_h = localSettings.excludeFiles) !== null && _h !== void 0 ? _h : [],
744
- excludeFilePath: excludeFiles !== null && excludeFiles !== void 0 ? excludeFiles : [],
745
- filePath: currentDir,
746
- };
747
- }
748
- else {
749
- answer = await getAnswer();
750
- }
751
- if (answer === null) {
752
- console.warn(chalk.red("Installation cancelled."));
753
- return;
754
- }
755
- const latestVersionOfCreatePrismaPhpApp = await fetchPackageVersion("create-prisma-php-app");
756
- const isCreatePrismaPhpAppInstalled = getInstalledPackageVersion("create-prisma-php-app");
757
- if (isCreatePrismaPhpAppInstalled) {
758
- if (compareVersions(isCreatePrismaPhpAppInstalled, latestVersionOfCreatePrismaPhpApp) === -1) {
759
- execSync(`npm uninstall -g create-prisma-php-app`, {
760
- stdio: "inherit",
761
- });
762
- execSync(`npm install -g create-prisma-php-app`, {
763
- stdio: "inherit",
764
- });
765
- }
766
- }
767
- else {
768
- execSync("npm install -g create-prisma-php-app", { stdio: "inherit" });
769
- }
770
- const latestVersionOfBrowserSync = await fetchPackageVersion("browser-sync");
771
- const isBrowserSyncInstalled = getInstalledPackageVersion("browser-sync");
772
- if (isBrowserSyncInstalled) {
773
- if (compareVersions(isBrowserSyncInstalled, latestVersionOfBrowserSync) ===
774
- -1) {
775
- execSync(`npm uninstall -g browser-sync`, {
776
- stdio: "inherit",
777
- });
778
- execSync(`npm install -g browser-sync`, {
779
- stdio: "inherit",
780
- });
781
- }
782
- }
783
- else {
784
- execSync("npm install -g browser-sync", { stdio: "inherit" });
785
- }
786
- // Create the project directory
787
- if (!projectName)
788
- fs.mkdirSync(answer.projectName);
789
- const currentDir = process.cwd();
790
- let projectPath = projectName
791
- ? currentDir
792
- : path.join(currentDir, answer.projectName);
793
- if (!projectName)
794
- process.chdir(answer.projectName);
795
- const dependencies = [
796
- "typescript",
797
- "@types/node",
798
- "ts-node",
799
- "http-proxy-middleware@^3.0.0",
800
- "chalk",
801
- "npm-run-all",
269
+ const websocketFolder = path.join(
270
+ projectPath,
271
+ "src",
272
+ "Lib",
273
+ "Websocket"
274
+ );
275
+ if (fs.existsSync(websocketFolder)) {
276
+ fs.rmSync(websocketFolder, { recursive: true, force: true }); // Use fs.rmSync instead of fs.rmdirSync
277
+ console.log(`Websocket folder was deleted successfully.`);
278
+ }
279
+ updateUninstallDependencies.push("chokidar-cli");
280
+ }
281
+ if (!updateAnswer.prisma) {
282
+ updateUninstallDependencies.push("prisma", "@prisma/client");
283
+ }
284
+ if (!updateAnswer.docker) {
285
+ const dockerFiles = [
286
+ ".dockerignore",
287
+ "docker-compose.yml",
288
+ "Dockerfile",
289
+ "apache.conf",
802
290
  ];
803
- if (answer.swaggerDocs) {
804
- dependencies.push("swagger-jsdoc");
805
- }
806
- if (answer.tailwindcss) {
807
- dependencies.push("tailwindcss", "autoprefixer", "postcss", "postcss-cli", "cssnano");
808
- }
809
- if (answer.websocket) {
810
- dependencies.push("chokidar-cli");
811
- }
812
- if (answer.prisma) {
813
- dependencies.push("prisma", "@prisma/client");
814
- }
815
- await installDependencies(projectPath, dependencies, true);
816
- if (!projectName) {
817
- execSync(`npx tsc --init`, { stdio: "inherit" });
818
- }
819
- if (answer.tailwindcss)
820
- execSync(`npx tailwindcss init -p`, { stdio: "inherit" });
821
- if (answer.prisma) {
822
- if (!fs.existsSync(path.join(projectPath, "prisma")))
823
- execSync(`npx prisma init`, { stdio: "inherit" });
824
- }
825
- await createDirectoryStructure(projectPath, answer);
826
- const publicDirPath = path.join(projectPath, "public");
827
- if (!fs.existsSync(publicDirPath)) {
828
- fs.mkdirSync(publicDirPath);
829
- }
830
- if (answer.swaggerDocs) {
831
- const swaggerDocsPath = path.join(projectPath, "src", "app", "swagger-docs");
832
- // Check if the directory exists, if not, create it
833
- if (!fs.existsSync(swaggerDocsPath)) {
834
- fs.mkdirSync(swaggerDocsPath, { recursive: true }); // 'recursive: true' creates parent directories if they don't exist
835
- }
836
- // Clone the Git repository into the swagger-docs directory
837
- execSync(`git clone https://github.com/TheSteelNinjaCode/prisma-php-swagger-docs.git ${swaggerDocsPath}`, { stdio: "inherit" });
838
- }
839
- if (updateAnswer === null || updateAnswer === void 0 ? void 0 : updateAnswer.isUpdate) {
840
- const updateUninstallDependencies = [];
841
- if (updateAnswer.backendOnly) {
842
- nonBackendFiles.forEach((file) => {
843
- const filePath = path.join(projectPath, "src", "app", file);
844
- if (fs.existsSync(filePath)) {
845
- fs.unlinkSync(filePath); // Delete each file if it exists
846
- console.log(`${file} was deleted successfully.`);
847
- }
848
- else {
849
- console.log(`${file} does not exist.`);
850
- }
851
- });
852
- const backendOnlyFolders = ["js", "css"];
853
- backendOnlyFolders.forEach((folder) => {
854
- const folderPath = path.join(projectPath, "src", "app", folder);
855
- if (fs.existsSync(folderPath)) {
856
- fs.rmSync(folderPath, { recursive: true, force: true }); // Use fs.rmSync instead of fs.rmdirSync
857
- console.log(`${folder} was deleted successfully.`);
858
- }
859
- else {
860
- console.log(`${folder} does not exist.`);
861
- }
862
- });
863
- }
864
- if (!updateAnswer.swaggerDocs) {
865
- const swaggerDocsFolder = path.join(projectPath, "src", "app", "swagger-docs");
866
- if (fs.existsSync(swaggerDocsFolder)) {
867
- fs.rmSync(swaggerDocsFolder, { recursive: true, force: true }); // Use fs.rmSync instead of fs.rmdirSync
868
- console.log(`swagger-docs was deleted successfully.`);
869
- }
870
- const swaggerFiles = ["swagger-setup.js"];
871
- swaggerFiles.forEach((file) => {
872
- const filePath = path.join(projectPath, "settings", file);
873
- if (fs.existsSync(filePath)) {
874
- fs.unlinkSync(filePath); // Delete each file if it exists
875
- console.log(`${file} was deleted successfully.`);
876
- }
877
- else {
878
- console.log(`${file} does not exist.`);
879
- }
880
- });
881
- updateUninstallDependencies.push("swagger-jsdoc");
882
- }
883
- if (!updateAnswer.tailwindcss) {
884
- const tailwindFiles = ["postcss.config.js", "tailwind.config.js"];
885
- tailwindFiles.forEach((file) => {
886
- const filePath = path.join(projectPath, file);
887
- if (fs.existsSync(filePath)) {
888
- fs.unlinkSync(filePath); // Delete each file if it exists
889
- console.log(`${file} was deleted successfully.`);
890
- }
891
- else {
892
- console.log(`${file} does not exist.`);
893
- }
894
- });
895
- updateUninstallDependencies.push("tailwindcss", "autoprefixer", "postcss", "postcss-cli", "cssnano");
896
- }
897
- if (!updateAnswer.websocket) {
898
- updateUninstallDependencies.push("chokidar-cli");
899
- }
900
- if (!updateAnswer.prisma) {
901
- updateUninstallDependencies.push("prisma", "@prisma/client");
902
- }
903
- if (!updateAnswer.docker) {
904
- const dockerFiles = [
905
- ".dockerignore",
906
- "docker-compose.yml",
907
- "Dockerfile",
908
- "apache.conf",
909
- ];
910
- dockerFiles.forEach((file) => {
911
- const filePath = path.join(projectPath, file);
912
- if (fs.existsSync(filePath)) {
913
- fs.unlinkSync(filePath); // Delete each file if it exists
914
- console.log(`${file} was deleted successfully.`);
915
- }
916
- else {
917
- console.log(`${file} does not exist.`);
918
- }
919
- });
920
- }
921
- if (updateUninstallDependencies.length > 0) {
922
- await uninstallDependencies(projectPath, updateUninstallDependencies, true);
923
- }
924
- }
925
- const projectPathModified = projectPath.replace(/\\/g, "\\");
926
- const bsConfig = bsConfigUrls(projectPathModified);
927
- const phpGenerateClassPath = answer.prisma ? "src/Lib/Prisma/Classes" : "";
928
- const prismaPhpConfig = {
929
- projectName: answer.projectName,
930
- projectRootPath: projectPathModified,
931
- phpEnvironment: "XAMPP",
932
- phpRootPathExe: "C:\\xampp\\php\\php.exe",
933
- phpGenerateClassPath,
934
- bsTarget: bsConfig.bsTarget,
935
- bsPathRewrite: bsConfig.bsPathRewrite,
936
- backendOnly: answer.backendOnly,
937
- swaggerDocs: answer.swaggerDocs,
938
- tailwindcss: answer.tailwindcss,
939
- websocket: answer.websocket,
940
- prisma: answer.prisma,
941
- docker: answer.docker,
942
- version: latestVersionOfCreatePrismaPhpApp,
943
- excludeFiles: (_j = updateAnswer === null || updateAnswer === void 0 ? void 0 : updateAnswer.excludeFiles) !== null && _j !== void 0 ? _j : [],
944
- };
945
- fs.writeFileSync(path.join(projectPath, "prisma-php.json"), JSON.stringify(prismaPhpConfig, null, 2), { flag: "w" });
946
- if (updateAnswer === null || updateAnswer === void 0 ? void 0 : updateAnswer.isUpdate) {
947
- execSync(`C:\\xampp\\php\\php.exe C:\\ProgramData\\ComposerSetup\\bin\\composer.phar update`, {
948
- stdio: "inherit",
949
- });
950
- }
951
- else {
952
- execSync(`C:\\xampp\\php\\php.exe C:\\ProgramData\\ComposerSetup\\bin\\composer.phar install`, {
953
- stdio: "inherit",
954
- });
291
+ dockerFiles.forEach((file) => {
292
+ const filePath = path.join(projectPath, file);
293
+ if (fs.existsSync(filePath)) {
294
+ fs.unlinkSync(filePath); // Delete each file if it exists
295
+ console.log(`${file} was deleted successfully.`);
296
+ } else {
297
+ console.log(`${file} does not exist.`);
298
+ }
299
+ });
300
+ }
301
+ if (updateUninstallDependencies.length > 0) {
302
+ await uninstallDependencies(
303
+ projectPath,
304
+ updateUninstallDependencies,
305
+ true
306
+ );
307
+ }
308
+ }
309
+ const projectPathModified = projectPath.replace(/\\/g, "\\");
310
+ const bsConfig = bsConfigUrls(projectPathModified);
311
+ const phpGenerateClassPath = answer.prisma ? "src/Lib/Prisma/Classes" : "";
312
+ const prismaPhpConfig = {
313
+ projectName: answer.projectName,
314
+ projectRootPath: projectPathModified,
315
+ phpEnvironment: "XAMPP",
316
+ phpRootPathExe: "C:\\xampp\\php\\php.exe",
317
+ phpGenerateClassPath,
318
+ bsTarget: bsConfig.bsTarget,
319
+ bsPathRewrite: bsConfig.bsPathRewrite,
320
+ backendOnly: answer.backendOnly,
321
+ swaggerDocs: answer.swaggerDocs,
322
+ tailwindcss: answer.tailwindcss,
323
+ websocket: answer.websocket,
324
+ prisma: answer.prisma,
325
+ docker: answer.docker,
326
+ ngrok: false,
327
+ version: latestVersionOfCreatePrismaPhpApp,
328
+ excludeFiles:
329
+ (_j =
330
+ updateAnswer === null || updateAnswer === void 0
331
+ ? void 0
332
+ : updateAnswer.excludeFiles) !== null && _j !== void 0
333
+ ? _j
334
+ : [],
335
+ };
336
+ fs.writeFileSync(
337
+ path.join(projectPath, "prisma-php.json"),
338
+ JSON.stringify(prismaPhpConfig, null, 2),
339
+ { flag: "w" }
340
+ );
341
+ if (
342
+ updateAnswer === null || updateAnswer === void 0
343
+ ? void 0
344
+ : updateAnswer.isUpdate
345
+ ) {
346
+ execSync(
347
+ `C:\\xampp\\php\\php.exe C:\\ProgramData\\ComposerSetup\\bin\\composer.phar update`,
348
+ {
349
+ stdio: "inherit",
955
350
  }
956
- console.log(`${chalk.green("Success!")} Prisma PHP project successfully created in ${answer.projectName}!`);
957
- }
958
- catch (error) {
959
- console.error("Error while creating the project:", error);
960
- process.exit(1);
961
- }
351
+ );
352
+ } else {
353
+ execSync(
354
+ `C:\\xampp\\php\\php.exe C:\\ProgramData\\ComposerSetup\\bin\\composer.phar install`,
355
+ {
356
+ stdio: "inherit",
357
+ }
358
+ );
359
+ }
360
+ console.log(
361
+ `${chalk.green("Success!")} Prisma PHP project successfully created in ${
362
+ answer.projectName
363
+ }!`
364
+ );
365
+ } catch (error) {
366
+ console.error("Error while creating the project:", error);
367
+ process.exit(1);
368
+ }
962
369
  }
963
370
  main();