create-prisma-php-app 1.6.13 → 1.6.14

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 +238 -222
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,65 +1,65 @@
1
1
  #!/usr/bin/env node
2
2
  import{execSync}from"child_process";import fs from"fs";import{fileURLToPath}from"url";import path from"path";import chalk from"chalk";import prompts from"prompts";import https from"https";const __filename=fileURLToPath(import.meta.url),__dirname=path.dirname(__filename);function configureBrowserSyncCommand(e,s){const t=s.PROJECT_ROOT_PATH.indexOf("\\htdocs\\");if(-1===t)return"";const n=s.PROJECT_ROOT_PATH.substring(0,t+"\\htdocs\\".length).replace(/\\/g,"\\\\"),i=s.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,s,t){const n=path.join(e,"package.json"),i=JSON.parse(fs.readFileSync(n,"utf8")),r=configureBrowserSyncCommand(e,s);i.scripts=Object.assign(Object.assign({},i.scripts),{postinstall:"prisma generate"});let c=[];t.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")),t.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,s){if(!s.websocket)return;const t=path.join(e,"composer.json");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"})),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");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");let n="";fs.existsSync(t)&&(n=fs.readFileSync(t,"utf8")),s.forEach((e=>{n.includes(e)||(n+=`\n${e}`)})),n=n.trimStart(),fs.writeFileSync(t,n)}function copyRecursiveSync(e,s){const t=fs.existsSync(e),n=t&&fs.statSync(e);t&&n&&n.isDirectory()?(fs.mkdirSync(s,{recursive:!0}),fs.readdirSync(e).forEach((t=>copyRecursiveSync(path.join(e,t),path.join(s,t))))):fs.copyFileSync(e,s)}async function executeCopy(e,s){s.forEach((({srcDir:s,destDir:t})=>{copyRecursiveSync(path.join(__dirname,s),path.join(e,t))}))}function modifyTailwindConfig(e){const s=path.join(e,"tailwind.config.js");let t=fs.readFileSync(s,"utf8");const n=["./src/app/**/*.{html,js,php}"].map((e=>` "${e}"`)).join(",\n");t=t.replace(/content: \[\],/g,`content: [\n${n}\n],`),fs.writeFileSync(s,t,"utf8")}function modifyPostcssConfig(e){const s=path.join(e,"postcss.config.js");fs.writeFileSync(s,"export default {\n plugins: {\n tailwindcss: {},\n autoprefixer: {},\n cssnano: {},\n },\n};","utf8")}function modifyIndexPHP(e,s){const t=path.join(e,"src","app","layout.php");try{let e=fs.readFileSync(t,"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=s?` <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(t,e,"utf8")}catch(e){}}async function updateOrCreateEnvFile(e,s){const t=path.join(e,".env");let n=fs.existsSync(t)?fs.readFileSync(t,"utf8"):"";n+=`${""!==n?"\n\n":""}${s}`,fs.writeFileSync(t,n)}async function createDirectoryStructure(e,s,t){[{src:"/bootstrap.php",dest:"/bootstrap.php"},{src:"/.htaccess",dest:"/.htaccess"},{src:"/../composer.json",dest:"/composer.json"}].forEach((({src:s,dest:t})=>{const n=path.join(__dirname,s),i=path.join(e,t),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,t,s),await updateComposerJson(e,s),await updateIndexJsForWebSocket(e,s),s.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"])}
3
3
  async function getAnswer(predefinedAnswers = {}) {
4
- var _a, _b, _c;
5
- console.log("🚀 ~ predefinedAnswers:", predefinedAnswers);
6
- const questions = [
7
- ...(!predefinedAnswers.projectName
8
- ? [
9
- {
10
- type: "text",
11
- name: "projectName",
12
- message: "What is your project named?",
13
- initial: "my-app",
14
- },
15
- ]
16
- : []),
17
- ...(!predefinedAnswers.projectName
18
- ? [
19
- {
20
- type: "toggle",
21
- name: "tailwindcss",
22
- message: `Would you like to use ${chalk.blue("Tailwind CSS")}?`,
23
- initial: true,
24
- active: "Yes",
25
- inactive: "No",
26
- },
27
- ]
28
- : []),
29
- ...(!predefinedAnswers.projectName
30
- ? [
31
- {
32
- type: "toggle",
33
- name: "websocket",
34
- message: `Would you like to use ${chalk.blue("Websocket")}?`,
35
- initial: true,
36
- active: "Yes",
37
- inactive: "No",
38
- },
39
- ]
40
- : []),
41
- ];
42
- console.log("🚀 ~ questions:", questions);
43
- const onCancel = () => {
44
- return false;
45
- };
46
- try {
47
- const response = await prompts(questions, { onCancel });
48
- if (Object.keys(response).length === 0) {
49
- return null;
50
- }
51
- return {
52
- projectName: response.projectName
53
- ? String(response.projectName).trim().replace(/ /g, "-")
54
- : (_a = predefinedAnswers.projectName) !== null && _a !== void 0 ? _a : "my-app",
55
- tailwindcss: (_b = response.tailwindcss) !== null && _b !== void 0 ? _b : predefinedAnswers.tailwindcss,
56
- websocket: (_c = response.websocket) !== null && _c !== void 0 ? _c : predefinedAnswers.websocket,
57
- };
58
- }
59
- catch (error) {
60
- console.error(chalk.red("Prompt error:"), error);
61
- return null;
4
+ var _a, _b, _c;
5
+ console.log("🚀 ~ predefinedAnswers:", predefinedAnswers);
6
+ const questions = [];
7
+ if (!predefinedAnswers.projectName) {
8
+ questions.push({
9
+ type: "text",
10
+ name: "projectName",
11
+ message: "What is your project named?",
12
+ initial: "my-app",
13
+ });
14
+ }
15
+ if (!predefinedAnswers.tailwindcss) {
16
+ questions.push({
17
+ type: "toggle",
18
+ name: "tailwindcss",
19
+ message: `Would you like to use ${chalk.blue("Tailwind CSS")}?`,
20
+ initial: true,
21
+ active: "Yes",
22
+ inactive: "No",
23
+ });
24
+ }
25
+ if (!predefinedAnswers.websocket) {
26
+ questions.push({
27
+ type: "toggle",
28
+ name: "websocket",
29
+ message: `Would you like to use ${chalk.blue("Websocket")}?`,
30
+ initial: true,
31
+ active: "Yes",
32
+ inactive: "No",
33
+ });
34
+ }
35
+ console.log("🚀 ~ questions:", questions);
36
+ const onCancel = () => {
37
+ return false;
38
+ };
39
+ try {
40
+ const response = await prompts(questions, { onCancel });
41
+ if (Object.keys(response).length === 0) {
42
+ return null;
62
43
  }
44
+ return {
45
+ projectName: response.projectName
46
+ ? String(response.projectName).trim().replace(/ /g, "-")
47
+ : (_a = predefinedAnswers.projectName) !== null && _a !== void 0
48
+ ? _a
49
+ : "my-app",
50
+ tailwindcss:
51
+ (_b = response.tailwindcss) !== null && _b !== void 0
52
+ ? _b
53
+ : predefinedAnswers.tailwindcss,
54
+ websocket:
55
+ (_c = response.websocket) !== null && _c !== void 0
56
+ ? _c
57
+ : predefinedAnswers.websocket,
58
+ };
59
+ } catch (error) {
60
+ console.error(chalk.red("Prompt error:"), error);
61
+ return null;
62
+ }
63
63
  }
64
64
  /**
65
65
  * Install dependencies in the specified directory.
@@ -68,181 +68,197 @@ async function getAnswer(predefinedAnswers = {}) {
68
68
  * @param {boolean} [isDev=false] - Whether to install the dependencies as devDependencies.
69
69
  */
70
70
  async function installDependencies(baseDir, dependencies, isDev = false) {
71
- console.log("Initializing new Node.js project...");
72
- // Initialize a package.json if it doesn't exist
73
- execSync("npm init -y", {
74
- stdio: "inherit",
75
- cwd: baseDir,
76
- });
77
- // Log the dependencies being installed
78
- console.log(`${isDev ? "Installing development dependencies" : "Installing dependencies"}:`);
79
- dependencies.forEach((dep) => console.log(`- ${chalk.blue(dep)}`));
80
- // Prepare the npm install command with the appropriate flag for dev dependencies
81
- const npmInstallCommand = `npm install ${isDev ? "--save-dev" : ""} ${dependencies.join(" ")}`;
82
- // Execute the npm install command
83
- execSync(npmInstallCommand, {
84
- stdio: "inherit",
85
- cwd: baseDir,
86
- });
71
+ console.log("Initializing new Node.js project...");
72
+ // Initialize a package.json if it doesn't exist
73
+ execSync("npm init -y", {
74
+ stdio: "inherit",
75
+ cwd: baseDir,
76
+ });
77
+ // Log the dependencies being installed
78
+ console.log(
79
+ `${
80
+ isDev ? "Installing development dependencies" : "Installing dependencies"
81
+ }:`
82
+ );
83
+ dependencies.forEach((dep) => console.log(`- ${chalk.blue(dep)}`));
84
+ // Prepare the npm install command with the appropriate flag for dev dependencies
85
+ const npmInstallCommand = `npm install ${
86
+ isDev ? "--save-dev" : ""
87
+ } ${dependencies.join(" ")}`;
88
+ // Execute the npm install command
89
+ execSync(npmInstallCommand, {
90
+ stdio: "inherit",
91
+ cwd: baseDir,
92
+ });
87
93
  }
88
94
  function fetchPackageVersion(packageName) {
89
- return new Promise((resolve, reject) => {
90
- https
91
- .get(`https://registry.npmjs.org/${packageName}`, (res) => {
92
- let data = "";
93
- res.on("data", (chunk) => (data += chunk));
94
- res.on("end", () => {
95
- try {
96
- const parsed = JSON.parse(data);
97
- resolve(parsed["dist-tags"].latest);
98
- }
99
- catch (error) {
100
- reject(new Error("Failed to parse JSON response"));
101
- }
102
- });
103
- })
104
- .on("error", (err) => reject(err));
105
- });
95
+ return new Promise((resolve, reject) => {
96
+ https
97
+ .get(`https://registry.npmjs.org/${packageName}`, (res) => {
98
+ let data = "";
99
+ res.on("data", (chunk) => (data += chunk));
100
+ res.on("end", () => {
101
+ try {
102
+ const parsed = JSON.parse(data);
103
+ resolve(parsed["dist-tags"].latest);
104
+ } catch (error) {
105
+ reject(new Error("Failed to parse JSON response"));
106
+ }
107
+ });
108
+ })
109
+ .on("error", (err) => reject(err));
110
+ });
106
111
  }
107
112
  async function main() {
108
- try {
109
- const args = process.argv.slice(2);
110
- let projectName = args[0];
111
- console.log("🚀 ~ main ~ projectName:", projectName);
112
- let answer = null;
113
- if (projectName) {
114
- let useTailwind = args.includes("--tailwind");
115
- let useWebsocket = args.includes("--websocket");
116
- const predefinedAnswers = {
117
- projectName,
118
- tailwindcss: useTailwind,
119
- websocket: useWebsocket,
120
- };
121
- answer = await getAnswer(predefinedAnswers);
122
- console.log("🚀 ~ main ~ answer:", answer);
123
- }
124
- else {
125
- answer = await getAnswer();
126
- }
127
- if (answer === null) {
128
- console.log(chalk.red("Installation cancelled."));
129
- return;
130
- }
131
- // execSync(`npm install -g create-prisma-php-app`, { stdio: "inherit" }); // TODO: Uncomment this line before publishing the package
132
- execSync(`npm install -g create-prisma-php-app@alpha-update-command`, {
133
- stdio: "inherit",
134
- }); // TODO: Uncomment this line before publishing the package
135
- // Support for browser-sync
136
- execSync(`npm install -g browser-sync`, { stdio: "inherit" });
137
- // Create the project directory
138
- if (!projectName)
139
- fs.mkdirSync(answer.projectName);
140
- const projectPath = path.join(process.cwd(), answer.projectName);
141
- process.chdir(answer.projectName);
142
- const dependencies = [
143
- "prisma",
144
- "@prisma/client",
145
- "typescript",
146
- "@types/node",
147
- "ts-node",
148
- "http-proxy-middleware",
149
- ];
150
- if (answer.tailwindcss) {
151
- dependencies.push("tailwindcss", "autoprefixer", "postcss", "postcss-cli", "cssnano");
152
- }
153
- if (answer.websocket) {
154
- dependencies.push("chokidar-cli");
155
- }
156
- if (answer.tailwindcss || answer.websocket) {
157
- dependencies.push("npm-run-all");
158
- }
159
- await installDependencies(projectPath, dependencies, true);
160
- execSync(`npx prisma init`, { stdio: "inherit" });
161
- execSync(`npx tsc --init`, { stdio: "inherit" });
162
- if (answer.tailwindcss) {
163
- execSync(`npx tailwindcss init -p`, { stdio: "inherit" });
164
- }
165
- const projectSettings = {
166
- PROJECT_NAME: answer.projectName,
167
- PROJECT_ROOT_PATH: projectPath.replace(/\\/g, "\\\\"),
168
- PHP_ROOT_PATH_EXE: "D:\\\\xampp\\\\php\\\\php.exe",
169
- PHP_GENERATE_CLASS_PATH: "src/lib/prisma/classes",
170
- };
171
- await createDirectoryStructure(projectPath, answer, projectSettings);
172
- // if (answer.tailwindcss) {
173
- // execSync(
174
- // `npx tailwindcss -i ./src/app/css/tailwind.css -o ./src/app/css/styles.css --minify`,
175
- // { stdio: "inherit" }
176
- // );
177
- // }
178
- // execSync(`composer install`, { stdio: "inherit" });
179
- // execSync(`composer dump-autoload`, { stdio: "inherit" });
180
- // Create settings file
181
- const settingsPath = path.join(projectPath, "settings", "project-settings.js");
182
- const settingsCode = `export const projectSettings = {
113
+ try {
114
+ const args = process.argv.slice(2);
115
+ let projectName = args[0];
116
+ console.log("🚀 ~ main ~ projectName:", projectName);
117
+ let answer = null;
118
+ if (projectName) {
119
+ let useTailwind = args.includes("--tailwind");
120
+ let useWebsocket = args.includes("--websocket");
121
+ const predefinedAnswers = {
122
+ projectName,
123
+ tailwindcss: useTailwind,
124
+ websocket: useWebsocket,
125
+ };
126
+ answer = await getAnswer(predefinedAnswers);
127
+ console.log("🚀 ~ main ~ answer:", answer);
128
+ } else {
129
+ answer = await getAnswer();
130
+ }
131
+ if (answer === null) {
132
+ console.log(chalk.red("Installation cancelled."));
133
+ return;
134
+ }
135
+ // execSync(`npm install -g create-prisma-php-app`, { stdio: "inherit" }); // TODO: Uncomment this line before publishing the package
136
+ execSync(`npm install -g create-prisma-php-app@alpha-update-command`, {
137
+ stdio: "inherit",
138
+ }); // TODO: Uncomment this line before publishing the package
139
+ // Support for browser-sync
140
+ execSync(`npm install -g browser-sync`, { stdio: "inherit" });
141
+ // Create the project directory
142
+ if (!projectName) fs.mkdirSync(answer.projectName);
143
+ const projectPath = path.join(process.cwd(), answer.projectName);
144
+ process.chdir(answer.projectName);
145
+ const dependencies = [
146
+ "prisma",
147
+ "@prisma/client",
148
+ "typescript",
149
+ "@types/node",
150
+ "ts-node",
151
+ "http-proxy-middleware",
152
+ ];
153
+ if (answer.tailwindcss) {
154
+ dependencies.push(
155
+ "tailwindcss",
156
+ "autoprefixer",
157
+ "postcss",
158
+ "postcss-cli",
159
+ "cssnano"
160
+ );
161
+ }
162
+ if (answer.websocket) {
163
+ dependencies.push("chokidar-cli");
164
+ }
165
+ if (answer.tailwindcss || answer.websocket) {
166
+ dependencies.push("npm-run-all");
167
+ }
168
+ await installDependencies(projectPath, dependencies, true);
169
+ execSync(`npx prisma init`, { stdio: "inherit" });
170
+ execSync(`npx tsc --init`, { stdio: "inherit" });
171
+ if (answer.tailwindcss) {
172
+ execSync(`npx tailwindcss init -p`, { stdio: "inherit" });
173
+ }
174
+ const projectSettings = {
175
+ PROJECT_NAME: answer.projectName,
176
+ PROJECT_ROOT_PATH: projectPath.replace(/\\/g, "\\\\"),
177
+ PHP_ROOT_PATH_EXE: "D:\\\\xampp\\\\php\\\\php.exe",
178
+ PHP_GENERATE_CLASS_PATH: "src/lib/prisma/classes",
179
+ };
180
+ await createDirectoryStructure(projectPath, answer, projectSettings);
181
+ // if (answer.tailwindcss) {
182
+ // execSync(
183
+ // `npx tailwindcss -i ./src/app/css/tailwind.css -o ./src/app/css/styles.css --minify`,
184
+ // { stdio: "inherit" }
185
+ // );
186
+ // }
187
+ // execSync(`composer install`, { stdio: "inherit" });
188
+ // execSync(`composer dump-autoload`, { stdio: "inherit" });
189
+ // Create settings file
190
+ const settingsPath = path.join(
191
+ projectPath,
192
+ "settings",
193
+ "project-settings.js"
194
+ );
195
+ const settingsCode = `export const projectSettings = {
183
196
  PROJECT_NAME: "${answer.projectName}",
184
197
  PROJECT_ROOT_PATH: "${projectPath.replace(/\\/g, "\\\\")}",
185
198
  PHP_ROOT_PATH_EXE: "D:\\\\xampp\\\\php\\\\php.exe",
186
199
  PHP_GENERATE_CLASS_PATH: "src/lib/prisma/classes",
187
200
  };`;
188
- fs.writeFileSync(settingsPath, settingsCode);
189
- // Create public directory
190
- fs.mkdirSync(path.join(projectPath, "public"));
191
- // Update css if tailwindcss is not chosen by the user
192
- if (!answer.tailwindcss) {
193
- // delete specific files of tailwindcss if not chosen
194
- const cssPath = path.join(projectPath, "src", "app", "css");
195
- const tailwindFiles = ["tailwind.css", "styles.css"];
196
- tailwindFiles.forEach((file) => {
197
- const filePath = path.join(cssPath, file);
198
- if (fs.existsSync(filePath)) {
199
- fs.unlinkSync(filePath); // Delete each file if it exists
200
- console.log(`${file} was deleted successfully.`);
201
- }
202
- else {
203
- console.log(`${file} does not exist.`);
204
- }
205
- });
201
+ fs.writeFileSync(settingsPath, settingsCode);
202
+ // Create public directory
203
+ fs.mkdirSync(path.join(projectPath, "public"));
204
+ // Update css if tailwindcss is not chosen by the user
205
+ if (!answer.tailwindcss) {
206
+ // delete specific files of tailwindcss if not chosen
207
+ const cssPath = path.join(projectPath, "src", "app", "css");
208
+ const tailwindFiles = ["tailwind.css", "styles.css"];
209
+ tailwindFiles.forEach((file) => {
210
+ const filePath = path.join(cssPath, file);
211
+ if (fs.existsSync(filePath)) {
212
+ fs.unlinkSync(filePath); // Delete each file if it exists
213
+ console.log(`${file} was deleted successfully.`);
214
+ } else {
215
+ console.log(`${file} does not exist.`);
206
216
  }
207
- // Update websocket if not chosen by the user
208
- if (!answer.websocket) {
209
- const wsPath = path.join(projectPath, "src", "lib", "websocket");
210
- // Check if the websocket directory exists
211
- if (fs.existsSync(wsPath)) {
212
- // Use fs.rmSync with recursive option set to true to delete the directory and its contents
213
- fs.rmSync(wsPath, { recursive: true, force: true }); // force option is not necessary but can be used to ensure deletion
214
- console.log("Websocket directory was deleted successfully.");
215
- }
216
- else {
217
- console.log("Websocket directory does not exist.");
218
- }
219
- // Update settings directory if websocket is not chosen
220
- const settingsPath = path.join(projectPath, "settings");
221
- const websocketFiles = ["restartWebsocket.cjs", "restart_websocket.bat"];
222
- websocketFiles.forEach((file) => {
223
- const filePath = path.join(settingsPath, file);
224
- if (fs.existsSync(filePath)) {
225
- fs.unlinkSync(filePath); // Delete each file if it exists
226
- console.log(`${file} was deleted successfully.`);
227
- }
228
- else {
229
- console.log(`${file} does not exist.`);
230
- }
231
- });
232
- }
233
- const version = await fetchPackageVersion("create-prisma-php-app");
234
- const prismaPhpConfig = {
235
- projectName: answer.projectName,
236
- tailwindcss: answer.tailwindcss,
237
- websocket: answer.websocket,
238
- version,
239
- };
240
- fs.writeFileSync(path.join(projectPath, "prisma-php.json"), JSON.stringify(prismaPhpConfig, null, 2));
241
- console.log(`${chalk.green("Success!")} Prisma PHP project successfully created in ${answer.projectName}!`);
217
+ });
242
218
  }
243
- catch (error) {
244
- console.error("Error while creating the project:", error);
245
- process.exit(1);
219
+ // Update websocket if not chosen by the user
220
+ if (!answer.websocket) {
221
+ const wsPath = path.join(projectPath, "src", "lib", "websocket");
222
+ // Check if the websocket directory exists
223
+ if (fs.existsSync(wsPath)) {
224
+ // Use fs.rmSync with recursive option set to true to delete the directory and its contents
225
+ fs.rmSync(wsPath, { recursive: true, force: true }); // force option is not necessary but can be used to ensure deletion
226
+ console.log("Websocket directory was deleted successfully.");
227
+ } else {
228
+ console.log("Websocket directory does not exist.");
229
+ }
230
+ // Update settings directory if websocket is not chosen
231
+ const settingsPath = path.join(projectPath, "settings");
232
+ const websocketFiles = ["restartWebsocket.cjs", "restart_websocket.bat"];
233
+ websocketFiles.forEach((file) => {
234
+ const filePath = path.join(settingsPath, file);
235
+ if (fs.existsSync(filePath)) {
236
+ fs.unlinkSync(filePath); // Delete each file if it exists
237
+ console.log(`${file} was deleted successfully.`);
238
+ } else {
239
+ console.log(`${file} does not exist.`);
240
+ }
241
+ });
246
242
  }
243
+ const version = await fetchPackageVersion("create-prisma-php-app");
244
+ const prismaPhpConfig = {
245
+ projectName: answer.projectName,
246
+ tailwindcss: answer.tailwindcss,
247
+ websocket: answer.websocket,
248
+ version,
249
+ };
250
+ fs.writeFileSync(
251
+ path.join(projectPath, "prisma-php.json"),
252
+ JSON.stringify(prismaPhpConfig, null, 2)
253
+ );
254
+ console.log(
255
+ `${chalk.green("Success!")} Prisma PHP project successfully created in ${
256
+ answer.projectName
257
+ }!`
258
+ );
259
+ } catch (error) {
260
+ console.error("Error while creating the project:", error);
261
+ process.exit(1);
262
+ }
247
263
  }
248
264
  main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "1.6.13",
3
+ "version": "1.6.14",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",