create-prisma-php-app 1.6.56 → 1.6.58
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 +29 -10
- package/dist/prisma-php.js +85 -73
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -73,6 +73,8 @@ function configureBrowserSyncCommand(baseDir, projectSettings) {
|
|
|
73
73
|
}
|
|
74
74
|
async function updatePackageJson(baseDir, projectSettings, answer) {
|
|
75
75
|
const packageJsonPath = path.join(baseDir, "package.json");
|
|
76
|
+
if (checkExcludeFiles(packageJsonPath))
|
|
77
|
+
return;
|
|
76
78
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
77
79
|
// Use the new function to configure the Browser Sync command
|
|
78
80
|
const browserSyncCommand = configureBrowserSyncCommand(baseDir, projectSettings);
|
|
@@ -109,6 +111,8 @@ async function updateComposerJson(baseDir, answer) {
|
|
|
109
111
|
if (!answer.websocket)
|
|
110
112
|
return;
|
|
111
113
|
const composerJsonPath = path.join(baseDir, "composer.json");
|
|
114
|
+
if (checkExcludeFiles(composerJsonPath))
|
|
115
|
+
return;
|
|
112
116
|
let composerJson;
|
|
113
117
|
// Check if the composer.json file exists
|
|
114
118
|
if (fs.existsSync(composerJsonPath)) {
|
|
@@ -133,6 +137,8 @@ async function updateIndexJsForWebSocket(baseDir, answer) {
|
|
|
133
137
|
return;
|
|
134
138
|
}
|
|
135
139
|
const indexPath = path.join(baseDir, "src", "app", "js", "index.js");
|
|
140
|
+
if (checkExcludeFiles(indexPath))
|
|
141
|
+
return;
|
|
136
142
|
let indexContent = fs.readFileSync(indexPath, "utf8");
|
|
137
143
|
// WebSocket initialization code to be appended
|
|
138
144
|
const webSocketCode = `
|
|
@@ -147,6 +153,8 @@ const ws = new WebSocket("ws://localhost:8080");
|
|
|
147
153
|
// This function updates the .gitignore file
|
|
148
154
|
async function createUpdateGitignoreFile(baseDir, additions) {
|
|
149
155
|
const gitignorePath = path.join(baseDir, ".gitignore");
|
|
156
|
+
if (checkExcludeFiles(gitignorePath))
|
|
157
|
+
return;
|
|
150
158
|
// Check if the .gitignore file exists, create if it doesn't
|
|
151
159
|
let gitignoreContent = "";
|
|
152
160
|
if (fs.existsSync(gitignorePath)) {
|
|
@@ -163,7 +171,6 @@ async function createUpdateGitignoreFile(baseDir, additions) {
|
|
|
163
171
|
}
|
|
164
172
|
// Recursive copy function
|
|
165
173
|
function copyRecursiveSync(src, dest) {
|
|
166
|
-
var _a;
|
|
167
174
|
console.log("🚀 ~ copyRecursiveSync ~ dest:", dest);
|
|
168
175
|
console.log("🚀 ~ copyRecursiveSync ~ src:", src);
|
|
169
176
|
const exists = fs.existsSync(src);
|
|
@@ -176,10 +183,8 @@ function copyRecursiveSync(src, dest) {
|
|
|
176
183
|
});
|
|
177
184
|
}
|
|
178
185
|
else {
|
|
179
|
-
if ((
|
|
180
|
-
console.log(`Skipping file: ${src}`);
|
|
186
|
+
if (checkExcludeFiles(dest))
|
|
181
187
|
return;
|
|
182
|
-
}
|
|
183
188
|
fs.copyFileSync(src, dest, 0);
|
|
184
189
|
}
|
|
185
190
|
}
|
|
@@ -194,6 +199,8 @@ async function executeCopy(baseDir, directoriesToCopy) {
|
|
|
194
199
|
function createOrUpdateTailwindConfig(baseDir) {
|
|
195
200
|
console.log("🚀 ~ createOrUpdateTailwindConfig ~ baseDir:", baseDir);
|
|
196
201
|
const filePath = path.join(baseDir, "tailwind.config.js");
|
|
202
|
+
if (checkExcludeFiles(filePath))
|
|
203
|
+
return;
|
|
197
204
|
const newContent = [
|
|
198
205
|
"./src/app/**/*.{html,js,php}",
|
|
199
206
|
// Add more paths as needed
|
|
@@ -209,6 +216,8 @@ function createOrUpdateTailwindConfig(baseDir) {
|
|
|
209
216
|
}
|
|
210
217
|
function modifyPostcssConfig(baseDir) {
|
|
211
218
|
const filePath = path.join(baseDir, "postcss.config.js");
|
|
219
|
+
if (checkExcludeFiles(filePath))
|
|
220
|
+
return;
|
|
212
221
|
const newContent = `export default {
|
|
213
222
|
plugins: {
|
|
214
223
|
tailwindcss: {},
|
|
@@ -219,10 +228,12 @@ function modifyPostcssConfig(baseDir) {
|
|
|
219
228
|
fs.writeFileSync(filePath, newContent, { flag: "w" });
|
|
220
229
|
console.log(chalk.green("postcss.config.js updated successfully."));
|
|
221
230
|
}
|
|
222
|
-
function
|
|
223
|
-
const
|
|
231
|
+
function modifyLayoutPHP(baseDir, useTailwind) {
|
|
232
|
+
const layoutPath = path.join(baseDir, "src", "app", "layout.php");
|
|
233
|
+
if (checkExcludeFiles(layoutPath))
|
|
234
|
+
return;
|
|
224
235
|
try {
|
|
225
|
-
let indexContent = fs.readFileSync(
|
|
236
|
+
let indexContent = fs.readFileSync(layoutPath, "utf8");
|
|
226
237
|
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>`;
|
|
227
238
|
// Tailwind CSS link or CDN script
|
|
228
239
|
const tailwindLink = useTailwind
|
|
@@ -230,7 +241,7 @@ function modifyIndexPHP(baseDir, useTailwind) {
|
|
|
230
241
|
: ` <script src="https://cdn.tailwindcss.com"></script> ${stylesAndLinks}`;
|
|
231
242
|
// Insert before the closing </head> tag
|
|
232
243
|
indexContent = indexContent.replace("</head>", `${tailwindLink}\n</head>`);
|
|
233
|
-
fs.writeFileSync(
|
|
244
|
+
fs.writeFileSync(layoutPath, indexContent, { flag: "w" });
|
|
234
245
|
console.log(chalk.green(`index.php modified successfully for ${useTailwind ? "local Tailwind CSS" : "Tailwind CSS CDN"}.`));
|
|
235
246
|
}
|
|
236
247
|
catch (error) {
|
|
@@ -240,6 +251,8 @@ function modifyIndexPHP(baseDir, useTailwind) {
|
|
|
240
251
|
// This function updates or creates the .env file
|
|
241
252
|
async function createOrUpdateEnvFile(baseDir, content) {
|
|
242
253
|
const envPath = path.join(baseDir, ".env");
|
|
254
|
+
if (checkExcludeFiles(envPath))
|
|
255
|
+
return;
|
|
243
256
|
let envContent = fs.existsSync(envPath)
|
|
244
257
|
? fs.readFileSync(envPath, "utf8")
|
|
245
258
|
: "";
|
|
@@ -249,6 +262,10 @@ async function createOrUpdateEnvFile(baseDir, content) {
|
|
|
249
262
|
fs.writeFileSync(envPath, envContent, { flag: "w" });
|
|
250
263
|
}
|
|
251
264
|
}
|
|
265
|
+
function checkExcludeFiles(destPath) {
|
|
266
|
+
var _a, _b;
|
|
267
|
+
return ((_b = (_a = updateAnswer === null || updateAnswer === void 0 ? void 0 : updateAnswer.excludeFiles) === null || _a === void 0 ? void 0 : _a.includes(destPath.replace(/\\/g, "/"))) !== null && _b !== void 0 ? _b : false);
|
|
268
|
+
}
|
|
252
269
|
async function createDirectoryStructure(baseDir, answer, projectSettings) {
|
|
253
270
|
console.log("🚀 ~ baseDir:", baseDir);
|
|
254
271
|
console.log("🚀 ~ answer:", answer);
|
|
@@ -294,6 +311,8 @@ async function createDirectoryStructure(baseDir, answer, projectSettings) {
|
|
|
294
311
|
filesToCopy.forEach(({ src, dest }) => {
|
|
295
312
|
const sourcePath = path.join(__dirname, src);
|
|
296
313
|
const destPath = path.join(baseDir, dest);
|
|
314
|
+
if (checkExcludeFiles(destPath))
|
|
315
|
+
return;
|
|
297
316
|
const code = fs.readFileSync(sourcePath, "utf8");
|
|
298
317
|
fs.writeFileSync(destPath, code, { flag: "w" });
|
|
299
318
|
});
|
|
@@ -303,11 +322,11 @@ async function createDirectoryStructure(baseDir, answer, projectSettings) {
|
|
|
303
322
|
await updateIndexJsForWebSocket(baseDir, answer);
|
|
304
323
|
if (answer.tailwindcss) {
|
|
305
324
|
createOrUpdateTailwindConfig(baseDir);
|
|
306
|
-
|
|
325
|
+
modifyLayoutPHP(baseDir, true);
|
|
307
326
|
modifyPostcssConfig(baseDir);
|
|
308
327
|
}
|
|
309
328
|
else {
|
|
310
|
-
|
|
329
|
+
modifyLayoutPHP(baseDir, false);
|
|
311
330
|
}
|
|
312
331
|
const envContent = `# PHPMailer
|
|
313
332
|
SMTP_HOST=
|
package/dist/prisma-php.js
CHANGED
|
@@ -9,88 +9,100 @@ const __filename = fileURLToPath(import.meta.url);
|
|
|
9
9
|
const __dirname = path.dirname(__filename);
|
|
10
10
|
const args = process.argv.slice(2);
|
|
11
11
|
const readJsonFile = (filePath) => {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const jsonData = fs.readFileSync(filePath, "utf8");
|
|
13
|
+
return JSON.parse(jsonData);
|
|
14
14
|
};
|
|
15
15
|
const executeCommand = (command, args = [], options = {}) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
reject(new Error(`Process exited with code ${code}`));
|
|
28
|
-
}
|
|
29
|
-
});
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
const process = spawn(
|
|
18
|
+
command,
|
|
19
|
+
args,
|
|
20
|
+
Object.assign({ stdio: "inherit", shell: true }, options)
|
|
21
|
+
);
|
|
22
|
+
process.on("error", (error) => {
|
|
23
|
+
console.error(`Execution error: ${error.message}`);
|
|
24
|
+
reject(error);
|
|
30
25
|
});
|
|
26
|
+
process.on("close", (code) => {
|
|
27
|
+
if (code === 0) {
|
|
28
|
+
resolve();
|
|
29
|
+
} else {
|
|
30
|
+
reject(new Error(`Process exited with code ${code}`));
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
|
31
34
|
};
|
|
32
35
|
async function getAnswer() {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
36
|
+
const questions = [
|
|
37
|
+
{
|
|
38
|
+
type: "toggle",
|
|
39
|
+
name: "shouldProceed",
|
|
40
|
+
message: `This command will update the ${chalk.blue(
|
|
41
|
+
"create-prisma-php-app"
|
|
42
|
+
)} package and overwrite all default files. ${chalk.blue(
|
|
43
|
+
"Do you want to proceed"
|
|
44
|
+
)}?`,
|
|
45
|
+
initial: false,
|
|
46
|
+
active: "Yes",
|
|
47
|
+
inactive: "No",
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
const onCancel = () => {
|
|
51
|
+
console.log(chalk.red("Operation cancelled by the user."));
|
|
52
|
+
process.exit(0);
|
|
53
|
+
};
|
|
54
|
+
const response = await prompts(questions, { onCancel });
|
|
55
|
+
if (Object.keys(response).length === 0) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
return response;
|
|
52
59
|
}
|
|
53
60
|
const main = async () => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
61
|
+
if (args.length > 0 && args[0] === "update") {
|
|
62
|
+
try {
|
|
63
|
+
const answer = await getAnswer();
|
|
64
|
+
if (
|
|
65
|
+
!(answer === null || answer === void 0 ? void 0 : answer.shouldProceed)
|
|
66
|
+
) {
|
|
67
|
+
console.log(chalk.red("Operation cancelled by the user."));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const currentDir = process.cwd();
|
|
71
|
+
const configPath = path.join(currentDir, "prisma-php.json");
|
|
72
|
+
if (!fs.existsSync(configPath)) {
|
|
73
|
+
console.error(
|
|
74
|
+
chalk.red(
|
|
75
|
+
"The configuration file 'prisma-php.json' was not found in the current directory."
|
|
76
|
+
)
|
|
77
|
+
);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const localSettings = readJsonFile(configPath);
|
|
81
|
+
const commandArgs = [localSettings.projectName];
|
|
82
|
+
if (localSettings.tailwindcss) commandArgs.push("--tailwindcss");
|
|
83
|
+
if (localSettings.websocket) commandArgs.push("--websocket");
|
|
84
|
+
console.log("Executing command...\n");
|
|
85
|
+
await executeCommand("npx", [
|
|
86
|
+
"create-prisma-php-app@alpha-update-command",
|
|
87
|
+
...commandArgs,
|
|
88
|
+
]);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
if (error instanceof Error) {
|
|
91
|
+
if (error.message.includes("no such file or directory")) {
|
|
92
|
+
console.error(
|
|
93
|
+
chalk.red(
|
|
94
|
+
"The configuration file 'prisma-php.json' was not found in the current directory."
|
|
95
|
+
)
|
|
96
|
+
);
|
|
88
97
|
}
|
|
98
|
+
} else {
|
|
99
|
+
console.error("Error in script execution:", error);
|
|
100
|
+
}
|
|
89
101
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
102
|
+
} else {
|
|
103
|
+
console.log("Command not recognized.");
|
|
104
|
+
}
|
|
93
105
|
};
|
|
94
106
|
main().catch((error) => {
|
|
95
|
-
|
|
107
|
+
console.error("Unhandled error in main function:", error);
|
|
96
108
|
});
|