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