create-prisma-php-app 1.6.29 → 1.6.31
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 +500 -446
- package/dist/prisma-php.js +31 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9,32 +9,40 @@ import https from "https";
|
|
|
9
9
|
const __filename = fileURLToPath(import.meta.url);
|
|
10
10
|
const __dirname = path.dirname(__filename);
|
|
11
11
|
function configureBrowserSyncCommand(baseDir, projectSettings) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
12
|
+
// Identify the base path dynamically up to and including 'htdocs'
|
|
13
|
+
const htdocsIndex = projectSettings.PROJECT_ROOT_PATH.indexOf("\\htdocs\\");
|
|
14
|
+
if (htdocsIndex === -1) {
|
|
15
|
+
console.error(
|
|
16
|
+
"Invalid PROJECT_ROOT_PATH. The path does not contain \\htdocs\\"
|
|
17
|
+
);
|
|
18
|
+
return ""; // Return an empty string or handle the error as appropriate
|
|
19
|
+
}
|
|
20
|
+
// Extract the path up to and including 'htdocs\\'
|
|
21
|
+
const basePathToRemove = projectSettings.PROJECT_ROOT_PATH.substring(
|
|
22
|
+
0,
|
|
23
|
+
htdocsIndex + "\\htdocs\\".length
|
|
24
|
+
);
|
|
25
|
+
// Escape backslashes for the regex pattern
|
|
26
|
+
const escapedBasePathToRemove = basePathToRemove.replace(/\\/g, "\\\\");
|
|
27
|
+
// Remove the base path and replace backslashes with forward slashes for URL compatibility
|
|
28
|
+
const relativeWebPath = projectSettings.PROJECT_ROOT_PATH.replace(
|
|
29
|
+
new RegExp(`^${escapedBasePathToRemove}`),
|
|
30
|
+
""
|
|
31
|
+
).replace(/\\/g, "/");
|
|
32
|
+
// Construct the Browser Sync command with the correct proxy URL, being careful not to affect the protocol part
|
|
33
|
+
let proxyUrl = `http://localhost/${relativeWebPath}`;
|
|
34
|
+
// Ensure the proxy URL does not end with a slash before appending '/public'
|
|
35
|
+
proxyUrl = proxyUrl.endsWith("/") ? proxyUrl.slice(0, -1) : proxyUrl;
|
|
36
|
+
// Clean the URL by replacing "//" with "/" but not affecting "http://"
|
|
37
|
+
// We replace instances of "//" that are not preceded by ":"
|
|
38
|
+
const cleanUrl = proxyUrl.replace(/(?<!:)(\/\/+)/g, "/");
|
|
39
|
+
const cleanRelativeWebPath = relativeWebPath.replace(/\/\/+/g, "/");
|
|
40
|
+
// Correct the relativeWebPath to ensure it does not start with a "/"
|
|
41
|
+
const adjustedRelativeWebPath = cleanRelativeWebPath.startsWith("/")
|
|
42
|
+
? cleanRelativeWebPath.substring(1)
|
|
43
|
+
: cleanRelativeWebPath;
|
|
44
|
+
// TypeScript content to write
|
|
45
|
+
const bsConfigTsContent = `
|
|
38
46
|
const { createProxyMiddleware } = require("http-proxy-middleware");
|
|
39
47
|
|
|
40
48
|
module.exports = {
|
|
@@ -64,237 +72,261 @@ function configureBrowserSyncCommand(baseDir, projectSettings) {
|
|
|
64
72
|
open: false,
|
|
65
73
|
ghostMode: false,
|
|
66
74
|
};`;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
// Determine the path and write the bs-config.js
|
|
76
|
+
const bsConfigPath = path.join(baseDir, "settings", "bs-config.cjs");
|
|
77
|
+
fs.writeFileSync(bsConfigPath, bsConfigTsContent, "utf8");
|
|
78
|
+
// Return the Browser Sync command string, using the cleaned URL
|
|
79
|
+
return `browser-sync start --config settings/bs-config.cjs`;
|
|
72
80
|
}
|
|
73
81
|
async function updatePackageJson(baseDir, projectSettings, answer) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
82
|
+
const packageJsonPath = path.join(baseDir, "package.json");
|
|
83
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
84
|
+
// Use the new function to configure the Browser Sync command
|
|
85
|
+
const browserSyncCommand = configureBrowserSyncCommand(
|
|
86
|
+
baseDir,
|
|
87
|
+
projectSettings
|
|
88
|
+
);
|
|
89
|
+
packageJson.scripts = Object.assign(Object.assign({}, packageJson.scripts), {
|
|
90
|
+
postinstall: "prisma generate",
|
|
91
|
+
});
|
|
92
|
+
let answersToInclude = [];
|
|
93
|
+
if (answer.tailwindcss) {
|
|
94
|
+
packageJson.scripts = Object.assign(
|
|
95
|
+
Object.assign({}, packageJson.scripts),
|
|
96
|
+
{
|
|
97
|
+
tailwind:
|
|
98
|
+
"postcss ./src/app/css/tailwind.css -o ./src/app/css/styles.css --watch",
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
answersToInclude.push("tailwind");
|
|
102
|
+
}
|
|
103
|
+
if (answer.websocket) {
|
|
104
|
+
packageJson.scripts = Object.assign(
|
|
105
|
+
Object.assign({}, packageJson.scripts),
|
|
106
|
+
{ websocket: "node ./settings/restartWebsocket.cjs" }
|
|
107
|
+
);
|
|
108
|
+
answersToInclude.push("websocket");
|
|
109
|
+
}
|
|
110
|
+
// Initialize with existing scripts
|
|
111
|
+
const updatedScripts = Object.assign({}, packageJson.scripts);
|
|
112
|
+
// Conditionally add "browser-sync" command
|
|
113
|
+
if (answersToInclude.length > 0) {
|
|
114
|
+
updatedScripts["browser-sync"] = browserSyncCommand;
|
|
115
|
+
}
|
|
116
|
+
// Conditionally set the "dev" command
|
|
117
|
+
updatedScripts.dev =
|
|
118
|
+
answersToInclude.length > 0
|
|
119
|
+
? `npm-run-all --parallel browser-sync ${answersToInclude.join(" ")}`
|
|
120
|
+
: browserSyncCommand;
|
|
121
|
+
// Finally, assign the updated scripts back to packageJson
|
|
122
|
+
packageJson.scripts = updatedScripts;
|
|
123
|
+
packageJson.type = "module";
|
|
124
|
+
packageJson.prisma = {
|
|
125
|
+
seed: "node prisma/seed.js",
|
|
126
|
+
};
|
|
127
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
106
128
|
}
|
|
107
129
|
async function updateComposerJson(baseDir, answer) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
130
|
+
if (!answer.websocket) return;
|
|
131
|
+
const composerJsonPath = path.join(baseDir, "composer.json");
|
|
132
|
+
let composerJson;
|
|
133
|
+
// Check if the composer.json file exists
|
|
134
|
+
if (fs.existsSync(composerJsonPath)) {
|
|
135
|
+
// Read the current composer.json content
|
|
136
|
+
const composerJsonContent = fs.readFileSync(composerJsonPath, "utf8");
|
|
137
|
+
composerJson = JSON.parse(composerJsonContent);
|
|
138
|
+
} else {
|
|
139
|
+
console.error("composer.json does not exist.");
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
// Conditionally add WebSocket dependency
|
|
143
|
+
if (answer.websocket) {
|
|
144
|
+
composerJson.require = Object.assign(
|
|
145
|
+
Object.assign({}, composerJson.require),
|
|
146
|
+
{ "cboden/ratchet": "^0.4.4" }
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
// Write the modified composer.json back to the file
|
|
150
|
+
fs.writeFileSync(composerJsonPath, JSON.stringify(composerJson, null, 2));
|
|
151
|
+
console.log("composer.json updated successfully.");
|
|
129
152
|
}
|
|
130
153
|
async function updateIndexJsForWebSocket(baseDir, answer) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
154
|
+
if (!answer.websocket) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const indexPath = path.join(baseDir, "src", "app", "js", "index.js");
|
|
158
|
+
let indexContent = fs.readFileSync(indexPath, "utf8");
|
|
159
|
+
// WebSocket initialization code to be appended
|
|
160
|
+
const webSocketCode = `
|
|
138
161
|
// WebSocket initialization
|
|
139
162
|
const ws = new WebSocket("ws://localhost:8080");
|
|
140
163
|
`;
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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.");
|
|
145
168
|
}
|
|
146
169
|
// This function updates the .gitignore file
|
|
147
170
|
async function createUpdateGitignoreFile(baseDir, additions) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
171
|
+
const gitignorePath = path.join(baseDir, ".gitignore");
|
|
172
|
+
// Check if the .gitignore file exists, create if it doesn't
|
|
173
|
+
let gitignoreContent = "";
|
|
174
|
+
if (fs.existsSync(gitignorePath)) {
|
|
175
|
+
gitignoreContent = fs.readFileSync(gitignorePath, "utf8");
|
|
176
|
+
}
|
|
177
|
+
additions.forEach((addition) => {
|
|
178
|
+
if (!gitignoreContent.includes(addition)) {
|
|
179
|
+
gitignoreContent += `\n${addition}`;
|
|
153
180
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
});
|
|
159
|
-
// Ensure there's no leading newline if the file was just created
|
|
160
|
-
gitignoreContent = gitignoreContent.trimStart();
|
|
161
|
-
fs.writeFileSync(gitignorePath, gitignoreContent);
|
|
181
|
+
});
|
|
182
|
+
// Ensure there's no leading newline if the file was just created
|
|
183
|
+
gitignoreContent = gitignoreContent.trimStart();
|
|
184
|
+
fs.writeFileSync(gitignorePath, gitignoreContent);
|
|
162
185
|
}
|
|
163
186
|
// Recursive copy function
|
|
164
187
|
function copyRecursiveSync(src, dest) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
fs.mkdirSync(dest, { recursive: true }); // Recreate the directory
|
|
174
|
-
fs.readdirSync(src).forEach((childItemName) => {
|
|
175
|
-
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName));
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
fs.copyFileSync(src, dest); // This line ensures files are overwritten
|
|
188
|
+
const exists = fs.existsSync(src);
|
|
189
|
+
const stats = exists && fs.statSync(src);
|
|
190
|
+
const isDirectory = exists && stats && stats.isDirectory();
|
|
191
|
+
console.log("🚀 ~ copyRecursiveSync ~ isDirectory:", isDirectory);
|
|
192
|
+
if (isDirectory) {
|
|
193
|
+
if (fs.existsSync(dest)) {
|
|
194
|
+
fs.rmSync(dest, { recursive: true, force: true }); // Remove the directory if it exists
|
|
180
195
|
}
|
|
196
|
+
fs.mkdirSync(dest, { recursive: true }); // Recreate the directory
|
|
197
|
+
fs.readdirSync(src).forEach((childItemName) => {
|
|
198
|
+
copyRecursiveSync(
|
|
199
|
+
path.join(src, childItemName),
|
|
200
|
+
path.join(dest, childItemName)
|
|
201
|
+
);
|
|
202
|
+
});
|
|
203
|
+
} else {
|
|
204
|
+
fs.copyFileSync(src, dest); // This line ensures files are overwritten
|
|
205
|
+
}
|
|
181
206
|
}
|
|
182
207
|
// Function to execute the recursive copy for entire directories
|
|
183
208
|
async function executeCopy(baseDir, directoriesToCopy) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
209
|
+
directoriesToCopy.forEach(({ srcDir, destDir }) => {
|
|
210
|
+
const sourcePath = path.join(__dirname, srcDir);
|
|
211
|
+
const destPath = path.join(baseDir, destDir);
|
|
212
|
+
copyRecursiveSync(sourcePath, destPath);
|
|
213
|
+
});
|
|
189
214
|
}
|
|
190
215
|
function modifyTailwindConfig(baseDir) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
216
|
+
const filePath = path.join(baseDir, "tailwind.config.js");
|
|
217
|
+
const newContent = [
|
|
218
|
+
"./src/app/**/*.{html,js,php}",
|
|
219
|
+
// Add more paths as needed
|
|
220
|
+
];
|
|
221
|
+
let configData = fs.readFileSync(filePath, "utf8");
|
|
222
|
+
const contentArrayString = newContent
|
|
223
|
+
.map((item) => ` "${item}"`)
|
|
224
|
+
.join(",\n");
|
|
225
|
+
configData = configData.replace(
|
|
226
|
+
/content: \[\],/g,
|
|
227
|
+
`content: [\n${contentArrayString}\n],`
|
|
228
|
+
);
|
|
229
|
+
fs.writeFileSync(filePath, configData, "utf8");
|
|
230
|
+
console.log(chalk.green("Tailwind configuration updated successfully."));
|
|
203
231
|
}
|
|
204
232
|
function modifyPostcssConfig(baseDir) {
|
|
205
|
-
|
|
206
|
-
|
|
233
|
+
const filePath = path.join(baseDir, "postcss.config.js");
|
|
234
|
+
const newContent = `export default {
|
|
207
235
|
plugins: {
|
|
208
236
|
tailwindcss: {},
|
|
209
237
|
autoprefixer: {},
|
|
210
238
|
cssnano: {},
|
|
211
239
|
},
|
|
212
240
|
};`;
|
|
213
|
-
|
|
214
|
-
|
|
241
|
+
fs.writeFileSync(filePath, newContent, "utf8");
|
|
242
|
+
console.log(chalk.green("postcss.config.js updated successfully."));
|
|
215
243
|
}
|
|
216
244
|
function modifyIndexPHP(baseDir, useTailwind) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
245
|
+
const indexPath = path.join(baseDir, "src", "app", "layout.php");
|
|
246
|
+
try {
|
|
247
|
+
let indexContent = fs.readFileSync(indexPath, "utf8");
|
|
248
|
+
const stylesAndLinks = `\n <link href="<?php echo $baseUrl; ?>css/index.css" rel="stylesheet">\n <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap" rel="stylesheet">\n <script src="<?php echo $baseUrl; ?>js/index.js"></script>`;
|
|
249
|
+
// Tailwind CSS link or CDN script
|
|
250
|
+
const tailwindLink = useTailwind
|
|
251
|
+
? ` <link href="<?php echo $baseUrl; ?>css/styles.css" rel="stylesheet"> ${stylesAndLinks}`
|
|
252
|
+
: ` <script src="https://cdn.tailwindcss.com"></script> ${stylesAndLinks}`;
|
|
253
|
+
// Insert before the closing </head> tag
|
|
254
|
+
indexContent = indexContent.replace("</head>", `${tailwindLink}\n</head>`);
|
|
255
|
+
fs.writeFileSync(indexPath, indexContent, "utf8");
|
|
256
|
+
console.log(
|
|
257
|
+
chalk.green(
|
|
258
|
+
`index.php modified successfully for ${
|
|
259
|
+
useTailwind ? "local Tailwind CSS" : "Tailwind CSS CDN"
|
|
260
|
+
}.`
|
|
261
|
+
)
|
|
262
|
+
);
|
|
263
|
+
} catch (error) {
|
|
264
|
+
console.error(chalk.red("Error modifying index.php:"), error);
|
|
265
|
+
}
|
|
233
266
|
}
|
|
234
267
|
// This function updates or creates the .env file
|
|
235
268
|
async function updateOrCreateEnvFile(baseDir, content) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
269
|
+
const envPath = path.join(baseDir, ".env");
|
|
270
|
+
let envContent = fs.existsSync(envPath)
|
|
271
|
+
? fs.readFileSync(envPath, "utf8")
|
|
272
|
+
: "";
|
|
273
|
+
envContent += `${envContent !== "" ? "\n\n" : ""}${content}`;
|
|
274
|
+
fs.writeFileSync(envPath, envContent);
|
|
242
275
|
}
|
|
243
276
|
async function createDirectoryStructure(baseDir, answer, projectSettings) {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
const envContent = `# PHPMailer
|
|
277
|
+
console.log("🚀 ~ baseDir:", baseDir);
|
|
278
|
+
console.log("🚀 ~ answer:", answer);
|
|
279
|
+
console.log("🚀 ~ projectSettings:", projectSettings);
|
|
280
|
+
const filesToCopy = [
|
|
281
|
+
{ src: "/bootstrap.php", dest: "/bootstrap.php" },
|
|
282
|
+
{ src: "/.htaccess", dest: "/.htaccess" },
|
|
283
|
+
{ src: "/../composer.json", dest: "/composer.json" },
|
|
284
|
+
];
|
|
285
|
+
// if (answer.websocket) {
|
|
286
|
+
// filesToCopy.push({
|
|
287
|
+
// src: "/../composer-websocket.lock",
|
|
288
|
+
// dest: "/composer.lock",
|
|
289
|
+
// });
|
|
290
|
+
// } else {
|
|
291
|
+
// filesToCopy.push({ src: "/../composer.lock", dest: "/composer.lock" });
|
|
292
|
+
// }
|
|
293
|
+
const directoriesToCopy = [
|
|
294
|
+
{
|
|
295
|
+
srcDir: "/settings",
|
|
296
|
+
destDir: "/settings",
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
srcDir: "/prisma",
|
|
300
|
+
destDir: "/prisma",
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
srcDir: "/src",
|
|
304
|
+
destDir: "/src",
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
srcDir: "/../vendor",
|
|
308
|
+
destDir: "/vendor",
|
|
309
|
+
},
|
|
310
|
+
];
|
|
311
|
+
console.log("🚀 ~ directoriesToCopy:", directoriesToCopy);
|
|
312
|
+
filesToCopy.forEach(({ src, dest }) => {
|
|
313
|
+
const sourcePath = path.join(__dirname, src);
|
|
314
|
+
const destPath = path.join(baseDir, dest);
|
|
315
|
+
const code = fs.readFileSync(sourcePath, "utf8");
|
|
316
|
+
fs.writeFileSync(destPath, code, { flag: "w" });
|
|
317
|
+
});
|
|
318
|
+
await executeCopy(baseDir, directoriesToCopy);
|
|
319
|
+
await updatePackageJson(baseDir, projectSettings, answer);
|
|
320
|
+
await updateComposerJson(baseDir, answer);
|
|
321
|
+
await updateIndexJsForWebSocket(baseDir, answer);
|
|
322
|
+
if (answer.tailwindcss) {
|
|
323
|
+
modifyTailwindConfig(baseDir);
|
|
324
|
+
modifyIndexPHP(baseDir, true);
|
|
325
|
+
modifyPostcssConfig(baseDir);
|
|
326
|
+
} else {
|
|
327
|
+
modifyIndexPHP(baseDir, false);
|
|
328
|
+
}
|
|
329
|
+
const envContent = `# PHPMailer
|
|
298
330
|
SMTP_HOST=
|
|
299
331
|
SMTP_USERNAME=
|
|
300
332
|
SMTP_PASSWORD=
|
|
@@ -302,63 +334,70 @@ SMTP_PORT=
|
|
|
302
334
|
SMTP_ENCRYPTION=ssl
|
|
303
335
|
MAIL_FROM=
|
|
304
336
|
MAIL_FROM_NAME=""`;
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
337
|
+
await updateOrCreateEnvFile(baseDir, envContent);
|
|
338
|
+
// Add vendor to .gitignore
|
|
339
|
+
await createUpdateGitignoreFile(baseDir, ["vendor"]);
|
|
308
340
|
}
|
|
309
341
|
async function getAnswer(predefinedAnswers = {}) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
342
|
+
var _a, _b, _c;
|
|
343
|
+
console.log("🚀 ~ predefinedAnswers:", predefinedAnswers);
|
|
344
|
+
const questions = [];
|
|
345
|
+
if (!predefinedAnswers.projectName) {
|
|
346
|
+
questions.push({
|
|
347
|
+
type: "text",
|
|
348
|
+
name: "projectName",
|
|
349
|
+
message: "What is your project named?",
|
|
350
|
+
initial: "my-app",
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
if (!predefinedAnswers.tailwindcss) {
|
|
354
|
+
questions.push({
|
|
355
|
+
type: "toggle",
|
|
356
|
+
name: "tailwindcss",
|
|
357
|
+
message: `Would you like to use ${chalk.blue("Tailwind CSS")}?`,
|
|
358
|
+
initial: true,
|
|
359
|
+
active: "Yes",
|
|
360
|
+
inactive: "No",
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
if (!predefinedAnswers.websocket) {
|
|
364
|
+
questions.push({
|
|
365
|
+
type: "toggle",
|
|
366
|
+
name: "websocket",
|
|
367
|
+
message: `Would you like to use ${chalk.blue("Websocket")}?`,
|
|
368
|
+
initial: true,
|
|
369
|
+
active: "Yes",
|
|
370
|
+
inactive: "No",
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
console.log("🚀 ~ questions:", questions);
|
|
374
|
+
const onCancel = () => {
|
|
375
|
+
return false;
|
|
376
|
+
};
|
|
377
|
+
try {
|
|
378
|
+
const response = await prompts(questions, { onCancel });
|
|
379
|
+
if (Object.keys(response).length === 0) {
|
|
380
|
+
return null;
|
|
340
381
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
382
|
+
return {
|
|
383
|
+
projectName: response.projectName
|
|
384
|
+
? String(response.projectName).trim().replace(/ /g, "-")
|
|
385
|
+
: (_a = predefinedAnswers.projectName) !== null && _a !== void 0
|
|
386
|
+
? _a
|
|
387
|
+
: "my-app",
|
|
388
|
+
tailwindcss:
|
|
389
|
+
(_b = response.tailwindcss) !== null && _b !== void 0
|
|
390
|
+
? _b
|
|
391
|
+
: predefinedAnswers.tailwindcss,
|
|
392
|
+
websocket:
|
|
393
|
+
(_c = response.websocket) !== null && _c !== void 0
|
|
394
|
+
? _c
|
|
395
|
+
: predefinedAnswers.websocket,
|
|
344
396
|
};
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
}
|
|
350
|
-
return {
|
|
351
|
-
projectName: response.projectName
|
|
352
|
-
? String(response.projectName).trim().replace(/ /g, "-")
|
|
353
|
-
: (_a = predefinedAnswers.projectName) !== null && _a !== void 0 ? _a : "my-app",
|
|
354
|
-
tailwindcss: (_b = response.tailwindcss) !== null && _b !== void 0 ? _b : predefinedAnswers.tailwindcss,
|
|
355
|
-
websocket: (_c = response.websocket) !== null && _c !== void 0 ? _c : predefinedAnswers.websocket,
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
catch (error) {
|
|
359
|
-
console.error(chalk.red("Prompt error:"), error);
|
|
360
|
-
return null;
|
|
361
|
-
}
|
|
397
|
+
} catch (error) {
|
|
398
|
+
console.error(chalk.red("Prompt error:"), error);
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
362
401
|
}
|
|
363
402
|
/**
|
|
364
403
|
* Install dependencies in the specified directory.
|
|
@@ -367,191 +406,206 @@ async function getAnswer(predefinedAnswers = {}) {
|
|
|
367
406
|
* @param {boolean} [isDev=false] - Whether to install the dependencies as devDependencies.
|
|
368
407
|
*/
|
|
369
408
|
async function installDependencies(baseDir, dependencies, isDev = false) {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
});
|
|
377
|
-
// Log the dependencies being installed
|
|
378
|
-
console.log(`${isDev ? "Installing development dependencies" : "Installing dependencies"}:`);
|
|
379
|
-
dependencies.forEach((dep) => console.log(`- ${chalk.blue(dep)}`));
|
|
380
|
-
// Prepare the npm install command with the appropriate flag for dev dependencies
|
|
381
|
-
const npmInstallCommand = `npm install ${isDev ? "--save-dev" : ""} ${dependencies.join(" ")}`;
|
|
382
|
-
// Execute the npm install command
|
|
383
|
-
execSync(npmInstallCommand, {
|
|
384
|
-
stdio: "inherit",
|
|
385
|
-
cwd: baseDir,
|
|
409
|
+
console.log("Initializing new Node.js project...");
|
|
410
|
+
// Initialize a package.json if it doesn't exist
|
|
411
|
+
if (!fs.existsSync(path.join(baseDir, "package.json")))
|
|
412
|
+
execSync("npm init -y", {
|
|
413
|
+
stdio: "inherit",
|
|
414
|
+
cwd: baseDir,
|
|
386
415
|
});
|
|
416
|
+
// Log the dependencies being installed
|
|
417
|
+
console.log(
|
|
418
|
+
`${
|
|
419
|
+
isDev ? "Installing development dependencies" : "Installing dependencies"
|
|
420
|
+
}:`
|
|
421
|
+
);
|
|
422
|
+
dependencies.forEach((dep) => console.log(`- ${chalk.blue(dep)}`));
|
|
423
|
+
// Prepare the npm install command with the appropriate flag for dev dependencies
|
|
424
|
+
const npmInstallCommand = `npm install ${
|
|
425
|
+
isDev ? "--save-dev" : ""
|
|
426
|
+
} ${dependencies.join(" ")}`;
|
|
427
|
+
// Execute the npm install command
|
|
428
|
+
execSync(npmInstallCommand, {
|
|
429
|
+
stdio: "inherit",
|
|
430
|
+
cwd: baseDir,
|
|
431
|
+
});
|
|
387
432
|
}
|
|
388
433
|
function fetchPackageVersion(packageName) {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
});
|
|
434
|
+
return new Promise((resolve, reject) => {
|
|
435
|
+
https
|
|
436
|
+
.get(`https://registry.npmjs.org/${packageName}`, (res) => {
|
|
437
|
+
let data = "";
|
|
438
|
+
res.on("data", (chunk) => (data += chunk));
|
|
439
|
+
res.on("end", () => {
|
|
440
|
+
try {
|
|
441
|
+
const parsed = JSON.parse(data);
|
|
442
|
+
resolve(parsed["dist-tags"].latest);
|
|
443
|
+
} catch (error) {
|
|
444
|
+
reject(new Error("Failed to parse JSON response"));
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
})
|
|
448
|
+
.on("error", (err) => reject(err));
|
|
449
|
+
});
|
|
406
450
|
}
|
|
407
451
|
async function main() {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
452
|
+
try {
|
|
453
|
+
const args = process.argv.slice(2);
|
|
454
|
+
let projectName = args[0];
|
|
455
|
+
console.log("🚀 ~ main ~ projectName:", projectName);
|
|
456
|
+
let answer = null;
|
|
457
|
+
if (projectName) {
|
|
458
|
+
let useTailwind = args.includes("--tailwind");
|
|
459
|
+
let useWebsocket = args.includes("--websocket");
|
|
460
|
+
const predefinedAnswers = {
|
|
461
|
+
projectName,
|
|
462
|
+
tailwindcss: useTailwind,
|
|
463
|
+
websocket: useWebsocket,
|
|
464
|
+
};
|
|
465
|
+
answer = await getAnswer(predefinedAnswers);
|
|
466
|
+
console.log("🚀 ~ main ~ answer:", answer);
|
|
467
|
+
} else {
|
|
468
|
+
answer = await getAnswer();
|
|
469
|
+
}
|
|
470
|
+
if (answer === null) {
|
|
471
|
+
console.log(chalk.red("Installation cancelled."));
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
// execSync(`npm install -g create-prisma-php-app`, { stdio: "inherit" }); // TODO: Uncomment this line before publishing the package
|
|
475
|
+
execSync(`npm install -g create-prisma-php-app@alpha-update-command`, {
|
|
476
|
+
stdio: "inherit",
|
|
477
|
+
}); // TODO: Uncomment this line before publishing the package
|
|
478
|
+
// Support for browser-sync
|
|
479
|
+
execSync(`npm install -g browser-sync`, { stdio: "inherit" });
|
|
480
|
+
// Create the project directory
|
|
481
|
+
if (!projectName) fs.mkdirSync(answer.projectName);
|
|
482
|
+
const currentDir = process.cwd();
|
|
483
|
+
console.log("🚀 ~ main ~ currentDir:", currentDir);
|
|
484
|
+
let projectPath = projectName
|
|
485
|
+
? currentDir
|
|
486
|
+
: path.join(currentDir, answer.projectName);
|
|
487
|
+
console.log("🚀 ~ main ~ projectPath:", projectPath);
|
|
488
|
+
if (!projectName) process.chdir(answer.projectName);
|
|
489
|
+
const dependencies = [
|
|
490
|
+
"prisma",
|
|
491
|
+
"@prisma/client",
|
|
492
|
+
"typescript",
|
|
493
|
+
"@types/node",
|
|
494
|
+
"ts-node",
|
|
495
|
+
"http-proxy-middleware",
|
|
496
|
+
];
|
|
497
|
+
if (answer.tailwindcss) {
|
|
498
|
+
dependencies.push(
|
|
499
|
+
"tailwindcss",
|
|
500
|
+
"autoprefixer",
|
|
501
|
+
"postcss",
|
|
502
|
+
"postcss-cli",
|
|
503
|
+
"cssnano"
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
if (answer.websocket) {
|
|
507
|
+
dependencies.push("chokidar-cli");
|
|
508
|
+
}
|
|
509
|
+
if (answer.tailwindcss || answer.websocket) {
|
|
510
|
+
dependencies.push("npm-run-all");
|
|
511
|
+
}
|
|
512
|
+
await installDependencies(projectPath, dependencies, true);
|
|
513
|
+
if (!projectName) {
|
|
514
|
+
execSync(`npx prisma init`, { stdio: "inherit" });
|
|
515
|
+
execSync(`npx tsc --init`, { stdio: "inherit" });
|
|
516
|
+
}
|
|
517
|
+
if (answer.tailwindcss) {
|
|
518
|
+
execSync(`npx tailwindcss init -p`, { stdio: "inherit" });
|
|
519
|
+
}
|
|
520
|
+
const projectSettings = {
|
|
521
|
+
PROJECT_NAME: answer.projectName,
|
|
522
|
+
PROJECT_ROOT_PATH: projectPath.replace(/\\/g, "\\\\"),
|
|
523
|
+
PHP_ROOT_PATH_EXE: "D:\\\\xampp\\\\php\\\\php.exe",
|
|
524
|
+
PHP_GENERATE_CLASS_PATH: "src/lib/prisma/classes",
|
|
525
|
+
};
|
|
526
|
+
await createDirectoryStructure(projectPath, answer, projectSettings);
|
|
527
|
+
// if (answer.tailwindcss) {
|
|
528
|
+
// execSync(
|
|
529
|
+
// `npx tailwindcss -i ./src/app/css/tailwind.css -o ./src/app/css/styles.css --minify`,
|
|
530
|
+
// { stdio: "inherit" }
|
|
531
|
+
// );
|
|
532
|
+
// }
|
|
533
|
+
// execSync(`composer install`, { stdio: "inherit" });
|
|
534
|
+
// execSync(`composer dump-autoload`, { stdio: "inherit" });
|
|
535
|
+
// Create settings file
|
|
536
|
+
const settingsPath = path.join(
|
|
537
|
+
projectPath,
|
|
538
|
+
"settings",
|
|
539
|
+
"project-settings.js"
|
|
540
|
+
);
|
|
541
|
+
const settingsCode = `export const projectSettings = {
|
|
491
542
|
PROJECT_NAME: "${answer.projectName}",
|
|
492
543
|
PROJECT_ROOT_PATH: "${projectPath.replace(/\\/g, "\\\\")}",
|
|
493
544
|
PHP_ROOT_PATH_EXE: "D:\\\\xampp\\\\php\\\\php.exe",
|
|
494
545
|
PHP_GENERATE_CLASS_PATH: "src/lib/prisma/classes",
|
|
495
546
|
};`;
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
else {
|
|
512
|
-
console.log(`${file} does not exist.`);
|
|
513
|
-
}
|
|
514
|
-
});
|
|
515
|
-
}
|
|
516
|
-
// Update websocket if not chosen by the user
|
|
517
|
-
if (!answer.websocket) {
|
|
518
|
-
const wsPath = path.join(projectPath, "src", "lib", "websocket");
|
|
519
|
-
// Check if the websocket directory exists
|
|
520
|
-
if (fs.existsSync(wsPath)) {
|
|
521
|
-
// Use fs.rmSync with recursive option set to true to delete the directory and its contents
|
|
522
|
-
fs.rmSync(wsPath, { recursive: true, force: true }); // force option is not necessary but can be used to ensure deletion
|
|
523
|
-
console.log("Websocket directory was deleted successfully.");
|
|
524
|
-
}
|
|
525
|
-
else {
|
|
526
|
-
console.log("Websocket directory does not exist.");
|
|
527
|
-
}
|
|
528
|
-
// Update settings directory if websocket is not chosen
|
|
529
|
-
const settingsPath = path.join(projectPath, "settings");
|
|
530
|
-
const websocketFiles = ["restartWebsocket.cjs", "restart_websocket.bat"];
|
|
531
|
-
websocketFiles.forEach((file) => {
|
|
532
|
-
const filePath = path.join(settingsPath, file);
|
|
533
|
-
if (fs.existsSync(filePath)) {
|
|
534
|
-
fs.unlinkSync(filePath); // Delete each file if it exists
|
|
535
|
-
console.log(`${file} was deleted successfully.`);
|
|
536
|
-
}
|
|
537
|
-
else {
|
|
538
|
-
console.log(`${file} does not exist.`);
|
|
539
|
-
}
|
|
540
|
-
});
|
|
547
|
+
fs.writeFileSync(settingsPath, settingsCode, { flag: "w" });
|
|
548
|
+
const publicDirPath = path.join(projectPath, "public");
|
|
549
|
+
if (!fs.existsSync(publicDirPath)) {
|
|
550
|
+
fs.mkdirSync(publicDirPath);
|
|
551
|
+
}
|
|
552
|
+
if (!answer.tailwindcss) {
|
|
553
|
+
const cssPath = path.join(projectPath, "src", "app", "css");
|
|
554
|
+
const tailwindFiles = ["tailwind.css", "styles.css"];
|
|
555
|
+
tailwindFiles.forEach((file) => {
|
|
556
|
+
const filePath = path.join(cssPath, file);
|
|
557
|
+
if (fs.existsSync(filePath)) {
|
|
558
|
+
fs.unlinkSync(filePath); // Delete each file if it exists
|
|
559
|
+
console.log(`${file} was deleted successfully.`);
|
|
560
|
+
} else {
|
|
561
|
+
console.log(`${file} does not exist.`);
|
|
541
562
|
}
|
|
542
|
-
|
|
543
|
-
const prismaPhpConfig = {
|
|
544
|
-
projectName: answer.projectName,
|
|
545
|
-
tailwindcss: answer.tailwindcss,
|
|
546
|
-
websocket: answer.websocket,
|
|
547
|
-
version,
|
|
548
|
-
};
|
|
549
|
-
fs.writeFileSync(path.join(projectPath, "prisma-php.json"), JSON.stringify(prismaPhpConfig, null, 2));
|
|
550
|
-
console.log(`${chalk.green("Success!")} Prisma PHP project successfully created in ${answer.projectName}!`);
|
|
563
|
+
});
|
|
551
564
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
565
|
+
// Update websocket if not chosen by the user
|
|
566
|
+
if (!answer.websocket) {
|
|
567
|
+
const wsPath = path.join(projectPath, "src", "lib", "websocket");
|
|
568
|
+
// Check if the websocket directory exists
|
|
569
|
+
if (fs.existsSync(wsPath)) {
|
|
570
|
+
// Use fs.rmSync with recursive option set to true to delete the directory and its contents
|
|
571
|
+
fs.rmSync(wsPath, { recursive: true, force: true }); // force option is not necessary but can be used to ensure deletion
|
|
572
|
+
console.log("Websocket directory was deleted successfully.");
|
|
573
|
+
} else {
|
|
574
|
+
console.log("Websocket directory does not exist.");
|
|
575
|
+
}
|
|
576
|
+
// Update settings directory if websocket is not chosen
|
|
577
|
+
const settingsPath = path.join(projectPath, "settings");
|
|
578
|
+
const websocketFiles = ["restartWebsocket.cjs", "restart_websocket.bat"];
|
|
579
|
+
websocketFiles.forEach((file) => {
|
|
580
|
+
const filePath = path.join(settingsPath, file);
|
|
581
|
+
if (fs.existsSync(filePath)) {
|
|
582
|
+
fs.unlinkSync(filePath); // Delete each file if it exists
|
|
583
|
+
console.log(`${file} was deleted successfully.`);
|
|
584
|
+
} else {
|
|
585
|
+
console.log(`${file} does not exist.`);
|
|
586
|
+
}
|
|
587
|
+
});
|
|
555
588
|
}
|
|
589
|
+
const version = await fetchPackageVersion("create-prisma-php-app");
|
|
590
|
+
const prismaPhpConfig = {
|
|
591
|
+
projectName: answer.projectName,
|
|
592
|
+
tailwindcss: answer.tailwindcss,
|
|
593
|
+
websocket: answer.websocket,
|
|
594
|
+
version,
|
|
595
|
+
};
|
|
596
|
+
fs.writeFileSync(
|
|
597
|
+
path.join(projectPath, "prisma-php.json"),
|
|
598
|
+
JSON.stringify(prismaPhpConfig, null, 2),
|
|
599
|
+
{ flag: "w" }
|
|
600
|
+
);
|
|
601
|
+
console.log(
|
|
602
|
+
`${chalk.green("Success!")} Prisma PHP project successfully created in ${
|
|
603
|
+
answer.projectName
|
|
604
|
+
}!`
|
|
605
|
+
);
|
|
606
|
+
} catch (error) {
|
|
607
|
+
console.error("Error while creating the project:", error);
|
|
608
|
+
process.exit(1);
|
|
609
|
+
}
|
|
556
610
|
}
|
|
557
611
|
main();
|
package/dist/prisma-php.js
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
2
|
+
import { spawn } from "child_process";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import prompts from "prompts";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = path.dirname(__filename);
|
|
9
|
+
const args = process.argv.slice(2);
|
|
10
|
+
const readJsonFile = (filePath) => {
|
|
11
|
+
const jsonData = fs.readFileSync(filePath, "utf8");
|
|
12
|
+
return JSON.parse(jsonData);
|
|
13
|
+
};
|
|
14
|
+
const executeCommand = (command, args = [], options = {}) => {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const process = spawn(command, args, Object.assign({ stdio: "inherit", shell: true }, options));
|
|
17
|
+
process.on("error", (error) => {
|
|
18
|
+
console.error(`Execution error: ${error.message}`);
|
|
19
|
+
reject(error);
|
|
20
|
+
});
|
|
21
|
+
process.on("close", (code) => {
|
|
22
|
+
if (code === 0) {
|
|
23
|
+
resolve();
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
reject(new Error(`Process exited with code ${code}`));
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
};
|
|
3
31
|
const main = async () => {
|
|
4
32
|
if (args.length > 0 && args[0] === "update") {
|
|
5
33
|
try {
|
|
@@ -16,11 +44,13 @@ const main = async () => {
|
|
|
16
44
|
const currentDir = process.cwd();
|
|
17
45
|
const configPath = path.join(currentDir, "prisma-php.json");
|
|
18
46
|
const localSettings = readJsonFile(configPath);
|
|
47
|
+
console.log("🚀 ~ main ~ localSettings:", localSettings);
|
|
19
48
|
const commandArgs = [localSettings.projectName];
|
|
20
49
|
if (localSettings.tailwindcss)
|
|
21
50
|
commandArgs.push("--tailwindcss");
|
|
22
51
|
if (localSettings.websocket)
|
|
23
52
|
commandArgs.push("--websocket");
|
|
53
|
+
console.log("🚀 ~ main ~ commandArgs:", commandArgs);
|
|
24
54
|
console.log("Executing command...\n");
|
|
25
55
|
await executeCommand("npx", [
|
|
26
56
|
"create-prisma-php-app@alpha-update-command",
|