@@ -6,6 +6,10 @@ var shell = require('shelljs');
6
6
var semver = require ( 'semver' ) ;
7
7
var _ = require ( 'lodash' ) ;
8
8
9
+ var process = require ( 'process' ) ;
10
+ // We are only interested in whether this environment variable exists, hence the !!
11
+ var NO_REMOTE_REQUESTS = ! ! process . env [ 'NG1_BUILD_NO_REMOTE_VERSION_REQUESTS' ] ;
12
+
9
13
var currentPackage , previousVersions , cdnVersion , gitRepoInfo ;
10
14
11
15
@@ -96,12 +100,12 @@ var getTaggedVersion = function() {
96
100
* @return {Array.<SemVer> } The collection of previous versions
97
101
*/
98
102
var getPreviousVersions = function ( ) {
99
- // always use the remote tags as the local clone might
103
+ // If we are allowing remote requests then use the remote tags as the local clone might
100
104
// not contain all commits when cloned with git clone --depth=...
101
- // Needed e.g. for Travis
105
+ // Otherwise just use the tags in the local repository
102
106
var repo_url = currentPackage . repository . url ;
103
- var tagResults = shell . exec ( 'git ls-remote --tags ' + repo_url ,
104
- { silent : true } ) ;
107
+ var query = NO_REMOTE_REQUESTS ? 'git tag' : 'git ls-remote --tags ' + repo_url ;
108
+ var tagResults = shell . exec ( query , { silent : true } ) ;
105
109
if ( tagResults . code === 0 ) {
106
110
return _ ( tagResults . output . match ( / v [ 0 - 9 ] .* [ 0 - 9 ] $ / mg) )
107
111
. map ( function ( tag ) {
@@ -138,15 +142,20 @@ var getCdnVersion = function() {
138
142
. reverse ( )
139
143
. reduce ( function ( cdnVersion , version ) {
140
144
if ( ! cdnVersion ) {
141
- // Note: need to use shell.exec and curl here
142
- // as version-infos returns its result synchronously...
143
- var cdnResult = shell . exec ( 'curl http://ajax.googleapis.com/ajax/libs/angularjs/' + version + '/angular.min.js ' +
144
- '--head --write-out "%{http_code}" -o /dev/null -silent' ,
145
- { silent : true } ) ;
146
- if ( cdnResult . code === 0 ) {
147
- var statusCode = cdnResult . output . trim ( ) ;
148
- if ( statusCode === '200' ) {
149
- cdnVersion = version ;
145
+ if ( NO_REMOTE_REQUESTS ) {
146
+ // We do not want to make any remote calls to the CDN so just use the most recent version
147
+ cdnVersion = version ;
148
+ } else {
149
+ // Note: need to use shell.exec and curl here
150
+ // as version-infos returns its result synchronously...
151
+ var cdnResult = shell . exec ( 'curl http://ajax.googleapis.com/ajax/libs/angularjs/' + version + '/angular.min.js ' +
152
+ '--head --write-out "%{http_code}" -o /dev/null -silent' ,
153
+ { silent : true } ) ;
154
+ if ( cdnResult . code === 0 ) {
155
+ var statusCode = cdnResult . output . trim ( ) ;
156
+ if ( statusCode === '200' ) {
157
+ cdnVersion = version ;
158
+ }
150
159
}
151
160
}
152
161
}
@@ -204,3 +213,13 @@ exports.gitRepoInfo = gitRepoInfo = getGitRepoInfo();
204
213
exports . previousVersions = previousVersions = getPreviousVersions ( ) ;
205
214
exports . cdnVersion = cdnVersion = getCdnVersion ( ) ;
206
215
exports . currentVersion = getTaggedVersion ( ) || getSnapshotVersion ( ) ;
216
+
217
+ if ( NO_REMOTE_REQUESTS ) {
218
+ console . log ( '==============================================================================================' ) ;
219
+ console . log ( 'Running with no remote requests for version data:' ) ;
220
+ console . log ( ' - this is due to the "NG1_BUILD_NO_REMOTE_VERSION_REQUESTS" environment variable being defined.' ) ;
221
+ console . log ( ' - be aware that the generated docs may not have valid or the most recent version information.' ) ;
222
+ console . log ( '==============================================================================================' ) ;
223
+ }
224
+ console . log ( 'CDN version:' , cdnVersion . raw ) ;
225
+ console . log ( 'Current version:' , exports . currentVersion . raw ) ;
0 commit comments