rotundasoftware / cartero

Modular front end development for multi-page web applications.
MIT License
204 stars 25 forks source link

Support for parcelsDirPath as patterns #35

Closed lagoasoft-lucasschmidt closed 9 years ago

lagoasoft-lucasschmidt commented 9 years ago

Hey guys, I have an use case that requires that I specify a pattern of folders, due to the dynamic aspect.

Basically I have an application that mounts many different applications. Currently I could add to my cartero configuration a bunch of folders, or a folder that holds them all. But the last case it cause issues like pages that are not pages are being considered parcels and stuff like that, so its extra processing being done for no reason.

Does it make sense, based on the current architecture, to add support to something like node-glob or similar when specifying those parcelsDirPath? I could take a look into it, if it makes sense.

dgbeck commented 9 years ago

Hi Lucas! Good to hear from you!

This seems like too much of a fringe case to bake into cartero proper. What you could do however is use parcel-finder to grab on the parcels in all the different directories (which you could grab using glob or whatever) and then run cartero on the collection of endpoints. For example (not tested):

var parcelFinder = require( 'parcel-finder' );
var async = require( 'async' );

var mainPaths = async.reduce( [ .. array of directory paths to scan .. ], [], function( mainPathsMemo, thisDirPath, next ) {
    parcelFinder( thisDirPath, function( err, detected ) {
        if (err) return next( err );

        next( null, mainPathsMemo.concat( _.reduce( detected, function( memo, thisPkg ) {
            return memo.concat( thisPkg.__mainPath );
        }, [] ) ) );
    } );
}, function( err, mainPaths ) {
    if( err ) throw err;

    var c = cartero( mainPaths, outputDir );
    // ...
}

We can keep an eye on this and see if it comes up again though. Thanks for the feedback!

lagoasoft-lucasschmidt commented 9 years ago

No problem. Thanks for the input, I will take a look at it.

dgbeck commented 9 years ago

Hi Lucas,

Check out 5.0.0, just published. Now the first argument to cartero accepts a glob that matches the entry points, instead of just the views directory. (For legacy support, using the views directory still works, although this is not documented.) I think this more explicit approach should map nicely onto this need!