|  | 
| 1 | 1 | 'use strict'; | 
| 2 | 2 | 
 | 
| 3 |  | -var childProcess = require('child_process'); | 
| 4 | 3 | var fs = require('fs'); | 
| 5 | 4 | var path = require('path'); | 
| 6 | 5 | var shell = require('shelljs'); | 
| 7 | 6 | var semver = require('semver'); | 
| 8 | 7 | var _ = require('lodash'); | 
| 9 | 8 | 
 | 
| 10 | 9 | var currentPackage, previousVersions, cdnVersion, gitRepoInfo; | 
| 11 |  | -var connectivityStatus = childProcess.execSync('node is-online.js', { cwd: __dirname, encoding: 'utf8' }).trim(); | 
| 12 |  | -var isOnline = connectivityStatus == 'online'; | 
| 13 |  | -console.log('Running ' + connectivityStatus); | 
|  | 10 | + | 
| 14 | 11 | 
 | 
| 15 | 12 | /** | 
| 16 | 13 |  * Load information about this project from the package.json | 
| @@ -103,68 +100,58 @@ var getPreviousVersions =  function() { | 
| 103 | 100 |   // not contain all commits when cloned with git clone --depth=... | 
| 104 | 101 |   // Needed e.g. for Travis | 
| 105 | 102 |   var repo_url = currentPackage.repository.url; | 
| 106 |  | -  if (isOnline) { | 
| 107 |  | -    console.log('looking up remote git tags...'); | 
| 108 |  | -    var tagResults = shell.exec('git ls-remote --tags ' + repo_url, | 
| 109 |  | -                                {silent: true}); | 
| 110 |  | -    if (tagResults.code === 0) { | 
| 111 |  | -      return _(tagResults.output.match(/v[0-9].*[0-9]$/mg)) | 
| 112 |  | -        .map(function(tag) { | 
| 113 |  | -          var version = semver.parse(tag); | 
| 114 |  | -          return version; | 
| 115 |  | -        }) | 
| 116 |  | -        .filter() | 
| 117 |  | -        .map(function(version) { | 
| 118 |  | -          // angular.js didn't follow semantic version until 1.20rc1 | 
| 119 |  | -          if ((version.major === 1 && version.minor === 0 && version.prerelease.length > 0) || (version.major === 1 && version.minor === 2 && version.prerelease[0] === 'rc1')) { | 
| 120 |  | -            version.version = [version.major, version.minor, version.patch].join('.') + version.prerelease.join(''); | 
| 121 |  | -            version.raw = 'v' + version.version; | 
| 122 |  | -          } | 
| 123 |  | -          version.docsUrl = 'http://code.angularjs.org/' + version.version + '/docs'; | 
| 124 |  | -          // Versions before 1.0.2 had a different docs folder name | 
| 125 |  | -          if (version.major < 1 || (version.major === 1 && version.minor === 0 && version.patch < 2)) { | 
| 126 |  | -            version.docsUrl += '-' + version.version; | 
| 127 |  | -            version.isOldDocsUrl = true; | 
| 128 |  | -          } | 
| 129 |  | -          return version; | 
| 130 |  | -        }) | 
| 131 |  | -        .sort(semver.compare) | 
| 132 |  | -        .value(); | 
| 133 |  | -    } | 
|  | 103 | +  var tagResults = shell.exec('git ls-remote --tags ' + repo_url, | 
|  | 104 | +                              {silent: true}); | 
|  | 105 | +  if (tagResults.code === 0) { | 
|  | 106 | +    return _(tagResults.output.match(/v[0-9].*[0-9]$/mg)) | 
|  | 107 | +      .map(function(tag) { | 
|  | 108 | +        var version = semver.parse(tag); | 
|  | 109 | +        return version; | 
|  | 110 | +      }) | 
|  | 111 | +      .filter() | 
|  | 112 | +      .map(function(version) { | 
|  | 113 | +        // angular.js didn't follow semantic version until 1.20rc1 | 
|  | 114 | +        if ((version.major === 1 && version.minor === 0 && version.prerelease.length > 0) || (version.major === 1 && version.minor === 2 && version.prerelease[0] === 'rc1')) { | 
|  | 115 | +          version.version = [version.major, version.minor, version.patch].join('.') + version.prerelease.join(''); | 
|  | 116 | +          version.raw = 'v' + version.version; | 
|  | 117 | +        } | 
|  | 118 | +        version.docsUrl = 'http://code.angularjs.org/' + version.version + '/docs'; | 
|  | 119 | +        // Versions before 1.0.2 had a different docs folder name | 
|  | 120 | +        if (version.major < 1 || (version.major === 1 && version.minor === 0 && version.patch < 2)) { | 
|  | 121 | +          version.docsUrl += '-' + version.version; | 
|  | 122 | +          version.isOldDocsUrl = true; | 
|  | 123 | +        } | 
|  | 124 | +        return version; | 
|  | 125 | +      }) | 
|  | 126 | +      .sort(semver.compare) | 
|  | 127 | +      .value(); | 
| 134 | 128 |   } else { | 
| 135 |  | -    console.log('-- skipping remote git tag lookup'); | 
|  | 129 | +    return []; | 
| 136 | 130 |   } | 
| 137 |  | -  return []; | 
| 138 | 131 | }; | 
| 139 | 132 | 
 | 
| 140 | 133 | var getCdnVersion = function() { | 
| 141 |  | -  if (isOnline) { | 
| 142 |  | -    console.log('searching for CDN versions...'); | 
| 143 |  | -    return _(previousVersions) | 
| 144 |  | -      .filter(function(tag) { | 
| 145 |  | -        return semver.satisfies(tag, currentPackage.branchVersion); | 
| 146 |  | -      }) | 
| 147 |  | -      .reverse() | 
| 148 |  | -      .reduce(function(cdnVersion, version) { | 
| 149 |  | -        if (!cdnVersion) { | 
| 150 |  | -          // Note: need to use shell.exec and curl here | 
| 151 |  | -          // as version-infos returns its result synchronously... | 
| 152 |  | -          var cdnResult = shell.exec('curl http://ajax.googleapis.com/ajax/libs/angularjs/' + version + '/angular.min.js ' + | 
| 153 |  | -                    '--head --write-out "%{http_code}" -o /dev/null -silent', | 
| 154 |  | -                                      {silent: true}); | 
| 155 |  | -          if (cdnResult.code === 0) { | 
| 156 |  | -            var statusCode = cdnResult.output.trim(); | 
| 157 |  | -            if (statusCode === '200') { | 
| 158 |  | -              console.log('-- found CDN version ' + version); | 
| 159 |  | -              cdnVersion = version; | 
| 160 |  | -            } | 
|  | 134 | +  return _(previousVersions) | 
|  | 135 | +    .filter(function(tag) { | 
|  | 136 | +      return semver.satisfies(tag, currentPackage.branchVersion); | 
|  | 137 | +    }) | 
|  | 138 | +    .reverse() | 
|  | 139 | +    .reduce(function(cdnVersion, version) { | 
|  | 140 | +      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; | 
| 161 | 150 |           } | 
| 162 | 151 |         } | 
| 163 |  | -        return cdnVersion; | 
| 164 |  | -      }, null); | 
| 165 |  | -  } else { | 
| 166 |  | -    console.log('-- skipping CDN version lookup'); | 
| 167 |  | -  } | 
|  | 152 | +      } | 
|  | 153 | +      return cdnVersion; | 
|  | 154 | +    }, null); | 
| 168 | 155 | }; | 
| 169 | 156 | 
 | 
| 170 | 157 | /** | 
| @@ -211,6 +198,7 @@ var getSnapshotVersion = function() { | 
| 211 | 198 |   return version; | 
| 212 | 199 | }; | 
| 213 | 200 | 
 | 
|  | 201 | + | 
| 214 | 202 | exports.currentPackage = currentPackage = getPackage(); | 
| 215 | 203 | exports.gitRepoInfo = gitRepoInfo = getGitRepoInfo(); | 
| 216 | 204 | exports.previousVersions = previousVersions = getPreviousVersions(); | 
|  | 
0 commit comments