manland / draw-my-project

A grunt plugin that draws your javascript project dependencies.
http://manland.github.io/draw-my-project
MIT License
4 stars 1 forks source link

grunt-draw-my-project

A grunt plugin that draws your javascript project dependencies.

Getting Started

This plugin requires Grunt ~0.4.2

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin by add this line in your package.json :

...
devDependencies: {
   ...
   "grunt-draw-my-project": "git://github.com/manland/draw-my-project.git"
   ...
}
...

And make a :

npm install

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-draw-my-project');

The "draw_my_project" task

Overview

In your project's Gruntfile, add a section named draw_my_project to the data object passed into grunt.initConfig().

grunt.initConfig({
  draw_my_project: {
    options: {
      // Task-specific options go here.
    },
    your_target: {
      // Target-specific file lists and/or options go here.
    },
  },
});

Options

options.type

Type: String Default value: angularjs Accepted values : angularjs, requirejs, nodejs, 'java'

A string value that is used to find node and dependecies type.

options.nbNodeByFile

Type: Int Default value: 1 Special value: -1 infinite search

An int to indicate the number of node who can be found in a file. In most case, one file have one class declaration, but for minified files all dependencies are in one file, so you must set this number to -1.

options.pathSeparator

Type: String Default value: /

A string value to indicate the path separator. Permit to aggregate same classes in the final graph. If options.type === angularjs and options.sortByAngularType === true all classes are grouped by service, factory, directive, controller or filter.

options.sortByAngularType

Type: Boolean Default value: true Ignored if options.type is not angularjs

A boolean value to indicate if classes must be grouped by service, factory, directive, controller or filter.

options.checkAngularjsInject

Type: Boolean Default value: false Ignored if options.type is not angularjs

A boolean value to indicate if $inject is used in the project (due to performance issue you must enable this option).

options.title

Type: String Default value: Draw my project

A string value that is used in title of html result page.

options.description

Type: String Default value: Draw your project dependencies !

A string value that is used in description of html result page.

options.favicon

Type: String Default value: assets/img/logo.png

A string value that is used in favicon of html result page.

options.link

Type: String Default value: https://github.com/manland/draw-my-project

A string value that is used to link in header.

options.urlLogo

Type: String Default value: assets/img/logo.png

A string value that is used in src of img header.

options.advices

Type: Object Default value: all advices Special value: false no advice

Advices :

All advices can have a configured gravityLevel set to 0 (not serious), 1 (significant) or 2 (hot). For example to put controllerImports to notSerious advice just add to your options :

options: {
  advices: {
    filenameChecker: {
      gravityLevel: 0
    }
  }
}

To desable fileClassName and tooInjectDependencies advices, or to configure filenameChecker for service end with Service instead of Srv and all directives start with draw (to avoid collision name) just put :

options: {
  advices: {
    fileClassName: false,
    tooInjectDependencies: false,
    filenameChecker: {
      prefix: {
        'directive': 'draw'
      },
      suffix: {
        'service': 'Service'
      }
    }
  }
}

options.source

Type: Object Default value: { srcInCode : false } Special value: false no source

An object to configure source generation. By default, it create a file for each source, and download it runtime (be carefull when you access to file:// with chrome doesn't permit to download source).

For a little project you can set { srcInCode : true } to take source with the generate site (and so avoid chrome security).

Usage Examples

Default Options

In this example, the default options are used. So if the app.js file is a simple AngularJs project with one Controller, the generated result should show a one wheel dependencies with one dependence.

grunt.initConfig({
  draw_my_project: {
    options: {},
    your_target: {
      files: {
        'dest/default_options': ['src/app.js'],
      }
    }
  },
});

Custom Options

In this example, custom options are used to generate dependencies. So if the minified.js file is a RequireJs project with all dependencies. The generated result should show a wheel dependencies with all dependences.

grunt.initConfig({
  draw_my_project: {
    options: {
      type: 'requirejs',
      nbNodeByFile: '-1',
      title: 'My project title',
      description: 'My project can do anything !'
    },
    your_target: {
      files: {
        'dest/default_options': ['src/minified.js'],
      }
    }
  },
});

Custom Options

In this example, custom options are used to generate dependencies. So if the *.js files are RequireJs project with all dependencies. The generated result should show a wheel dependencies with all dependences.

grunt.initConfig({
  draw_my_project: {
    options: {
      type: 'requirejs',
      nbNodeByFile: '-1',
      title: 'My project title',
      description: 'My project can do anything !'
    },
    your_target: {
      files: {
        'dest/default_options': ['src/**/*.js'],
      }
    }
  },
});

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

0.5.2

0.5.1

0.5.0

0.4.0

0.3.4

0.3.3

0.3.2

0.3.1

0.3.0

0.2.3

0.2.2

0.2.1

0.2.0

0.1.3

0.1.2

0.1.1

0.1.0