create-prisma-php-app 4.0.0-alpha.47 → 4.0.0-alpha.48

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.
Files changed (2) hide show
  1. package/dist/index.js +165 -198
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1023,116 +1023,6 @@ function composerPkg(name) {
1023
1023
  ? `${name}:${composerPinnedVersions[name]}`
1024
1024
  : name;
1025
1025
  }
1026
- async function downloadStarterKit(starterKit, tempDir) {
1027
- if (!starterKit.source) {
1028
- throw new Error("No source defined for starter kit");
1029
- }
1030
- const { type, url, branch = "main", subfolder } = starterKit.source;
1031
- switch (type) {
1032
- case "git":
1033
- console.log(chalk.blue(`Cloning ${starterKit.name} from ${url}...`));
1034
- const cloneCommand = branch
1035
- ? `git clone -b ${branch} --depth 1 ${url} ${tempDir}`
1036
- : `git clone --depth 1 ${url} ${tempDir}`;
1037
- execSync(cloneCommand, { stdio: "inherit" });
1038
- // Remove .git directory
1039
- const gitDir = path.join(tempDir, ".git");
1040
- if (fs.existsSync(gitDir)) {
1041
- fs.rmSync(gitDir, { recursive: true, force: true });
1042
- }
1043
- // Return the subfolder if specified
1044
- return subfolder ? path.join(tempDir, subfolder) : tempDir;
1045
- case "npm":
1046
- console.log(chalk.blue(`Downloading ${starterKit.name} from npm...`));
1047
- execSync(`npm pack ${url}`, { cwd: tempDir, stdio: "inherit" });
1048
- // Extract the tarball
1049
- const tarball = fs.readdirSync(tempDir).find((f) => f.endsWith(".tgz"));
1050
- if (tarball) {
1051
- execSync(`tar -xzf ${tarball}`, { cwd: tempDir });
1052
- fs.unlinkSync(path.join(tempDir, tarball));
1053
- return path.join(tempDir, "package");
1054
- }
1055
- throw new Error("Failed to extract npm package");
1056
- case "url":
1057
- throw new Error("URL download not implemented yet");
1058
- default:
1059
- throw new Error(`Unsupported source type: ${type}`);
1060
- }
1061
- }
1062
- async function mergeStarterKitFiles(starterKitPath, projectPath, answer) {
1063
- console.log(chalk.blue("Merging starter kit files..."));
1064
- // First, check if starter kit has a prisma-php.json to preserve excludeFiles
1065
- const starterKitConfigPath = path.join(starterKitPath, "prisma-php.json");
1066
- let starterKitExcludeFiles = [];
1067
- if (fs.existsSync(starterKitConfigPath)) {
1068
- try {
1069
- const starterKitConfig = JSON.parse(
1070
- fs.readFileSync(starterKitConfigPath, "utf8")
1071
- );
1072
- starterKitExcludeFiles = starterKitConfig.excludeFiles || [];
1073
- console.log(
1074
- chalk.blue(
1075
- `Found ${starterKitExcludeFiles.length} excluded files in starter kit`
1076
- )
1077
- );
1078
- } catch (error) {
1079
- console.warn(chalk.yellow("Failed to parse starter kit prisma-php.json"));
1080
- }
1081
- }
1082
- // Temporarily store excludeFiles for the copy process
1083
- const tempUpdateAnswer = updateAnswer;
1084
- updateAnswer = {
1085
- ...answer,
1086
- isUpdate: false, // Treat as new project for copying
1087
- excludeFiles: starterKitExcludeFiles,
1088
- excludeFilePath: starterKitExcludeFiles.map((file) =>
1089
- path.join(projectPath, file).replace(/\\/g, "/")
1090
- ),
1091
- };
1092
- // Copy all files from starter kit
1093
- copyRecursiveSync(starterKitPath, projectPath, answer);
1094
- // Restore original updateAnswer
1095
- updateAnswer = tempUpdateAnswer;
1096
- // Handle starter kit specific configuration
1097
- const starterKitConfig = path.join(starterKitPath, "starter-kit.json");
1098
- if (fs.existsSync(starterKitConfig)) {
1099
- const config = JSON.parse(fs.readFileSync(starterKitConfig, "utf8"));
1100
- // Handle post-install scripts
1101
- if (config.postInstall) {
1102
- console.log(chalk.blue("Running post-install scripts..."));
1103
- for (const script of config.postInstall) {
1104
- console.log(chalk.gray(`Running: ${script}`));
1105
- execSync(script, { cwd: projectPath, stdio: "inherit" });
1106
- }
1107
- }
1108
- // Handle additional dependencies
1109
- if (config.additionalNpmDependencies) {
1110
- await installNpmDependencies(
1111
- projectPath,
1112
- config.additionalNpmDependencies.map(npmPkg),
1113
- true
1114
- );
1115
- }
1116
- if (config.additionalComposerDependencies) {
1117
- await installComposerDependencies(
1118
- projectPath,
1119
- config.additionalComposerDependencies.map(composerPkg)
1120
- );
1121
- }
1122
- }
1123
- // Store the excludeFiles for later use in main()
1124
- if (starterKitExcludeFiles.length > 0) {
1125
- // Create a temporary marker file to pass excludeFiles to main()
1126
- const tempConfigPath = path.join(
1127
- projectPath,
1128
- ".temp-starter-kit-config.json"
1129
- );
1130
- fs.writeFileSync(
1131
- tempConfigPath,
1132
- JSON.stringify({ excludeFiles: starterKitExcludeFiles })
1133
- );
1134
- }
1135
- }
1136
1026
  async function setupStarterKit(baseDir, answer) {
1137
1027
  if (!answer.starterKit) return;
1138
1028
  let starterKit = null;
@@ -1161,35 +1051,53 @@ async function setupStarterKit(baseDir, answer) {
1161
1051
  return;
1162
1052
  }
1163
1053
  console.log(chalk.green(`Setting up ${starterKit.name}...`));
1164
- // If it's a custom starter kit with source, download it
1054
+ // If it's a custom starter kit with source, clone it directly to the target directory
1165
1055
  if (starterKit.source) {
1166
- const tempDir = path.join(baseDir, ".temp-starter-kit");
1167
1056
  try {
1168
- // Create temp directory
1169
- if (fs.existsSync(tempDir)) {
1170
- fs.rmSync(tempDir, { recursive: true, force: true });
1057
+ // Clone directly to the target directory
1058
+ const cloneCommand = starterKit.source.branch
1059
+ ? `git clone -b ${starterKit.source.branch} --depth 1 ${starterKit.source.url} ${baseDir}`
1060
+ : `git clone --depth 1 ${starterKit.source.url} ${baseDir}`;
1061
+ execSync(cloneCommand, { stdio: "inherit" });
1062
+ // Remove .git directory
1063
+ const gitDir = path.join(baseDir, ".git");
1064
+ if (fs.existsSync(gitDir)) {
1065
+ fs.rmSync(gitDir, { recursive: true, force: true });
1171
1066
  }
1172
- fs.mkdirSync(tempDir, { recursive: true });
1173
- // Download the starter kit
1174
- const kitPath = await downloadStarterKit(starterKit, tempDir);
1175
- // Merge files from starter kit
1176
- await mergeStarterKitFiles(kitPath, baseDir, answer);
1177
- // Check if starter kit has its own configuration
1178
- const kitConfigPath = path.join(kitPath, "prisma-php-starter.json");
1179
- if (fs.existsSync(kitConfigPath)) {
1180
- const kitConfig = JSON.parse(fs.readFileSync(kitConfigPath, "utf8"));
1181
- // Override features with starter kit configuration
1182
- Object.assign(answer, kitConfig.features || {});
1183
- console.log(chalk.green(`Applied starter kit configuration`));
1067
+ console.log(chalk.blue("Starter kit cloned successfully!"));
1068
+ // Update the project name in the existing prisma-php.json
1069
+ const configPath = path.join(baseDir, "prisma-php.json");
1070
+ if (fs.existsSync(configPath)) {
1071
+ try {
1072
+ const existingConfig = JSON.parse(
1073
+ fs.readFileSync(configPath, "utf8")
1074
+ );
1075
+ // Only update project-specific fields, preserve everything else
1076
+ const projectPathModified = baseDir.replace(/\\/g, "\\");
1077
+ const bsConfig = bsConfigUrls(projectPathModified);
1078
+ existingConfig.projectName = answer.projectName;
1079
+ existingConfig.projectRootPath = projectPathModified;
1080
+ existingConfig.bsTarget = bsConfig.bsTarget;
1081
+ existingConfig.bsPathRewrite = bsConfig.bsPathRewrite;
1082
+ // Update version to latest
1083
+ const latestVersion = await fetchPackageVersion(
1084
+ "create-prisma-php-app"
1085
+ );
1086
+ existingConfig.version = latestVersion;
1087
+ fs.writeFileSync(configPath, JSON.stringify(existingConfig, null, 2));
1088
+ console.log(
1089
+ chalk.green("Updated prisma-php.json with new project details")
1090
+ );
1091
+ } catch (error) {
1092
+ console.warn(
1093
+ chalk.yellow(
1094
+ "Failed to update prisma-php.json, will create new one"
1095
+ )
1096
+ );
1097
+ }
1184
1098
  }
1185
- // Clean up temp directory
1186
- fs.rmSync(tempDir, { recursive: true, force: true });
1187
1099
  } catch (error) {
1188
1100
  console.error(chalk.red(`Failed to setup starter kit: ${error}`));
1189
- // Clean up temp directory on error
1190
- if (fs.existsSync(tempDir)) {
1191
- fs.rmSync(tempDir, { recursive: true, force: true });
1192
- }
1193
1101
  throw error;
1194
1102
  }
1195
1103
  }
@@ -1243,10 +1151,27 @@ async function main() {
1243
1151
  return;
1244
1152
  }
1245
1153
  let answer = null;
1154
+ let isStarterKitProject = false;
1246
1155
  if (projectName) {
1247
1156
  const currentDir = process.cwd();
1248
1157
  const configPath = path.join(currentDir, "prisma-php.json");
1249
- if (fs.existsSync(configPath)) {
1158
+ // Check if it's a starter kit project
1159
+ if (starterKitFromArgs && starterKitSource) {
1160
+ isStarterKitProject = true;
1161
+ const predefinedAnswers = {
1162
+ projectName,
1163
+ starterKit: starterKitFromArgs,
1164
+ starterKitSource: starterKitSource,
1165
+ backendOnly: args.includes("--backend-only"),
1166
+ swaggerDocs: args.includes("--swagger-docs"),
1167
+ tailwindcss: args.includes("--tailwindcss"),
1168
+ websocket: args.includes("--websocket"),
1169
+ mcp: args.includes("--mcp"),
1170
+ prisma: args.includes("--prisma"),
1171
+ docker: args.includes("--docker"),
1172
+ };
1173
+ answer = await getAnswer(predefinedAnswers);
1174
+ } else if (fs.existsSync(configPath)) {
1250
1175
  // It's an update - read existing settings
1251
1176
  const localSettings = readJsonFile(configPath);
1252
1177
  let excludeFiles = [];
@@ -1357,33 +1282,86 @@ async function main() {
1357
1282
  const currentDir = process.cwd();
1358
1283
  let projectPath;
1359
1284
  if (projectName) {
1360
- // Check if we're in an existing project (has prisma-php.json) or creating a new one
1361
- const configPath = path.join(currentDir, "prisma-php.json");
1362
- const projectNamePath = path.join(currentDir, projectName);
1363
- const projectNameConfigPath = path.join(
1364
- projectNamePath,
1365
- "prisma-php.json"
1366
- );
1367
- if (fs.existsSync(configPath)) {
1368
- // We're updating an existing project in current directory
1369
- projectPath = currentDir;
1370
- } else if (
1371
- fs.existsSync(projectNamePath) &&
1372
- fs.existsSync(projectNameConfigPath)
1373
- ) {
1374
- // We're updating an existing project in the named directory
1375
- projectPath = projectNamePath;
1376
- process.chdir(projectNamePath);
1377
- } else {
1378
- // We're creating a new project with the given name
1285
+ if (isStarterKitProject) {
1286
+ // For starter kit projects, create directory first
1287
+ const projectNamePath = path.join(currentDir, projectName);
1379
1288
  if (!fs.existsSync(projectNamePath)) {
1380
1289
  fs.mkdirSync(projectNamePath, { recursive: true });
1381
1290
  }
1382
1291
  projectPath = projectNamePath;
1383
- process.chdir(projectNamePath);
1292
+ // Clone the starter kit first
1293
+ await setupStarterKit(projectPath, answer);
1294
+ // Change to project directory
1295
+ process.chdir(projectPath);
1296
+ // Now check if it has prisma-php.json and treat as update
1297
+ const configPath = path.join(projectPath, "prisma-php.json");
1298
+ if (fs.existsSync(configPath)) {
1299
+ // Read the existing config and merge with CLI overrides
1300
+ const existingConfig = JSON.parse(
1301
+ fs.readFileSync(configPath, "utf8")
1302
+ );
1303
+ // Override with CLI arguments if provided
1304
+ if (args.includes("--backend-only"))
1305
+ existingConfig.backendOnly = true;
1306
+ if (args.includes("--swagger-docs"))
1307
+ existingConfig.swaggerDocs = true;
1308
+ if (args.includes("--tailwindcss")) existingConfig.tailwindcss = true;
1309
+ if (args.includes("--websocket")) existingConfig.websocket = true;
1310
+ if (args.includes("--mcp")) existingConfig.mcp = true;
1311
+ if (args.includes("--prisma")) existingConfig.prisma = true;
1312
+ if (args.includes("--docker")) existingConfig.docker = true;
1313
+ // Update answer with existing config
1314
+ answer = {
1315
+ ...answer,
1316
+ backendOnly: existingConfig.backendOnly,
1317
+ swaggerDocs: existingConfig.swaggerDocs,
1318
+ tailwindcss: existingConfig.tailwindcss,
1319
+ websocket: existingConfig.websocket,
1320
+ mcp: existingConfig.mcp,
1321
+ prisma: existingConfig.prisma,
1322
+ docker: existingConfig.docker,
1323
+ };
1324
+ // Set up as an update
1325
+ let excludeFiles = [];
1326
+ existingConfig.excludeFiles?.map((file) => {
1327
+ const filePath = path.join(projectPath, file);
1328
+ if (fs.existsSync(filePath))
1329
+ excludeFiles.push(filePath.replace(/\\/g, "/"));
1330
+ });
1331
+ updateAnswer = {
1332
+ ...answer,
1333
+ isUpdate: true,
1334
+ excludeFiles: existingConfig.excludeFiles ?? [],
1335
+ excludeFilePath: excludeFiles ?? [],
1336
+ filePath: projectPath,
1337
+ };
1338
+ }
1339
+ } else {
1340
+ // Regular project handling (existing logic)
1341
+ const configPath = path.join(currentDir, "prisma-php.json");
1342
+ const projectNamePath = path.join(currentDir, projectName);
1343
+ const projectNameConfigPath = path.join(
1344
+ projectNamePath,
1345
+ "prisma-php.json"
1346
+ );
1347
+ if (fs.existsSync(configPath)) {
1348
+ projectPath = currentDir;
1349
+ } else if (
1350
+ fs.existsSync(projectNamePath) &&
1351
+ fs.existsSync(projectNameConfigPath)
1352
+ ) {
1353
+ projectPath = projectNamePath;
1354
+ process.chdir(projectNamePath);
1355
+ } else {
1356
+ if (!fs.existsSync(projectNamePath)) {
1357
+ fs.mkdirSync(projectNamePath, { recursive: true });
1358
+ }
1359
+ projectPath = projectNamePath;
1360
+ process.chdir(projectNamePath);
1361
+ }
1384
1362
  }
1385
1363
  } else {
1386
- // Interactive mode - create directory with answer.projectName
1364
+ // Interactive mode
1387
1365
  fs.mkdirSync(answer.projectName, { recursive: true });
1388
1366
  projectPath = path.join(currentDir, answer.projectName);
1389
1367
  process.chdir(answer.projectName);
@@ -1436,8 +1414,8 @@ async function main() {
1436
1414
  if (answer.prisma) {
1437
1415
  execSync("npm install -g prisma-client-php", { stdio: "inherit" });
1438
1416
  }
1439
- // Add starter kit setup before npm/composer installation
1440
- if (answer.starterKit) {
1417
+ // Only setup starter kit if it's not already done
1418
+ if (answer.starterKit && !isStarterKitProject) {
1441
1419
  await setupStarterKit(projectPath, answer);
1442
1420
  }
1443
1421
  await installNpmDependencies(projectPath, npmDependencies, true);
@@ -1673,48 +1651,37 @@ async function main() {
1673
1651
  await uninstallComposerDependencies(projectPath, composerToUninstall);
1674
1652
  }
1675
1653
  }
1676
- const projectPathModified = projectPath.replace(/\\/g, "\\");
1677
- const bsConfig = bsConfigUrls(projectPathModified);
1678
- let starterKitExcludeFiles = [];
1679
- const tempConfigPath = path.join(
1680
- projectPath,
1681
- ".temp-starter-kit-config.json"
1682
- );
1683
- if (fs.existsSync(tempConfigPath)) {
1684
- try {
1685
- const tempConfig = JSON.parse(fs.readFileSync(tempConfigPath, "utf8"));
1686
- starterKitExcludeFiles = tempConfig.excludeFiles || [];
1687
- fs.unlinkSync(tempConfigPath); // Clean up temp file
1688
- } catch (error) {
1689
- console.warn("Failed to read temp starter kit config");
1690
- }
1654
+ // Skip creating prismaPhpConfig if it's a starter kit project that already has one
1655
+ if (
1656
+ !isStarterKitProject ||
1657
+ !fs.existsSync(path.join(projectPath, "prisma-php.json"))
1658
+ ) {
1659
+ // Create prisma-php.json with all the existing logic
1660
+ const projectPathModified = projectPath.replace(/\\/g, "\\");
1661
+ const bsConfig = bsConfigUrls(projectPathModified);
1662
+ const prismaPhpConfig = {
1663
+ projectName: answer.projectName,
1664
+ projectRootPath: projectPathModified,
1665
+ phpEnvironment: "XAMPP",
1666
+ phpRootPathExe: "C:\\xampp\\php\\php.exe",
1667
+ bsTarget: bsConfig.bsTarget,
1668
+ bsPathRewrite: bsConfig.bsPathRewrite,
1669
+ backendOnly: answer.backendOnly,
1670
+ swaggerDocs: answer.swaggerDocs,
1671
+ tailwindcss: answer.tailwindcss,
1672
+ websocket: answer.websocket,
1673
+ mcp: answer.mcp,
1674
+ prisma: answer.prisma,
1675
+ docker: answer.docker,
1676
+ version: latestVersionOfCreatePrismaPhpApp,
1677
+ excludeFiles: updateAnswer?.excludeFiles ?? [],
1678
+ };
1679
+ fs.writeFileSync(
1680
+ path.join(projectPath, "prisma-php.json"),
1681
+ JSON.stringify(prismaPhpConfig, null, 2),
1682
+ { flag: "w" }
1683
+ );
1691
1684
  }
1692
- // Then update the prismaPhpConfig creation:
1693
- const prismaPhpConfig = {
1694
- projectName: answer.projectName,
1695
- projectRootPath: projectPathModified,
1696
- phpEnvironment: "XAMPP",
1697
- phpRootPathExe: "C:\\xampp\\php\\php.exe",
1698
- bsTarget: bsConfig.bsTarget,
1699
- bsPathRewrite: bsConfig.bsPathRewrite,
1700
- backendOnly: answer.backendOnly,
1701
- swaggerDocs: answer.swaggerDocs,
1702
- tailwindcss: answer.tailwindcss,
1703
- websocket: answer.websocket,
1704
- mcp: answer.mcp,
1705
- prisma: answer.prisma,
1706
- docker: answer.docker,
1707
- version: latestVersionOfCreatePrismaPhpApp,
1708
- excludeFiles:
1709
- starterKitExcludeFiles.length > 0
1710
- ? starterKitExcludeFiles
1711
- : updateAnswer?.excludeFiles ?? [],
1712
- };
1713
- fs.writeFileSync(
1714
- path.join(projectPath, "prisma-php.json"),
1715
- JSON.stringify(prismaPhpConfig, null, 2),
1716
- { flag: "w" }
1717
- );
1718
1685
  if (updateAnswer?.isUpdate) {
1719
1686
  execSync(
1720
1687
  "C:\\xampp\\php\\php.exe C:\\ProgramData\\ComposerSetup\\bin\\composer.phar update",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "4.0.0-alpha.47",
3
+ "version": "4.0.0-alpha.48",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",