create-prisma-php-app 4.0.0-alpha.40 → 4.0.0-alpha.45

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 CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  import { execSync, spawnSync } from "child_process";
3
3
  import fs from "fs";
4
4
  import { fileURLToPath } from "url";
@@ -1811,42 +1811,122 @@ async function main() {
1811
1811
  }
1812
1812
  // Check for existing config to merge with
1813
1813
  let existingConfig = null;
1814
- const currentDirConfigPath = path.join(process.cwd(), "prisma-php.json");
1815
1814
  const finalProjectConfigPath = path.join(projectPath, "prisma-php.json");
1816
- // First, check current directory (where command is run) for existing config
1817
- if (
1818
- fs.existsSync(currentDirConfigPath) &&
1819
- currentDirConfigPath !== finalProjectConfigPath
1820
- ) {
1821
- try {
1822
- const rawConfig = fs.readFileSync(currentDirConfigPath, "utf8");
1823
- existingConfig = JSON.parse(rawConfig);
1824
- console.log(
1825
- chalk.blue(
1826
- "Found existing configuration in current directory, using exclusions..."
1827
- )
1815
+ // Function to find prisma-php.json files with excludeFiles
1816
+ const findConfigWithExclusions = (searchDir, preferredProjectName) => {
1817
+ const entries = fs.readdirSync(searchDir, { withFileTypes: true });
1818
+ // First, try to find the preferred project directory
1819
+ if (preferredProjectName) {
1820
+ const preferredEntry = entries.find(
1821
+ (entry) =>
1822
+ entry.isDirectory() &&
1823
+ entry.name.toLowerCase() === preferredProjectName.toLowerCase()
1828
1824
  );
1825
+ if (preferredEntry) {
1826
+ const preferredConfigPath = path.join(
1827
+ searchDir,
1828
+ preferredEntry.name,
1829
+ "prisma-php.json"
1830
+ );
1831
+ if (fs.existsSync(preferredConfigPath)) {
1832
+ try {
1833
+ const config = JSON.parse(
1834
+ fs.readFileSync(preferredConfigPath, "utf8")
1835
+ );
1836
+ if (config.excludeFiles && config.excludeFiles.length > 0) {
1837
+ console.log(
1838
+ chalk.blue(
1839
+ `Found preferred configuration with exclusions in: ${preferredEntry.name}/`
1840
+ )
1841
+ );
1842
+ console.log(
1843
+ chalk.gray(
1844
+ `Preferred excludeFiles: ${JSON.stringify(
1845
+ config.excludeFiles
1846
+ )}`
1847
+ )
1848
+ );
1849
+ return config;
1850
+ }
1851
+ } catch (error) {
1852
+ console.warn(
1853
+ chalk.yellow(
1854
+ `Could not read preferred config in ${preferredEntry.name}/`
1855
+ )
1856
+ );
1857
+ }
1858
+ }
1859
+ }
1860
+ }
1861
+ // If no preferred project found, search all directories
1862
+ for (const entry of entries) {
1863
+ if (
1864
+ entry.isDirectory() &&
1865
+ (!preferredProjectName ||
1866
+ entry.name.toLowerCase() !== preferredProjectName.toLowerCase())
1867
+ ) {
1868
+ const subConfigPath = path.join(
1869
+ searchDir,
1870
+ entry.name,
1871
+ "prisma-php.json"
1872
+ );
1873
+ if (fs.existsSync(subConfigPath)) {
1874
+ try {
1875
+ const config = JSON.parse(fs.readFileSync(subConfigPath, "utf8"));
1876
+ if (config.excludeFiles && config.excludeFiles.length > 0) {
1877
+ console.log(
1878
+ chalk.blue(
1879
+ `Found fallback configuration with exclusions in: ${entry.name}/`
1880
+ )
1881
+ );
1882
+ console.log(
1883
+ chalk.gray(
1884
+ `Fallback excludeFiles: ${JSON.stringify(
1885
+ config.excludeFiles
1886
+ )}`
1887
+ )
1888
+ );
1889
+ return config;
1890
+ }
1891
+ } catch (error) {
1892
+ console.warn(
1893
+ chalk.yellow(`Could not read config in ${entry.name}/`)
1894
+ );
1895
+ }
1896
+ }
1897
+ }
1898
+ }
1899
+ return null;
1900
+ };
1901
+ // If no config in current directory, search subdirectories for configs with excludeFiles
1902
+ if (!existingConfig) {
1903
+ console.log(
1904
+ chalk.blue("Searching for existing configurations with exclusions...")
1905
+ );
1906
+ // Extract project name from starter kit source URL to prioritize the right project
1907
+ let preferredProjectName;
1908
+ if (answer.starterKitSource) {
1909
+ const urlParts = answer.starterKitSource.split("/");
1910
+ const repoName = urlParts[urlParts.length - 1].replace(".git", "");
1911
+ preferredProjectName = repoName;
1829
1912
  console.log(
1830
1913
  chalk.gray(
1831
- `Source excludeFiles: ${JSON.stringify(
1832
- existingConfig.excludeFiles || []
1833
- )}`
1914
+ `Looking for local project matching: ${preferredProjectName}`
1834
1915
  )
1835
1916
  );
1836
- } catch (error) {
1837
- console.warn(chalk.yellow("Could not read current directory config"));
1838
- existingConfig = null;
1839
1917
  }
1918
+ existingConfig = findConfigWithExclusions(
1919
+ currentDir,
1920
+ preferredProjectName
1921
+ );
1840
1922
  }
1841
- // If no config in current directory, check the target project directory
1923
+ // If still no config, check the target project directory
1842
1924
  if (!existingConfig && fs.existsSync(finalProjectConfigPath)) {
1843
1925
  try {
1844
1926
  const rawConfig = fs.readFileSync(finalProjectConfigPath, "utf8");
1845
1927
  existingConfig = JSON.parse(rawConfig);
1846
1928
  console.log(
1847
- chalk.blue(
1848
- "Found existing configuration in project directory, merging..."
1849
- )
1929
+ chalk.blue("Found existing configuration in project directory")
1850
1930
  );
1851
1931
  console.log(
1852
1932
  chalk.gray(
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  import chalk from"chalk";import{spawn}from"child_process";import fs from"fs";import path from"path";import prompts from"prompts";const args=process.argv.slice(2),readJsonFile=e=>{const o=fs.readFileSync(e,"utf8");return JSON.parse(o)},executeCommand=(e,o=[],t={})=>new Promise(((r,s)=>{const a=spawn(e,o,{stdio:"inherit",shell:!0,...t});a.on("error",(e=>{s(e)})),a.on("close",(e=>{0===e?r():s(new Error(`Process exited with code ${e}`))}))}));async function getAnswer(){const e=[{type:"toggle",name:"shouldProceed",message:`This command will update the ${chalk.blue("create-prisma-php-app")} package and overwrite all default files. ${chalk.blue("Do you want to proceed")}?`,initial:!1,active:"Yes",inactive:"No"}],o=await prompts(e,{onCancel:()=>{process.exit(0)}});return 0===Object.keys(o).length?null:o}const commandsToExecute={update:"npx pp update project"};
3
3
  const main = async () => {
4
4
  if (args.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "4.0.0-alpha.40",
3
+ "version": "4.0.0-alpha.45",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",