0

What tool can I use to create a "clean" archived file for a PHP WordPress Plugin that I can publish to clients, or wordpress.org?

When I want to publish a WordPress plugin to my clients I create an installable ZIP archive from that plugin. Since I use Git, it has a lot of development files and directories that I do not want to include into the build that I publish to my clients.

In the zip archive that I currently create for every version release, I make sure to e.g. remove the .git directory, the .gitignore and README.md files, the .vscode directory, the codekit config file, but leave the node_modules and vendor directories in.

I do this by coping the project directory to my desktop, remove the development files and directories, create the ZIP archive, rename that to the latest version, then I upload that via (s)FTP so my clients can reach it.

This is not so much a problem the first time I publish, but gets very tedious with every (small) version update.

There must be a better way to do this but I am probably searching by the wrong terms.


I've looked into;

  • Git Archive: This also removes the ./vendor and ./node_modules for example
  • Gitlab CI/CD (where the repositories of the plugins live): This seems way to complex, don't actually need integration and depolyment, just archiving
  • Jenkings: Seems way overkill for what I'm trying to accomplish here
  • Gulp: This task runner seems to be more of a tool to be used continuously while developing (watching/building .sass files etc) and not for building after the code is finished
  • Phing: Seems to be a very powerful tool, maybe too powerful? Is this the way to go or are there better solutions?

... and another ton of tools


TL;DR How do I create a "clean" zip archive of a PHP git project without development files and folders?

Script47
  • 14,230
  • 4
  • 45
  • 66
Ronaldt
  • 440
  • 4
  • 13
  • '*Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.*' – Script47 Sep 18 '19 at 08:59
  • I get that, but with the risk of sounding like a little 16 year old....here goes: I tried describing the problem, I've described what I've tried (did not keep a diary for every script I made and tool I've tried but kept it general enough for you to relate). I tried to give context for my question. -- I know there must be some kind of workflow that people follow, I'm just not able to find it. How do you suggest finding a solution for it, or refraining my question according to the guidelines? – Ronaldt Sep 18 '19 at 09:32
  • You might be better off at [wordpress.stackexchange](https://wordpress.stackexchange.com/). Though, read their guidelines. – Script47 Sep 18 '19 at 09:34
  • My question goes beyond that scope; basically any git-project written in php, or basic html with javascript node_modules for example. They all have development files and folders that need to be included or excluded when publishing them, am I right? – Ronaldt Sep 18 '19 at 09:37

1 Answers1

0

You can add the unwanted files to .gitignore, only keep the wanted file under control.

Then get all the files under control which you wanted with git then zip these files. Refer to How to list all the files in a commit? and Git - List all files currently under source control?

zip with git ls-tree -r master --name-only | zip out.zip -@

unzip it with unzip out.zip -d test


If you want to zip file not under control, you can use add the file to file list with something like,

{ git ls-tree -r master --name-only; find /vendor /node_modules -type f; } | zip out.zip -@

LF00
  • 27,015
  • 29
  • 156
  • 295
  • Thanks Kris. I've tried something similar with git-archive ("create an archive of files from a named tree"). But I need more control over what to include and/or exclude from the repository. For example, the /vendor and /node_modules need to be included in the zip file, but are also added to the .gitignore file (and thus, are ignored when creating the archive). Tried first creating the zip, then adding the folders back into it manually. I'm looking for an workflow that does that for me. Any tips? – Ronaldt Sep 18 '19 at 09:48
  • 1
    `{ git ls-tree -r master --name-only; find /vendor /node_modules -type f; } | zip out.zip -@` will works for you. – LF00 Sep 18 '19 at 10:08
  • Interesting Kris, I did not know that syntax of combining the git and find commands. However, it still includes the .gitignore and other files that are actually listed in the .gitignore file. Am I missing something? – Ronaldt Sep 18 '19 at 11:32