ngDpTask
Summary
Defines a grunt task to build the list of sources (css and js) of an AngularJS application.
// Register task
var openVeoApi = require('@openveo/api');
grunt.registerMultiTask('ngDp', openVeoApi.grunt.ngDpTask(grunt));
// Configure task
grunt.initConfig({
'ngDp': {
options: {
basePath: '/path/to/the/',
cssPrefix: '../../other/css/path/',
jsPrefix: '../../other/js/path/'
},
app1: {
src: '/path/to/the/app1/**\/*.*',
dest: '/path/to/the/app1/topology.json'
},
app2: {
src: '/path/to/the/app2**\/*.*',
dest: '/path/to/the/app2/topology.json'
}
}
});
// Ouput example (/path/to/the/app1/topology.json)
{
js: ['../..other/js/path/app1/file1.js', '../..other/js/path/app1/file2.js', [...]],
css: ['../..other/css/path/app1/file1.css', '../..other/css/path/app1/file2.css', [...]]
}
AngularJS applications, which respect components architecture, need to be loaded in the right order as some components may depend on other components. This task helps build an array of JavaScript files and css / scss files in the right order.
For this to work, each module must be declared in a separated file and a single file should not define AngularJS elements belonging to several different modules.
Available options are:
- basePath: The base path which will be replaced by the cssPrefix or jsPrefix
- cssPrefix: For CSS / SCSS files, replace the basePath by this prefix
- jsPrefix: For JS files, replace the basePath by this prefix
Item Index
Methods
buildTree
Syntax
Summary
Builds the dependencies tree.
Parameters:
-
scripts
ArrayThe flat list of scripts with for each script:
- dependencies The list of dependency names of the script
- definitions The list of definition names of the script
- path The script path
Returns:
The list of scripts with their dependencies
findDependencies
Syntax
findDependencies
-
expression
Summary
Finds out AngularJS definitions and dependencies for the given content.
This is recursive.
The following JavaScript expressions are used to identify definitions:
- angular.module('moduleName', [])
- angular.module('moduleName').component()
- angular.module('moduleName').directive()
- angular.module('moduleName').controller()
- angular.module('moduleName').factory()
- angular.module('moduleName').service()
- angular.module('moduleName').constant()
- angular.module('moduleName').service()
- angular.module('moduleName').decorator()
- angular.module('moduleName').filter()
- angular.module('moduleName').config()
- angular.module('moduleName').run()
The following JavaScript expressions are used to identify dependencies:
- MyAngularJsElement.$inject = ['Dependency1', 'Dependency2'];
- angular.module('moduleName', ['DependencyModule'])
The following JavaScript expressions are used to identify associated modules:
- angular.module('moduleName')
Parameters:
-
expression
ObjectThe JavaScript expression to analyze
findLongestDependencyChains
Syntax
Summary
Browses a flat list of scripts to find a script longest dependency chains.
Each script may have several dependencies, each dependency can also have several dependencies. findLongestDependencyChains helps find the longest dependency chain of one of the script. As the script may have several longest dependency chain, a list of chains is returned.
A chain is an ordered list of script paths.
This is recursive.
Parameters:
-
scripts
ArrayThe flat list of scripts with for each script:
- dependencies The list of dependency names of the script
- definitions The list of definition names of the script
- path The script path
-
[script]
Object optionalThe script to analyze (default to the first one of the list of scripts)
-
[modulesToIgnore]
Array optionalThe list of module names to ignore to avoid circular dependencies
Returns:
The longest dependency chains
findScript
Syntax
Summary
Fetches a script from a list of scripts.
Parameters:
Returns:
The found script or null if not found
getResources
Syntax
Summary
Retrieves CSS and JS files from tree of scripts in a flattened order.
Parameters:
-
tree
ObjectThe tree of resources
Returns:
An object with:
- css The list of css files in the right order
- js The list of js files in the right order the list of JS files
getTreeResources
Syntax
Summary
Retrieves CSS and JS files from tree of scripts in a flattened order.
This is recursive.
Parameters:
Returns:
An object with:
- childrenCss The list of children CSS files
- childrenJs The list of children CSS files
- subChildrenCss The list of sub children CSS files
- subChildrenJs The list of sub children JS files