Skip to content
Permalink
Browse files

Simplify the terminal command args syntax for custom builds. Update R…

…EADME
  • Loading branch information...
rwaldron committed Jun 12, 2012
1 parent 47298a7 commit f13de6b3d6256f457da0a3c8274ba33656f8df4f
Showing with 81 additions and 12 deletions.
  1. +14 −5 README.md
  2. +67 −7 grunt.js
@@ -75,6 +75,7 @@ The built version of jQuery will be put in the `dist/` subdirectory.
Starting in jQuery 1.8, special builds can now be created that optionally exclude or include any of the following modules:

- ajax
- css
- dimensions
- effects
- offset
@@ -85,34 +86,42 @@ To create a custom build, use the following special `grunt` commands:
Exclude **ajax**:

```bash
grunt build:*:*:-ajax
grunt custom:-ajax
```

Exclude **css**:

```bash
grunt custom:-css
```

Exclude **dimensions**:

```bash
grunt build:*:*:-dimensions
grunt custom:-dimensions
```

Exclude **effects**:

```bash
grunt build:*:*:-effects
grunt custom:-effects
```

Exclude **offset**:

```bash
grunt build:*:*:-offset
grunt custom:-offset
```

Exclude **all** optional modules:

```bash
grunt build:*:*:-ajax:-dimensions:-effects:-offset
grunt custom:-ajax,-css,-dimensions,-effects,-offset

This comment has been minimized.

Copy link
@mikesherov

mikesherov Jun 13, 2012

Member

technically, grunt custom:-ajax,-css will do, as the rest are dependent.

```


Note: dependencies will be handled internally, by the build process.


Running the Unit Tests
--------------------------------------
@@ -181,7 +181,41 @@ module.exports = function( grunt ) {
});


// Special "alias" task to make custom build creation less grawlix-y
grunt.registerTask( "custom", function() {
var done = this.async(),
args = [].slice.call(arguments),
modules = args.length ? args[0].replace(/,/g, ":") : "";


// Translation example
//
// grunt build:+ajax,-dimensions,-effects,-offset

This comment has been minimized.

Copy link
@mikesherov

mikesherov Jun 13, 2012

Member

grunt custom:

This comment has been minimized.

Copy link
@rwaldron

rwaldron Jun 13, 2012

Author Member

So... did you bother looking at the follow up commit that fixed this? Less noise please.

This comment has been minimized.

Copy link
@mikesherov

mikesherov Jun 13, 2012

Member

I look at commits serially. My apologies.

This comment has been minimized.

Copy link
@rwaldron

rwaldron Jun 13, 2012

Author Member

ugh, sorry... I replied to these when I should've been napping. Sorry for sounding like a cranky brat.

//
// Becomes:
//
// grunt build:*:*:-ajax:-dimensions:-effects:-offset

grunt.log.writeln( "Creating custom build...\n" );

grunt.utils.spawn({
cmd: "grunt",
args: [ "build:*:*:" + modules ]
}, function( err, result ) {
if ( err ) {
grunt.verbose.error();
done( err );
return;
}

grunt.log.writeln( result.replace("Done, without errors.", "") );

done();
});
});

// Special concat/build task to handle various jQuery build requirements
//
grunt.registerMultiTask(
"build",
"Concatenate source (include/exclude modules with +/- flags), embed date/version",
@@ -190,6 +224,7 @@ module.exports = function( grunt ) {
var i,
compiled = "",
modules = this.flags,
explicit = Object.keys(modules).length > 1,
optIn = !modules["*"],
name = this.file.dest,
excluded = {},
@@ -208,16 +243,17 @@ module.exports = function( grunt ) {
}
};


// figure out which files to exclude based on these rules in this order:
// explicit > implicit (explicit also means a dependency/dependent that was explicit)
// exclude > include
// examples:
// *: none (implicit exclude)
// *:* all (implicit include)
// *:*:-effects all except effects (explicit > implicit)
// *:*:-css all except css and it's deps (explicit)
// *:*:-css:+effects all except css and it's deps (explicit exclude from dep. trumps explicit include)
// *:+effects none except effects and it's deps (explicit include from dep. trumps implicit exclude)
// *:*:-css all except css and its deps (explicit)
// *:*:-css:+effects all except css and its deps (explicit exclude from dep. trumps explicit include)
// *:+effects none except effects and its deps (explicit include from dep. trumps implicit exclude)
this.file.src.forEach(function( filepath ) {
var flag = filepath.flag;

@@ -236,13 +272,37 @@ module.exports = function( grunt ) {

// conditionally concatenate source
this.file.src.forEach(function( filepath ) {
var flag = filepath.flag;
var flag = filepath.flag,
specified = false,
message = "";

if ( flag ) {
if ( excluded[ flag ] !== undefined ) {
log.writeln( "Excluding " + flag + ": '" + filepath.src + "'." );
return;

This comment has been minimized.

Copy link
@mikesherov

mikesherov Jun 13, 2012

Member

@rwldrn, by removing this return, you have removed the ability to do grunt build:*:+effects, that is, the ability to exclude all optional except effects. Please run all the cases I outlined in that big comment on L253, and verify they work.

This comment has been minimized.

Copy link
@mikesherov

mikesherov Jun 13, 2012

Member

also breaks grunt build:* which should remove all optional modules.

This comment has been minimized.

Copy link
@rwaldron

rwaldron Jun 13, 2012

Author Member

I'm not going to be able to get to this until Sunday (maybe?) so feel free to iron it out.

I think you can easily support the same behaviour without modifying this... incidentally, we don't want to make the end dev have to type this: grunt build:*:+effects, so we need a better (easier) way to type this and get the same effect.

grunt build:* is probably a bad way to say "remove all things", "*" is generally zero or more "build zero or more" reads like non-sense in this context

This comment has been minimized.

Copy link
@rwaldron

rwaldron Jun 13, 2012

Author Member

BTW, This wasn't some hair-brained scheme I cooked up on my own, @dmethvin and I discussed this and agreed that we didn't like the ":::" requirement -- before any code was written/changed.

This comment has been minimized.

Copy link
@mikesherov

mikesherov Jun 13, 2012

Member

@rwldrn, wasn't accusing you of any hair-brainedness, I was just reporting what I saw as a bug. I like your custom task a lot. I was just pointing it out. Feel free to act accordingly :-)

message = ( "Excluding " + flag ).red;
specified = true;
} else {
message = ( "Including " + flag ).green;

// If this module was actually specified by the
// builder, then st the flag to include it in the
// output list
if ( modules[ "+" + flag ] ) {
specified = true;
}
}
log.writeln( "Including " + flag + ": '" + filepath.src + "'." );

// Only display the inclusion/exclusion list when handling
// an explicit list.
//
// Additionally, only display modules that have been specified
// by the user
if ( explicit && specified ) {
grunt.log.writetableln([ 27, 30 ], [
message,
( "(" + filepath.src + ")").grey
]);
}

filepath = filepath.src;
}

0 comments on commit f13de6b

Please sign in to comment.
You can’t perform that action at this time.