Created
November 20, 2015 13:01
-
-
Save DakuTree/d53a5d92e3e5ec5ff610 to your computer and use it in GitHub Desktop.
Copy/Rename files with Composer+PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
//This method uses PHP to copy/rename files. | |
"require": { | |
//... | |
}, | |
//List the files to copy/rename here. | |
"vendor-copy": { | |
"file/to/move/example.txt" : "location/to/move/to/example.txt", | |
"file/to/rename/example.txt" : "file/to/rename/example2.txt", | |
"file/to/copy/and/rename/example.txt" : "a/b/c/abc.txt" | |
}, | |
"scripts": { | |
//Code breakdown: | |
// php -r \" | |
// array_map('copy', | |
// array_keys( | |
// json_decode(file_get_contents('composer.json'), TRUE)['vendor-copy'] | |
// ), | |
// json_decode(file_get_contents('composer.json'), TRUE)['vendor-copy'] | |
// ) | |
//\"; | |
//The above code was built to work cross-platform, which is why it looks a bit inefficent in how it does things (Can't use variables). | |
//Linux requires the use of single quotes (but has support for double quotes), and Windows only supports double quotes. | |
// Sadly, Linux uses $ for bash variables within double quotes, which essentially restricts us from using any sort of variable. | |
//If there is a better way of doing this cross-platform, please let me know. | |
"post-install-cmd" : [ | |
"php -r \"array_map('copy', array_keys(json_decode(file_get_contents('composer.json'), TRUE)['vendor-copy']), json_decode(file_get_contents('composer.json'), TRUE)['vendor-copy']);\"" | |
], | |
"post-update-cmd" : [ | |
"php -r \"array_map('copy', array_keys(json_decode(file_get_contents('composer.json'), TRUE)['vendor-copy']), json_decode(file_get_contents('composer.json'), TRUE)['vendor-copy']);\"" | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment