node_modules/grunt-angular-builder/tasks/middleware/analyzeSourceCode.js
/**
 * An AngularJS source code loader and analyser middleware.
 *
 * @constructor
 * @implements {MiddlewareInterface}
 * @param {Context} context The execution context for the middleware stack.
 */
An AngularJS source code loader and analyser middleware.
@constructor
@implements {MiddlewareInterface}
@param {Context} context The execution context for the middleware stack.
An AngularJS source code loader and analyser middleware . @constructor @implements { MiddlewareInterface } @param { Context } context The execution context for the middleware stack .
function AnalyzeSourceCodeMiddleware (context)
{
  var grunt = context.grunt;
  this.analyze = function (filesArray)
  {
    var src = util.sortFilesBeforeSubfolders (filesArray.src);
    src.forEach (function (path)
    {
      if (!grunt.file.exists (path)) {
        warn ('Source file "' + path + '" not found.');
        return;
      }
      var script = grunt.file.read (path);
      var moduleHeaders;
      try {
        moduleHeaders = sourceExtract.extractModuleHeaders (script);
      }
      catch (e) {
        if (typeof e === 'string')
          return warn (e + NL + reportErrorLocation (path));
        throw e;
      }
      if (!moduleHeaders.length) {
        if (!filesArray.forceInclude || !grunt.file.isMatch ({matchBase: true}, filesArray.forceInclude, path)) {
          info ('Ignored file: %', path.cyan);
          return;
        }
        context.standaloneScripts.push ({
          path:    path,
          content: script
        });
      }
      else moduleHeaders.forEach (function (header)
      {
        setupModuleInfo (header, script, path);
      });
    });
  };
  this.trace = function (module)
  {
  };
  this.build = function (targetScript)
  {
  };
  function setupModuleInfo (moduleHeader, fileContent, filePath)
  {
    var module = context.modules[moduleHeader.name];
    if (!module)
      module = context.modules[moduleHeader.name] = new ModuleDef (moduleHeader.name);
    else if (module.external)
      return;
    else if (module.head && !moduleHeader.append)
      fatal ('Can\'t redeclare module <cyan>%</cyan>', moduleHeader.name);
    if (moduleHeader.append) {
      if (!~module.bodyPaths.indexOf (filePath)) {
        module.bodies.push (fileContent);
        module.bodyPaths.push (filePath);
      }
    }
    else {
      if (module.head)
        fatal ('Duplicate module definition: <cyan>%</cyan>', moduleHeader.name);
      module.head = fileContent;
      module.headPath = filePath;
      module.requires = moduleHeader.requires;
    }
    module.configFn = moduleHeader.configFn;
  }
}
function AnalyzeSourceCodeMiddleware ( context ) { var grunt = context . grunt ; this . analyze = function ( filesArray ) { var src = util . sortFilesBeforeSubfolders ( filesArray . src ) ; src . forEach ( function ( path ) { if ( ! grunt . file . exists ( path ) ) { warn ( 'Source file "' + path + '" not found.' ) ; return ; } var script = grunt . file . read ( path ) ; var moduleHeaders ; try { moduleHeaders = sourceExtract . extractModuleHeaders ( script ) ; } catch ( e ) { if ( typeof e === 'string' ) return warn ( e + NL + reportErrorLocation ( path ) ) ; throw e ; } if ( ! moduleHeaders . length ) { if ( ! filesArray . forceInclude || ! grunt . file . isMatch ( { matchBase : true } , filesArray . forceInclude , path ) ) { info ( 'Ignored file: %' , path . cyan ) ; return ; } context . standaloneScripts . push ( { path : path , content : script } ) ; } else moduleHeaders . forEach ( function ( header ) { setupModuleInfo ( header , script , path ) ; } ) ; } ) ; } ; this . trace = function ( module ) { } ; this . build = function ( targetScript ) { } ; function setupModuleInfo ( moduleHeader , fileContent , filePath ) { var module = context . modules [ moduleHeader . name ] ; if ( ! module ) module = context . modules [ moduleHeader . name ] = new ModuleDef ( moduleHeader . name ) ; else if ( module . external ) return ; else if ( module . head && ! moduleHeader . append ) fatal ( 'Can\'t redeclare module <cyan>%</cyan>' , moduleHeader . name ) ; if ( moduleHeader . append ) { if ( ! ~ module . bodyPaths . indexOf ( filePath ) ) { module . bodies . push ( fileContent ) ; module . bodyPaths . push ( filePath ) ; } } else { if ( module . head ) fatal ( 'Duplicate module definition: <cyan>%</cyan>' , moduleHeader . name ) ; module . head = fileContent ; module . headPath = filePath ; module . requires = moduleHeader . requires ; } module . configFn = moduleHeader . configFn ; } }
An AngularJS source code loader and analyser middleware.
An AngularJS source code loader and analyser middleware .
//-------------------------------------------------------------------------------------------------------------------- // PUBLIC API //-------------------------------------------------------------------------------------------------------------------- // Load the script files and scan them for module definitions. // Read the script and scan it for module declarations. /** @type {ModuleHeaderInfo[]} */ // Ignore irrelevant files. /* jshint unused: vars */ // Do nothing /* jshint unused: vars */ // Do nothing //-------------------------------------------------------------------------------------------------------------------- // PRIVATE //-------------------------------------------------------------------------------------------------------------------- /**
   * Store information about the specified module retrieved from the given source code on the specified file.
   *
   * @param {ModuleHeaderInfo} moduleHeader
   * @param {string} fileContent
   * @param {string} filePath
   */ // Get information about the specified module. // If this is the first time a specific module is mentioned, create the respective information record. // Skip the file if it defines an external module. // Reject additional attempts to redeclare a module (only appending is allowed). // The file is appending definitions to a module declared elsewhere. // Append the file path to the paths list. // Otherwise, the file contains a module declaration.