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