Giter Club home page Giter Club logo

ng-dependencies's Introduction

#ng-dependencies

Analyze javascript code using esprima and return a list of objects representing the module dependencies in the code.

This is based on gulp-angular-filesort. I extracted the module dependency code because I need to find a way to dynamically generate a root angular module that depends on a list of angular modules as Bower packages.

Usage

var fs = require('fs');
var ngDeps = require('ng-dependencies');

var deps = ngDeps(fs.readFileSync('./someNgModule.js'));

console.log(deps);

If the content of ./someNgModle.js is as following:

angular.module('test', ['one']).run(function () {
  // run some logic
});
angular.module('another', []);
angular.module('another').Controller('Ctrl', ['$scope', function ($scope) {
  // some controller logic
}]);
angular.module('useThis').run(function () {
  // ...
});

This will output:

{
  dependencies: ['one', 'useThis'],
  modules: {
    'test': ['one'],
    'another': []
  }
}

Special Cases

If multiple declarations of the same module is encountered, (according to Angular Doc), the later declaration will overwrite any existing module that is declared with the same module name.

For example, the following content:

angular.module('test', ['one']);
angular.module('test', ['another']);

will output:

  {
    dependencies: ['another'],
    modules: {
      'test': ['another']
    }
  }

Change log

0.1.1 - fixing repo url in package.json and removing unnecessary dependency.

0.1.0 - simplified output format; added detection for angular.js itself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.