elkuku / EasyCreator

EasyCreator helps creating extensions for the Joomla! CMS
http://extensions.joomla.org/extensions/miscellaneous/development/5908
50 stars 23 forks source link

How to create a precopy script to strip all comments? #14

Open machadoug opened 11 years ago

machadoug commented 11 years ago

Greetings,

My extension has almost 2Mb and, because most shared servers have a 2Mb upload limit, I need to reduce the package size without removing any code or image. So I thought about running the php --strip (command line) on all PHP files.

Is that possible? If so, how can I accomplish it?

Thanks for your help,

Douglas

elkuku commented 11 years ago

Hello Douglas, nice Idea. It reminds me to write some more documentation..

Let me try to write something down here:

What EasyCreator does is creating the required structure for the package in a temp directory and copy the project files here. So the place where you actually can modify your source code for distribution without modifying the original code would be after the files have been copied. I call this Post Copy.

So the steps to achieve what you are trying (if I understand you right) would be:

So here you would create a new build action Script for the event Post Copy. The build action Script simply calls a custom script supplying optional parameters provided by EasyCreator such as

The syntax is the usual path/to/script --parameter=value

I have created a small script that uses the build in PHP function php_strip_whitespace() what would be the parameter -w on the CLI. I did not found the parameter --strip you mentioned. Where does that come from ?

Here is the srcipty: https://gist.github.com/4083057 Note that the script expects an environment variable JOOMLA_PLATFORM_PATH, that points to a Joomla! platform, to be set up. Of course you may write it in "plain PHP" or in any other language you prefer.

In your build action you would use something like this as the Path: /path/to/stripcomments.php --dir=${temp_dir}

Does this work for you ?

machadoug commented 11 years ago

Dear Nikolai,

Many many thanks for your help. It is exactly what I needed

For some reason it did not work, so I had to: require getenv('JOOMLA_PLATFORM_PATH').'/libraries/import.php'; With: require '../libraries/import.php';

Also, I need to be able to add the copyright information because JED requires it on all files, so I've made a few changes. Please take a look here: https://gist.github.com/4089355

The question now is how to get this information from EasyCreator?

Also, the script does not seem to be executed when creating packages (using version 0.0.18 because in 0.0.19 it is not creating packages);

Thanks again and have a great weekend,

Douglas

machadoug commented 10 years ago

@elkuku,

Can we get that copyright information from EasyCreator OR even better, ignore the first block comment?

Best regards,

machadoug commented 10 years ago

@elkuku,

I have updated the srcipty, so it will keep the first comment in each file: https://gist.github.com/machadoug/4089355

It is working correctly in a single extension package, however it is not working I create a package extension type.

I'm using the latest EasyCreator version.

Here is part of the debug message:

17:56:57 INFO   Starting CleanUp
17:56:57 INFO   0 language version files deleted
17:56:57 INFO   Performing build actions type: postcopy
17:56:57 INFO   Executing: JROOT/cli/stripcomments.php --dir=/var/www/joomla/temp/com_contactenhanced52c5a8687a04e
17:56:57 ERROR  Script: ${j_root}/cli/stripcomments.php --dir=${temp_dir} finished with exit status 2
17:56:57 INFO   1 actions executed
17:56:57 INFO   File deleted /var/www/joomla/temp/com_contactenhanced52c5a8687a04e/admin/contactenhanced.xml
17:56:57 INFO   Starting manifest

Can you please help me to fix this?

Best regards,

elkuku commented 10 years ago

Hello Douglas, happy new year :wink: The first thing that comes to my mind, looking at this script from one year ago.., is that some Joomla! stuff regarding libraries/framework/cms-libraries might have changed....

Could you execute the script on its own and see what happens ?

I agree the EasyCreator log output is not very helpful :P

machadoug commented 10 years ago

@elkuku,

Thanks for your reply.

I have execute the script on it's own and it worked correctly.

I don't think it is a problem related to libraries/framework/cms-libraries because it works when I create a component, module or plugin, it just doesn't run when I create a package (pkg) extension.

A very happy and blessed 2014 for you too! ;-)

Best regards,