create-prisma-php-app 1.6.14 → 1.6.16
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 +133 -252
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,264 +1,145 @@
|
|
|
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,
|
|
3
|
-
async function getAnswer(predefinedAnswers = {}) {
|
|
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;
|
|
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
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Install dependencies in the specified directory.
|
|
66
|
-
* @param {string} baseDir - The base directory where to install the dependencies.
|
|
67
|
-
* @param {string[]} dependencies - The list of dependencies to install.
|
|
68
|
-
* @param {boolean} [isDev=false] - Whether to install the dependencies as devDependencies.
|
|
69
|
-
*/
|
|
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(
|
|
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
|
-
});
|
|
93
|
-
}
|
|
94
|
-
function fetchPackageVersion(packageName) {
|
|
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
|
-
});
|
|
111
|
-
}
|
|
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||i.push({type:"text",name:"projectName",message:"What is your project named?",initial:"my-app"}),e.tailwindcss||i.push({type:"toggle",name:"tailwindcss",message:`Would you like to use ${chalk.blue("Tailwind CSS")}?`,initial:!0,active:"Yes",inactive:"No"}),e.websocket||i.push({type:"toggle",name:"websocket",message:`Would you like to use ${chalk.blue("Websocket")}?`,initial:!0,active:"Yes",inactive:"No"});const c=()=>!1;try{const r=await prompts(i,{onCancel:c});return 0===Object.keys(r).length?null:{projectName:r.projectName?String(r.projectName).trim().replace(/ /g,"-"):null!==(t=e.projectName)&&void 0!==t?t:"my-app",tailwindcss:null!==(s=r.tailwindcss)&&void 0!==s?s:e.tailwindcss,websocket:null!==(n=r.websocket)&&void 0!==n?n:e.websocket}}catch(e){return null}}async function installDependencies(e,t,s=!1){fs.existsSync(path.join(e,"package.json"))||execSync("npm init -y",{stdio:"inherit",cwd:e}),t.forEach((e=>{}));const n=`npm install ${s?"--save-dev":""} ${t.join(" ")}`;execSync(n,{stdio:"inherit",cwd:e})}function fetchPackageVersion(e){return new Promise(((t,s)=>{https.get(`https://registry.npmjs.org/${e}`,(e=>{let n="";e.on("data",(e=>n+=e)),e.on("end",(()=>{try{const e=JSON.parse(n);t(e["dist-tags"].latest)}catch(e){s(new Error("Failed to parse JSON response"))}}))})).on("error",(e=>s(e)))}))}
|
|
112
3
|
async function main() {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
// Create settings file
|
|
190
|
-
const settingsPath = path.join(
|
|
191
|
-
projectPath,
|
|
192
|
-
"settings",
|
|
193
|
-
"project-settings.js"
|
|
194
|
-
);
|
|
195
|
-
const settingsCode = `export const projectSettings = {
|
|
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
|
+
answer = await getAnswer(predefinedAnswers);
|
|
18
|
+
console.log("🚀 ~ main ~ answer:", answer);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
answer = await getAnswer();
|
|
22
|
+
}
|
|
23
|
+
if (answer === null) {
|
|
24
|
+
console.log(chalk.red("Installation cancelled."));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
// execSync(`npm install -g create-prisma-php-app`, { stdio: "inherit" }); // TODO: Uncomment this line before publishing the package
|
|
28
|
+
execSync(`npm install -g create-prisma-php-app@alpha-update-command`, {
|
|
29
|
+
stdio: "inherit",
|
|
30
|
+
}); // TODO: Uncomment this line before publishing the package
|
|
31
|
+
// Support for browser-sync
|
|
32
|
+
execSync(`npm install -g browser-sync`, { stdio: "inherit" });
|
|
33
|
+
// Create the project directory
|
|
34
|
+
if (!projectName)
|
|
35
|
+
fs.mkdirSync(answer.projectName);
|
|
36
|
+
const projectPath = path.join(process.cwd(), answer.projectName);
|
|
37
|
+
if (!projectName)
|
|
38
|
+
process.chdir(answer.projectName);
|
|
39
|
+
const dependencies = [
|
|
40
|
+
"prisma",
|
|
41
|
+
"@prisma/client",
|
|
42
|
+
"typescript",
|
|
43
|
+
"@types/node",
|
|
44
|
+
"ts-node",
|
|
45
|
+
"http-proxy-middleware",
|
|
46
|
+
];
|
|
47
|
+
if (answer.tailwindcss) {
|
|
48
|
+
dependencies.push("tailwindcss", "autoprefixer", "postcss", "postcss-cli", "cssnano");
|
|
49
|
+
}
|
|
50
|
+
if (answer.websocket) {
|
|
51
|
+
dependencies.push("chokidar-cli");
|
|
52
|
+
}
|
|
53
|
+
if (answer.tailwindcss || answer.websocket) {
|
|
54
|
+
dependencies.push("npm-run-all");
|
|
55
|
+
}
|
|
56
|
+
await installDependencies(projectPath, dependencies, true);
|
|
57
|
+
execSync(`npx prisma init`, { stdio: "inherit" });
|
|
58
|
+
execSync(`npx tsc --init`, { stdio: "inherit" });
|
|
59
|
+
if (answer.tailwindcss) {
|
|
60
|
+
execSync(`npx tailwindcss init -p`, { stdio: "inherit" });
|
|
61
|
+
}
|
|
62
|
+
const projectSettings = {
|
|
63
|
+
PROJECT_NAME: answer.projectName,
|
|
64
|
+
PROJECT_ROOT_PATH: projectPath.replace(/\\/g, "\\\\"),
|
|
65
|
+
PHP_ROOT_PATH_EXE: "D:\\\\xampp\\\\php\\\\php.exe",
|
|
66
|
+
PHP_GENERATE_CLASS_PATH: "src/lib/prisma/classes",
|
|
67
|
+
};
|
|
68
|
+
await createDirectoryStructure(projectPath, answer, projectSettings);
|
|
69
|
+
// if (answer.tailwindcss) {
|
|
70
|
+
// execSync(
|
|
71
|
+
// `npx tailwindcss -i ./src/app/css/tailwind.css -o ./src/app/css/styles.css --minify`,
|
|
72
|
+
// { stdio: "inherit" }
|
|
73
|
+
// );
|
|
74
|
+
// }
|
|
75
|
+
// execSync(`composer install`, { stdio: "inherit" });
|
|
76
|
+
// execSync(`composer dump-autoload`, { stdio: "inherit" });
|
|
77
|
+
// Create settings file
|
|
78
|
+
const settingsPath = path.join(projectPath, "settings", "project-settings.js");
|
|
79
|
+
const settingsCode = `export const projectSettings = {
|
|
196
80
|
PROJECT_NAME: "${answer.projectName}",
|
|
197
81
|
PROJECT_ROOT_PATH: "${projectPath.replace(/\\/g, "\\\\")}",
|
|
198
82
|
PHP_ROOT_PATH_EXE: "D:\\\\xampp\\\\php\\\\php.exe",
|
|
199
83
|
PHP_GENERATE_CLASS_PATH: "src/lib/prisma/classes",
|
|
200
84
|
};`;
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
85
|
+
fs.writeFileSync(settingsPath, settingsCode);
|
|
86
|
+
// Create public directory
|
|
87
|
+
fs.mkdirSync(path.join(projectPath, "public"));
|
|
88
|
+
// Update css if tailwindcss is not chosen by the user
|
|
89
|
+
if (!answer.tailwindcss) {
|
|
90
|
+
// delete specific files of tailwindcss if not chosen
|
|
91
|
+
const cssPath = path.join(projectPath, "src", "app", "css");
|
|
92
|
+
const tailwindFiles = ["tailwind.css", "styles.css"];
|
|
93
|
+
tailwindFiles.forEach((file) => {
|
|
94
|
+
const filePath = path.join(cssPath, file);
|
|
95
|
+
if (fs.existsSync(filePath)) {
|
|
96
|
+
fs.unlinkSync(filePath); // Delete each file if it exists
|
|
97
|
+
console.log(`${file} was deleted successfully.`);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
console.log(`${file} does not exist.`);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
216
103
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
104
|
+
// Update websocket if not chosen by the user
|
|
105
|
+
if (!answer.websocket) {
|
|
106
|
+
const wsPath = path.join(projectPath, "src", "lib", "websocket");
|
|
107
|
+
// Check if the websocket directory exists
|
|
108
|
+
if (fs.existsSync(wsPath)) {
|
|
109
|
+
// Use fs.rmSync with recursive option set to true to delete the directory and its contents
|
|
110
|
+
fs.rmSync(wsPath, { recursive: true, force: true }); // force option is not necessary but can be used to ensure deletion
|
|
111
|
+
console.log("Websocket directory was deleted successfully.");
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
console.log("Websocket directory does not exist.");
|
|
115
|
+
}
|
|
116
|
+
// Update settings directory if websocket is not chosen
|
|
117
|
+
const settingsPath = path.join(projectPath, "settings");
|
|
118
|
+
const websocketFiles = ["restartWebsocket.cjs", "restart_websocket.bat"];
|
|
119
|
+
websocketFiles.forEach((file) => {
|
|
120
|
+
const filePath = path.join(settingsPath, file);
|
|
121
|
+
if (fs.existsSync(filePath)) {
|
|
122
|
+
fs.unlinkSync(filePath); // Delete each file if it exists
|
|
123
|
+
console.log(`${file} was deleted successfully.`);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
console.log(`${file} does not exist.`);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
240
129
|
}
|
|
241
|
-
|
|
130
|
+
const version = await fetchPackageVersion("create-prisma-php-app");
|
|
131
|
+
const prismaPhpConfig = {
|
|
132
|
+
projectName: answer.projectName,
|
|
133
|
+
tailwindcss: answer.tailwindcss,
|
|
134
|
+
websocket: answer.websocket,
|
|
135
|
+
version,
|
|
136
|
+
};
|
|
137
|
+
fs.writeFileSync(path.join(projectPath, "prisma-php.json"), JSON.stringify(prismaPhpConfig, null, 2));
|
|
138
|
+
console.log(`${chalk.green("Success!")} Prisma PHP project successfully created in ${answer.projectName}!`);
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
console.error("Error while creating the project:", error);
|
|
142
|
+
process.exit(1);
|
|
242
143
|
}
|
|
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
|
-
}
|
|
263
144
|
}
|
|
264
145
|
main();
|