OpenVeo server API for plugins

API Docs for: 7.0.0
Show:

ngDpTask

Module: grunt

static

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

Methods

buildTree

Syntax

buildTree

(
  • scripts
)
Array private

Summary

Builds the dependencies tree.

Parameters:

  • scripts Array

    The 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:

Array:

The list of scripts with their dependencies

findDependencies

Syntax

findDependencies

(
  • expression
)
private

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 Object

    The JavaScript expression to analyze

findLongestDependencyChains

Syntax

findLongestDependencyChains

(
  • scripts
  • [script]
  • [modulesToIgnore]
)
Array private

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 Array

    The 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 optional

    The script to analyze (default to the first one of the list of scripts)

  • [modulesToIgnore] Array optional

    The list of module names to ignore to avoid circular dependencies

Returns:

Array:

The longest dependency chains

findScript

Syntax

findScript

(
  • scripts
  • property
  • value
)
Object | Null private

Summary

Fetches a script from a list of scripts.

Parameters:

  • scripts Array

    The list of scripts

  • property String

    The script property used to identify the script to fetch

  • value String

    The expected value of the script property

Returns:

Object | Null:

The found script or null if not found

getResources

Syntax

getResources

(
  • tree
)
Object private

Summary

Retrieves CSS and JS files from tree of scripts in a flattened order.

Parameters:

  • tree Object

    The tree of resources

Returns:

Object:

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

getTreeResources

(
  • node
)
Object private

Summary

Retrieves CSS and JS files from tree of scripts in a flattened order.

This is recursive.

Parameters:

  • node Object

    The node from where to start

    • path String

      The file path

    • styles Array

      The list of css / scss file paths

Returns:

Object:

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