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