Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to copy non-php files (/folders) #31

Open
Spreeuw opened this issue Aug 11, 2021 · 7 comments
Open

Add an option to copy non-php files (/folders) #31

Spreeuw opened this issue Aug 11, 2021 · 7 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@Spreeuw
Copy link

Spreeuw commented Aug 11, 2021

When utilizing libraries that contain files like fonts (tecnickcom/tcpdf) or other non-php assets (composer/ca-bundle is a library built around a cacert.pem file), these assets are not copied over by Strauss. We currently resolve this with a bash script that runs after Strauss, but it would be nice to be able to tell Strauss which folders to copy over, or even to let it copy all the files/folders for a specific library?

@BrianHenryIE
Copy link
Owner

BrianHenryIE commented Aug 11, 2021

You can use override_autoload to add a files key to the package's existing autoload configuration with the extra files you want.

Adding the res folder to composer/ca-bundle is straightforward:

{
  "require": {
    "composer/ca-bundle": "1.2.10"
  },
  "require-dev": {
    "brianhenryie/strauss": "0.10.4"
  },
  "extra": {
    "strauss": {
      "target_directory": "strauss",
      "namespace_prefix": "Issue31\\",
      "override_autoload": {
        "composer/ca-bundle": {
            "psr-4": {
              "Composer\\CaBundle\\": "src"
            },
            "files": [
              "res"
            ]
        }
      }
    }
  }
}

tecnickcom/tcpdf's fonts folder contains PHP files that you probably don't want to prefix, so add that path to the exclude_from_prefix/file_patterns key.

{
  "require": {
    "tecnickcom/tcpdf": "6.4.2"
  },
  "require-dev": {
    "brianhenryie/strauss": "0.10.4"
  },
  "extra": {
    "strauss": {
      "target_directory": "strauss",
      "namespace_prefix": "Issue31\\",
      "override_autoload": {
        "tecnickcom/tcpdf": {
          "classmap": [
            "config",
            "include",
            "tcpdf.php",
            "tcpdf_parser.php",
            "tcpdf_import.php",
            "tcpdf_barcodes_1d.php",
            "tcpdf_barcodes_2d.php",
            "include/tcpdf_colors.php",
            "include/tcpdf_filters.php",
            "include/tcpdf_font_data.php",
            "include/tcpdf_fonts.php",
            "include/tcpdf_images.php",
            "include/tcpdf_static.php",
            "include/barcodes/datamatrix.php",
            "include/barcodes/pdf417.php",
            "include/barcodes/qrcode.php"
          ],
          "files": [
            "fonts"
          ]
        }
      },
      "exclude_from_prefix": {
        "file_patterns": [
          "/^psr.*$/",
          "~^tecnickcom/tcpdf/fonts.*~"
        ]
      }
    }
  }
}

TBH, most of the classmap they have defined is unnecessary here. Once the directory is specified, everything inside it will be copied.

I'll leave this open until I update the README with a few lines about this.

@BrianHenryIE BrianHenryIE added the documentation Improvements or additions to documentation label Aug 11, 2021
@Spreeuw
Copy link
Author

Spreeuw commented Aug 12, 2021

Thanks for working that out! I think we'll stick to copying afterwards in that case, for simplicity sake. Configuring the autoloader part feels like an unnecessary extra step if all you want is the files to be copied.

@rickmacgillis
Copy link

Excellent. This worked well for copying directories I need. Thank you @BrianHenryIE.

Stripped down version:

"extra": {
    "strauss": {
      "override_autoload": {
        "composer/ca-bundle": {
            "files": [
              "res"
            ]
        }
      }
    }
  }

@BrianHenryIE
Copy link
Owner

I'm considering this functionality, maybe like:

"extra": {
    "strauss": {
      "copy_files": {
        "composer/ca-bundle": [
            "res"
          ]
      }
    }
  }

It would really just be merged back into the override_autoload key mentioned above, but it's a little clearer.

What's the best name? extra_files, include_files, additional_files, just files?

@Spreeuw
Copy link
Author

Spreeuw commented Mar 8, 2023

@alexmigf

@alexmigf
Copy link

alexmigf commented Mar 9, 2023

@BrianHenryIE extra_files or additional_files seems fine to me.

@UVLabs
Copy link

UVLabs commented Mar 21, 2023

@BrianHenryIE I had need for something like this due to how Dompdf works. By default strauss does not copy some of the root files. The VERSION file is actually needed by dompdf or else it throws an error when using the library.

See this line: https://github.com/dompdf/dompdf/blob/v2.0.3/src/Dompdf.php#L261

I had to the following to get all the files into the prefixed directory:

"override_autoload": {
 "dompdf/dompdf": {
  "classmap": ["."]
 }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants