tasks/html2js.js
function generateModule (f) {

      // f.dest must be a string or write will fail
      var moduleNames = [];
      var filePaths = f.src.filter(existsFilter);

      if (options.watch) {
        watcher.add(filePaths);
      }

      var modules = filePaths.map(function (filepath) {

        var moduleName = normalizePath(path.relative(options.base, filepath));
        if (grunt.util.kindOf(options.rename) === 'function') {
          moduleName = options.rename(moduleName);
        }
        moduleNames.push(options.quoteChar + moduleName + options.quoteChar);

        var compiled;

        if (options.watch && (compiled = fileCache[filepath])) {
          // return compiled file contents from cache
          return compiled;
        }

        if (options.target === 'js') {
          compiled = compileTemplate(moduleName, filepath, options);
        } else if (options.target === 'coffee') {
          compiled = compileCoffeeTemplate(moduleName, filepath, options);
        } else {
          grunt.fail.fatal('Unknown target "' + options.target + '" specified');
        }

        if (options.watch) {
          // store compiled file contents in cache
          fileCache[filepath] = compiled;
        }

        return compiled;
      });

      // don't generate empty modules
      if (!modules.length) {
        return;
      }

      counter += modules.length;
      modules = modules.join('\n');

      var fileHeader = options.fileHeaderString !== '' ? options.fileHeaderString + '\n' : '';
      var fileFooter = options.fileFooterString !== '' ? options.fileFooterString + '\n' : '';
      var bundle = '';
      var targetModule = f.module || options.module;
      var indentString = options.indentString;
      var quoteChar = options.quoteChar;
      var strict = (options.useStrict) ? indentString + quoteChar + 'use strict' + quoteChar + ';\n' : '';
      var amdPrefix = '';
      var amdSuffix = '';
      // If options.module is a function, use that to get the targetModule
      if (grunt.util.kindOf(targetModule) === 'function') {
        targetModule = targetModule(f, target);
      }

      if (options.amd) {
        amdPrefix = options.amdPrefixString;
        amdSuffix = options.amdSuffixString;
      }

      if (!targetModule && options.singleModule) {
        throw new Error('When using singleModule: true be sure to specify a (target) module');
      }

      if (options.existingModule && !options.singleModule) {
        throw new Error('When using existingModule: true be sure to set singleModule: true');
      }

      if (options.singleModule) {
        var moduleSuffix = options.existingModule ? '' : ', []';
        if (options.target === 'js') {
          bundle = 'angular.module(' + quoteChar + targetModule + quoteChar + moduleSuffix + ').run([' + quoteChar + '$templateCache' + quoteChar + ', function($templateCache) {\n' + strict;
          modules += '\n}]);\n';
        } else if (options.target === 'coffee') {
          bundle = 'angular.module(' + quoteChar + targetModule + quoteChar + moduleSuffix + ').run([' + quoteChar + '$templateCache' + quoteChar + ', ($templateCache) ->\n';
          modules += '\n])\n';
        }
      } else if (targetModule) {
        //Allow a 'no targetModule if module is null' option
        bundle = 'angular.module(' + quoteChar + targetModule + quoteChar + ', [' + moduleNames.join(', ') + '])';
        if (options.target === 'js') {
          bundle += ';';
        }

        bundle += '\n\n';
      }
      grunt.file.write(f.dest, grunt.util.normalizelf(fileHeader + amdPrefix + bundle + modules + amdSuffix + fileFooter));
    }
function generateModule (f) {

      // f.dest must be a string or write will fail
      var moduleNames = [];
      var filePaths = f.src.filter(existsFilter);

      if (options.watch) {
        watcher.add(filePaths);
      }

      var modules = filePaths.map(function (filepath) {

        var moduleName = normalizePath(path.relative(options.base, filepath));
        if (grunt.util.kindOf(options.rename) === 'function') {
          moduleName = options.rename(moduleName);
        }
        moduleNames.push(options.quoteChar + moduleName + options.quoteChar);

        var compiled;

        if (options.watch && (compiled = fileCache[filepath])) {
          // return compiled file contents from cache
          return compiled;
        }

        if (options.target === 'js') {
          compiled = compileTemplate(moduleName, filepath, options);
        } else if (options.target === 'coffee') {
          compiled = compileCoffeeTemplate(moduleName, filepath, options);
        } else {
          grunt.fail.fatal('Unknown target "' + options.target + '" specified');
        }

        if (options.watch) {
          // store compiled file contents in cache
          fileCache[filepath] = compiled;
        }

        return compiled;
      });

      // don't generate empty modules
      if (!modules.length) {
        return;
      }

      counter += modules.length;
      modules = modules.join('\n');

      var fileHeader = options.fileHeaderString !== '' ? options.fileHeaderString + '\n' : '';
      var fileFooter = options.fileFooterString !== '' ? options.fileFooterString + '\n' : '';
      var bundle = '';
      var targetModule = f.module || options.module;
      var indentString = options.indentString;
      var quoteChar = options.quoteChar;
      var strict = (options.useStrict) ? indentString + quoteChar + 'use strict' + quoteChar + ';\n' : '';
      var amdPrefix = '';
      var amdSuffix = '';
      // If options.module is a function, use that to get the targetModule
      if (grunt.util.kindOf(targetModule) === 'function') {
        targetModule = targetModule(f, target);
      }

      if (options.amd) {
        amdPrefix = options.amdPrefixString;
        amdSuffix = options.amdSuffixString;
      }

      if (!targetModule && options.singleModule) {
        throw new Error('When using singleModule: true be sure to specify a (target) module');
      }

      if (options.existingModule && !options.singleModule) {
        throw new Error('When using existingModule: true be sure to set singleModule: true');
      }

      if (options.singleModule) {
        var moduleSuffix = options.existingModule ? '' : ', []';
        if (options.target === 'js') {
          bundle = 'angular.module(' + quoteChar + targetModule + quoteChar + moduleSuffix + ').run([' + quoteChar + '$templateCache' + quoteChar + ', function($templateCache) {\n' + strict;
          modules += '\n}]);\n';
        } else if (options.target === 'coffee') {
          bundle = 'angular.module(' + quoteChar + targetModule + quoteChar + moduleSuffix + ').run([' + quoteChar + '$templateCache' + quoteChar + ', ($templateCache) ->\n';
          modules += '\n])\n';
        }
      } else if (targetModule) {
        //Allow a 'no targetModule if module is null' option
        bundle = 'angular.module(' + quoteChar + targetModule + quoteChar + ', [' + moduleNames.join(', ') + '])';
        if (options.target === 'js') {
          bundle += ';';
        }

        bundle += '\n\n';
      }
      grunt.file.write(f.dest, grunt.util.normalizelf(fileHeader + amdPrefix + bundle + modules + amdSuffix + fileFooter));
    }
function generateModule ( f ) { // f.dest must be a string or write will fail var moduleNames = [ ] ; var filePaths = f . src . filter ( existsFilter ) ; if ( options . watch ) { watcher . add ( filePaths ) ; } var modules = filePaths . map ( function ( filepath ) { var moduleName = normalizePath ( path . relative ( options . base , filepath ) ) ; if ( grunt . util . kindOf ( options . rename ) === 'function' ) { moduleName = options . rename ( moduleName ) ; } moduleNames . push ( options . quoteChar + moduleName + options . quoteChar ) ; var compiled ; if ( options . watch && ( compiled = fileCache [ filepath ] ) ) { // return compiled file contents from cache return compiled ; } if ( options . target === 'js' ) { compiled = compileTemplate ( moduleName , filepath , options ) ; } else if ( options . target === 'coffee' ) { compiled = compileCoffeeTemplate ( moduleName , filepath , options ) ; } else { grunt . fail . fatal ( 'Unknown target "' + options . target + '" specified' ) ; } if ( options . watch ) { // store compiled file contents in cache fileCache [ filepath ] = compiled ; } return compiled ; } ) ; // don't generate empty modules if ( ! modules . length ) { return ; } counter += modules . length ; modules = modules . join ( '\n' ) ; var fileHeader = options . fileHeaderString !== '' ? options . fileHeaderString + '\n' : '' ; var fileFooter = options . fileFooterString !== '' ? options . fileFooterString + '\n' : '' ; var bundle = '' ; var targetModule = f . module || options . module ; var indentString = options . indentString ; var quoteChar = options . quoteChar ; var strict = ( options . useStrict ) ? indentString + quoteChar + 'use strict' + quoteChar + ';\n' : '' ; var amdPrefix = '' ; var amdSuffix = '' ; // If options.module is a function, use that to get the targetModule if ( grunt . util . kindOf ( targetModule ) === 'function' ) { targetModule = targetModule ( f , target ) ; } if ( options . amd ) { amdPrefix = options . amdPrefixString ; amdSuffix = options . amdSuffixString ; } if ( ! targetModule && options . singleModule ) { throw new Error ( 'When using singleModule: true be sure to specify a (target) module' ) ; } if ( options . existingModule && ! options . singleModule ) { throw new Error ( 'When using existingModule: true be sure to set singleModule: true' ) ; } if ( options . singleModule ) { var moduleSuffix = options . existingModule ? '' : ', []' ; if ( options . target === 'js' ) { bundle = 'angular.module(' + quoteChar + targetModule + quoteChar + moduleSuffix + ').run([' + quoteChar + '$templateCache' + quoteChar + ', function($templateCache) {\n' + strict ; modules += '\n}]);\n' ; } else if ( options . target === 'coffee' ) { bundle = 'angular.module(' + quoteChar + targetModule + quoteChar + moduleSuffix + ').run([' + quoteChar + '$templateCache' + quoteChar + ', ($templateCache) ->\n' ; modules += '\n])\n' ; } } else if ( targetModule ) { //Allow a 'no targetModule if module is null' option bundle = 'angular.module(' + quoteChar + targetModule + quoteChar + ', [' + moduleNames . join ( ', ' ) + '])' ; if ( options . target === 'js' ) { bundle += ';' ; } bundle += '\n\n' ; } grunt . file . write ( f . dest , grunt . util . normalizelf ( fileHeader + amdPrefix + bundle + modules + amdSuffix + fileFooter ) ) ; }
generate a separate module
generate a separate module