Skip to content

Commit 7c7ce92

Browse files
author
Contra
committed
move logging to gulp-util, use gulp-util for pretty times. templating now exists in gulp-util
1 parent 2b9936d commit 7c7ce92

File tree

5 files changed

+85
-78
lines changed

5 files changed

+85
-78
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# gulp changelog
22

3+
## 2.4 - 2.6
4+
5+
- Moved stuff to gulp-util
6+
- Quit exposing createGlobStream (just use the glob-stream module)
7+
- More logging
8+
- Prettier time durations
9+
- Tons of documentation changes
10+
- gulp.trigger(tasks...) as a through stream
11+
312
## 1.2-2.4 (11/12/13)
413

514
- src buffer=false fixed for 0.8 and 0.9 (remember to .resume() on these versions before consuming)

README.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ gulp.task('somename', ['array','of','task','names'], function(){
149149
});
150150
```
151151

152+
If the dependencies are asynchronous, it is not guaranteed that they will finish before `'somename'` is executed. To ensure they are completely finished, you need to make sure the dependency tasks have asynchronous support through one of the methods outlined below. The most simple method is to return the stream. By returning the stream, Orchestrator is able to listen for the end event and only run `'somename'` once each dependencies' stream end event has been emitted.
153+
152154
##### Async tasks
153155

154156
With callbacks:
@@ -216,7 +218,7 @@ gulp.watch("js/**/*.js", function(event){
216218
217219
### gulp.env
218220
219-
gulp.env is an optimist arguments object. Running `gulp test dostuff --production` will yield `{_:["test","dostuff"],production:true}`
221+
gulp.env is an optimist arguments object. Running `gulp test dostuff --production` will yield `{_:["test","dostuff"],production:true}`. Plugins don't use this.
220222
221223
## gulp cli
222224
@@ -278,12 +280,14 @@ gulp.src('./client/scripts/*.js')
278280
## Plugin Guidelines
279281
280282
1. file.contents should always go out the same way it came in
281-
2. Do not pass the file object downstream until you are done with it
282-
3. Make use of the gulp-util library. Do you need to change a file's extension or do some tedious path crap? Try looking there first and add it if it doesn't exist
283-
4. Use gulp.log when you need to log messages
284-
5. Remember: Your plugin should only do one thing! It should not have a complex config object that makes it do multiple things. It should not concat and add headers/footers. This is not grunt. Keep it simple.
285-
6. Do not throw errors. Emit them from the stream (or pass them to the callback if using event-stream's .map).
286-
7. Add "gulpplugin" as a keyword in your package.json so you show up on our search
283+
- Respect buffered, streaming, and non-read files as well as folders!
284+
1. Do not pass the file object downstream until you are done with it
285+
1. Make use of the gulp-util library. Templating, CLI colors, logging. Do you need to change a file's extension or do some tedious fs crap? Try looking there first and add it if it doesn't exist
286+
1. Remember: Your plugin should only do one thing! It should not have a complex config object that makes it do multiple things. It should not concat and add headers/footers. This is not grunt. Keep it simple.
287+
1. Do not throw errors. Emit them from the stream (or pass them to the callback if using event-stream's .map).
288+
1. Add "gulpplugin" as a keyword in your package.json so you show up on our search
289+
290+
If you don't follow these guidelines and somebody notices your plugin will be shitlisted from the ecosystem.
287291
288292
## LICENSE
289293

bin/gulp.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ var path = require('path');
44
var fs = require('fs');
55

66
var argv = require('optimist').argv;
7-
var chalk = require('chalk');
87
var resolve = require('resolve');
98
var findup = require('findup-sync');
9+
var gutil = require('gulp-util');
1010

1111
var tasks = argv._;
1212
var cliPkg = require('../package.json');
13-
var cliGulp = require('../');
1413

1514
var localBaseDir = process.cwd();
1615

@@ -19,7 +18,7 @@ loadRequires(argv.require, localBaseDir);
1918
var gulpFile = getGulpFile(localBaseDir);
2019

2120
if (!gulpFile) {
22-
cliGulp.log(chalk.red('No Gulpfile found'));
21+
gutil.log(gutil.colors.red('No Gulpfile found'));
2322
process.exit(1);
2423
}
2524

@@ -29,34 +28,34 @@ var localPkg = findLocalGulpPackage(gulpFile);
2928

3029
// print some versions and shit
3130
if (argv.v || argv.version) {
32-
cliGulp.log('CLI version', cliPkg.version);
31+
gutil.log('CLI version', cliPkg.version);
3332
if (localGulp) {
34-
cliGulp.log('Local version', localPkg.version);
33+
gutil.log('Local version', localPkg.version);
3534
}
3635
process.exit(0);
3736
}
3837

3938
if (!localGulp) {
40-
cliGulp.log(chalk.red('No local gulp install found in'), getLocalBase(gulpFile));
41-
cliGulp.log(chalk.red('You need to npm install it first'));
39+
gutil.log(gutil.colors.red('No local gulp install found in'), getLocalBase(gulpFile));
40+
gutil.log(gutil.colors.red('You need to npm install it first'));
4241
process.exit(1);
4342
}
4443

4544
// Mix CLI flags into gulp
46-
localGulp.env = argv;
45+
localGulp.env = gutil.env;
4746

4847
// Load their gulpfile and run it
49-
cliGulp.log('Using file', chalk.magenta(gulpFile));
48+
gutil.log('Using file', gutil.colors.magenta(gulpFile));
5049
loadGulpFile(localGulp, gulpFile, tasks);
5150

5251
function loadRequires(requires, baseDir) {
5352
if (typeof requires === 'undefined') requires = [];
5453
if (!Array.isArray(requires)) requires = [requires];
5554
return requires.map(function(modName){
56-
cliGulp.log('Requiring external module', chalk.magenta(modName));
55+
gutil.log('Requiring external module', gutil.colors.magenta(modName));
5756
var mod = findLocalModule(modName, baseDir);
5857
if (typeof mod === 'undefined') {
59-
cliGulp.log('Failed to load external module', chalk.magenta(modName))
58+
gutil.log('Failed to load external module', gutil.colors.magenta(modName));
6059
}
6160
});
6261
}
@@ -90,7 +89,7 @@ function findLocalGulpPackage(gulpFile){
9089
function loadGulpFile(localGulp, gulpFile, tasks){
9190
var gulpFileCwd = path.dirname(gulpFile);
9291
process.chdir(gulpFileCwd);
93-
cliGulp.log('Working directory changed to', chalk.magenta(gulpFileCwd));
92+
gutil.log('Working directory changed to', gutil.colors.magenta(gulpFileCwd));
9493

9594
var theGulpfile = require(gulpFile);
9695

index.js

+7-14
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
var util = require('util');
66
var Orchestrator = require('orchestrator');
7-
var chalk = require('chalk');
7+
var gutil = require('gulp-util');
88

99
// format orchestrator errors
1010
var formatError = function(e) {
@@ -19,33 +19,27 @@ function Gulp(){
1919

2020
// Logging
2121
this.on('task_start', function(e){
22-
gulp.log('Running', "'"+chalk.cyan(e.task)+"'...");
22+
gutil.log('Running', "'"+gutil.colors.cyan(e.task)+"'...");
2323
});
2424
this.on('task_stop', function(e){
25-
gulp.log('Finished', "'"+chalk.cyan(e.task)+"' in "+chalk.magenta(e.duration)+" seconds");
25+
var time = gutil.prettyTime(e.duration);
26+
gutil.log('Finished', "'"+gutil.colors.cyan(e.task)+"'", "in", gutil.colors.magenta(time.value), time.shortUnit);
2627
});
2728

2829
this.on('task_err', function(e){
2930
var msg = formatError(e);
30-
gulp.log('Errored', "'"+chalk.cyan(e.task)+"' in "+chalk.magenta(e.duration)+" seconds "+chalk.red(msg));
31+
var time = gutil.prettyTime(e.duration);
32+
gutil.log('Errored', "'"+gutil.colors.cyan(e.task)+"'", "in", gutil.colors.magenta(time.value), time.shortUnit, gutil.colors.red(msg));
3133
});
3234
}
3335
util.inherits(Gulp, Orchestrator);
3436

35-
Gulp.prototype.log = function(){
36-
if (this.env.silent) return;
37-
var sig = '['+chalk.green('gulp')+']';
38-
var args = Array.prototype.slice.call(arguments);
39-
args.unshift(sig);
40-
console.log.apply(console, args);
41-
return this;
42-
};
43-
4437
Gulp.prototype.taskQueue = Gulp.prototype.seq;
4538
Gulp.prototype.task = Gulp.prototype.add;
4639
Gulp.prototype.run = function(){
4740
var tasks = Array.prototype.slice.call(arguments);
4841

42+
// impose our opinion of "default" tasks onto orchestrator
4943
if (!tasks.length) {
5044
tasks = ['default'];
5145
}
@@ -56,7 +50,6 @@ Gulp.prototype.src = require('./lib/createInputStream');
5650
Gulp.prototype.dest = require('./lib/createOutputStream');
5751
Gulp.prototype.watch = require('./lib/watchFile');
5852

59-
Gulp.prototype.createGlobStream = require('glob-stream').create;
6053
Gulp.prototype.formatFile = require('./lib/formatFile');
6154
Gulp.prototype.bufferFile = require('./lib/bufferFile');
6255
Gulp.prototype.streamFile = require('./lib/streamFile');

package.json

+47-45
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,49 @@
11
{
2-
"name":"gulp",
3-
"description":"The streaming build system",
4-
"version":"2.6.0",
5-
"homepage":"http://github.com/wearefractal/gulp",
6-
"repository":"git://github.com/wearefractal/gulp.git",
7-
"author":"Fractal <[email protected]> (http://wearefractal.com/)",
8-
"main":"./index.js",
9-
"preferGlobal":true,
10-
"tags":["build","stream","system"],
11-
12-
"bin":{
13-
"gulp":"./bin/gulp.js"
14-
},
15-
"dependencies":{
16-
"event-stream":"3.0.x",
17-
"glob-stream":"0.1.x",
18-
"mkdirp":"0.3.x",
19-
"optimist":"0.6.x",
20-
"gulp-util":"1.0.x",
21-
"gaze":"0.4.x",
22-
"orchestrator": "0.1.x",
23-
"chalk":"0.3.x",
24-
"resolve":"0.6.x",
25-
"semver":"2.2.x",
26-
"findup-sync":"0.1.x"
27-
},
28-
"devDependencies":{
29-
"mocha":"*",
30-
"should":"*",
31-
"rimraf":"*",
32-
"q": "*",
33-
"jshint": "*"
34-
},
35-
"scripts":{
36-
"test":"mocha && jshint"
37-
},
38-
"engines":{
39-
"node":">= 0.7"
40-
},
41-
"licenses":[
42-
{
43-
"type":"MIT",
44-
"url":"http://github.com/wearefractal/gulp/raw/master/LICENSE"
45-
}
46-
]
2+
"name": "gulp",
3+
"description": "The streaming build system",
4+
"version": "2.6.1",
5+
"homepage": "http://github.com/wearefractal/gulp",
6+
"repository": "git://github.com/wearefractal/gulp.git",
7+
"author": "Fractal <[email protected]> (http://wearefractal.com/)",
8+
"main": "./index.js",
9+
"preferGlobal": true,
10+
"tags": [
11+
"build",
12+
"stream",
13+
"system"
14+
],
15+
"bin": {
16+
"gulp": "./bin/gulp.js"
17+
},
18+
"dependencies": {
19+
"event-stream": "~3.0.16",
20+
"glob-stream": "~0.1.0",
21+
"mkdirp": "~0.3.5",
22+
"optimist": "~0.6.0",
23+
"gulp-util": "~1.1.1",
24+
"gaze": "~0.4.3",
25+
"orchestrator": "~0.1.0",
26+
"resolve": "~0.6.1",
27+
"semver": "~2.2.1",
28+
"findup-sync": "~0.1.2"
29+
},
30+
"devDependencies": {
31+
"mocha": "*",
32+
"should": "*",
33+
"rimraf": "*",
34+
"q": "*",
35+
"jshint": "*"
36+
},
37+
"scripts": {
38+
"test": "mocha && jshint"
39+
},
40+
"engines": {
41+
"node": ">= 0.7"
42+
},
43+
"licenses": [
44+
{
45+
"type": "MIT",
46+
"url": "http://github.com/wearefractal/gulp/raw/master/LICENSE"
47+
}
48+
]
4749
}

0 commit comments

Comments
 (0)