@@ -6,6 +6,10 @@ var shell = require('shelljs');
66var semver = require ( 'semver' ) ;
77var _ = require ( 'lodash' ) ;
88
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+
913var currentPackage , previousVersions , cdnVersion , gitRepoInfo ;
1014
1115
@@ -96,12 +100,12 @@ var getTaggedVersion = function() {
96100 * @return {Array.<SemVer> } The collection of previous versions
97101 */
98102var 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
100104 // 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
102106 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 } ) ;
105109 if ( tagResults . code === 0 ) {
106110 return _ ( tagResults . output . match ( / v [ 0 - 9 ] .* [ 0 - 9 ] $ / mg) )
107111 . map ( function ( tag ) {
@@ -138,15 +142,20 @@ var getCdnVersion = function() {
138142 . reverse ( )
139143 . reduce ( function ( cdnVersion , version ) {
140144 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+ }
150159 }
151160 }
152161 }
@@ -204,3 +213,13 @@ exports.gitRepoInfo = gitRepoInfo = getGitRepoInfo();
204213exports . previousVersions = previousVersions = getPreviousVersions ( ) ;
205214exports . cdnVersion = cdnVersion = getCdnVersion ( ) ;
206215exports . 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