wilr / grunt-shopify

Grunt plug-in for publishing Shopify theme assets
BSD 3-Clause "New" or "Revised" License
107 stars 32 forks source link

Grunt-Shopify runs twice? #16

Closed terkelg closed 7 years ago

terkelg commented 11 years ago

I have the following setup: A folder named src with all my sass, images, template etc. organized in subdirectories. I use grunt-contrib-copy, grunt-watch and grunt-newer to “compile” this into a valid Shopify theme structure. Grunt-newer is used to only copy changed files. Let’s say I edit and save my theme.liquid in my src folder, I get the following response:

screen shot 2013-09-21 at 14 21 10

It looks like the grunt-shopify run twice. I tried to debug, but with no luck. I tried to add a delay to grunt-shopify, but the same thing happens.

I guess grunt-shopify watch and looks for changes, and react immediately, before the file is done being copied with grunt-contrib-copy. I tried setting different options in watch like options.spawn and options.debounceDelay, but with no luck.

Both grunt-shopify and grunt-contrib-copy looks for changes in the app folder, but is it possible to somehow control the order in which they run?

My current watch setup:

watch: {
  copy: {
    files: '<%= project.src %>/**',
    tasks: ['newer:copy:shopify']
  },
  shopify: {
    files: ["app/**"],
    tasks: ["shopify"]
  }
}

Could it be that grunt-contrib-copy touches the files twice, and thereby trigger shopify-grunt twice?

In the end the file get’s uploaded and everything works fine, but the error really annoy me. And I can’t figure out why this happens.

wilr commented 11 years ago

Is there any other watchers or grunt files running? At the watcher stage there shouldn't be anything involved with the plugin (i.e grunt-contrib-watch is being on the app folder so should never touch the src folder) from that setup

terkelg commented 11 years ago

It's the only watch and Gruntfile running. But if you look at the terminal screenshot, you can see that the first upload is from the src folder and the second is from the app folder. Everything runs smoothly if I remove the grunt-contrib-copy from the Gruntfile.

farneman commented 11 years ago

I'm seeing the same issue as well. I'm working out of a shop folder and then using ryanburnette/grunt-shopify-theme to copy over the necessary files to a dist folder. According to my terminal output grunt-shopify uploads the changed file from shop first then after grunt-shopify-theme runs grunt-shopify again uploads the changed file from dist.

farneman commented 11 years ago

Since grunt-shopify-theme also uses grunt-contrib-copy I tested disabling that task and when I did only one upload happened on change. So maybe some sort of conflict with grunt-contrib-copy triggers the first erroneous upload?

terkelg commented 11 years ago

@farneman exactly! grunt-shopify trigger before other tasks defined in watch.

justinmetros commented 10 years ago

Same issue here. Overall it works well and files get uploaded, just 5% weird that its trying to upload initially on a file save from a directory not specified in the files array, seemingly out of turn. Don't have a solution and this won't stop my enjoyment of the plugin, but any insight would be much appreciated :) All plays well when not combined with another task that uses watch, in this case grunt-contrib-sass. Here's a screengrab and my watch for good measure:

grunt-shopify

watch: {
        css: {
          files: ['_sass/**/*.scss'],
          tasks: ['sass','cssc'],
          options: {
            spawn: false,
          }
        },
        shopify: {
          files: ['theme/assets/**','theme/config/**','theme/layout/**','theme/snippets/**','theme/templates/**'],
          tasks: ["shopify"]
        }
      }

Edit: https://github.com/erickreutz/grunt-shopify this version fixes the multiple upload issue for me. Sorry if I jumped the gun, new to this plugin. Thanks so much all for the great work. Cheers!

ctalkington commented 10 years ago

I believe the issue is that the watch event doesn't respect which target. now v0.5 of watch does include the target as an arg so we may be use that but my latest changes should also prevent from uploading anything not in base path (which is cwd if not using a base)

graygilmore commented 10 years ago

I think this is the commit that fixes it: https://github.com/erickreutz/grunt-shopify/commit/39c29e81b6209ba3fe78ab0b92270270453a366d?w=1

I'm getting a similar bug.

It's great that it's letting me know that that file isn't allowed, but it shouldn't really be checking outside of the folders I declare for it to watch anyways.

watch:
    styles:
        files: ["styles/*"]
        tasks: ["concat"]
    shopify:
        files: ["assets/*","config/*","layout/*","snippets/*","templates/*"]
        tasks: ["shopify"]
cshold commented 9 years ago

Agreed with Gray above. No need to watch/notify me of files outside those declared in files.

wilr commented 7 years ago

Should now be resolved.