Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cyparu committed Apr 10, 2014
0 parents commit bf304c5
Show file tree
Hide file tree
Showing 16 changed files with 630 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# ignore Node submodules & temp
node_modules
target

# ignore editor files
.brackets.json
16 changes: 16 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"preset": "jquery",
"disallowLeftStickedOperators": ["?", "+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
"disallowRightStickedOperators": ["?", "+", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
"requireParenthesesAroundIIFE": true,
"disallowSpacesInsideArrayBrackets": true,
"requireSpacesInsideArrayBrackets": null,
"disallowImplicitTypeConversion": ["string"],
"disallowEmptyBlocks": true,
"disallowSpacesInsideParentheses": true,
"validateJSDoc": {
"checkParamNames": true,
"checkRedundantParams": true,
"requireParamTypes": true
}
}
18 changes: 18 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"indent": 2,
"node": true,
"browser": false,
"bitwise": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true
}
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# ignore Node submodules & temp
node_modules
target

# ignore editor files
.brackets.json
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
`time-require` changelog
======================

- v0.0.1 (2014.03.10)
+ Initial release
20 changes: 20 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2014 Jaguard
MIT License - http://opensource.org/licenses/mit-license.php

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# `time-require` @ [![Jaguard OSS 100%](http://img.shields.io/badge/Jaguard_OSS-100%-red.svg)](http://oss.jaguard.com) [![Built with gulp.js](http://img.shields.io/badge/built%20with-gulp.js-red.svg)](http://gulpjs.com)

> 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).

## 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)
- Drone.io build: [![Build Status](https://drone.io/github.com/jaguard/time-require/status.png)](https://drone.io/github.com/jaguard/time-require/latest)
- Dependencies: [![Dependencies status](https://david-dm.org/jaguard/time-require/status.svg?theme=shields.io)](https://david-dm.org/jaguard/time-require#info=dependencies)
- Dev Dependencies: [![Dev Dependencies status](https://david-dm.org/jaguard/time-require/dev-status.svg?theme=shields.io)](https://david-dm.org/jaguard/time-require#info=devDependencies)

Default usage (non-verbose) showing required modules in loaded order, above 1% treshold
![default](doc/time_require_default.png)

Verbose (all) & sorted usage showing all required modules in sorted order
![verbose-sorted](doc/time_require_verbose_sorted.png)

## Install

Install with [npm](https://npmjs.org/package/time-require)

```
npm install --save time-require
```

## Usage

Embeded usage, generally as first `require()` call in your main module).
```js
require("time-require");
```
External usage with `--require` preload supported by [Liftoff](https://github.com/tkellen/node-liftoff) driven CLI modules like [gulp.js](http://gulpjs.com/) or [Grunt-Next](https://github.com/gruntjs/grunt-next)
```
gulp --require time-require --sorted
```

## Display layout

Modules loading that take less than `1%` of the total time are hidden to reduce clutter.
To show **all** the modules use the `--verbose` (or `--V`) flag on the running CLI.
To **sort** the modules according to the loading time (longest on top) use the `--sorted` (or `--s`) flag on the running CLI.

## Documentation

Detailed API documentation can be found in ['doc'](doc/api.md) folder.

## Development

Detailed development documentation can be found in ['doc'](doc/dev.md) folder.

## License

MIT © [Jaguard OSS](http://oss.jaguard.com)

## Changelog

- v0.0.1 (2014.03.10)
+ Initial release
3 changes: 3 additions & 0 deletions doc/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## API documentation for time-require

TODO: Detail usage
32 changes: 32 additions & 0 deletions doc/dev.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## Developer documentation for `time-require`

`time-require` use [gulp.js](http://gulpjs.com) for build

#### clean
```
gulp clean
```
#### build
```
gulp
```
or explicitelly
```
gulp build
```
#### run tests
```
gulp test
```
#### lint all sources
```
gulp lint
```
#### generate documentation
```
gulp doc
```
#### watch
```
gulp watch
```
Binary file added doc/time_require_default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/time_require_verbose_sorted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
164 changes: 164 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/**
* gulpfile - Include gulp.js build tasks definitions
*
* @author Ciprian Popa (cyparu)
* @since 0.0.1
* @version 0.0.1
*/

"use strict";

var gulp = require("gulp"), // http://gulpjs.com
$ = require("gulp-load-plugins")(), // lazy loading plugins: https://github.com/jackfranklin/gulp-load-plugins
gutil = require("gulp-util"), // https://github.com/gulpjs/gulp
log = gutil.log,
// watching flag
watching = false,
// project config
/* jshint -W015 */
project = {
js: ["*.js", "lib/**/*.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
tmp: "target", // target directory
dist: "dist" // dist directory
};

// --------------------
// helper functions
// --------------------

/**
* Pipe a cache with the specified name just if the current task was triggered by the watcher
*/
function cache(name) {
return $.if(watching, $.cached(name));
}

/**
* Wrap src to automatically set the base to current working directory
*/
function src(glob, opt) {
opt = opt || {};
opt.base = opt.base || process.cwd();
return gulp.src(glob, opt);
}

/**
* Wrap gulp.task for more expressive usage
*/
function task(name, deps, fn) {
return gulp.task(name, deps, fn);
}

/**
* Wrap gulp.watch with file change reporting and watching flag setting for triggered tasks
*/
function watch(glob, opt, fn) {
var watcher = gulp.watch(glob, opt, fn);
// show change
watcher.on("change", function(event) {
// set watching flag
watching = true;
// log the change
log("The file " + gutil.colors.yellow(event.path) + " was " + gutil.colors.green(event.type));
});
return watcher;
}

// --------------------
// tasks
// --------------------

// define "clean" task for cleaning all the generated and temporary files
task("clean", function() {
log("Remove temporary files");
return src(project.tmp, { read: false }).pipe($.clean());
});

// define "jslint" task for JavaScript linting
task("jshint", function() {
log("Linting JavaScript files");
return src(project.js)
.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
});

// 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());
});

// define "jsonlint" task for JSON linting
task("jsonlint", function() {
log("Linting JSON files");
return src(project.json)
.pipe(cache("json")) // enable caching just when watching
.pipe($.jsonlint())
.pipe($.jsonlint.reporter());
});

// define "md" task for HTML generation from .md files
task("md", function() {
log("Generating HTML documentation from Markdown files");
return src(project.md, { base: process.cwd() })
.pipe(cache("md")) // enable caching just when watching
.pipe($.markdown())
.pipe(gulp.dest(project.tmp + "/doc/html"));
});

// define "mdpdf" task for PDF generation from .md files
task("mdpdf", function() {
log("Generating PDF documentation from Markdown files");
return src(project.md, { base: process.cwd() })
.pipe(cache("md-pdf")) // enable caching just when watching
.pipe($.markdownPdf())
.pipe(gulp.dest(project.tmp + "/doc/pdf"));
});

// define "docco" task for annotated source code documentation
task("docco", function() {
log("Generating Docco annotated documentation for JavaScript files");
return src(project.js, { base: process.cwd() })
.pipe(cache("docco")) // enable caching just when watching
.pipe($.docco({ layout: "classic" }))
.pipe(gulp.dest(project.tmp + "/doc/js/source"));
});

// define "jsdoc" task for API source code documentation
task("jsdoc", function() {
log("Generating JSDoc3 API documentation for JavaScript files");
return src(project.js, { base: process.cwd() })
.pipe(cache("jdoc")) // enable caching just when watching
.pipe($.jsdoc(project.tmp + "/doc/js/api"));
});

// define "test" for Jasmine testing
task("test", function() {
log("Execute Jasmine tests/specs");
return src(project.specs)
.pipe(cache("specs")) // enable caching just when watching
.pipe($.jasmine({ verbose: true }));
});

// define "watch" task to start watch/interactive development mode
task("watch", function() {
log("Watching project files...");
watch(project.js, ["jshint", "jscs"]);
watch(project.json, ["jsonlint"]);
watch(project.specs, ["test"]);
});

// 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"]);

// define default task
task("default", ["build"]);
Loading

0 comments on commit bf304c5

Please sign in to comment.