Skip to content

Commit

Permalink
move logging to gulp-util, use gulp-util for pretty times. templating…
Browse files Browse the repository at this point in the history
… now exists in gulp-util
  • Loading branch information
Contra committed Dec 4, 2013
1 parent 2b9936d commit 7c7ce92
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 78 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# gulp changelog

## 2.4 - 2.6

- Moved stuff to gulp-util
- Quit exposing createGlobStream (just use the glob-stream module)
- More logging
- Prettier time durations
- Tons of documentation changes
- gulp.trigger(tasks...) as a through stream

## 1.2-2.4 (11/12/13)

- src buffer=false fixed for 0.8 and 0.9 (remember to .resume() on these versions before consuming)
Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ gulp.task('somename', ['array','of','task','names'], function(){
});
```

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.

##### Async tasks

With callbacks:
Expand Down Expand Up @@ -216,7 +218,7 @@ gulp.watch("js/**/*.js", function(event){
### gulp.env
gulp.env is an optimist arguments object. Running `gulp test dostuff --production` will yield `{_:["test","dostuff"],production:true}`
gulp.env is an optimist arguments object. Running `gulp test dostuff --production` will yield `{_:["test","dostuff"],production:true}`. Plugins don't use this.
## gulp cli
Expand Down Expand Up @@ -278,12 +280,14 @@ gulp.src('./client/scripts/*.js')
## Plugin Guidelines
1. file.contents should always go out the same way it came in
2. Do not pass the file object downstream until you are done with it
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
4. Use gulp.log when you need to log messages
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.
6. Do not throw errors. Emit them from the stream (or pass them to the callback if using event-stream's .map).
7. Add "gulpplugin" as a keyword in your package.json so you show up on our search
- Respect buffered, streaming, and non-read files as well as folders!
1. Do not pass the file object downstream until you are done with it
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
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.
1. Do not throw errors. Emit them from the stream (or pass them to the callback if using event-stream's .map).
1. Add "gulpplugin" as a keyword in your package.json so you show up on our search
If you don't follow these guidelines and somebody notices your plugin will be shitlisted from the ecosystem.
## LICENSE
Expand Down
23 changes: 11 additions & 12 deletions bin/gulp.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ var path = require('path');
var fs = require('fs');

var argv = require('optimist').argv;
var chalk = require('chalk');
var resolve = require('resolve');
var findup = require('findup-sync');
var gutil = require('gulp-util');

var tasks = argv._;
var cliPkg = require('../package.json');
var cliGulp = require('../');

var localBaseDir = process.cwd();

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

if (!gulpFile) {
cliGulp.log(chalk.red('No Gulpfile found'));
gutil.log(gutil.colors.red('No Gulpfile found'));
process.exit(1);
}

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

// print some versions and shit
if (argv.v || argv.version) {
cliGulp.log('CLI version', cliPkg.version);
gutil.log('CLI version', cliPkg.version);
if (localGulp) {
cliGulp.log('Local version', localPkg.version);
gutil.log('Local version', localPkg.version);
}
process.exit(0);
}

if (!localGulp) {
cliGulp.log(chalk.red('No local gulp install found in'), getLocalBase(gulpFile));
cliGulp.log(chalk.red('You need to npm install it first'));
gutil.log(gutil.colors.red('No local gulp install found in'), getLocalBase(gulpFile));
gutil.log(gutil.colors.red('You need to npm install it first'));
process.exit(1);
}

// Mix CLI flags into gulp
localGulp.env = argv;
localGulp.env = gutil.env;

// Load their gulpfile and run it
cliGulp.log('Using file', chalk.magenta(gulpFile));
gutil.log('Using file', gutil.colors.magenta(gulpFile));
loadGulpFile(localGulp, gulpFile, tasks);

function loadRequires(requires, baseDir) {
if (typeof requires === 'undefined') requires = [];
if (!Array.isArray(requires)) requires = [requires];
return requires.map(function(modName){
cliGulp.log('Requiring external module', chalk.magenta(modName));
gutil.log('Requiring external module', gutil.colors.magenta(modName));
var mod = findLocalModule(modName, baseDir);
if (typeof mod === 'undefined') {
cliGulp.log('Failed to load external module', chalk.magenta(modName))
gutil.log('Failed to load external module', gutil.colors.magenta(modName));
}
});
}
Expand Down Expand Up @@ -90,7 +89,7 @@ function findLocalGulpPackage(gulpFile){
function loadGulpFile(localGulp, gulpFile, tasks){
var gulpFileCwd = path.dirname(gulpFile);
process.chdir(gulpFileCwd);
cliGulp.log('Working directory changed to', chalk.magenta(gulpFileCwd));
gutil.log('Working directory changed to', gutil.colors.magenta(gulpFileCwd));

var theGulpfile = require(gulpFile);

Expand Down
21 changes: 7 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

var util = require('util');
var Orchestrator = require('orchestrator');
var chalk = require('chalk');
var gutil = require('gulp-util');

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

// Logging
this.on('task_start', function(e){
gulp.log('Running', "'"+chalk.cyan(e.task)+"'...");
gutil.log('Running', "'"+gutil.colors.cyan(e.task)+"'...");
});
this.on('task_stop', function(e){
gulp.log('Finished', "'"+chalk.cyan(e.task)+"' in "+chalk.magenta(e.duration)+" seconds");
var time = gutil.prettyTime(e.duration);
gutil.log('Finished', "'"+gutil.colors.cyan(e.task)+"'", "in", gutil.colors.magenta(time.value), time.shortUnit);
});

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

Gulp.prototype.log = function(){
if (this.env.silent) return;
var sig = '['+chalk.green('gulp')+']';
var args = Array.prototype.slice.call(arguments);
args.unshift(sig);
console.log.apply(console, args);
return this;
};

Gulp.prototype.taskQueue = Gulp.prototype.seq;
Gulp.prototype.task = Gulp.prototype.add;
Gulp.prototype.run = function(){
var tasks = Array.prototype.slice.call(arguments);

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

Gulp.prototype.createGlobStream = require('glob-stream').create;
Gulp.prototype.formatFile = require('./lib/formatFile');
Gulp.prototype.bufferFile = require('./lib/bufferFile');
Gulp.prototype.streamFile = require('./lib/streamFile');
Expand Down
92 changes: 47 additions & 45 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
{
"name":"gulp",
"description":"The streaming build system",
"version":"2.6.0",
"homepage":"http://github.com/wearefractal/gulp",
"repository":"git://github.com/wearefractal/gulp.git",
"author":"Fractal <[email protected]> (http://wearefractal.com/)",
"main":"./index.js",
"preferGlobal":true,
"tags":["build","stream","system"],

"bin":{
"gulp":"./bin/gulp.js"
},
"dependencies":{
"event-stream":"3.0.x",
"glob-stream":"0.1.x",
"mkdirp":"0.3.x",
"optimist":"0.6.x",
"gulp-util":"1.0.x",
"gaze":"0.4.x",
"orchestrator": "0.1.x",
"chalk":"0.3.x",
"resolve":"0.6.x",
"semver":"2.2.x",
"findup-sync":"0.1.x"
},
"devDependencies":{
"mocha":"*",
"should":"*",
"rimraf":"*",
"q": "*",
"jshint": "*"
},
"scripts":{
"test":"mocha && jshint"
},
"engines":{
"node":">= 0.7"
},
"licenses":[
{
"type":"MIT",
"url":"http://github.com/wearefractal/gulp/raw/master/LICENSE"
}
]
"name": "gulp",
"description": "The streaming build system",
"version": "2.6.1",
"homepage": "http://github.com/wearefractal/gulp",
"repository": "git://github.com/wearefractal/gulp.git",
"author": "Fractal <[email protected]> (http://wearefractal.com/)",
"main": "./index.js",
"preferGlobal": true,
"tags": [
"build",
"stream",
"system"
],
"bin": {
"gulp": "./bin/gulp.js"
},
"dependencies": {
"event-stream": "~3.0.16",
"glob-stream": "~0.1.0",
"mkdirp": "~0.3.5",
"optimist": "~0.6.0",
"gulp-util": "~1.1.1",
"gaze": "~0.4.3",
"orchestrator": "~0.1.0",
"resolve": "~0.6.1",
"semver": "~2.2.1",
"findup-sync": "~0.1.2"
},
"devDependencies": {
"mocha": "*",
"should": "*",
"rimraf": "*",
"q": "*",
"jshint": "*"
},
"scripts": {
"test": "mocha && jshint"
},
"engines": {
"node": ">= 0.7"
},
"licenses": [
{
"type": "MIT",
"url": "http://github.com/wearefractal/gulp/raw/master/LICENSE"
}
]
}

0 comments on commit 7c7ce92

Please sign in to comment.