Skip to content

Commit

Permalink
* gulpfile.js: add notifyError for stream error notification, add `…
Browse files Browse the repository at this point in the history
…seqTask` for sequential task control, fix `project.js` config replacing `lib/` with `src/`

* README.md: detail project hosting [@bitbucket](https://bitbucket.org/jaguard/time-require) & mirror [@github](https://github.com/jaguard/time-require).
* LICENSE.md renamed to LICENSE to keep it as a simple text file
* package.json: changed version to 0.1.1, set the [GitHub](https://github.com/jaguard/time-require) mirror as repository, add `run-sequence` for task order control, add `gulp-notify` for notification support
  • Loading branch information
cyparu committed Apr 10, 2014
1 parent cb19a67 commit fa86106
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
`time-require` changelog
======================

- v0.1.1 (2014.04.10)
* gulpfile.js: add `notifyError` for stream error notification, add `seqTask` for sequential task control, fix `project.js` config replacing `lib/` with `src/`
* README.md: detail project hosting [@BitBucket](https://bitbucket.org/jaguard/time-require) & mirror [@GitHub](https://github.com/jaguard/time-require).
* LICENSE.md renamed to LICENSE to keep it as a simple text file
* package.json: set the [GitHub](https://github.com/jaguard/time-require) mirror as repository, add `run-sequence` for task order control, add `gulp-notify` for notification support
- v0.1.0 (2014.04.10)
+ Added `.travis.yml` file for travis-ci.org build support
+ Published `time-require` module to [npm](https://www.npmjs.org/package/time-require)
Expand Down
File renamed without changes.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
> Displays the execution time for Node.js modules loading by hooking and tracing all `require()` calls.
This module was inspired by [@sindresorhus](https://twitter.com/sindresorhus)'s [time-grunt](https://github.com/sindresorhus/time-grunt).

**NOTE:** The project is hosted [@BitBucket](https://bitbucket.org/jaguard/time-require) but a mirror is available as well [@GitHub](https://github.com/jaguard/time-require).

## Project status
- NPM version: [![NPM version](https://badge.fury.io/js/time-require.svg)](https://www.npmjs.org/package/time-require)
- Travis-CI build: [![Build Status](http://img.shields.io/travis/jaguard/time-require.svg)](http://travis-ci.org/jaguard/time-require)
Expand Down Expand Up @@ -43,18 +45,23 @@ To **sort** the modules according to the loading time (longest on top) use the `

## Documentation

Detailed API documentation can be found in ['doc'](https://bitbucket.org/jaguard/time-require/raw/master/doc/api.md) folder.
Detailed API documentation can be found in ['doc'](https://bitbucket.org/jaguard/time-require/src/master/doc/api.md) folder.

## Development

Detailed development documentation can be found in ['doc'](https://bitbucket.org/jaguard/time-require/raw/master/doc/dev.md) folder.
Detailed development documentation can be found in ['doc'](https://bitbucket.org/jaguard/time-require/src/master/doc/dev.md) folder.

## License

MIT © [Jaguard OSS](http://oss.jaguard.com)
[MIT](https://bitbucket.org/jaguard/time-require/raw/master/LICENSE) © [Jaguard OSS](http://oss.jaguard.com)

## Changelog

- v0.1.1 (2014.04.10)
* gulpfile.js: add `notifyError` for stream error notification, add `seqTask` for sequential task control, fix `project.js` config replacing `lib/` with `src/`
* README.md: detail project hosting [@BitBucket](https://bitbucket.org/jaguard/time-require) & mirror [@GitHub](https://github.com/jaguard/time-require).
* LICENSE.md renamed to LICENSE to keep it as a simple text file
* package.json: set the [GitHub](https://github.com/jaguard/time-require) mirror as repository, add `run-sequence` for task order control, add `gulp-notify` for notification support
- v0.1.0 (2014.04.10)
+ Added `.travis.yml` file for travis-ci.org build support
+ Published `time-require` module to [npm](https://www.npmjs.org/package/time-require)
Expand Down
41 changes: 35 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@

var gulp = require("gulp"), // http://gulpjs.com
$ = require("gulp-load-plugins")(), // lazy loading plugins: https://github.com/jackfranklin/gulp-load-plugins
sequence = require("run-sequence"), // specify run order https://github.com/OverZealous/run-sequence
gutil = require("gulp-util"), // https://github.com/gulpjs/gulp
log = gutil.log,
colors = gutil.colors,
// watching flag
watching = false,
// project config
/* jshint -W015 */
project = {
js: ["*.js", "lib/**/*.js", "test/**/*.js"], // include JavaScript files
js: ["*.js", "src/**/*.js", "test/**/*.js"], // include JavaScript files
specs: ["test/**/*.spec.js"], // include JavaScript files
md: ["*.md", "doc/*.md"], // include all markdown files
json: ["*.json", ".*rc"], // include all json and rc files
Expand All @@ -36,6 +38,22 @@ function cache(name) {
return $.if(watching, $.cached(name));
}

/**
* Add error notification for the specified stream using the type as a title prefix
*/
function notifyError(stream, type) {
stream.on("error", function(err) {
var title = type + " error",
message = err.message;
log(colors.red(title) + ": " + colors.yellow(message));
$.notify({
title: title,
message: message
});
});
return stream;
}

/**
* Wrap src to automatically set the base to current working directory
*/
Expand All @@ -52,6 +70,17 @@ function task(name, deps, fn) {
return gulp.task(name, deps, fn);
}

/**
* Wrap gulp.task usage for sequencial execution for more expressive usage
*/
function seqTask(name) {
var tasks = Array.prototype.slice.call(arguments, 1);
task(name, function(cb) { // run the tasks in the specified order
tasks.push(cb);
sequence.apply(undefined, tasks);
});
}

/**
* Wrap gulp.watch with file change reporting and watching flag setting for triggered tasks
*/
Expand All @@ -62,7 +91,7 @@ function watch(glob, opt, fn) {
// set watching flag
watching = true;
// log the change
log("The file " + gutil.colors.yellow(event.path) + " was " + gutil.colors.green(event.type));
log("The file " + colors.yellow(event.path) + " was " + colors.green(event.type));
});
return watcher;
}
Expand All @@ -84,15 +113,15 @@ task("jshint", function() {
.pipe(cache("js")) // enable caching just when watching
.pipe($.jshint())
.pipe($.jshint.reporter("jshint-stylish"))
.pipe($.if(!watching, $.jshint.reporter("fail"))); // fail if not running under watcher
.pipe($.if(!watching, notifyError($.jshint.reporter("fail"), "JSHint"))); // fail if not running under watcher
});

// define "jscs" task for JavaScript code style constraints
task("jscs", function() {
log("Linting JavaScript files");
return src(project.js)
.pipe(cache("jscs")) // enable caching just when watching
.pipe($.jscs());
.pipe(notifyError($.jscs(), "JSCS"));
});

// define "jsonlint" task for JSON linting
Expand Down Expand Up @@ -144,7 +173,7 @@ task("test", function() {
log("Execute Jasmine tests/specs");
return src(project.specs)
.pipe(cache("specs")) // enable caching just when watching
.pipe($.jasmine({ verbose: true }));
.pipe(notifyError($.jasmine({ verbose: true }),"Jasmine"));
});

// define "watch" task to start watch/interactive development mode
Expand All @@ -158,7 +187,7 @@ task("watch", function() {
// define top tasks & aliases
task("lint", ["jsonlint", "jshint", "jscs"]);
task("doc", ["jsdoc", "docco", "md"]); // TODO: "mdpdf" removed, pdf generation will block
task("build", ["lint", "test", "doc"]);
seqTask("build", "clean", "lint", "test", "doc"); // run sequentially

// define default task
task("default", ["build"]);
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
{
"name": "time-require",
"version": "0.1.0",
"version": "0.1.1",
"description": "Displays the execution time for Node.js modules loading; inspired by @sindresorhus 'time-grunt'",
"url": "https://bitbucket.org/jaguard/time-require",
"homepage": "https://bitbucket.org/jaguard/time-require",
"keywords": ["require", "measure", "time", "profile"],
"author": {
Expand All @@ -12,7 +11,7 @@
},
"repository": {
"type": "git",
"url": "git://bitbucket.org/jaguard/time-require"
"url": "git://github.com/jaguard/time-require"
},
"bugs": {
"url": "https://bitbucket.org/jaguard/time-require/issues"
Expand All @@ -32,6 +31,7 @@
"gulp": "~3.6.0",
"gulp-util": "~2.2.14",
"gulp-load-plugins": "~0.5.0",
"run-sequence": "~0.3.6",
"gulp-clean": "~0.2.4",
"gulp-cached": "~0.0.3",
"gulp-jshint": "~1.5.2",
Expand All @@ -44,12 +44,13 @@
"gulp-markdown-pdf": "~0.2.0",
"gulp-jsdoc": "~0.1.2",
"gulp-jasmine": "~0.2.0",
"gulp-notify": "~1.2.5",
"jshint-stylish": "~0.1.5"
},
"licenses": [
{
"type": "MIT",
"url": "https://bitbucket.org/jaguard/time-require/raw/master/LICENSE.md"
"url": "https://bitbucket.org/jaguard/time-require/raw/master/LICENSE"
}
],
"engines": {
Expand Down

0 comments on commit fa86106

Please sign in to comment.