A grunt plugin that draws your javascript project dependencies.
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');
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.
},
},
});
Type: String
Default value: angularjs
Accepted values : angularjs
, requirejs
, nodejs
, 'java'
A string value that is used to find node and dependecies type.
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.
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.
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.
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).
Type: String
Default value: Draw my project
A string value that is used in title of html result page.
Type: String
Default value: Draw your project dependencies !
A string value that is used in description of html result page.
Type: String
Default value: assets/img/logo.png
A string value that is used in favicon of html result page.
Type: String
Default value: https://github.com/manland/draw-my-project
A string value that is used to link in header.
Type: String
Default value: assets/img/logo.png
A string value that is used in src of img header.
Type: Object
Default value: all advices
Special value: false
no advice
Advices :
A controller must import $scope and 1 service (its own).
A class must have same name as its own filename.
A class with no import and no class point to it.
An array of string node type (service, factory, directory...).
Default is []
.Use of $rootScope is bad.
Controller size must not be greater than 20% of services.
An integer between 0 and 1 wich represents the percent of services for controllers.
Default is 0.2
.A class must not inject more than 5 classes.
An integer wich represent the number max of imports.
Default is 5
.A class must end with Srv if it's a service, Ctrl for a controller.
An object where key is node type and value is the prefix.
Default is {}.
An object where key is node type and value is the suffix.
Default is {'service': 'Srv', 'factory': 'Srv', 'controller': 'Ctrl'}.
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'
}
}
}
}
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).
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'],
}
}
},
});
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'],
}
}
},
});
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'],
}
}
},
});
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.
checkAngularjsInject
option at true
)