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

Provide more intuitive API for combining JS files in a given order #4

Closed
eskimoblood opened this Issue Dec 28, 2011 · 9 comments

Comments

Projects
None yet
4 participants
@eskimoblood

eskimoblood commented Dec 28, 2011

The order of the combined scriptes are not the same as in the includes array. It seems they are added in alphabetical order by default.

@eriwen

This comment has been minimized.

Show comment
Hide comment
@eriwen

eriwen Dec 28, 2011

Owner

To preserve a given order with FileCollection objects in Gradle, you have to declare separate FileCollection objects and then add them like this:

combineJs {
    fileB = fileTree(dir: "${projectDir}/src/test/resources", includes: ['fileB.js'])
    fileA = fileTree(dir: "${projectDir}/src/test/resources", includes: ['fileA.js'])
    inputs.files fileB + fileA
    outputs.file file("${buildDir}/all.js")
}

I know this is not intuitive and I'm working with the Gradle guys on a more elegant way to accomplish this.

I am going to keep this open as a feature request for a more straightforward way to combine in a specified order.

Owner

eriwen commented Dec 28, 2011

To preserve a given order with FileCollection objects in Gradle, you have to declare separate FileCollection objects and then add them like this:

combineJs {
    fileB = fileTree(dir: "${projectDir}/src/test/resources", includes: ['fileB.js'])
    fileA = fileTree(dir: "${projectDir}/src/test/resources", includes: ['fileA.js'])
    inputs.files fileB + fileA
    outputs.file file("${buildDir}/all.js")
}

I know this is not intuitive and I'm working with the Gradle guys on a more elegant way to accomplish this.

I am going to keep this open as a feature request for a more straightforward way to combine in a specified order.

@eskimoblood

This comment has been minimized.

Show comment
Hide comment
@eskimoblood

eskimoblood Dec 28, 2011

Could you put the above example in the README?

eskimoblood commented Dec 28, 2011

Could you put the above example in the README?

@eriwen

This comment has been minimized.

Show comment
Hide comment
@eriwen

eriwen Dec 28, 2011

Owner

Yep, doing that now :)

Owner

eriwen commented Dec 28, 2011

Yep, doing that now :)

@eriwen

This comment has been minimized.

Show comment
Hide comment
@eriwen

eriwen Mar 10, 2012

Owner

This will be addressed by the new API changes coming in 0.5

Owner

eriwen commented Mar 10, 2012

This will be addressed by the new API changes coming in 0.5

@eriwen

This comment has been minimized.

Show comment
Hide comment
@eriwen

eriwen Jun 20, 2012

Owner

Using internal Gradle sourcesets in 1.0, which is a nicer API.

Owner

eriwen commented Jun 20, 2012

Using internal Gradle sourcesets in 1.0, which is a nicer API.

@eriwen eriwen closed this Jun 20, 2012

@pdwinkel

This comment has been minimized.

Show comment
Hide comment
@pdwinkel

pdwinkel Jun 25, 2012

You closed this issue, but how can we preserve the order of the files?
I tried the following:

javascript.source {
    main {
       js {
          srcDir 'src/main/javascript'
          include 'fileA.js', 'fileB.js', 'fileC.js', 'fileD.js'
       }
    }
}

pdwinkel commented Jun 25, 2012

You closed this issue, but how can we preserve the order of the files?
I tried the following:

javascript.source {
    main {
       js {
          srcDir 'src/main/javascript'
          include 'fileA.js', 'fileB.js', 'fileC.js', 'fileD.js'
       }
    }
}
@robinhh

This comment has been minimized.

Show comment
Hide comment
@robinhh

robinhh Jul 10, 2012

@pdwinkel Since I've asked myself the same question: I think your code uses a FileTree and hence does not provide any order. If you want to preserve file order you should use a file collection instead, for example

task combine(type: com.eriwen.gradle.js.tasks.CombineJsTask) {
  source = files('src/main/js/first.js', 'src/main/js/second.js')
  dest = file('....js')
}

robinhh commented Jul 10, 2012

@pdwinkel Since I've asked myself the same question: I think your code uses a FileTree and hence does not provide any order. If you want to preserve file order you should use a file collection instead, for example

task combine(type: com.eriwen.gradle.js.tasks.CombineJsTask) {
  source = files('src/main/js/first.js', 'src/main/js/second.js')
  dest = file('....js')
}
@eriwen

This comment has been minimized.

Show comment
Hide comment
@eriwen

eriwen Jul 10, 2012

Owner

@pdwinkel: @robinhh is right. Until we get AMD/CommonJS in here, you can also use:

javascript.source {
    jquery {
        js {
            srcDir "src/vendor"
            include "jquery*.js"
        }
    }
    custom {
        js {
            srcDir "src/js"
            include "myfile.js"
        }
        compileClasspath += jquery.outputs
    }
}

It's not the best solution, yet. We're working on it.

Owner

eriwen commented Jul 10, 2012

@pdwinkel: @robinhh is right. Until we get AMD/CommonJS in here, you can also use:

javascript.source {
    jquery {
        js {
            srcDir "src/vendor"
            include "jquery*.js"
        }
    }
    custom {
        js {
            srcDir "src/js"
            include "myfile.js"
        }
        compileClasspath += jquery.outputs
    }
}

It's not the best solution, yet. We're working on it.

@pdwinkel

This comment has been minimized.

Show comment
Hide comment
@pdwinkel

pdwinkel Jul 10, 2012

Thanks for the hints.
I'm gonna use RequireJS, so AMD support will solve the problem.

pdwinkel commented Jul 10, 2012

Thanks for the hints.
I'm gonna use RequireJS, so AMD support will solve the problem.

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