Skip to content

Conversation

jbblanchet
Copy link

First draft of adding external streams to assets. Fixes #75 and #30. I updated an undocumented piece of code that appeared to do a similar job. If this is an acceptable solution, I'll create tests and update the doc.

Sample usage (with typescript):

// create stream of virtual files
var tsStream = gulp.src("src/**/*.ts")
        .pipe(ts());

    // pass stream to assets, multiple streams are supported
    var assets = useref.assets({}, tsStream);

    // use gulp-useref normally
    return gulp.src("src/index.html")
        .pipe(assets)
        .pipe(assets.restore())
        .pipe(useref())
        .pipe(gulp.dest("dist"));

@jbblanchet
Copy link
Author

This appears to change the code created by #108, but it is undocumented, untested and I couldn't make it work.

This modifies the code created by #70, but I'm not sure is this code is supported or not. It isn't documented or tested, and the last comment before the merge was "please try this out" and comments after the merge seem to indicate it doesn't work. If that code was supposed to work, I'll move the additional asset streams to the options instead of arguments.

@jbblanchet jbblanchet mentioned this pull request Jun 25, 2015
@jonkemp
Copy link
Owner

jonkemp commented Jun 26, 2015

I'm unclear on what this does. Does it add support for #75 and #30 or does it fix #70?

@jbblanchet
Copy link
Author

I misunderstood the intention of #70, and I now see that it is unrelated to the passing of assets streams. I've updated the code accordingly.

Usage is now:

// create stream of virtual files
var tsStream = gulp.src("src/**/*.ts")
        .pipe(ts());

    // pass stream to assets, multiple streams are supported
    var assets = useref.assets({ additionalStreams: tsStream });

    // use gulp-useref normally
    return gulp.src("src/index.html")
        .pipe(assets)
        .pipe(assets.restore())
        .pipe(useref())
        .pipe(gulp.dest("dist"));

This pull request is not ready to be merged. File order is not preserved between physical and virtual files, and I have an issue with using gulp-inject in the same workflow that I'm still looking into. This is more a request for comments or suggestions. :)

@jbblanchet
Copy link
Author

Ok, this takes care of the ordering and the race condition with gulp-inject. Example workflow is:

var tsStream = gulp.src("src/**/*.ts")
        .pipe(ts());

    var assets = useref.assets({ additionalStreams: tsStream });

    return gulp.src("src/index.html")
        .pipe(inject(tsStream, {relative: true}))
        .pipe(assets)
        .pipe(assets.restore())
        .pipe(useref())
        .pipe(gulp.dest("dist"));

I'll test it with my full workflow (wiredep, rev, etc) on monday when I'm back at the office, but for now it looks good. I'd like to know if you'd be willing to pull, and if so, I'll update the docs and create some automated tests.

@jonkemp
Copy link
Owner

jonkemp commented Jun 27, 2015

I'm interested. I need to look at it more in depth though before I can decide.
Just to be clear, the feature requests in #75 and #30 are what this is addressing? I also don't understand the use case with TypeScript. Can you explain that further?
Thanks!

@jbblanchet
Copy link
Author

Yes, this is addressing both these issues. I'm using typescript here, but I could also be using sass, less, coffeescript, dart, angular-templatecache, etc.

Currently if I want to use gulp-useref with typescript, I have to generate the files, save them to a temp directory, then use gulp-useref. This pull request lets me pass streams of generated files to useref instead, which is more "gulpy".

In my last example I'm using gulp-inject to automatically add the script tags for the files generated by typescript to my index.html before running gulp-useref.

Let me know if you have any questions.

Thanks.

@jonkemp
Copy link
Owner

jonkemp commented Jun 27, 2015

Yes, looks good. Please continue this work. Thanks!

@jbblanchet
Copy link
Author

Ok, I think I finally solved the race condition between the streams. Changes appear worst than they really are since I add to re-indent most of the assets function. Basically, the change since the last version is waiting for the additional assets to run the main assets function. Still trying to break it, will let you know when I'm done.

@jonkemp
Copy link
Owner

jonkemp commented Jul 8, 2015

Was this done or forgotten?

@jbblanchet
Copy link
Author

Neither. The code looks good to go, I was planning on creating some automated tests and updating the readme this weekend.

@jbblanchet
Copy link
Author

All done.

@jonkemp
Copy link
Owner

jonkemp commented Jul 15, 2015

Can you squash your commits?

@jbblanchet
Copy link
Author

Done.

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

Successfully merging this pull request may close these issues.

2 participants