create-prisma-php-app 4.0.0-alpha.4 → 4.0.0-alpha.5
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 +352 -423
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7,451 +7,380 @@ import{execSync}from"child_process";import fs from"fs";import{fileURLToPath}from
|
|
|
7
7
|
* @param {boolean} [isDev=false] - Whether to install the dependencies as devDependencies.
|
|
8
8
|
*/
|
|
9
9
|
async function installNpmDependencies(baseDir, dependencies, isDev = false) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
console.log("Initializing new Node.js project...");
|
|
11
|
+
// Initialize a package.json if it doesn't exist
|
|
12
|
+
if (!fs.existsSync(path.join(baseDir, "package.json"))) {
|
|
13
|
+
execSync("npm init -y", {
|
|
14
|
+
stdio: "inherit",
|
|
15
|
+
cwd: baseDir,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
// Log the dependencies being installed
|
|
19
|
+
console.log(`${isDev ? "Installing development dependencies" : "Installing dependencies"}:`);
|
|
20
|
+
dependencies.forEach((dep) => console.log(`- ${chalk.blue(dep)}`));
|
|
21
|
+
// Prepare the npm install command with the appropriate flag for dev dependencies
|
|
22
|
+
const npmInstallCommand = `npm install ${isDev ? "--save-dev" : ""} ${dependencies.join(" ")}`;
|
|
23
|
+
// Execute the npm install command
|
|
24
|
+
execSync(npmInstallCommand, {
|
|
25
|
+
stdio: "inherit",
|
|
26
|
+
cwd: baseDir,
|
|
16
27
|
});
|
|
17
|
-
}
|
|
18
|
-
// Log the dependencies being installed
|
|
19
|
-
console.log(
|
|
20
|
-
`${
|
|
21
|
-
isDev ? "Installing development dependencies" : "Installing dependencies"
|
|
22
|
-
}:`
|
|
23
|
-
);
|
|
24
|
-
dependencies.forEach((dep) => console.log(`- ${chalk.blue(dep)}`));
|
|
25
|
-
// Prepare the npm install command with the appropriate flag for dev dependencies
|
|
26
|
-
const npmInstallCommand = `npm install ${
|
|
27
|
-
isDev ? "--save-dev" : ""
|
|
28
|
-
} ${dependencies.join(" ")}`;
|
|
29
|
-
// Execute the npm install command
|
|
30
|
-
execSync(npmInstallCommand, {
|
|
31
|
-
stdio: "inherit",
|
|
32
|
-
cwd: baseDir,
|
|
33
|
-
});
|
|
34
28
|
}
|
|
35
29
|
async function installComposerDependencies(baseDir, dependencies) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
console.log("Initializing new Composer project...");
|
|
31
|
+
// Initialize a composer.json if it doesn't exist
|
|
32
|
+
if (!fs.existsSync(path.join(baseDir, "composer.json"))) {
|
|
33
|
+
execSync(`composer init -n --name="tsnc/prisma-php-app" --require="php:^8.2"`, {
|
|
34
|
+
stdio: "inherit",
|
|
35
|
+
cwd: baseDir,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
// Log the dependencies being installed
|
|
39
|
+
console.log("Installing Composer dependencies:");
|
|
40
|
+
dependencies.forEach((dep) => console.log(`- ${chalk.blue(dep)}`));
|
|
41
|
+
// Prepare the composer require command
|
|
42
|
+
const composerRequireCommand = `C:\\xampp\\php\\php.exe C:\\ProgramData\\ComposerSetup\\bin\\composer.phar require ${dependencies.join(" ")}`;
|
|
43
|
+
// Execute the composer require command
|
|
44
|
+
execSync(composerRequireCommand, {
|
|
42
45
|
stdio: "inherit",
|
|
43
46
|
cwd: baseDir,
|
|
44
|
-
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
// Log the dependencies being installed
|
|
48
|
-
console.log("Installing Composer dependencies:");
|
|
49
|
-
dependencies.forEach((dep) => console.log(`- ${chalk.blue(dep)}`));
|
|
50
|
-
// Prepare the composer require command
|
|
51
|
-
const composerRequireCommand = `C:\\xampp\\php\\php.exe C:\\ProgramData\\ComposerSetup\\bin\\composer.phar require ${dependencies.join(
|
|
52
|
-
" "
|
|
53
|
-
)}`;
|
|
54
|
-
// Execute the composer require command
|
|
55
|
-
execSync(composerRequireCommand, {
|
|
56
|
-
stdio: "inherit",
|
|
57
|
-
cwd: baseDir,
|
|
58
|
-
});
|
|
47
|
+
});
|
|
59
48
|
}
|
|
60
49
|
const npmPinnedVersions = {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
50
|
+
"@tailwindcss/postcss": "^4.1.11",
|
|
51
|
+
"@types/browser-sync": "^2.29.0",
|
|
52
|
+
"@types/node": "^24.0.7",
|
|
53
|
+
"@types/prompts": "^2.4.9",
|
|
54
|
+
"browser-sync": "^3.0.4",
|
|
55
|
+
chalk: "^5.4.1",
|
|
56
|
+
"chokidar-cli": "^3.0.0",
|
|
57
|
+
cssnano: "^7.0.7",
|
|
58
|
+
"http-proxy-middleware": "^3.0.5",
|
|
59
|
+
"npm-run-all": "^4.1.5",
|
|
60
|
+
"php-parser": "^3.2.4",
|
|
61
|
+
postcss: "^8.5.6",
|
|
62
|
+
"postcss-cli": "^11.0.1",
|
|
63
|
+
prompts: "^2.4.2",
|
|
64
|
+
tailwindcss: "^4.1.11",
|
|
65
|
+
tsx: "^4.20.3",
|
|
66
|
+
typescript: "^5.8.3",
|
|
78
67
|
};
|
|
79
68
|
function npmPkg(name) {
|
|
80
|
-
|
|
69
|
+
return npmPinnedVersions[name] ? `${name}@${npmPinnedVersions[name]}` : name;
|
|
81
70
|
}
|
|
82
71
|
const composerPinnedVersions = {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
72
|
+
"vlucas/phpdotenv": "^5.6.2",
|
|
73
|
+
"firebase/php-jwt": "^6.11.1",
|
|
74
|
+
"phpmailer/phpmailer": "^6.10.0",
|
|
75
|
+
"guzzlehttp/guzzle": "^7.9.3",
|
|
76
|
+
"ezyang/htmlpurifier": "^4.18.0",
|
|
77
|
+
"symfony/uid": "^7.2.0",
|
|
78
|
+
"brick/math": "^0.13.1",
|
|
79
|
+
"cboden/ratchet": "^0.4.4",
|
|
80
|
+
"tsnc/prisma-php": "^1.0.0",
|
|
92
81
|
};
|
|
93
82
|
function composerPkg(name) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
83
|
+
return composerPinnedVersions[name]
|
|
84
|
+
? `${name}:${composerPinnedVersions[name]}`
|
|
85
|
+
: name;
|
|
97
86
|
}
|
|
98
87
|
async function main() {
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
} else {
|
|
149
|
-
answer = await getAnswer();
|
|
150
|
-
}
|
|
151
|
-
if (answer === null) {
|
|
152
|
-
console.warn(chalk.red("Installation cancelled."));
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
const latestVersionOfCreatePrismaPhpApp = await fetchPackageVersion(
|
|
156
|
-
"create-prisma-php-app"
|
|
157
|
-
);
|
|
158
|
-
const isCreatePrismaPhpAppInstalled = getInstalledPackageVersion(
|
|
159
|
-
"create-prisma-php-app"
|
|
160
|
-
);
|
|
161
|
-
if (isCreatePrismaPhpAppInstalled) {
|
|
162
|
-
if (
|
|
163
|
-
compareVersions(
|
|
164
|
-
isCreatePrismaPhpAppInstalled,
|
|
165
|
-
latestVersionOfCreatePrismaPhpApp
|
|
166
|
-
) === -1
|
|
167
|
-
) {
|
|
168
|
-
execSync("npm uninstall -g create-prisma-php-app", {
|
|
169
|
-
stdio: "inherit",
|
|
170
|
-
});
|
|
171
|
-
execSync("npm install -g create-prisma-php-app", {
|
|
172
|
-
stdio: "inherit",
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
} else {
|
|
176
|
-
execSync("npm install -g create-prisma-php-app", { stdio: "inherit" });
|
|
177
|
-
}
|
|
178
|
-
// Create the project directory
|
|
179
|
-
if (!projectName) fs.mkdirSync(answer.projectName);
|
|
180
|
-
const currentDir = process.cwd();
|
|
181
|
-
let projectPath = projectName
|
|
182
|
-
? currentDir
|
|
183
|
-
: path.join(currentDir, answer.projectName);
|
|
184
|
-
if (!projectName) process.chdir(answer.projectName);
|
|
185
|
-
let npmDependencies = [
|
|
186
|
-
npmPkg("typescript"),
|
|
187
|
-
npmPkg("@types/node"),
|
|
188
|
-
npmPkg("tsx"),
|
|
189
|
-
npmPkg("http-proxy-middleware"),
|
|
190
|
-
npmPkg("chalk"),
|
|
191
|
-
npmPkg("npm-run-all"),
|
|
192
|
-
npmPkg("browser-sync"),
|
|
193
|
-
npmPkg("@types/browser-sync"),
|
|
194
|
-
npmPkg("php-parser"),
|
|
195
|
-
];
|
|
196
|
-
let composerDependencies = [
|
|
197
|
-
composerPkg("vlucas/phpdotenv"),
|
|
198
|
-
composerPkg("firebase/php-jwt"),
|
|
199
|
-
composerPkg("phpmailer/phpmailer"),
|
|
200
|
-
composerPkg("guzzlehttp/guzzle"),
|
|
201
|
-
composerPkg("ezyang/htmlpurifier"),
|
|
202
|
-
composerPkg("symfony/uid"),
|
|
203
|
-
composerPkg("brick/math"),
|
|
204
|
-
composerPkg("tsnc/prisma-php"),
|
|
205
|
-
];
|
|
206
|
-
if (answer.swaggerDocs) {
|
|
207
|
-
npmDependencies.push(
|
|
208
|
-
npmPkg("swagger-jsdoc"),
|
|
209
|
-
npmPkg("@types/swagger-jsdoc")
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
if (answer.swaggerDocs && answer.prisma) {
|
|
213
|
-
npmDependencies.push(npmPkg("prompts"), npmPkg("@types/prompts"));
|
|
214
|
-
}
|
|
215
|
-
if (answer.tailwindcss) {
|
|
216
|
-
npmDependencies.push(
|
|
217
|
-
npmPkg("tailwindcss"),
|
|
218
|
-
npmPkg("postcss"),
|
|
219
|
-
npmPkg("postcss-cli"),
|
|
220
|
-
npmPkg("@tailwindcss/postcss"),
|
|
221
|
-
npmPkg("cssnano")
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
if (answer.websocket) {
|
|
225
|
-
npmDependencies.push(npmPkg("chokidar-cli"));
|
|
226
|
-
composerDependencies.push("cboden/ratchet");
|
|
227
|
-
}
|
|
228
|
-
if (answer.prisma) {
|
|
229
|
-
execSync("npm install -g prisma-client-php", { stdio: "inherit" });
|
|
230
|
-
}
|
|
231
|
-
await installNpmDependencies(projectPath, npmDependencies, true);
|
|
232
|
-
await installComposerDependencies(projectPath, composerDependencies);
|
|
233
|
-
if (!projectName) {
|
|
234
|
-
execSync("npx tsc --init", { stdio: "inherit" });
|
|
235
|
-
}
|
|
236
|
-
await createDirectoryStructure(projectPath, answer);
|
|
237
|
-
if (answer.prisma) {
|
|
238
|
-
execSync("npx ppo init --prisma-php", { stdio: "inherit" });
|
|
239
|
-
}
|
|
240
|
-
if (answer.swaggerDocs) {
|
|
241
|
-
const swaggerDocsPath = path.join(
|
|
242
|
-
projectPath,
|
|
243
|
-
"src",
|
|
244
|
-
"app",
|
|
245
|
-
"swagger-docs"
|
|
246
|
-
);
|
|
247
|
-
// Check if the directory exists
|
|
248
|
-
if (fs.existsSync(swaggerDocsPath)) {
|
|
249
|
-
// If it exists and is not empty, remove it before cloning
|
|
250
|
-
if (fs.readdirSync(swaggerDocsPath).length > 0) {
|
|
251
|
-
console.log("Removing existing swagger-docs directory...");
|
|
252
|
-
fs.rmSync(swaggerDocsPath, { recursive: true, force: true });
|
|
88
|
+
try {
|
|
89
|
+
const args = process.argv.slice(2);
|
|
90
|
+
let projectName = args[0];
|
|
91
|
+
let answer = null;
|
|
92
|
+
if (projectName) {
|
|
93
|
+
let useBackendOnly = args.includes("--backend-only");
|
|
94
|
+
let useSwaggerDocs = args.includes("--swagger-docs");
|
|
95
|
+
let useTailwind = args.includes("--tailwindcss");
|
|
96
|
+
let useWebsocket = args.includes("--websocket");
|
|
97
|
+
let usePrisma = args.includes("--prisma");
|
|
98
|
+
let useDocker = args.includes("--docker");
|
|
99
|
+
const predefinedAnswers = {
|
|
100
|
+
projectName,
|
|
101
|
+
backendOnly: useBackendOnly,
|
|
102
|
+
swaggerDocs: useSwaggerDocs,
|
|
103
|
+
tailwindcss: useTailwind,
|
|
104
|
+
websocket: useWebsocket,
|
|
105
|
+
prisma: usePrisma,
|
|
106
|
+
docker: useDocker,
|
|
107
|
+
};
|
|
108
|
+
answer = await getAnswer(predefinedAnswers);
|
|
109
|
+
if (answer === null) {
|
|
110
|
+
console.log(chalk.red("Installation cancelled."));
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const currentDir = process.cwd();
|
|
114
|
+
const configPath = path.join(currentDir, "prisma-php.json");
|
|
115
|
+
if (fs.existsSync(configPath)) {
|
|
116
|
+
const localSettings = readJsonFile(configPath);
|
|
117
|
+
let excludeFiles = [];
|
|
118
|
+
localSettings.excludeFiles?.map((file) => {
|
|
119
|
+
const filePath = path.join(currentDir, file);
|
|
120
|
+
if (fs.existsSync(filePath))
|
|
121
|
+
excludeFiles.push(filePath.replace(/\\/g, "/"));
|
|
122
|
+
});
|
|
123
|
+
updateAnswer = {
|
|
124
|
+
projectName,
|
|
125
|
+
backendOnly: answer?.backendOnly ?? false,
|
|
126
|
+
swaggerDocs: answer?.swaggerDocs ?? false,
|
|
127
|
+
tailwindcss: answer?.tailwindcss ?? false,
|
|
128
|
+
websocket: answer?.websocket ?? false,
|
|
129
|
+
prisma: answer?.prisma ?? false,
|
|
130
|
+
docker: answer?.docker ?? false,
|
|
131
|
+
isUpdate: true,
|
|
132
|
+
excludeFiles: localSettings.excludeFiles ?? [],
|
|
133
|
+
excludeFilePath: excludeFiles ?? [],
|
|
134
|
+
filePath: currentDir,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
253
137
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
execSync(
|
|
257
|
-
`git clone https://github.com/TheSteelNinjaCode/prisma-php-swagger-docs.git ${swaggerDocsPath}`,
|
|
258
|
-
{ stdio: "inherit" }
|
|
259
|
-
);
|
|
260
|
-
// delete the folder .git
|
|
261
|
-
fs.rmSync(path.join(swaggerDocsPath, ".git"), {
|
|
262
|
-
recursive: true,
|
|
263
|
-
force: true,
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
if (updateAnswer?.isUpdate) {
|
|
267
|
-
const updateUninstallNpmDependencies = [];
|
|
268
|
-
const updateUninstallComposerDependencies = [];
|
|
269
|
-
if (updateAnswer.backendOnly) {
|
|
270
|
-
nonBackendFiles.forEach((file) => {
|
|
271
|
-
const filePath = path.join(projectPath, "src", "app", file);
|
|
272
|
-
if (fs.existsSync(filePath)) {
|
|
273
|
-
fs.unlinkSync(filePath); // Delete each file if it exists
|
|
274
|
-
console.log(`${file} was deleted successfully.`);
|
|
275
|
-
} else {
|
|
276
|
-
console.log(`${file} does not exist.`);
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
const backendOnlyFolders = ["js", "css"];
|
|
280
|
-
backendOnlyFolders.forEach((folder) => {
|
|
281
|
-
const folderPath = path.join(projectPath, "src", "app", folder);
|
|
282
|
-
if (fs.existsSync(folderPath)) {
|
|
283
|
-
fs.rmSync(folderPath, { recursive: true, force: true }); // Use fs.rmSync instead of fs.rmdirSync
|
|
284
|
-
console.log(`${folder} was deleted successfully.`);
|
|
285
|
-
} else {
|
|
286
|
-
console.log(`${folder} does not exist.`);
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
if (!updateAnswer.swaggerDocs) {
|
|
291
|
-
const swaggerDocsFolder = path.join(
|
|
292
|
-
projectPath,
|
|
293
|
-
"src",
|
|
294
|
-
"app",
|
|
295
|
-
"swagger-docs"
|
|
296
|
-
);
|
|
297
|
-
if (fs.existsSync(swaggerDocsFolder)) {
|
|
298
|
-
fs.rmSync(swaggerDocsFolder, { recursive: true, force: true }); // Use fs.rmSync instead of fs.rmdirSync
|
|
299
|
-
console.log(`swagger-docs was deleted successfully.`);
|
|
138
|
+
else {
|
|
139
|
+
answer = await getAnswer();
|
|
300
140
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
if (fs.existsSync(filePath)) {
|
|
305
|
-
fs.unlinkSync(filePath); // Delete each file if it exists
|
|
306
|
-
console.log(`${file} was deleted successfully.`);
|
|
307
|
-
} else {
|
|
308
|
-
console.log(`${file} does not exist.`);
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
updateUninstallNpmDependencies.push(
|
|
312
|
-
"swagger-jsdoc",
|
|
313
|
-
"@types/swagger-jsdoc",
|
|
314
|
-
"prompts",
|
|
315
|
-
"@types/prompts"
|
|
316
|
-
);
|
|
317
|
-
}
|
|
318
|
-
if (!updateAnswer.tailwindcss) {
|
|
319
|
-
const tailwindFiles = ["postcss.config.js"];
|
|
320
|
-
tailwindFiles.forEach((file) => {
|
|
321
|
-
const filePath = path.join(projectPath, file);
|
|
322
|
-
if (fs.existsSync(filePath)) {
|
|
323
|
-
fs.unlinkSync(filePath); // Delete each file if it exists
|
|
324
|
-
console.log(`${file} was deleted successfully.`);
|
|
325
|
-
} else {
|
|
326
|
-
console.log(`${file} does not exist.`);
|
|
327
|
-
}
|
|
328
|
-
});
|
|
329
|
-
updateUninstallNpmDependencies.push(
|
|
330
|
-
"tailwindcss",
|
|
331
|
-
"postcss",
|
|
332
|
-
"postcss-cli",
|
|
333
|
-
"@tailwindcss/postcss",
|
|
334
|
-
"cssnano"
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
|
-
if (!updateAnswer.websocket) {
|
|
338
|
-
const websocketFiles = [
|
|
339
|
-
"restart-websocket.ts",
|
|
340
|
-
"restart-websocket.bat",
|
|
341
|
-
];
|
|
342
|
-
websocketFiles.forEach((file) => {
|
|
343
|
-
const filePath = path.join(projectPath, "settings", file);
|
|
344
|
-
if (fs.existsSync(filePath)) {
|
|
345
|
-
fs.unlinkSync(filePath); // Delete each file if it exists
|
|
346
|
-
console.log(`${file} was deleted successfully.`);
|
|
347
|
-
} else {
|
|
348
|
-
console.log(`${file} does not exist.`);
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
const websocketFolder = path.join(projectPath, "src", "Websocket");
|
|
352
|
-
if (fs.existsSync(websocketFolder)) {
|
|
353
|
-
fs.rmSync(websocketFolder, { recursive: true, force: true }); // Use fs.rmSync instead of fs.rmdirSync
|
|
354
|
-
console.log(`Websocket folder was deleted successfully.`);
|
|
141
|
+
if (answer === null) {
|
|
142
|
+
console.warn(chalk.red("Installation cancelled."));
|
|
143
|
+
return;
|
|
355
144
|
}
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
145
|
+
const latestVersionOfCreatePrismaPhpApp = await fetchPackageVersion("create-prisma-php-app");
|
|
146
|
+
const isCreatePrismaPhpAppInstalled = getInstalledPackageVersion("create-prisma-php-app");
|
|
147
|
+
if (isCreatePrismaPhpAppInstalled) {
|
|
148
|
+
if (compareVersions(isCreatePrismaPhpAppInstalled, latestVersionOfCreatePrismaPhpApp) === -1) {
|
|
149
|
+
execSync("npm uninstall -g create-prisma-php-app", {
|
|
150
|
+
stdio: "inherit",
|
|
151
|
+
});
|
|
152
|
+
execSync("npm install -g create-prisma-php-app", {
|
|
153
|
+
stdio: "inherit",
|
|
154
|
+
});
|
|
155
|
+
}
|
|
363
156
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
157
|
+
else {
|
|
158
|
+
execSync("npm install -g create-prisma-php-app", { stdio: "inherit" });
|
|
159
|
+
}
|
|
160
|
+
// Create the project directory
|
|
161
|
+
if (!projectName)
|
|
162
|
+
fs.mkdirSync(answer.projectName);
|
|
163
|
+
const currentDir = process.cwd();
|
|
164
|
+
let projectPath = projectName
|
|
165
|
+
? currentDir
|
|
166
|
+
: path.join(currentDir, answer.projectName);
|
|
167
|
+
if (!projectName)
|
|
168
|
+
process.chdir(answer.projectName);
|
|
169
|
+
let npmDependencies = [
|
|
170
|
+
npmPkg("typescript"),
|
|
171
|
+
npmPkg("@types/node"),
|
|
172
|
+
npmPkg("tsx"),
|
|
173
|
+
npmPkg("http-proxy-middleware"),
|
|
174
|
+
npmPkg("chalk"),
|
|
175
|
+
npmPkg("npm-run-all"),
|
|
176
|
+
npmPkg("browser-sync"),
|
|
177
|
+
npmPkg("@types/browser-sync"),
|
|
178
|
+
npmPkg("php-parser"),
|
|
380
179
|
];
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
);
|
|
397
|
-
}
|
|
398
|
-
if (updateUninstallComposerDependencies.length > 0) {
|
|
399
|
-
await uninstallComposerDependencies(
|
|
400
|
-
projectPath,
|
|
401
|
-
updateUninstallComposerDependencies
|
|
402
|
-
);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
const projectPathModified = projectPath.replace(/\\/g, "\\");
|
|
406
|
-
const bsConfig = bsConfigUrls(projectPathModified);
|
|
407
|
-
const prismaPhpConfig = {
|
|
408
|
-
projectName: answer.projectName,
|
|
409
|
-
projectRootPath: projectPathModified,
|
|
410
|
-
phpEnvironment: "XAMPP",
|
|
411
|
-
phpRootPathExe: "C:\\xampp\\php\\php.exe",
|
|
412
|
-
bsTarget: bsConfig.bsTarget,
|
|
413
|
-
bsPathRewrite: bsConfig.bsPathRewrite,
|
|
414
|
-
backendOnly: answer.backendOnly,
|
|
415
|
-
swaggerDocs: answer.swaggerDocs,
|
|
416
|
-
tailwindcss: answer.tailwindcss,
|
|
417
|
-
websocket: answer.websocket,
|
|
418
|
-
prisma: answer.prisma,
|
|
419
|
-
docker: answer.docker,
|
|
420
|
-
version: latestVersionOfCreatePrismaPhpApp,
|
|
421
|
-
excludeFiles: updateAnswer?.excludeFiles ?? [],
|
|
422
|
-
};
|
|
423
|
-
fs.writeFileSync(
|
|
424
|
-
path.join(projectPath, "prisma-php.json"),
|
|
425
|
-
JSON.stringify(prismaPhpConfig, null, 2),
|
|
426
|
-
{ flag: "w" }
|
|
427
|
-
);
|
|
428
|
-
if (updateAnswer?.isUpdate) {
|
|
429
|
-
execSync(
|
|
430
|
-
"C:\\xampp\\php\\php.exe C:\\ProgramData\\ComposerSetup\\bin\\composer.phar update",
|
|
431
|
-
{
|
|
432
|
-
stdio: "inherit",
|
|
180
|
+
let composerDependencies = [
|
|
181
|
+
composerPkg("vlucas/phpdotenv"),
|
|
182
|
+
composerPkg("firebase/php-jwt"),
|
|
183
|
+
composerPkg("phpmailer/phpmailer"),
|
|
184
|
+
composerPkg("guzzlehttp/guzzle"),
|
|
185
|
+
composerPkg("ezyang/htmlpurifier"),
|
|
186
|
+
composerPkg("symfony/uid"),
|
|
187
|
+
composerPkg("brick/math"),
|
|
188
|
+
composerPkg("tsnc/prisma-php"),
|
|
189
|
+
];
|
|
190
|
+
if (answer.swaggerDocs) {
|
|
191
|
+
npmDependencies.push(npmPkg("swagger-jsdoc"), npmPkg("@types/swagger-jsdoc"));
|
|
192
|
+
}
|
|
193
|
+
if (answer.swaggerDocs && answer.prisma) {
|
|
194
|
+
npmDependencies.push(npmPkg("prompts"), npmPkg("@types/prompts"));
|
|
433
195
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
execSync(
|
|
437
|
-
"C:\\xampp\\php\\php.exe C:\\ProgramData\\ComposerSetup\\bin\\composer.phar install",
|
|
438
|
-
{
|
|
439
|
-
stdio: "inherit",
|
|
196
|
+
if (answer.tailwindcss) {
|
|
197
|
+
npmDependencies.push(npmPkg("tailwindcss"), npmPkg("postcss"), npmPkg("postcss-cli"), npmPkg("@tailwindcss/postcss"), npmPkg("cssnano"));
|
|
440
198
|
}
|
|
441
|
-
|
|
199
|
+
if (answer.websocket) {
|
|
200
|
+
npmDependencies.push(npmPkg("chokidar-cli"));
|
|
201
|
+
composerDependencies.push("cboden/ratchet");
|
|
202
|
+
}
|
|
203
|
+
if (answer.prisma) {
|
|
204
|
+
execSync("npm install -g prisma-client-php", { stdio: "inherit" });
|
|
205
|
+
}
|
|
206
|
+
await installNpmDependencies(projectPath, npmDependencies, true);
|
|
207
|
+
await installComposerDependencies(projectPath, composerDependencies);
|
|
208
|
+
if (!projectName) {
|
|
209
|
+
execSync("npx tsc --init", { stdio: "inherit" });
|
|
210
|
+
}
|
|
211
|
+
await createDirectoryStructure(projectPath, answer);
|
|
212
|
+
if (answer.prisma) {
|
|
213
|
+
execSync("npx ppo init --prisma-php", { stdio: "inherit" });
|
|
214
|
+
}
|
|
215
|
+
if (answer.swaggerDocs) {
|
|
216
|
+
const swaggerDocsPath = path.join(projectPath, "src", "app", "swagger-docs");
|
|
217
|
+
// Check if the directory exists
|
|
218
|
+
if (fs.existsSync(swaggerDocsPath)) {
|
|
219
|
+
// If it exists and is not empty, remove it before cloning
|
|
220
|
+
if (fs.readdirSync(swaggerDocsPath).length > 0) {
|
|
221
|
+
console.log("Removing existing swagger-docs directory...");
|
|
222
|
+
fs.rmSync(swaggerDocsPath, { recursive: true, force: true });
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// Clone the Git repository into the swagger-docs directory
|
|
226
|
+
execSync(`git clone https://github.com/TheSteelNinjaCode/prisma-php-swagger-docs.git ${swaggerDocsPath}`, { stdio: "inherit" });
|
|
227
|
+
// delete the folder .git
|
|
228
|
+
fs.rmSync(path.join(swaggerDocsPath, ".git"), {
|
|
229
|
+
recursive: true,
|
|
230
|
+
force: true,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
if (updateAnswer?.isUpdate) {
|
|
234
|
+
const updateUninstallNpmDependencies = [];
|
|
235
|
+
const updateUninstallComposerDependencies = [];
|
|
236
|
+
if (updateAnswer.backendOnly) {
|
|
237
|
+
nonBackendFiles.forEach((file) => {
|
|
238
|
+
const filePath = path.join(projectPath, "src", "app", file);
|
|
239
|
+
if (fs.existsSync(filePath)) {
|
|
240
|
+
fs.unlinkSync(filePath); // Delete each file if it exists
|
|
241
|
+
console.log(`${file} was deleted successfully.`);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
console.log(`${file} does not exist.`);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
const backendOnlyFolders = ["js", "css"];
|
|
248
|
+
backendOnlyFolders.forEach((folder) => {
|
|
249
|
+
const folderPath = path.join(projectPath, "src", "app", folder);
|
|
250
|
+
if (fs.existsSync(folderPath)) {
|
|
251
|
+
fs.rmSync(folderPath, { recursive: true, force: true }); // Use fs.rmSync instead of fs.rmdirSync
|
|
252
|
+
console.log(`${folder} was deleted successfully.`);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
console.log(`${folder} does not exist.`);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
if (!updateAnswer.swaggerDocs) {
|
|
260
|
+
const swaggerDocsFolder = path.join(projectPath, "src", "app", "swagger-docs");
|
|
261
|
+
if (fs.existsSync(swaggerDocsFolder)) {
|
|
262
|
+
fs.rmSync(swaggerDocsFolder, { recursive: true, force: true }); // Use fs.rmSync instead of fs.rmdirSync
|
|
263
|
+
console.log(`swagger-docs was deleted successfully.`);
|
|
264
|
+
}
|
|
265
|
+
const swaggerFiles = ["swagger-config.ts"];
|
|
266
|
+
swaggerFiles.forEach((file) => {
|
|
267
|
+
const filePath = path.join(projectPath, "settings", file);
|
|
268
|
+
if (fs.existsSync(filePath)) {
|
|
269
|
+
fs.unlinkSync(filePath); // Delete each file if it exists
|
|
270
|
+
console.log(`${file} was deleted successfully.`);
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
console.log(`${file} does not exist.`);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
updateUninstallNpmDependencies.push("swagger-jsdoc", "@types/swagger-jsdoc", "prompts", "@types/prompts");
|
|
277
|
+
}
|
|
278
|
+
if (!updateAnswer.tailwindcss) {
|
|
279
|
+
const tailwindFiles = ["postcss.config.js"];
|
|
280
|
+
tailwindFiles.forEach((file) => {
|
|
281
|
+
const filePath = path.join(projectPath, file);
|
|
282
|
+
if (fs.existsSync(filePath)) {
|
|
283
|
+
fs.unlinkSync(filePath); // Delete each file if it exists
|
|
284
|
+
console.log(`${file} was deleted successfully.`);
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
console.log(`${file} does not exist.`);
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
updateUninstallNpmDependencies.push("tailwindcss", "postcss", "postcss-cli", "@tailwindcss/postcss", "cssnano");
|
|
291
|
+
}
|
|
292
|
+
if (!updateAnswer.websocket) {
|
|
293
|
+
const websocketFiles = [
|
|
294
|
+
"restart-websocket.ts",
|
|
295
|
+
"restart-websocket.bat",
|
|
296
|
+
];
|
|
297
|
+
websocketFiles.forEach((file) => {
|
|
298
|
+
const filePath = path.join(projectPath, "settings", file);
|
|
299
|
+
if (fs.existsSync(filePath)) {
|
|
300
|
+
fs.unlinkSync(filePath); // Delete each file if it exists
|
|
301
|
+
console.log(`${file} was deleted successfully.`);
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
console.log(`${file} does not exist.`);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
const websocketFolder = path.join(projectPath, "src", "Websocket");
|
|
308
|
+
if (fs.existsSync(websocketFolder)) {
|
|
309
|
+
fs.rmSync(websocketFolder, { recursive: true, force: true }); // Use fs.rmSync instead of fs.rmdirSync
|
|
310
|
+
console.log(`Websocket folder was deleted successfully.`);
|
|
311
|
+
}
|
|
312
|
+
const websocketServerFile = path.join(projectPath, "websocket-server.php");
|
|
313
|
+
if (fs.existsSync(websocketServerFile)) {
|
|
314
|
+
fs.unlinkSync(websocketServerFile); // Delete the file if it exists
|
|
315
|
+
console.log(`websocket-server.php was deleted successfully.`);
|
|
316
|
+
}
|
|
317
|
+
updateUninstallNpmDependencies.push("chokidar-cli");
|
|
318
|
+
updateUninstallComposerDependencies.push("cboden/ratchet");
|
|
319
|
+
}
|
|
320
|
+
if (!updateAnswer.prisma) {
|
|
321
|
+
updateUninstallNpmDependencies.push("prisma", "@prisma/client", "@prisma/internals");
|
|
322
|
+
}
|
|
323
|
+
if (!updateAnswer.docker) {
|
|
324
|
+
const dockerFiles = [
|
|
325
|
+
".dockerignore",
|
|
326
|
+
"docker-compose.yml",
|
|
327
|
+
"Dockerfile",
|
|
328
|
+
"apache.conf",
|
|
329
|
+
];
|
|
330
|
+
dockerFiles.forEach((file) => {
|
|
331
|
+
const filePath = path.join(projectPath, file);
|
|
332
|
+
if (fs.existsSync(filePath)) {
|
|
333
|
+
fs.unlinkSync(filePath); // Delete each file if it exists
|
|
334
|
+
console.log(`${file} was deleted successfully.`);
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
console.log(`${file} does not exist.`);
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
if (updateUninstallNpmDependencies.length > 0) {
|
|
342
|
+
await uninstallNpmDependencies(projectPath, updateUninstallNpmDependencies, true);
|
|
343
|
+
}
|
|
344
|
+
if (updateUninstallComposerDependencies.length > 0) {
|
|
345
|
+
await uninstallComposerDependencies(projectPath, updateUninstallComposerDependencies);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
const projectPathModified = projectPath.replace(/\\/g, "\\");
|
|
349
|
+
const bsConfig = bsConfigUrls(projectPathModified);
|
|
350
|
+
const prismaPhpConfig = {
|
|
351
|
+
projectName: answer.projectName,
|
|
352
|
+
projectRootPath: projectPathModified,
|
|
353
|
+
phpEnvironment: "XAMPP",
|
|
354
|
+
phpRootPathExe: "C:\\xampp\\php\\php.exe",
|
|
355
|
+
bsTarget: bsConfig.bsTarget,
|
|
356
|
+
bsPathRewrite: bsConfig.bsPathRewrite,
|
|
357
|
+
backendOnly: answer.backendOnly,
|
|
358
|
+
swaggerDocs: answer.swaggerDocs,
|
|
359
|
+
tailwindcss: answer.tailwindcss,
|
|
360
|
+
websocket: answer.websocket,
|
|
361
|
+
prisma: answer.prisma,
|
|
362
|
+
docker: answer.docker,
|
|
363
|
+
version: latestVersionOfCreatePrismaPhpApp,
|
|
364
|
+
excludeFiles: updateAnswer?.excludeFiles ?? [],
|
|
365
|
+
};
|
|
366
|
+
fs.writeFileSync(path.join(projectPath, "prisma-php.json"), JSON.stringify(prismaPhpConfig, null, 2), { flag: "w" });
|
|
367
|
+
if (updateAnswer?.isUpdate) {
|
|
368
|
+
execSync("C:\\xampp\\php\\php.exe C:\\ProgramData\\ComposerSetup\\bin\\composer.phar update", {
|
|
369
|
+
stdio: "inherit",
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
execSync("C:\\xampp\\php\\php.exe C:\\ProgramData\\ComposerSetup\\bin\\composer.phar install", {
|
|
374
|
+
stdio: "inherit",
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
console.log("\n=========================\n");
|
|
378
|
+
console.log(`${chalk.green("Success!")} Prisma PHP project successfully created in ${chalk.green(`${currentDir.replace(/\\/g, "/")}/${answer.projectName}`)}!`);
|
|
379
|
+
console.log("\n=========================");
|
|
380
|
+
}
|
|
381
|
+
catch (error) {
|
|
382
|
+
console.error("Error while creating the project:", error);
|
|
383
|
+
process.exit(1);
|
|
442
384
|
}
|
|
443
|
-
console.log("\n=========================\n");
|
|
444
|
-
console.log(
|
|
445
|
-
`${chalk.green(
|
|
446
|
-
"Success!"
|
|
447
|
-
)} Prisma PHP project successfully created in ${chalk.green(
|
|
448
|
-
`${currentDir.replace(/\\/g, "/")}/${answer.projectName}`
|
|
449
|
-
)}!`
|
|
450
|
-
);
|
|
451
|
-
console.log("\n=========================");
|
|
452
|
-
} catch (error) {
|
|
453
|
-
console.error("Error while creating the project:", error);
|
|
454
|
-
process.exit(1);
|
|
455
|
-
}
|
|
456
385
|
}
|
|
457
386
|
main();
|