Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
feat(script): Set ngModule to Closure namespace.
Browse files Browse the repository at this point in the history
When using Closure, it is common to reference Angular module dependencies by the name property of the module.
This looks like:
```
goog.provide('bar.module');
goog.require('foo.module');
bar.module = angular.module('bar.module', [foo.module.name]);
```
This change makes it possible for this kind of reference instead of having to refer to the dependent module as a string.
  • Loading branch information
wesalvaro committed Feb 27, 2015
1 parent 0523f83 commit 091a88c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions scripts/gulp-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,15 @@ exports.addClosurePrefixes = function() {
return through2.obj(function(file, enc, next) {
var moduleInfo = getModuleInfo(file.contents);
if (moduleInfo.module) {

var provide = 'goog.provide(\'' + moduleNameToClosureName(moduleInfo.module) + '\');';
var closureModuleName = moduleNameToClosureName(moduleInfo.module);
var provide = 'goog.provide(\'' + closureModuleName + '\');';
var requires = (moduleInfo.dependencies || []).sort().map(function(dep) {
return dep.indexOf(moduleInfo.module) === 0 ? '' : 'goog.require(\'' + moduleNameToClosureName(dep) + '\');';
}).join('\n');

// Assign the module to the provided Closure namespace:
file.contents.replace('angular.module', closureModuleName + ' = angular.module');

file.contents = new Buffer(
provide + '\n' + requires + '\n' + file.contents.toString()
);
Expand Down

0 comments on commit 091a88c

Please sign in to comment.