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

Clean flag for builds #977

Open
WalkerCodeRanger opened this Issue May 26, 2015 · 15 comments

Comments

Projects
None yet
@WalkerCodeRanger

WalkerCodeRanger commented May 26, 2015

I know in this question on stack overflow one of the brunch contributors suggested using rm -rf public/ through npm scripts as the answer for the equivalent of a clean command. I really don't think that is a good answer. A tool like brunch should really support doing clean builds. Three options I can think of (in order from worst to best):

  • Production build should always do a clean and build, since production is the time it really matters if you have extra junk files.
  • Add a --clean flag to build
  • Since the output directory should only contain the output of the build, just delete any files that don't match the current output

The last seems to fit best with the brunch approach and would fit well with watch. So for example, I could rename an asset and brunch watch would copy the new asset over and realize that the old asset name was no longer part of the output and delete it.

@es128

This comment has been minimized.

Show comment
Hide comment
@es128

es128 May 26, 2015

Member

There are people who depend on Brunch NOT doing this. But feel free to submit a PR that adds it as an option behind the --clean CLI switch as in your second suggestion (should work for both watch and build, regardless of environment).

Member

es128 commented May 26, 2015

There are people who depend on Brunch NOT doing this. But feel free to submit a PR that adds it as an option behind the --clean CLI switch as in your second suggestion (should work for both watch and build, regardless of environment).

@paulmillr

This comment has been minimized.

Show comment
Hide comment
@paulmillr

paulmillr May 26, 2015

Member

I'm kinda reluctant to this. More flags, more complication.

What is your exact use case? Why not just use rm -rf? Because in my apps we're doing something different except for removing the files like every time.

For example, packing the result with Cordova. Or similar.

Member

paulmillr commented May 26, 2015

I'm kinda reluctant to this. More flags, more complication.

What is your exact use case? Why not just use rm -rf? Because in my apps we're doing something different except for removing the files like every time.

For example, packing the result with Cordova. Or similar.

@WalkerCodeRanger

This comment has been minimized.

Show comment
Hide comment
@WalkerCodeRanger

WalkerCodeRanger May 27, 2015

I'm not familiar enough with Cordova to understand why cleaning would be a problem with it. I would think most workflows would want extra files (like old assets etc) in the public directory cleaned up to prevent them from being deployed. I guess if brunch was being used as part of a larger build process with grunt/gulp/etc that was putting other files into public/ you might not want those deleted, even then, I would think you would want them rebuilt.

I'm a .NET developer who was considering switching an AngularJS project that someone else setup for me using yeoman and grunt to brunch. Within the first 5 minutes of using brunch, I realized it wasn't cleaning up files and didn't have an option for doing this. I found this when I had messed up my config and was outputting my js file to the wrong location. After fixing the config, I found the old js file hadn't been cleaned up. This can also happen when renaming or removing assets etc. I think most build tools have some support for either a clean build or for cleaning up extraneous files since it is a common issue when building. Indeed the Gruntfile.js setup for me by yeoman does that as the first step of a build.

Perhaps I am missing something, but I thought it would be pretty obvious to have some kind of clean support. All the tools brunch is compared to do.

WalkerCodeRanger commented May 27, 2015

I'm not familiar enough with Cordova to understand why cleaning would be a problem with it. I would think most workflows would want extra files (like old assets etc) in the public directory cleaned up to prevent them from being deployed. I guess if brunch was being used as part of a larger build process with grunt/gulp/etc that was putting other files into public/ you might not want those deleted, even then, I would think you would want them rebuilt.

I'm a .NET developer who was considering switching an AngularJS project that someone else setup for me using yeoman and grunt to brunch. Within the first 5 minutes of using brunch, I realized it wasn't cleaning up files and didn't have an option for doing this. I found this when I had messed up my config and was outputting my js file to the wrong location. After fixing the config, I found the old js file hadn't been cleaned up. This can also happen when renaming or removing assets etc. I think most build tools have some support for either a clean build or for cleaning up extraneous files since it is a common issue when building. Indeed the Gruntfile.js setup for me by yeoman does that as the first step of a build.

Perhaps I am missing something, but I thought it would be pretty obvious to have some kind of clean support. All the tools brunch is compared to do.

@paulmillr paulmillr added the feature label May 27, 2015

@paulmillr

This comment has been minimized.

Show comment
Hide comment
@paulmillr

paulmillr May 27, 2015

Member

Thanks for the detailed answer.

On the implementation side, we'll need to also track the full list of files in public directory and map each output to input.

Member

paulmillr commented May 27, 2015

Thanks for the detailed answer.

On the implementation side, we'll need to also track the full list of files in public directory and map each output to input.

@es128

This comment has been minimized.

Show comment
Hide comment
@es128

es128 May 27, 2015

Member

Other tools have this as a necessary evil for when they can't make their workflows work without temp files. That's the main reason it's always a step for grunt anyway.

So Brunch hasn't needed it. But I think it would be ok to add the option.

In addition to a CLI switch it could be a config option to just cause it to happen every time without thinking about it if a project chooses.

Member

es128 commented May 27, 2015

Other tools have this as a necessary evil for when they can't make their workflows work without temp files. That's the main reason it's always a step for grunt anyway.

So Brunch hasn't needed it. But I think it would be ok to add the option.

In addition to a CLI switch it could be a config option to just cause it to happen every time without thinking about it if a project chooses.

@olegskl

This comment has been minimized.

Show comment
Hide comment
@olegskl

olegskl Jun 5, 2015

Contributor

+1 Cleaning up public should really be the default option set to true.

Contributor

olegskl commented Jun 5, 2015

+1 Cleaning up public should really be the default option set to true.

@es128

This comment has been minimized.

Show comment
Hide comment
@es128

es128 Jun 5, 2015

Member

@olegskl as mentioned that would be a potentially dangerous breaking change for projects that deliberately bring other files into their public dir by other means/processes. If the option is added it to the pre-2.0 Brunch it would have to default to false.

Member

es128 commented Jun 5, 2015

@olegskl as mentioned that would be a potentially dangerous breaking change for projects that deliberately bring other files into their public dir by other means/processes. If the option is added it to the pre-2.0 Brunch it would have to default to false.

@Bartmax

This comment has been minimized.

Show comment
Hide comment
@Bartmax

Bartmax Jun 6, 2015

Contributor

I'm the OP of the related SO question and I'm not a big fan of the proposed solution.

Another option will be to create a brunch.output file like

{
  javascripts: ['file1.js', 'file2.js']
  styles: ['style.css', 'other.css']
  assets: ['font.ttf', 'image.png']
}

then imagine i update the config so now file1.js and file2.js became app.js
then brunch can compare the arrays and delete file1.js and file2.js and replaces the output file with

{
  javascripts: ['app.js']
  styles: ['style.css', 'other.css']
  assets: ['font.ttf', 'image.png']
}

in config, you can have a new option clean that supports brunch-files(default) | all | none | [values]
clean: brunch-files will removes any diff from output files.
clean: all will delete everything from public folder.
clean: ['javascripts'] which will only remove diff script files.
clean: none won't delete anything.

if there's no brunch-output file then no delete will happen

this can be added as default because it will not affect current projects because it only touches brunch generated files.

I don't know if it's worth having another file brunch-output, just suggesting another solution to discuss.

side-effect bonus: this brunch-output will also serve as a debugging tool, you get to clearly see which files were created by brunch.
side-effect bonus 2: you can have a brunch clean command that removes any file listed on brunch-output on public directory.

Contributor

Bartmax commented Jun 6, 2015

I'm the OP of the related SO question and I'm not a big fan of the proposed solution.

Another option will be to create a brunch.output file like

{
  javascripts: ['file1.js', 'file2.js']
  styles: ['style.css', 'other.css']
  assets: ['font.ttf', 'image.png']
}

then imagine i update the config so now file1.js and file2.js became app.js
then brunch can compare the arrays and delete file1.js and file2.js and replaces the output file with

{
  javascripts: ['app.js']
  styles: ['style.css', 'other.css']
  assets: ['font.ttf', 'image.png']
}

in config, you can have a new option clean that supports brunch-files(default) | all | none | [values]
clean: brunch-files will removes any diff from output files.
clean: all will delete everything from public folder.
clean: ['javascripts'] which will only remove diff script files.
clean: none won't delete anything.

if there's no brunch-output file then no delete will happen

this can be added as default because it will not affect current projects because it only touches brunch generated files.

I don't know if it's worth having another file brunch-output, just suggesting another solution to discuss.

side-effect bonus: this brunch-output will also serve as a debugging tool, you get to clearly see which files were created by brunch.
side-effect bonus 2: you can have a brunch clean command that removes any file listed on brunch-output on public directory.

@pikeas

This comment has been minimized.

Show comment
Hide comment
@pikeas

pikeas Jun 16, 2015

+1 for clean flag/config setting!

pikeas commented Jun 16, 2015

+1 for clean flag/config setting!

@jugimaster

This comment has been minimized.

Show comment
Hide comment
@jugimaster

jugimaster Jun 24, 2015

+1 for a cleanup step. The config setting seems like a good idea.

I can't help but wonder why isn't this a feature already. Has no one thought of removing source maps for production builds?! That's what led me to this issue, and I'm just scraping together my first ever Brunch config here!

jugimaster commented Jun 24, 2015

+1 for a cleanup step. The config setting seems like a good idea.

I can't help but wonder why isn't this a feature already. Has no one thought of removing source maps for production builds?! That's what led me to this issue, and I'm just scraping together my first ever Brunch config here!

@dustinrjo

This comment has been minimized.

Show comment
Hide comment
@dustinrjo

dustinrjo Jul 29, 2015

+1 for the flag.
+2 for not doing it by default. I too have apps that combine brunch compiled files with other files output from other tools into the same directory.

dustinrjo commented Jul 29, 2015

+1 for the flag.
+2 for not doing it by default. I too have apps that combine brunch compiled files with other files output from other tools into the same directory.

@es128 es128 added this to the 1.9 milestone Jul 29, 2015

@paulmillr paulmillr modified the milestones: 1.9, 2.1 Nov 20, 2015

@paulmillr paulmillr changed the title from Should support clean or automatically clean up output to Clean flag for builds Dec 14, 2015

@paulmillr paulmillr removed this from the 2.2 milestone Jan 26, 2016

@harryfinn

This comment has been minimized.

Show comment
Hide comment
@harryfinn

harryfinn Mar 28, 2016

+1 for the flag - like @Bartmax's suggestion of a clean: brunch-files option against brunch diff!

Any update on this feature regarding potential milestone?

harryfinn commented Mar 28, 2016

+1 for the flag - like @Bartmax's suggestion of a clean: brunch-files option against brunch diff!

Any update on this feature regarding potential milestone?

@paulmillr

This comment has been minimized.

Show comment
Hide comment
@paulmillr

paulmillr Mar 28, 2016

Member

We'll try to focus on the feature as a part of 2.7 release (mid apr)

Member

paulmillr commented Mar 28, 2016

We'll try to focus on the feature as a part of 2.7 release (mid apr)

@ysle

This comment has been minimized.

Show comment
Hide comment
@ysle

ysle May 13, 2016

we have the 2.7 already since a while, but i'm not quite sure about this is given or not already. Changelog is at 2.6 khm :)

whatever, it's 👍 !

ysle commented May 13, 2016

we have the 2.7 already since a while, but i'm not quite sure about this is given or not already. Changelog is at 2.6 khm :)

whatever, it's 👍 !

@goshakkk

This comment has been minimized.

Show comment
Hide comment
@goshakkk

goshakkk May 13, 2016

Contributor

@ysle no, we have not worked on this yet, but we will eventually

Implementation wise, adding an artifact file (where to? root? public?) might not be the cleanest solution, but then, there doesn't seem to be a different option for tracking which files were produced by brunch and which were not.

Should the cleaning happen only during initial start and not through the run time of watch?

Also, this will still leave files in public generated by brunch plugins (in onCompile for example).

@paulmillr @es128 do you have any thoughts regarding this?

Contributor

goshakkk commented May 13, 2016

@ysle no, we have not worked on this yet, but we will eventually

Implementation wise, adding an artifact file (where to? root? public?) might not be the cleanest solution, but then, there doesn't seem to be a different option for tracking which files were produced by brunch and which were not.

Should the cleaning happen only during initial start and not through the run time of watch?

Also, this will still leave files in public generated by brunch plugins (in onCompile for example).

@paulmillr @es128 do you have any thoughts regarding this?

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