The easiest way to pack/zip folder after file changes

hi,
I am looking for a way how to create zip file of specific folder in my project after I make some change in source code. I could compare it to SASS file watcher. Every time I change something in tha folder I want this folder to be zipped.

any suggestions?

10 comments
Comment actions Permalink

Hi there,

Well ... you can do this with custom file watcher. But ...

  • you have to write custom batch/shell script that will do the zipping yourself (e.g use unique timestamps in file name etc).
  • if you modify 2 files at the same time in such folder, the file watcher will be fired twice: once for each modified file (which may not be what you want)


If you are still interested:

  • create custom scope that will include files/folders that you want to watch
  • create new watcher and use that newly created scope there; you may need to set "file type" to "any"
  • the program to execute would be your custom script; you may hardcode paths inside it .. or pass it as a parameter
0
Comment actions Permalink

hi Andriy,
thing is I don't know how to create such a Watcher. I don't have any experience with Webstorm or IDEA plugin development.
And so far I didn't find any useful guide for my specific case.

My requirements are pretty simple. Files will not changes simultaneously, usually I edit 1 file at the time :)
I don't know where to start. Can you point me to some good resources?

Thanks

0
Comment actions Permalink
I don't have any experience with Webstorm or IDEA plugin development.

This has nothing to do with plugin development, at all.


You can see standard file watcher settings for common tasks here: http://confluence.jetbrains.com/display/PhpStorm/File+Watchers+in+PhpStorm

Based on those you should figure out what needs to be done for custom file.


For example: this is custom file watcher that just copies .js files from one folder to another and renames them a bit (P.S. this is for Windows):
screen01.png

Custom batch script used in that custom file watcher: copy-raw.cmd

copy /Y %1.js /B ..\js\%1.min.js /B
0
Comment actions Permalink

I created watcher attached in screenshot. But  exception occurred while executing watcher and there is only error "An exception occurred while executing watcher... "

Concept is: 1. There is 'dirs' directory in my project and it has many template subdirectories. something like sub projects.

- dirs
-- subdir1
--- subdir1.zip
-- subdir2
--- subdir2.zip

I want to to create archive for every subdir in which file has changed.
I still need to implement routine to parse $FilePath and find subdir name in it.

But anyway here is script I have so far

#!/bin/sh
parentDir="../dirs"
tpldir=$1
archiveName=$tpldir".zip"

if [ $# -eq 0 ]; then
 echo "Argument is missing"
 exit 1
fi

if [ -e $tpldir/$archiveName ]; then
    echo "Archive $archiveName found. Deleting ..."
    rm $tpldir/$archiveName
fi

# bash check if I am in 'dirs' directory
if [ -d $parentDir ]; then
    if [ -e $tpldir ]; then
        # echo "Template dir exists"
            echo "Packing "$tpldir
            pushd $tpldir
            zip -r -9 -q $archiveName .
            popd
            cd ..
            exit 0
    else
        echo "Template $tpldir does not exists"
        exit 2
    fi
    else
        echo "You are not in 'dirs' directory"
        exit 3
fi



Attachment(s):
Screenshot 2014-11-12 22.11.04.png
0
Comment actions Permalink

I don't know what i am doing wrong here. when I run script from command line './script.sh subdir' it works

0
Comment actions Permalink

ok, I found stupid erro in Watcher setup. I used $FileName instead $FileName$ ..
Now I need to make this parsing routing, which will be hard I guess. I am not fun of batch scripting :(

0
Comment actions Permalink

I'm not Linux user so cannot help with bash coding.

My only comment about you having "Immediate file sync" enabled -- this will execute watcher even if you just add a space in file -- it will not wait for file to be saved as it will save it for you after like 1 sec delay or so.

0
Comment actions Permalink

Is it possible to execute it only after save?

0
Comment actions Permalink

Yes -- by unchecking that option.

0
Comment actions Permalink

AAh, of course. Thanks!

0

Please sign in to leave a comment.