create-prisma-php-app 1.11.534 → 1.11.536
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 +601 -714
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10,51 +10,43 @@ const __filename = fileURLToPath(import.meta.url);
|
|
|
10
10
|
const __dirname = path.dirname(__filename);
|
|
11
11
|
let updateAnswer = null;
|
|
12
12
|
function bsConfigUrls(projectSettings) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
// Identify the base path dynamically up to and including 'htdocs'
|
|
14
|
+
const htdocsIndex = projectSettings.PROJECT_ROOT_PATH.indexOf("\\htdocs\\");
|
|
15
|
+
if (htdocsIndex === -1) {
|
|
16
|
+
console.error("Invalid PROJECT_ROOT_PATH. The path does not contain \\htdocs\\");
|
|
17
|
+
return {
|
|
18
|
+
bsTarget: "",
|
|
19
|
+
bsPathRewrite: {},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
// Extract the path up to and including 'htdocs\\'
|
|
23
|
+
const basePathToRemove = projectSettings.PROJECT_ROOT_PATH.substring(0, htdocsIndex + "\\htdocs\\".length);
|
|
24
|
+
// Escape backslashes for the regex pattern
|
|
25
|
+
const escapedBasePathToRemove = basePathToRemove.replace(/\\/g, "\\\\");
|
|
26
|
+
// Remove the base path and replace backslashes with forward slashes for URL compatibility
|
|
27
|
+
const relativeWebPath = projectSettings.PROJECT_ROOT_PATH.replace(new RegExp(`^${escapedBasePathToRemove}`), "").replace(/\\/g, "/");
|
|
28
|
+
// Construct the Browser Sync command with the correct proxy URL, being careful not to affect the protocol part
|
|
29
|
+
let proxyUrl = `http://localhost/${relativeWebPath}`;
|
|
30
|
+
// Ensure the proxy URL does not end with a slash before appending '/public'
|
|
31
|
+
proxyUrl = proxyUrl.endsWith("/") ? proxyUrl.slice(0, -1) : proxyUrl;
|
|
32
|
+
// Clean the URL by replacing "//" with "/" but not affecting "http://"
|
|
33
|
+
// We replace instances of "//" that are not preceded by ":"
|
|
34
|
+
const cleanUrl = proxyUrl.replace(/(?<!:)(\/\/+)/g, "/");
|
|
35
|
+
const cleanRelativeWebPath = relativeWebPath.replace(/\/\/+/g, "/");
|
|
36
|
+
// Correct the relativeWebPath to ensure it does not start with a "/"
|
|
37
|
+
const adjustedRelativeWebPath = cleanRelativeWebPath.startsWith("/")
|
|
38
|
+
? cleanRelativeWebPath.substring(1)
|
|
39
|
+
: cleanRelativeWebPath;
|
|
19
40
|
return {
|
|
20
|
-
|
|
21
|
-
|
|
41
|
+
bsTarget: `${cleanUrl}/`,
|
|
42
|
+
bsPathRewrite: {
|
|
43
|
+
"^/": `/${adjustedRelativeWebPath}/`,
|
|
44
|
+
},
|
|
22
45
|
};
|
|
23
|
-
}
|
|
24
|
-
// Extract the path up to and including 'htdocs\\'
|
|
25
|
-
const basePathToRemove = projectSettings.PROJECT_ROOT_PATH.substring(
|
|
26
|
-
0,
|
|
27
|
-
htdocsIndex + "\\htdocs\\".length
|
|
28
|
-
);
|
|
29
|
-
// Escape backslashes for the regex pattern
|
|
30
|
-
const escapedBasePathToRemove = basePathToRemove.replace(/\\/g, "\\\\");
|
|
31
|
-
// Remove the base path and replace backslashes with forward slashes for URL compatibility
|
|
32
|
-
const relativeWebPath = projectSettings.PROJECT_ROOT_PATH.replace(
|
|
33
|
-
new RegExp(`^${escapedBasePathToRemove}`),
|
|
34
|
-
""
|
|
35
|
-
).replace(/\\/g, "/");
|
|
36
|
-
// Construct the Browser Sync command with the correct proxy URL, being careful not to affect the protocol part
|
|
37
|
-
let proxyUrl = `http://localhost/${relativeWebPath}`;
|
|
38
|
-
// Ensure the proxy URL does not end with a slash before appending '/public'
|
|
39
|
-
proxyUrl = proxyUrl.endsWith("/") ? proxyUrl.slice(0, -1) : proxyUrl;
|
|
40
|
-
// Clean the URL by replacing "//" with "/" but not affecting "http://"
|
|
41
|
-
// We replace instances of "//" that are not preceded by ":"
|
|
42
|
-
const cleanUrl = proxyUrl.replace(/(?<!:)(\/\/+)/g, "/");
|
|
43
|
-
const cleanRelativeWebPath = relativeWebPath.replace(/\/\/+/g, "/");
|
|
44
|
-
// Correct the relativeWebPath to ensure it does not start with a "/"
|
|
45
|
-
const adjustedRelativeWebPath = cleanRelativeWebPath.startsWith("/")
|
|
46
|
-
? cleanRelativeWebPath.substring(1)
|
|
47
|
-
: cleanRelativeWebPath;
|
|
48
|
-
return {
|
|
49
|
-
bsTarget: `${cleanUrl}/`,
|
|
50
|
-
bsPathRewrite: {
|
|
51
|
-
"^/": `/${adjustedRelativeWebPath}/`,
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
46
|
}
|
|
55
47
|
function configureBrowserSyncCommand(baseDir) {
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
// TypeScript content to write
|
|
49
|
+
const bsConfigTsContent = `const { createProxyMiddleware } = require("http-proxy-middleware");
|
|
58
50
|
const fs = require("fs");
|
|
59
51
|
|
|
60
52
|
const jsonData = fs.readFileSync("prisma-php.json", "utf8");
|
|
@@ -80,329 +72,291 @@ module.exports = {
|
|
|
80
72
|
open: false,
|
|
81
73
|
ghostMode: false,
|
|
82
74
|
};`;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
75
|
+
// Determine the path and write the bs-config.js
|
|
76
|
+
const bsConfigPath = path.join(baseDir, "settings", "bs-config.cjs");
|
|
77
|
+
fs.writeFileSync(bsConfigPath, bsConfigTsContent, "utf8");
|
|
78
|
+
// Return the Browser Sync command string, using the cleaned URL
|
|
79
|
+
return `browser-sync start --config settings/bs-config.cjs`;
|
|
88
80
|
}
|
|
89
81
|
async function updatePackageJson(baseDir, answer) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
projectName: "node settings/project-name.cjs"
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
? `npm-run-all --parallel projectName browser-sync ${answersToInclude.join(
|
|
130
|
-
" "
|
|
131
|
-
)}`
|
|
132
|
-
: `npm-run-all --parallel projectName browser-sync`;
|
|
133
|
-
// Finally, assign the updated scripts back to packageJson
|
|
134
|
-
packageJson.scripts = updatedScripts;
|
|
135
|
-
packageJson.type = "module";
|
|
136
|
-
if (answer.prisma)
|
|
137
|
-
packageJson.prisma = {
|
|
138
|
-
seed: "node prisma/seed.js",
|
|
139
|
-
};
|
|
140
|
-
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
82
|
+
const packageJsonPath = path.join(baseDir, "package.json");
|
|
83
|
+
if (checkExcludeFiles(packageJsonPath))
|
|
84
|
+
return;
|
|
85
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
86
|
+
// Use the new function to configure the Browser Sync command
|
|
87
|
+
const browserSyncCommand = configureBrowserSyncCommand(baseDir);
|
|
88
|
+
packageJson.scripts = Object.assign(Object.assign({}, packageJson.scripts), { projectName: "node settings/project-name.cjs" });
|
|
89
|
+
let answersToInclude = [];
|
|
90
|
+
if (answer.tailwindcss) {
|
|
91
|
+
packageJson.scripts = Object.assign(Object.assign({}, packageJson.scripts), { tailwind: "postcss ./src/app/css/tailwind.css -o ./src/app/css/styles.css --watch" });
|
|
92
|
+
answersToInclude.push("tailwind");
|
|
93
|
+
}
|
|
94
|
+
if (answer.websocket) {
|
|
95
|
+
packageJson.scripts = Object.assign(Object.assign({}, packageJson.scripts), { websocket: "node ./settings/restart-websocket.cjs" });
|
|
96
|
+
answersToInclude.push("websocket");
|
|
97
|
+
}
|
|
98
|
+
// if (answer.prisma) {
|
|
99
|
+
// packageJson.scripts = {
|
|
100
|
+
// ...packageJson.scripts,
|
|
101
|
+
// postinstall: "prisma generate",
|
|
102
|
+
// };
|
|
103
|
+
// }
|
|
104
|
+
// Initialize with existing scripts
|
|
105
|
+
const updatedScripts = Object.assign({}, packageJson.scripts);
|
|
106
|
+
// Conditionally add "browser-sync" command
|
|
107
|
+
updatedScripts["browser-sync"] = browserSyncCommand;
|
|
108
|
+
// Conditionally set the "dev" command
|
|
109
|
+
updatedScripts.dev =
|
|
110
|
+
answersToInclude.length > 0
|
|
111
|
+
? `npm-run-all --parallel projectName browser-sync ${answersToInclude.join(" ")}`
|
|
112
|
+
: `npm-run-all --parallel projectName browser-sync`;
|
|
113
|
+
// Finally, assign the updated scripts back to packageJson
|
|
114
|
+
packageJson.scripts = updatedScripts;
|
|
115
|
+
packageJson.type = "module";
|
|
116
|
+
if (answer.prisma)
|
|
117
|
+
packageJson.prisma = {
|
|
118
|
+
seed: "node prisma/seed.js",
|
|
119
|
+
};
|
|
120
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
141
121
|
}
|
|
142
122
|
async function updateComposerJson(baseDir, answer) {
|
|
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
|
-
// Write the modified composer.json back to the file
|
|
169
|
-
fs.writeFileSync(composerJsonPath, JSON.stringify(composerJson, null, 2));
|
|
170
|
-
console.log("composer.json updated successfully.");
|
|
123
|
+
const composerJsonPath = path.join(baseDir, "composer.json");
|
|
124
|
+
if (checkExcludeFiles(composerJsonPath))
|
|
125
|
+
return;
|
|
126
|
+
let composerJson;
|
|
127
|
+
// Check if the composer.json file exists
|
|
128
|
+
if (fs.existsSync(composerJsonPath)) {
|
|
129
|
+
// Read the current composer.json content
|
|
130
|
+
const composerJsonContent = fs.readFileSync(composerJsonPath, "utf8");
|
|
131
|
+
composerJson = JSON.parse(composerJsonContent);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
console.error("composer.json does not exist.");
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
// Conditionally add WebSocket dependency
|
|
138
|
+
if (answer.websocket) {
|
|
139
|
+
composerJson.require = Object.assign(Object.assign({}, composerJson.require), { "cboden/ratchet": "^0.4.4" });
|
|
140
|
+
}
|
|
141
|
+
if (answer.prisma) {
|
|
142
|
+
composerJson.require = Object.assign(Object.assign({}, composerJson.require), { "ramsey/uuid": "5.x-dev", "hidehalo/nanoid-php": "1.x-dev" });
|
|
143
|
+
}
|
|
144
|
+
// Write the modified composer.json back to the file
|
|
145
|
+
fs.writeFileSync(composerJsonPath, JSON.stringify(composerJson, null, 2));
|
|
146
|
+
console.log("composer.json updated successfully.");
|
|
171
147
|
}
|
|
172
148
|
async function updateIndexJsForWebSocket(baseDir, answer) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
149
|
+
if (!answer.websocket) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const indexPath = path.join(baseDir, "src", "app", "js", "index.js");
|
|
153
|
+
if (checkExcludeFiles(indexPath))
|
|
154
|
+
return;
|
|
155
|
+
let indexContent = fs.readFileSync(indexPath, "utf8");
|
|
156
|
+
// WebSocket initialization code to be appended
|
|
157
|
+
const webSocketCode = `
|
|
181
158
|
// WebSocket initialization
|
|
182
159
|
const ws = new WebSocket("ws://localhost:8080");
|
|
183
160
|
`;
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
161
|
+
// Append WebSocket code if user chose to use WebSocket
|
|
162
|
+
indexContent += webSocketCode;
|
|
163
|
+
fs.writeFileSync(indexPath, indexContent, "utf8");
|
|
164
|
+
console.log("WebSocket code added to index.js successfully.");
|
|
188
165
|
}
|
|
189
166
|
// This function updates the .gitignore file
|
|
190
167
|
async function createUpdateGitignoreFile(baseDir, additions) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
additions.forEach((addition) => {
|
|
199
|
-
if (!gitignoreContent.includes(addition)) {
|
|
200
|
-
gitignoreContent += `\n${addition}`;
|
|
168
|
+
const gitignorePath = path.join(baseDir, ".gitignore");
|
|
169
|
+
if (checkExcludeFiles(gitignorePath))
|
|
170
|
+
return;
|
|
171
|
+
// Check if the .gitignore file exists, create if it doesn't
|
|
172
|
+
let gitignoreContent = "";
|
|
173
|
+
if (fs.existsSync(gitignorePath)) {
|
|
174
|
+
gitignoreContent = fs.readFileSync(gitignorePath, "utf8");
|
|
201
175
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
176
|
+
additions.forEach((addition) => {
|
|
177
|
+
if (!gitignoreContent.includes(addition)) {
|
|
178
|
+
gitignoreContent += `\n${addition}`;
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
// Ensure there's no leading newline if the file was just created
|
|
182
|
+
gitignoreContent = gitignoreContent.trimStart();
|
|
183
|
+
fs.writeFileSync(gitignorePath, gitignoreContent);
|
|
206
184
|
}
|
|
207
185
|
// Recursive copy function
|
|
208
186
|
function copyRecursiveSync(src, dest, answer) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
!answer.websocket &&
|
|
234
|
-
(dest.includes("restart-websocket.cjs") ||
|
|
235
|
-
dest.includes("restart-websocket.bat"))
|
|
236
|
-
)
|
|
237
|
-
return;
|
|
238
|
-
fs.copyFileSync(src, dest, 0);
|
|
239
|
-
}
|
|
187
|
+
console.log("🚀 ~ copyRecursiveSync ~ dest:", dest);
|
|
188
|
+
console.log("🚀 ~ copyRecursiveSync ~ src:", src);
|
|
189
|
+
const exists = fs.existsSync(src);
|
|
190
|
+
const stats = exists && fs.statSync(src);
|
|
191
|
+
const isDirectory = exists && stats && stats.isDirectory();
|
|
192
|
+
if (isDirectory) {
|
|
193
|
+
if (!fs.existsSync(dest))
|
|
194
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
195
|
+
fs.readdirSync(src).forEach((childItemName) => {
|
|
196
|
+
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName), answer);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
if (checkExcludeFiles(dest))
|
|
201
|
+
return;
|
|
202
|
+
if (!answer.tailwindcss &&
|
|
203
|
+
(dest.includes("tailwind.css") || dest.includes("styles.css")))
|
|
204
|
+
return;
|
|
205
|
+
if (!answer.websocket &&
|
|
206
|
+
(dest.includes("restart-websocket.cjs") ||
|
|
207
|
+
dest.includes("restart-websocket.bat")))
|
|
208
|
+
return;
|
|
209
|
+
fs.copyFileSync(src, dest, 0);
|
|
210
|
+
}
|
|
240
211
|
}
|
|
241
212
|
// Function to execute the recursive copy for entire directories
|
|
242
213
|
async function executeCopy(baseDir, directoriesToCopy, answer) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
214
|
+
directoriesToCopy.forEach(({ srcDir, destDir }) => {
|
|
215
|
+
const sourcePath = path.join(__dirname, srcDir);
|
|
216
|
+
const destPath = path.join(baseDir, destDir);
|
|
217
|
+
const destLower = destPath.toLowerCase();
|
|
218
|
+
if (!answer.websocket &&
|
|
219
|
+
(destLower.includes("src\\lib\\websocket") ||
|
|
220
|
+
destLower.includes("src/lib/websocket")))
|
|
221
|
+
return;
|
|
222
|
+
// if (!answer.prisma && dest.toLowerCase().includes("Prisma")) return;
|
|
223
|
+
copyRecursiveSync(sourcePath, destPath, answer);
|
|
224
|
+
});
|
|
248
225
|
}
|
|
249
226
|
function createOrUpdateTailwindConfig(baseDir) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
/content: \[\],/g,
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
fs.writeFileSync(filePath, configData, { flag: "w" });
|
|
267
|
-
console.log(chalk.green("Tailwind configuration updated successfully."));
|
|
227
|
+
console.log("🚀 ~ createOrUpdateTailwindConfig ~ baseDir:", baseDir);
|
|
228
|
+
const filePath = path.join(baseDir, "tailwind.config.js");
|
|
229
|
+
if (checkExcludeFiles(filePath))
|
|
230
|
+
return;
|
|
231
|
+
const newContent = [
|
|
232
|
+
"./src/app/**/*.{html,js,php}",
|
|
233
|
+
// Add more paths as needed
|
|
234
|
+
];
|
|
235
|
+
let configData = fs.readFileSync(filePath, "utf8");
|
|
236
|
+
console.log("🚀 ~ createOrUpdateTailwindConfig ~ configData:", configData);
|
|
237
|
+
const contentArrayString = newContent
|
|
238
|
+
.map((item) => ` "${item}"`)
|
|
239
|
+
.join(",\n");
|
|
240
|
+
configData = configData.replace(/content: \[\],/g, `content: [\n${contentArrayString}\n],`);
|
|
241
|
+
fs.writeFileSync(filePath, configData, { flag: "w" });
|
|
242
|
+
console.log(chalk.green("Tailwind configuration updated successfully."));
|
|
268
243
|
}
|
|
269
244
|
function modifyPostcssConfig(baseDir) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
245
|
+
const filePath = path.join(baseDir, "postcss.config.js");
|
|
246
|
+
if (checkExcludeFiles(filePath))
|
|
247
|
+
return;
|
|
248
|
+
const newContent = `export default {
|
|
273
249
|
plugins: {
|
|
274
250
|
tailwindcss: {},
|
|
275
251
|
autoprefixer: {},
|
|
276
252
|
cssnano: {},
|
|
277
253
|
},
|
|
278
254
|
};`;
|
|
279
|
-
|
|
280
|
-
|
|
255
|
+
fs.writeFileSync(filePath, newContent, { flag: "w" });
|
|
256
|
+
console.log(chalk.green("postcss.config.js updated successfully."));
|
|
281
257
|
}
|
|
282
258
|
function modifyLayoutPHP(baseDir, useTailwind) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
);
|
|
302
|
-
} catch (error) {
|
|
303
|
-
console.error(chalk.red("Error modifying index.php:"), error);
|
|
304
|
-
}
|
|
259
|
+
const layoutPath = path.join(baseDir, "src", "app", "layout.php");
|
|
260
|
+
if (checkExcludeFiles(layoutPath))
|
|
261
|
+
return;
|
|
262
|
+
try {
|
|
263
|
+
let indexContent = fs.readFileSync(layoutPath, "utf8");
|
|
264
|
+
const stylesAndLinks = `\n <link href="<?php echo $baseUrl; ?>css/index.css" rel="stylesheet">\n <script src="<?php echo $baseUrl; ?>js/index.js"></script>\n <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">`;
|
|
265
|
+
// Tailwind CSS link or CDN script
|
|
266
|
+
const tailwindLink = useTailwind
|
|
267
|
+
? ` <link href="<?php echo $baseUrl; ?>css/styles.css" rel="stylesheet"> ${stylesAndLinks}`
|
|
268
|
+
: ` <script src="https://cdn.tailwindcss.com"></script> ${stylesAndLinks}`;
|
|
269
|
+
// Insert before the closing </head> tag
|
|
270
|
+
indexContent = indexContent.replace("</head>", `${tailwindLink}\n</head>`);
|
|
271
|
+
fs.writeFileSync(layoutPath, indexContent, { flag: "w" });
|
|
272
|
+
console.log(chalk.green(`index.php modified successfully for ${useTailwind ? "local Tailwind CSS" : "Tailwind CSS CDN"}.`));
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
console.error(chalk.red("Error modifying index.php:"), error);
|
|
276
|
+
}
|
|
305
277
|
}
|
|
306
278
|
// This function updates or creates the .env file
|
|
307
279
|
async function createOrUpdateEnvFile(baseDir, content) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
280
|
+
const envPath = path.join(baseDir, ".env");
|
|
281
|
+
if (checkExcludeFiles(envPath))
|
|
282
|
+
return;
|
|
283
|
+
let envContent = fs.existsSync(envPath)
|
|
284
|
+
? fs.readFileSync(envPath, "utf8")
|
|
285
|
+
: "";
|
|
286
|
+
// Check if the content already exists in the .env file
|
|
287
|
+
if (!envContent.includes(content)) {
|
|
288
|
+
envContent += `${envContent !== "" ? "\n\n" : ""}${content}`;
|
|
289
|
+
fs.writeFileSync(envPath, envContent, { flag: "w" });
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
console.log(".env file already contains the content.");
|
|
293
|
+
}
|
|
320
294
|
}
|
|
321
295
|
function checkExcludeFiles(destPath) {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
: updateAnswer.isUpdate)
|
|
327
|
-
)
|
|
328
|
-
return false;
|
|
329
|
-
return (_b =
|
|
330
|
-
(_a =
|
|
331
|
-
updateAnswer === null || updateAnswer === void 0
|
|
332
|
-
? void 0
|
|
333
|
-
: updateAnswer.excludeFilePath) === null || _a === void 0
|
|
334
|
-
? void 0
|
|
335
|
-
: _a.includes(destPath.replace(/\\/g, "/"))) !== null && _b !== void 0
|
|
336
|
-
? _b
|
|
337
|
-
: false;
|
|
296
|
+
var _a, _b;
|
|
297
|
+
if (!(updateAnswer === null || updateAnswer === void 0 ? void 0 : updateAnswer.isUpdate))
|
|
298
|
+
return false;
|
|
299
|
+
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);
|
|
338
300
|
}
|
|
339
301
|
async function createDirectoryStructure(baseDir, answer) {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
filesToCopy.push(
|
|
353
|
-
{ src: "/.env", dest: "/.env" },
|
|
354
|
-
{ src: "/tsconfig.json", dest: "/tsconfig.json" }
|
|
355
|
-
);
|
|
356
|
-
if (updateAnswer.tailwindcss) {
|
|
357
|
-
filesToCopy.push(
|
|
358
|
-
{ src: "/postcss.config.js", dest: "/postcss.config.js" },
|
|
359
|
-
{ src: "/tailwind.config.js", dest: "/tailwind.config.js" }
|
|
360
|
-
);
|
|
302
|
+
console.log("🚀 ~ baseDir:", baseDir);
|
|
303
|
+
console.log("🚀 ~ answer:", answer);
|
|
304
|
+
const filesToCopy = [
|
|
305
|
+
{ src: "/bootstrap.php", dest: "/bootstrap.php" },
|
|
306
|
+
{ src: "/.htaccess", dest: "/.htaccess" },
|
|
307
|
+
{ src: "/../composer.json", dest: "/composer.json" },
|
|
308
|
+
];
|
|
309
|
+
if (updateAnswer === null || updateAnswer === void 0 ? void 0 : updateAnswer.isUpdate) {
|
|
310
|
+
filesToCopy.push({ src: "/.env", dest: "/.env" }, { src: "/tsconfig.json", dest: "/tsconfig.json" });
|
|
311
|
+
if (updateAnswer.tailwindcss) {
|
|
312
|
+
filesToCopy.push({ src: "/postcss.config.js", dest: "/postcss.config.js" }, { src: "/tailwind.config.js", dest: "/tailwind.config.js" });
|
|
313
|
+
}
|
|
361
314
|
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
315
|
+
const directoriesToCopy = [
|
|
316
|
+
{
|
|
317
|
+
srcDir: "/settings",
|
|
318
|
+
destDir: "/settings",
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
srcDir: "/src",
|
|
322
|
+
destDir: "/src",
|
|
323
|
+
},
|
|
324
|
+
];
|
|
325
|
+
if (answer.prisma) {
|
|
326
|
+
directoriesToCopy.push({
|
|
327
|
+
srcDir: "/prisma",
|
|
328
|
+
destDir: "/prisma",
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
console.log("🚀 ~ directoriesToCopy:", directoriesToCopy);
|
|
332
|
+
filesToCopy.forEach(({ src, dest }) => {
|
|
333
|
+
const sourcePath = path.join(__dirname, src);
|
|
334
|
+
const destPath = path.join(baseDir, dest);
|
|
335
|
+
if (checkExcludeFiles(destPath))
|
|
336
|
+
return;
|
|
337
|
+
const code = fs.readFileSync(sourcePath, "utf8");
|
|
338
|
+
fs.writeFileSync(destPath, code, { flag: "w" });
|
|
377
339
|
});
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
if (answer.tailwindcss) {
|
|
392
|
-
createOrUpdateTailwindConfig(baseDir);
|
|
393
|
-
modifyLayoutPHP(baseDir, true);
|
|
394
|
-
modifyPostcssConfig(baseDir);
|
|
395
|
-
} else {
|
|
396
|
-
modifyLayoutPHP(baseDir, false);
|
|
397
|
-
}
|
|
398
|
-
const prismaEnvContent = `# Environment variables declared in this file are automatically made available to Prisma.
|
|
340
|
+
await executeCopy(baseDir, directoriesToCopy, answer);
|
|
341
|
+
await updatePackageJson(baseDir, answer);
|
|
342
|
+
await updateComposerJson(baseDir, answer);
|
|
343
|
+
await updateIndexJsForWebSocket(baseDir, answer);
|
|
344
|
+
if (answer.tailwindcss) {
|
|
345
|
+
createOrUpdateTailwindConfig(baseDir);
|
|
346
|
+
modifyLayoutPHP(baseDir, true);
|
|
347
|
+
modifyPostcssConfig(baseDir);
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
modifyLayoutPHP(baseDir, false);
|
|
351
|
+
}
|
|
352
|
+
const prismaEnvContent = `# Environment variables declared in this file are automatically made available to Prisma.
|
|
399
353
|
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
|
|
400
354
|
|
|
401
355
|
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
|
|
402
356
|
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
|
|
403
357
|
|
|
404
358
|
DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"`;
|
|
405
|
-
|
|
359
|
+
const prismaPHPEnvContent = `# Prisma PHP Auth Secret Key For development only - Change this in production
|
|
406
360
|
AUTH_SECRET=uxsjXVPHN038DEYls2Kw0QUgBcXKUyrjv416nIFWPY4=
|
|
407
361
|
|
|
408
362
|
# PHPMailer
|
|
@@ -413,93 +367,84 @@ AUTH_SECRET=uxsjXVPHN038DEYls2Kw0QUgBcXKUyrjv416nIFWPY4=
|
|
|
413
367
|
# SMTP_ENCRYPTION=ssl or tls
|
|
414
368
|
# MAIL_FROM=john.doe@gmail.com
|
|
415
369
|
# MAIL_FROM_NAME="John Doe"`;
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
370
|
+
let envContent = prismaPHPEnvContent;
|
|
371
|
+
if (answer.prisma) {
|
|
372
|
+
envContent = `${prismaEnvContent}\n\n${prismaPHPEnvContent}`;
|
|
373
|
+
await createOrUpdateEnvFile(baseDir, envContent);
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
await createOrUpdateEnvFile(baseDir, envContent);
|
|
377
|
+
}
|
|
378
|
+
// Add vendor to .gitignore
|
|
379
|
+
await createUpdateGitignoreFile(baseDir, ["vendor", ".env", "node_modules"]);
|
|
425
380
|
}
|
|
426
381
|
async function getAnswer(predefinedAnswers = {}) {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
}
|
|
438
|
-
if (!predefinedAnswers.tailwindcss) {
|
|
439
|
-
questionsArray.push({
|
|
440
|
-
type: "toggle",
|
|
441
|
-
name: "tailwindcss",
|
|
442
|
-
message: `Would you like to use ${chalk.blue("Tailwind CSS")}?`,
|
|
443
|
-
initial: true,
|
|
444
|
-
active: "Yes",
|
|
445
|
-
inactive: "No",
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
if (!predefinedAnswers.websocket) {
|
|
449
|
-
questionsArray.push({
|
|
450
|
-
type: "toggle",
|
|
451
|
-
name: "websocket",
|
|
452
|
-
message: `Would you like to use ${chalk.blue("Websocket")}?`,
|
|
453
|
-
initial: true,
|
|
454
|
-
active: "Yes",
|
|
455
|
-
inactive: "No",
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
if (!predefinedAnswers.prisma) {
|
|
459
|
-
questionsArray.push({
|
|
460
|
-
type: "toggle",
|
|
461
|
-
name: "prisma",
|
|
462
|
-
message: `Would you like to use ${chalk.blue("Prisma PHP ORM")}?`,
|
|
463
|
-
initial: true,
|
|
464
|
-
active: "Yes",
|
|
465
|
-
inactive: "No",
|
|
466
|
-
});
|
|
467
|
-
}
|
|
468
|
-
const questions = questionsArray;
|
|
469
|
-
console.log("🚀 ~ questions:", questions);
|
|
470
|
-
const onCancel = () => {
|
|
471
|
-
console.log(chalk.red("Operation cancelled by the user."));
|
|
472
|
-
process.exit(0);
|
|
473
|
-
};
|
|
474
|
-
try {
|
|
475
|
-
const response = await prompts(questions, { onCancel });
|
|
476
|
-
console.log("🚀 ~ response:", response);
|
|
477
|
-
if (Object.keys(response).length === 0) {
|
|
478
|
-
return null;
|
|
382
|
+
var _a, _b, _c, _d;
|
|
383
|
+
console.log("🚀 ~ predefinedAnswers:", predefinedAnswers);
|
|
384
|
+
const questionsArray = [];
|
|
385
|
+
if (!predefinedAnswers.projectName) {
|
|
386
|
+
questionsArray.push({
|
|
387
|
+
type: "text",
|
|
388
|
+
name: "projectName",
|
|
389
|
+
message: "What is your project named?",
|
|
390
|
+
initial: "my-app",
|
|
391
|
+
});
|
|
479
392
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
(
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
393
|
+
if (!predefinedAnswers.tailwindcss) {
|
|
394
|
+
questionsArray.push({
|
|
395
|
+
type: "toggle",
|
|
396
|
+
name: "tailwindcss",
|
|
397
|
+
message: `Would you like to use ${chalk.blue("Tailwind CSS")}?`,
|
|
398
|
+
initial: true,
|
|
399
|
+
active: "Yes",
|
|
400
|
+
inactive: "No",
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
if (!predefinedAnswers.websocket) {
|
|
404
|
+
questionsArray.push({
|
|
405
|
+
type: "toggle",
|
|
406
|
+
name: "websocket",
|
|
407
|
+
message: `Would you like to use ${chalk.blue("Websocket")}?`,
|
|
408
|
+
initial: true,
|
|
409
|
+
active: "Yes",
|
|
410
|
+
inactive: "No",
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
if (!predefinedAnswers.prisma) {
|
|
414
|
+
questionsArray.push({
|
|
415
|
+
type: "toggle",
|
|
416
|
+
name: "prisma",
|
|
417
|
+
message: `Would you like to use ${chalk.blue("Prisma PHP ORM")}?`,
|
|
418
|
+
initial: true,
|
|
419
|
+
active: "Yes",
|
|
420
|
+
inactive: "No",
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
const questions = questionsArray;
|
|
424
|
+
console.log("🚀 ~ questions:", questions);
|
|
425
|
+
const onCancel = () => {
|
|
426
|
+
console.log(chalk.red("Operation cancelled by the user."));
|
|
427
|
+
process.exit(0);
|
|
498
428
|
};
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
429
|
+
try {
|
|
430
|
+
const response = await prompts(questions, { onCancel });
|
|
431
|
+
console.log("🚀 ~ response:", response);
|
|
432
|
+
if (Object.keys(response).length === 0) {
|
|
433
|
+
return null;
|
|
434
|
+
}
|
|
435
|
+
return {
|
|
436
|
+
projectName: response.projectName
|
|
437
|
+
? String(response.projectName).trim().replace(/ /g, "-")
|
|
438
|
+
: (_a = predefinedAnswers.projectName) !== null && _a !== void 0 ? _a : "my-app",
|
|
439
|
+
tailwindcss: (_b = response.tailwindcss) !== null && _b !== void 0 ? _b : predefinedAnswers.tailwindcss,
|
|
440
|
+
websocket: (_c = response.websocket) !== null && _c !== void 0 ? _c : predefinedAnswers.websocket,
|
|
441
|
+
prisma: (_d = response.prisma) !== null && _d !== void 0 ? _d : predefinedAnswers.prisma,
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
catch (error) {
|
|
445
|
+
console.error(chalk.red("Prompt error:"), error);
|
|
446
|
+
return null;
|
|
447
|
+
}
|
|
503
448
|
}
|
|
504
449
|
/**
|
|
505
450
|
* Install dependencies in the specified directory.
|
|
@@ -508,329 +453,271 @@ async function getAnswer(predefinedAnswers = {}) {
|
|
|
508
453
|
* @param {boolean} [isDev=false] - Whether to install the dependencies as devDependencies.
|
|
509
454
|
*/
|
|
510
455
|
async function installDependencies(baseDir, dependencies, isDev = false) {
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
456
|
+
console.log("Initializing new Node.js project...");
|
|
457
|
+
// Initialize a package.json if it doesn't exist
|
|
458
|
+
if (!fs.existsSync(path.join(baseDir, "package.json")))
|
|
459
|
+
execSync("npm init -y", {
|
|
460
|
+
stdio: "inherit",
|
|
461
|
+
cwd: baseDir,
|
|
462
|
+
});
|
|
463
|
+
// Log the dependencies being installed
|
|
464
|
+
console.log(`${isDev ? "Installing development dependencies" : "Installing dependencies"}:`);
|
|
465
|
+
dependencies.forEach((dep) => console.log(`- ${chalk.blue(dep)}`));
|
|
466
|
+
// Prepare the npm install command with the appropriate flag for dev dependencies
|
|
467
|
+
const npmInstallCommand = `npm install ${isDev ? "--save-dev" : ""} ${dependencies.join(" ")}`;
|
|
468
|
+
// Execute the npm install command
|
|
469
|
+
execSync(npmInstallCommand, {
|
|
470
|
+
stdio: "inherit",
|
|
471
|
+
cwd: baseDir,
|
|
517
472
|
});
|
|
518
|
-
// Log the dependencies being installed
|
|
519
|
-
console.log(
|
|
520
|
-
`${
|
|
521
|
-
isDev ? "Installing development dependencies" : "Installing dependencies"
|
|
522
|
-
}:`
|
|
523
|
-
);
|
|
524
|
-
dependencies.forEach((dep) => console.log(`- ${chalk.blue(dep)}`));
|
|
525
|
-
// Prepare the npm install command with the appropriate flag for dev dependencies
|
|
526
|
-
const npmInstallCommand = `npm install ${
|
|
527
|
-
isDev ? "--save-dev" : ""
|
|
528
|
-
} ${dependencies.join(" ")}`;
|
|
529
|
-
// Execute the npm install command
|
|
530
|
-
execSync(npmInstallCommand, {
|
|
531
|
-
stdio: "inherit",
|
|
532
|
-
cwd: baseDir,
|
|
533
|
-
});
|
|
534
473
|
}
|
|
535
474
|
async function uninstallDependencies(baseDir, dependencies, isDev = false) {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
cwd: baseDir,
|
|
546
|
-
});
|
|
475
|
+
console.log("Uninstalling dependencies:");
|
|
476
|
+
dependencies.forEach((dep) => console.log(`- ${chalk.blue(dep)}`));
|
|
477
|
+
// Prepare the npm uninstall command with the appropriate flag for dev dependencies
|
|
478
|
+
const npmUninstallCommand = `npm uninstall ${isDev ? "--save-dev" : "--save"} ${dependencies.join(" ")}`;
|
|
479
|
+
// Execute the npm uninstall command
|
|
480
|
+
execSync(npmUninstallCommand, {
|
|
481
|
+
stdio: "inherit",
|
|
482
|
+
cwd: baseDir,
|
|
483
|
+
});
|
|
547
484
|
}
|
|
548
485
|
function fetchPackageVersion(packageName) {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
486
|
+
return new Promise((resolve, reject) => {
|
|
487
|
+
https
|
|
488
|
+
.get(`https://registry.npmjs.org/${packageName}`, (res) => {
|
|
489
|
+
let data = "";
|
|
490
|
+
res.on("data", (chunk) => (data += chunk));
|
|
491
|
+
res.on("end", () => {
|
|
492
|
+
try {
|
|
493
|
+
const parsed = JSON.parse(data);
|
|
494
|
+
resolve(parsed["dist-tags"].latest);
|
|
495
|
+
}
|
|
496
|
+
catch (error) {
|
|
497
|
+
reject(new Error("Failed to parse JSON response"));
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
})
|
|
501
|
+
.on("error", (err) => reject(err));
|
|
502
|
+
});
|
|
565
503
|
}
|
|
566
504
|
const readJsonFile = (filePath) => {
|
|
567
|
-
|
|
568
|
-
|
|
505
|
+
const jsonData = fs.readFileSync(filePath, "utf8");
|
|
506
|
+
return JSON.parse(jsonData);
|
|
569
507
|
};
|
|
570
508
|
async function main() {
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
prisma:
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
"
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
509
|
+
var _a, _b, _c, _d, _e, _f;
|
|
510
|
+
try {
|
|
511
|
+
const args = process.argv.slice(2);
|
|
512
|
+
let projectName = args[0];
|
|
513
|
+
let answer = null;
|
|
514
|
+
if (projectName) {
|
|
515
|
+
let useTailwind = args.includes("--tailwindcss");
|
|
516
|
+
let useWebsocket = args.includes("--websocket");
|
|
517
|
+
let usePrisma = args.includes("--prisma");
|
|
518
|
+
const predefinedAnswers = {
|
|
519
|
+
projectName,
|
|
520
|
+
tailwindcss: useTailwind,
|
|
521
|
+
websocket: useWebsocket,
|
|
522
|
+
prisma: usePrisma,
|
|
523
|
+
};
|
|
524
|
+
console.log("🚀 ~ main ~ predefinedAnswers:", predefinedAnswers);
|
|
525
|
+
answer = await getAnswer(predefinedAnswers);
|
|
526
|
+
if (answer === null) {
|
|
527
|
+
console.log(chalk.red("Installation cancelled."));
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
const currentDir = process.cwd();
|
|
531
|
+
const configPath = path.join(currentDir, "prisma-php.json");
|
|
532
|
+
const localSettings = readJsonFile(configPath);
|
|
533
|
+
let excludeFiles = [];
|
|
534
|
+
(_a = localSettings.excludeFiles) === null || _a === void 0 ? void 0 : _a.map((file) => {
|
|
535
|
+
const filePath = path.join(currentDir, file);
|
|
536
|
+
if (fs.existsSync(filePath))
|
|
537
|
+
excludeFiles.push(filePath.replace(/\\/g, "/"));
|
|
538
|
+
});
|
|
539
|
+
updateAnswer = {
|
|
540
|
+
projectName,
|
|
541
|
+
tailwindcss: (_b = answer === null || answer === void 0 ? void 0 : answer.tailwindcss) !== null && _b !== void 0 ? _b : false,
|
|
542
|
+
websocket: (_c = answer === null || answer === void 0 ? void 0 : answer.websocket) !== null && _c !== void 0 ? _c : false,
|
|
543
|
+
prisma: (_d = answer === null || answer === void 0 ? void 0 : answer.prisma) !== null && _d !== void 0 ? _d : false,
|
|
544
|
+
isUpdate: true,
|
|
545
|
+
excludeFiles: (_e = localSettings.excludeFiles) !== null && _e !== void 0 ? _e : [],
|
|
546
|
+
excludeFilePath: excludeFiles !== null && excludeFiles !== void 0 ? excludeFiles : [],
|
|
547
|
+
filePath: currentDir,
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
else {
|
|
551
|
+
answer = await getAnswer();
|
|
552
|
+
}
|
|
553
|
+
if (answer === null) {
|
|
554
|
+
console.log(chalk.red("Installation cancelled."));
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
execSync(`npm install -g create-prisma-php-app`, { stdio: "inherit" }); // TODO: Uncomment this line before publishing the package
|
|
558
|
+
// Support for browser-sync
|
|
559
|
+
execSync(`npm install -g browser-sync`, { stdio: "inherit" });
|
|
560
|
+
// Create the project directory
|
|
561
|
+
if (!projectName)
|
|
562
|
+
fs.mkdirSync(answer.projectName);
|
|
563
|
+
const currentDir = process.cwd();
|
|
564
|
+
let projectPath = projectName
|
|
565
|
+
? currentDir
|
|
566
|
+
: path.join(currentDir, answer.projectName);
|
|
567
|
+
if (!projectName)
|
|
568
|
+
process.chdir(answer.projectName);
|
|
569
|
+
const dependencies = [
|
|
570
|
+
"typescript",
|
|
571
|
+
"@types/node",
|
|
572
|
+
"ts-node",
|
|
573
|
+
"http-proxy-middleware@^3.0.0",
|
|
574
|
+
"npm-run-all",
|
|
575
|
+
];
|
|
576
|
+
if (answer.tailwindcss) {
|
|
577
|
+
dependencies.push("tailwindcss", "autoprefixer", "postcss", "postcss-cli", "cssnano");
|
|
578
|
+
}
|
|
579
|
+
if (answer.websocket) {
|
|
580
|
+
dependencies.push("chokidar-cli");
|
|
581
|
+
}
|
|
582
|
+
if (answer.prisma) {
|
|
583
|
+
dependencies.push("prisma", "@prisma/client");
|
|
584
|
+
}
|
|
585
|
+
await installDependencies(projectPath, dependencies, true);
|
|
586
|
+
if (!projectName) {
|
|
587
|
+
execSync(`npx tsc --init`, { stdio: "inherit" });
|
|
588
|
+
}
|
|
589
|
+
if (answer.tailwindcss)
|
|
590
|
+
execSync(`npx tailwindcss init -p`, { stdio: "inherit" });
|
|
591
|
+
if (answer.prisma) {
|
|
592
|
+
if (!fs.existsSync(path.join(projectPath, "prisma")))
|
|
593
|
+
execSync(`npx prisma init`, { stdio: "inherit" });
|
|
594
|
+
}
|
|
595
|
+
await createDirectoryStructure(projectPath, answer);
|
|
596
|
+
const publicDirPath = path.join(projectPath, "public");
|
|
597
|
+
if (!fs.existsSync(publicDirPath)) {
|
|
598
|
+
fs.mkdirSync(publicDirPath);
|
|
599
|
+
}
|
|
600
|
+
// if (!answer.tailwindcss) {
|
|
601
|
+
// const cssPath = path.join(projectPath, "src", "app", "css");
|
|
602
|
+
// const tailwindFiles = ["tailwind.css", "styles.css"];
|
|
603
|
+
// tailwindFiles.forEach((file) => {
|
|
604
|
+
// const filePath = path.join(cssPath, file);
|
|
605
|
+
// if (fs.existsSync(filePath)) {
|
|
606
|
+
// fs.unlinkSync(filePath); // Delete each file if it exists
|
|
607
|
+
// console.log(`${file} was deleted successfully.`);
|
|
608
|
+
// } else {
|
|
609
|
+
// console.log(`${file} does not exist.`);
|
|
610
|
+
// }
|
|
611
|
+
// });
|
|
612
|
+
// }
|
|
613
|
+
// Update websocket if not chosen by the user
|
|
614
|
+
// if (!answer.websocket) {
|
|
615
|
+
// const wsPath = path.join(projectPath, "src", "Lib", "Websocket");
|
|
616
|
+
// // Check if the websocket directory exists
|
|
617
|
+
// if (fs.existsSync(wsPath)) {
|
|
618
|
+
// // Use fs.rmSync with recursive option set to true to delete the directory and its contents
|
|
619
|
+
// fs.rmSync(wsPath, { recursive: true, force: true }); // force option is not necessary but can be used to ensure deletion
|
|
620
|
+
// console.log("Websocket directory was deleted successfully.");
|
|
621
|
+
// } else {
|
|
622
|
+
// console.log("Websocket directory does not exist.");
|
|
623
|
+
// }
|
|
624
|
+
// // Update settings directory if websocket is not chosen
|
|
625
|
+
// const settingsPath = path.join(projectPath, "settings");
|
|
626
|
+
// const websocketFiles = ["restart-websocket.cjs", "restart-websocket.bat"];
|
|
627
|
+
// websocketFiles.forEach((file) => {
|
|
628
|
+
// const filePath = path.join(settingsPath, file);
|
|
629
|
+
// if (fs.existsSync(filePath)) {
|
|
630
|
+
// fs.unlinkSync(filePath); // Delete each file if it exists
|
|
631
|
+
// console.log(`${file} was deleted successfully.`);
|
|
632
|
+
// } else {
|
|
633
|
+
// console.log(`${file} does not exist.`);
|
|
634
|
+
// }
|
|
635
|
+
// });
|
|
636
|
+
// }
|
|
637
|
+
if (!answer.prisma) {
|
|
638
|
+
const prismaPath = path.join(projectPath, "prisma");
|
|
639
|
+
const prismClassPath = path.join(projectPath, "src", "Lib", "Prisma");
|
|
640
|
+
// Check if the prisma directory exists
|
|
641
|
+
if (fs.existsSync(prismaPath)) {
|
|
642
|
+
// Use fs.rmSync with recursive option set to true to delete the directory and its contents
|
|
643
|
+
fs.rmSync(prismaPath, { recursive: true, force: true }); // force option is not necessary but can be used to ensure deletion
|
|
644
|
+
console.log("Prisma directory was deleted successfully.");
|
|
645
|
+
}
|
|
646
|
+
else {
|
|
647
|
+
console.log("Prisma directory does not exist.");
|
|
648
|
+
}
|
|
649
|
+
// Check if the prisma class directory exists
|
|
650
|
+
if (fs.existsSync(prismClassPath)) {
|
|
651
|
+
// Use fs.rmSync with recursive option set to true to delete the directory and its contents
|
|
652
|
+
fs.rmSync(prismClassPath, { recursive: true, force: true }); // force option is not necessary but can be used to ensure deletion
|
|
653
|
+
console.log("Prisma class directory was deleted successfully.");
|
|
654
|
+
}
|
|
655
|
+
else {
|
|
656
|
+
console.log("Prisma class directory does not exist.");
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
if (updateAnswer === null || updateAnswer === void 0 ? void 0 : updateAnswer.isUpdate) {
|
|
660
|
+
const updateUninstallDependencies = [];
|
|
661
|
+
if (!updateAnswer.tailwindcss) {
|
|
662
|
+
const tailwindFiles = ["postcss.config.js", "tailwind.config.js"];
|
|
663
|
+
tailwindFiles.forEach((file) => {
|
|
664
|
+
const filePath = path.join(projectPath, file);
|
|
665
|
+
if (fs.existsSync(filePath)) {
|
|
666
|
+
fs.unlinkSync(filePath); // Delete each file if it exists
|
|
667
|
+
console.log(`${file} was deleted successfully.`);
|
|
668
|
+
}
|
|
669
|
+
else {
|
|
670
|
+
console.log(`${file} does not exist.`);
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
updateUninstallDependencies.push("tailwindcss", "autoprefixer", "postcss", "postcss-cli", "cssnano");
|
|
674
|
+
}
|
|
675
|
+
if (!updateAnswer.websocket) {
|
|
676
|
+
updateUninstallDependencies.push("chokidar-cli");
|
|
677
|
+
}
|
|
678
|
+
if (!updateAnswer.prisma) {
|
|
679
|
+
updateUninstallDependencies.push("prisma", "@prisma/client");
|
|
680
|
+
}
|
|
681
|
+
if (updateUninstallDependencies.length > 0) {
|
|
682
|
+
await uninstallDependencies(projectPath, updateUninstallDependencies, true);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
const version = await fetchPackageVersion("create-prisma-php-app");
|
|
686
|
+
const projectPathModified = projectPath.replace(/\\/g, "\\");
|
|
687
|
+
const PHP_GENERATE_CLASS_PATH = answer.prisma
|
|
688
|
+
? "src/Lib/Prisma/Classes"
|
|
689
|
+
: "";
|
|
690
|
+
const projectSettings = {
|
|
691
|
+
PROJECT_NAME: answer.projectName,
|
|
692
|
+
PROJECT_ROOT_PATH: projectPathModified,
|
|
693
|
+
PHP_ROOT_PATH_EXE: "C:\\\\xampp\\\\php\\\\php.exe",
|
|
694
|
+
PHP_GENERATE_CLASS_PATH,
|
|
695
|
+
};
|
|
696
|
+
const bsConfig = bsConfigUrls(projectSettings);
|
|
697
|
+
const phpGenerateClassPath = answer.prisma ? "src/Lib/Prisma/Classes" : "";
|
|
698
|
+
const prismaPhpConfig = {
|
|
699
|
+
projectName: answer.projectName,
|
|
700
|
+
projectRootPath: projectPathModified,
|
|
701
|
+
phpEnvironment: "XAMPP",
|
|
702
|
+
phpRootPathExe: "C:\\xampp\\php\\php.exe",
|
|
703
|
+
phpGenerateClassPath,
|
|
704
|
+
bsTarget: bsConfig.bsTarget,
|
|
705
|
+
bsPathRewrite: bsConfig.bsPathRewrite,
|
|
706
|
+
tailwindcss: answer.tailwindcss,
|
|
707
|
+
websocket: answer.websocket,
|
|
708
|
+
prisma: answer.prisma,
|
|
709
|
+
version,
|
|
710
|
+
excludeFiles: (_f = updateAnswer === null || updateAnswer === void 0 ? void 0 : updateAnswer.excludeFiles) !== null && _f !== void 0 ? _f : [],
|
|
711
|
+
};
|
|
712
|
+
fs.writeFileSync(path.join(projectPath, "prisma-php.json"), JSON.stringify(prismaPhpConfig, null, 2), { flag: "w" });
|
|
713
|
+
execSync(`D:\\xampp\\php\\php.exe C:\\ProgramData\\ComposerSetup\\bin\\composer.phar install`, {
|
|
714
|
+
stdio: "inherit",
|
|
759
715
|
});
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
"cssnano"
|
|
766
|
-
);
|
|
767
|
-
}
|
|
768
|
-
if (!updateAnswer.websocket) {
|
|
769
|
-
updateUninstallDependencies.push("chokidar-cli");
|
|
770
|
-
}
|
|
771
|
-
if (!updateAnswer.prisma) {
|
|
772
|
-
updateUninstallDependencies.push("prisma", "@prisma/client");
|
|
773
|
-
}
|
|
774
|
-
if (updateUninstallDependencies.length > 0) {
|
|
775
|
-
await uninstallDependencies(
|
|
776
|
-
projectPath,
|
|
777
|
-
updateUninstallDependencies,
|
|
778
|
-
true
|
|
779
|
-
);
|
|
780
|
-
}
|
|
716
|
+
console.log(`${chalk.green("Success!")} Prisma PHP project successfully created in ${answer.projectName}!`);
|
|
717
|
+
}
|
|
718
|
+
catch (error) {
|
|
719
|
+
console.error("Error while creating the project:", error);
|
|
720
|
+
process.exit(1);
|
|
781
721
|
}
|
|
782
|
-
const version = await fetchPackageVersion("create-prisma-php-app");
|
|
783
|
-
const projectPathModified = projectPath.replace(/\\/g, "\\");
|
|
784
|
-
const PHP_GENERATE_CLASS_PATH = answer.prisma
|
|
785
|
-
? "src/Lib/Prisma/Classes"
|
|
786
|
-
: "";
|
|
787
|
-
const projectSettings = {
|
|
788
|
-
PROJECT_NAME: answer.projectName,
|
|
789
|
-
PROJECT_ROOT_PATH: projectPathModified,
|
|
790
|
-
PHP_ROOT_PATH_EXE: "C:\\\\xampp\\\\php\\\\php.exe",
|
|
791
|
-
PHP_GENERATE_CLASS_PATH,
|
|
792
|
-
};
|
|
793
|
-
const bsConfig = bsConfigUrls(projectSettings);
|
|
794
|
-
const phpGenerateClassPath = answer.prisma ? "src/Lib/Prisma/Classes" : "";
|
|
795
|
-
const prismaPhpConfig = {
|
|
796
|
-
projectName: answer.projectName,
|
|
797
|
-
projectRootPath: projectPathModified,
|
|
798
|
-
phpEnvironment: "XAMPP",
|
|
799
|
-
phpRootPathExe: "C:\\xampp\\php\\php.exe",
|
|
800
|
-
phpGenerateClassPath,
|
|
801
|
-
bsTarget: bsConfig.bsTarget,
|
|
802
|
-
bsPathRewrite: bsConfig.bsPathRewrite,
|
|
803
|
-
tailwindcss: answer.tailwindcss,
|
|
804
|
-
websocket: answer.websocket,
|
|
805
|
-
prisma: answer.prisma,
|
|
806
|
-
version,
|
|
807
|
-
excludeFiles:
|
|
808
|
-
(_f =
|
|
809
|
-
updateAnswer === null || updateAnswer === void 0
|
|
810
|
-
? void 0
|
|
811
|
-
: updateAnswer.excludeFiles) !== null && _f !== void 0
|
|
812
|
-
? _f
|
|
813
|
-
: [],
|
|
814
|
-
};
|
|
815
|
-
fs.writeFileSync(
|
|
816
|
-
path.join(projectPath, "prisma-php.json"),
|
|
817
|
-
JSON.stringify(prismaPhpConfig, null, 2),
|
|
818
|
-
{ flag: "w" }
|
|
819
|
-
);
|
|
820
|
-
execSync(
|
|
821
|
-
`D:\\xampp\\php\\php.exe C:\\ProgramData\\ComposerSetup\\bin\\composer.phar install`,
|
|
822
|
-
{
|
|
823
|
-
stdio: "inherit",
|
|
824
|
-
}
|
|
825
|
-
);
|
|
826
|
-
console.log(
|
|
827
|
-
`${chalk.green("Success!")} Prisma PHP project successfully created in ${
|
|
828
|
-
answer.projectName
|
|
829
|
-
}!`
|
|
830
|
-
);
|
|
831
|
-
} catch (error) {
|
|
832
|
-
console.error("Error while creating the project:", error);
|
|
833
|
-
process.exit(1);
|
|
834
|
-
}
|
|
835
722
|
}
|
|
836
723
|
main();
|