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

ignore folders/files #20

Closed
artknight opened this issue Feb 8, 2017 · 22 comments
Closed

ignore folders/files #20

artknight opened this issue Feb 8, 2017 · 22 comments

Comments

@artknight
Copy link

I am not sure if this lib has the ability to ingore certain folders/files within a source folder. If it does, would you please provide an example on how to set it up.

Thanks,

PS: great job on the plugin!

@artknight artknight changed the title ignore filders/files ignore folders/files Feb 8, 2017
@AndyOGo
Copy link
Owner

AndyOGo commented Feb 9, 2017

@artknight
Sure it can:)
I see, I will add a more elaborate example, but if you check the doc's Usage section, it says:

Commands:
  sources  One or more globs, files or directories to be mirrored (glob
           exclusions are supported as well - ! prefix)

So every files/folders you want to exclude need to be prefixed by !, like:

sync-glob 'src/images/*' '!src/images/exclude.png' dist/images

Hope that helps, I will leave it open until I updated the docs.

@AndyOGo
Copy link
Owner

AndyOGo commented Feb 28, 2017

Any improvements regarding docs will be tracked in #22

@AndyOGo AndyOGo closed this as completed Feb 28, 2017
@artknight
Copy link
Author

So, I tried running this

node node_modules\.bin\sync-glob "project/*" "!*.db" "!*.gitignore" "[!aspnet_client|BIN|WEB-INF|css|clients]" "\\server1\project"

and it does not seem to work. I am assuming my syntax is incorrect.

basically i want to sync all files/folders except for *.db, *.gitignore and none of the other folders inside the []

@AndyOGo
Copy link
Owner

AndyOGo commented Mar 24, 2017

@artknight

May I ask you to provide your folder structure?

From your code I assume you want to sync all first children only or project/ dir.
In that case !*.db will have no effect, because it would exlcude only files ending with .db from your current working directory, but project/ is a sub directory of your current working dir.
Hence I assume !project/*.db is more accurate.

I strongly advise you to make yourself familiar with GLOB patterns and especially how directories and folders are supposed to work in UNIX style (cwd, root, etc.).

A good primer on GLOBs can be found here https://github.com/isaacs/node-glob#glob-primer

Good Luck

@artknight
Copy link
Author

artknight commented Mar 24, 2017

So the folder structure is as follows

project/cfc
project/cfc/file1.cfc
project/cfc/file2.cfc
project/css
project/css/file1.css
project/css/file2.css
project/images
project/images/company
project/images/company/file1.png
project/images/company/file2.png
project/images/icons
project/images/icons/icon1.png
project/images/icons/icon2.png
...
project/BIN
project/WEB-INF
...
project/application.cfc
project/index.cfm
...

So, basically I need to sync everything (files & folders) to the local server \\server1\project except for:

  1. files with extension .db
  2. .gitignore files
  3. BIN folder
  4. WEB-INF folder
  5. inside images i need to ignore folders like company and icons but sync everything else

etc...

@AndyOGo
Copy link
Owner

AndyOGo commented Mar 30, 2017

@artknight
I see.

So what you need is something like:

sync-glob 'project/**/*' '!project/{BIN,WEB-INF}/' '!**/*.{db,gitignore}' '!project/images/{company,icons}/' targetDir

You can provide sync-glob with one or more source items and the last item is always your desired target directory.

What it does

  • 'project/**/*' grabs all files and folders recursively within project/ dir
  • '!project/{BIN,WEB-INF}/' excludes project/BIN/ and project/WEB-INF/ by utilizing glob's ! exclamation mark prefix (which means exclusion)
  • '!**/*.{db,gitignore}' excludes all .db and .gitignore files recursively
  • '!project/images/{company,icons}/' excludes project/images/company/ folder and project/images/icons/
  • targetDir put your desired target dir here, I guess /server1/project

Hope this helps and really make sure to study stuff about Unix files and folder structures, Globbing and stuff like that 😉

@artknight
Copy link
Author

@AndyOGo thank you for your help. So I got it to work but there are a few questions I do have. I see that it deletes the destination folder before mirroring. ( DELETE L:\web\project\account )
Is that something that was intended? The reason i am asking is b/c my destination folder has certain folders that need to be kept/ignored by the process so the destination folder should not be deleted but merely mirrored.

Also I noticed that folders such as css or company are still getting copied over.

Here is the string that I am running

$ node_modules\.bin\sync-glob "account/**/*" "!**/*.{db,gitignore}" "!account/**/{aspnet_client,BIN,WEB-INF,css,companies}/" "L:\web\project\account"

@AndyOGo
Copy link
Owner

AndyOGo commented Apr 5, 2017

@artknight
No problem, I'm happy to help, though I have not much time.
Regrading your question of initial deletion. That is the default behavior and it can be controlled by --delete (enabling it) or --no-delete (disabling it).
More docs can be found here and here (API) - The naming could be discussed, may initial-deletion is more clear

Oh, if the exclusion ! prefix really doesn't work as intended, then it's a bug on my side. I would need a failing test then I can fix it.

@AndyOGo
Copy link
Owner

AndyOGo commented Apr 5, 2017

It seems you have a typo, is companies or company?

@artknight
Copy link
Author

artknight commented Apr 5, 2017 via email

@AndyOGo
Copy link
Owner

AndyOGo commented Apr 5, 2017

hmh, then it seems to be a bug.
May I ask you which os are you using?
I could test on osx.

@artknight
Copy link
Author

artknight commented Apr 5, 2017 via email

@AndyOGo AndyOGo reopened this Apr 10, 2017
@AndyOGo AndyOGo added the bug label Apr 10, 2017
@AndyOGo
Copy link
Owner

AndyOGo commented Apr 10, 2017

I just found out that node-glob and node-glob-all respectively still use unix paths even on windows and transpile it internally.
See https://www.npmjs.com/package/glob#windows

@AndyOGo
Copy link
Owner

AndyOGo commented Apr 10, 2017

Windows

console.log test\sync.spec.js:26
    [ 'remove',
      [ 'tmp\\mock\\a.txt', 'tmp\\sync\\tmp\\mock\\a.txt' ] ]

Should be same as on OS X

console.log test/sync.spec.js:26
    [ 'remove', [ 'tmp/mock/a.txt', 'tmp/sync/a.txt' ] ]

@AndyOGo
Copy link
Owner

AndyOGo commented Dec 21, 2017

there was a bug in isGlob regarding glob exclusions #48 and got fixed by #49
May this has improved too.

@artknight
Copy link
Author

artknight commented Jan 13, 2018

@AndyOGo I finally got around to test this. I just synced up to the latest ( v 1.3.8 ) and it still does not seem to work. Here is the string i am running node_modules\.bin\sync-glob --no-delete "account/**/*" "!account/images/psd" "L:\web\project\account"

Unfortunately it did copy over the psd folder :(

@artknight
Copy link
Author

@AndyOGo I tried to run the same on my mac and it started complaining about account/images/psd not being found. So, finally after digging through some glob docs I figured it out! It needed {,/**} at the end to make sure not only the directory but also anything inside it gets ignored. Here is the final string

sync-glob --no-delete --watch "account/**/*" "!**/*.{db,gitignore}" "!account/**/{WEB-INF,css,companies,psd}{,/**}" "L:\web\project\account"

@AndyOGo
Copy link
Owner

AndyOGo commented Jan 13, 2018

@artknight
Ahhh, I see. Yeah that's actually true. I expand every single directory by **/*. But don't do it for directory listings...
I should add that definitely to the docs.

Thank you very much.

@artknight
Copy link
Author

artknight commented Jan 14, 2018

@AndyOGo curious, is there a way to watch to combine two different watches into one. Basically what i ended up doing is running both of the sync watches in separate terminals

sync 1
sync-glob --no-delete --watch "account/**/*" "!**/*.{db,gitignore}" "!account/**/{WEB-INF,css,companies,psd}{,/**}" "L:\web\project\account"

sunc 2
sync-glob --no-delete --watch "account/css/css/**/*" "L:\web\project\account\css"

basically the first one will copy/watch everything in the root directory except for the css folder. The second one will only sync/watch the css folder

@AndyOGo
Copy link
Owner

AndyOGo commented Jan 14, 2018

@artknight
Well, I would say. Either you keep both and run them by a third npm script, like:
Just create one npm script for each in your package.json.
And in a third script just run them in parallel by stuff like npm-run-all or concurrently.
There are plenty of paralization utilizes for npm scripts, above are my fovorites, just pick whatever suits you best.

Theoretically you should just be able to use (without excluding the css folder):
sync-glob --no-delete --watch "account/**/*" "!**/*.{db,gitignore}" "!account/**/{WEB-INF,companies,psd}{,/**}" "L:\web\project\account"
But your second sync script has two css folders nested "account/css/css/**/*".
If it's a typo, above should work, if not I suggest to change your directory tree.

Hope that helps.

@artknight
Copy link
Author

@AndyOGo yeah the css/css are rightfully nested hence the need for the second script :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants