|
1 | 1 | 'use strict';
|
2 | 2 |
|
| 3 | +var childProcess = require('child_process'); |
3 | 4 | var fs = require('fs');
|
4 | 5 | var path = require('path');
|
5 | 6 | var shell = require('shelljs');
|
6 | 7 | var semver = require('semver');
|
7 | 8 | var _ = require('lodash');
|
8 | 9 |
|
9 | 10 | var currentPackage, previousVersions, cdnVersion, gitRepoInfo;
|
10 |
| - |
| 11 | +var connectivityStatus = childProcess.execSync('node is-online.js', { cwd: __dirname, encoding: 'utf8' }).trim(); |
| 12 | +var isOnline = connectivityStatus == 'online'; |
| 13 | +console.log('Running ' + connectivityStatus); |
11 | 14 |
|
12 | 15 | /**
|
13 | 16 | * Load information about this project from the package.json
|
@@ -100,58 +103,68 @@ var getPreviousVersions = function() {
|
100 | 103 | // not contain all commits when cloned with git clone --depth=...
|
101 | 104 | // Needed e.g. for Travis
|
102 | 105 | var repo_url = currentPackage.repository.url;
|
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(); |
| 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 | + } |
128 | 134 | } else {
|
129 |
| - return []; |
| 135 | + console.log('-- skipping remote git tag lookup'); |
130 | 136 | }
|
| 137 | + return []; |
131 | 138 | };
|
132 | 139 |
|
133 | 140 | var getCdnVersion = function() {
|
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; |
| 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 | + } |
150 | 161 | }
|
151 | 162 | }
|
152 |
| - } |
153 |
| - return cdnVersion; |
154 |
| - }, null); |
| 163 | + return cdnVersion; |
| 164 | + }, null); |
| 165 | + } else { |
| 166 | + console.log('-- skipping CDN version lookup'); |
| 167 | + } |
155 | 168 | };
|
156 | 169 |
|
157 | 170 | /**
|
@@ -198,7 +211,6 @@ var getSnapshotVersion = function() {
|
198 | 211 | return version;
|
199 | 212 | };
|
200 | 213 |
|
201 |
| - |
202 | 214 | exports.currentPackage = currentPackage = getPackage();
|
203 | 215 | exports.gitRepoInfo = gitRepoInfo = getGitRepoInfo();
|
204 | 216 | exports.previousVersions = previousVersions = getPreviousVersions();
|
|
0 commit comments