Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 857d78d

Browse files
chore(version-info): add offline-build support
Previously it was slow and problematic to run builds if you were not connected to the internet because the build scripts make requests to github and the Google CDN to find out version information. You can now disable these requests by setting the NG1_BUILD_NO_REMOTE_VERSION_REQUESTS environment variable to a non-empty value Closes #14769
1 parent 16d915c commit 857d78d

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

lib/versions/version-info.js

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ var shell = require('shelljs');
66
var semver = require('semver');
77
var _ = 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+
913
var currentPackage, previousVersions, cdnVersion, gitRepoInfo;
1014

1115

@@ -96,12 +100,12 @@ var getTaggedVersion = function() {
96100
* @return {Array.<SemVer>} The collection of previous versions
97101
*/
98102
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
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();
204213
exports.previousVersions = previousVersions = getPreviousVersions();
205214
exports.cdnVersion = cdnVersion = getCdnVersion();
206215
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

Comments
 (0)