diff --git a/Gruntfile.js b/Gruntfile.js index c29f87b43624..35cfc7b8d4d8 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -17,6 +17,10 @@ module.exports = function(grunt) { NG_VERSION.cdn = versionInfo.cdnVersion; var dist = 'angular-'+ NG_VERSION.full; + if (versionInfo.cdnVersion == null) { + throw new Error('Unable to read CDN version, are you offline or has the CDN not been properly pushed?'); + } + //config grunt.initConfig({ NG_VERSION: NG_VERSION, diff --git a/docs/app/e2e/app.scenario.js b/docs/app/e2e/app.scenario.js index f25d5d8233a5..7dfe4b15434c 100644 --- a/docs/app/e2e/app.scenario.js +++ b/docs/app/e2e/app.scenario.js @@ -39,7 +39,7 @@ describe('docs.angularjs.org', function () { it('should change the page content when clicking a link to a service', function () { - browser.get('build/docs/index.html'); + browser.get('build/docs/index-production.html'); var ngBindLink = element(by.css('.definition-table td a[href="api/ng/directive/ngClick"]')); ngBindLink.click(); @@ -51,33 +51,33 @@ describe('docs.angularjs.org', function () { it('should be resilient to trailing slashes', function() { - browser.get('build/docs/index.html#!/api/ng/function/angular.noop/'); + browser.get('build/docs/index-production.html#!/api/ng/function/angular.noop/'); var pageBody = element(by.css('h1')); expect(pageBody.getText()).toEqual('angular.noop'); }); it('should be resilient to trailing "index"', function() { - browser.get('build/docs/index.html#!/api/ng/function/angular.noop/index'); + browser.get('build/docs/index-production.html#!/api/ng/function/angular.noop/index'); var pageBody = element(by.css('h1')); expect(pageBody.getText()).toEqual('angular.noop'); }); it('should be resilient to trailing "index/"', function() { - browser.get('build/docs/index.html#!/api/ng/function/angular.noop/index/'); + browser.get('build/docs/index-production.html#!/api/ng/function/angular.noop/index/'); var pageBody = element(by.css('h1')); expect(pageBody.getText()).toEqual('angular.noop'); }); it('should display formatted error messages on error doc pages', function() { - browser.get('build/docs/index.html#!error/ng/areq?p0=Missing&p1=not%20a%20function,%20got%20undefined'); + browser.get('build/docs/index-production.html#!error/ng/areq?p0=Missing&p1=not%20a%20function,%20got%20undefined'); expect(element(by.css('.minerr-errmsg')).getText()).toEqual("Argument 'Missing' is not a function, got undefined"); }); it("should display an error if the page does not exist", function() { - browser.get('build/docs/index.html#!/api/does/not/exist'); + browser.get('build/docs/index-production.html#!/api/does/not/exist'); expect(element(by.css('h1')).getText()).toBe('Oops!'); }); diff --git a/lib/versions/version-info.js b/lib/versions/version-info.js index cf3f000cbd58..73df518a8740 100644 --- a/lib/versions/version-info.js +++ b/lib/versions/version-info.js @@ -6,6 +6,10 @@ var shell = require('shelljs'); var semver = require('semver'); var _ = require('lodash'); +var process = require('process'); +// We are only interested in whether this environment variable exists, hence the !! +var NO_REMOTE_REQUESTS = !!process.env['NG1_BUILD_NO_REMOTE_VERSION_REQUESTS']; + var currentPackage, previousVersions, cdnVersion, gitRepoInfo; @@ -96,12 +100,12 @@ var getTaggedVersion = function() { * @return {Array.} The collection of previous versions */ var getPreviousVersions = function() { - // always use the remote tags as the local clone might + // If we are allowing remote requests then use the remote tags as the local clone might // not contain all commits when cloned with git clone --depth=... - // Needed e.g. for Travis + // Otherwise just use the tags in the local repository var repo_url = currentPackage.repository.url; - var tagResults = shell.exec('git ls-remote --tags ' + repo_url, - {silent: true}); + var query = NO_REMOTE_REQUESTS ? 'git tag' : 'git ls-remote --tags ' + repo_url; + var tagResults = shell.exec(query, {silent: true}); if (tagResults.code === 0) { return _(tagResults.output.match(/v[0-9].*[0-9]$/mg)) .map(function(tag) { @@ -138,15 +142,20 @@ var getCdnVersion = function() { .reverse() .reduce(function(cdnVersion, version) { if (!cdnVersion) { - // Note: need to use shell.exec and curl here - // as version-infos returns its result synchronously... - var cdnResult = shell.exec('curl http://ajax.googleapis.com/ajax/libs/angularjs/' + version + '/angular.min.js ' + - '--head --write-out "%{http_code}" -o /dev/null -silent', - {silent: true}); - if (cdnResult.code === 0) { - var statusCode = cdnResult.output.trim(); - if (statusCode === '200') { - cdnVersion = version; + if (NO_REMOTE_REQUESTS) { + // We do not want to make any remote calls to the CDN so just use the most recent version + cdnVersion = version; + } else { + // Note: need to use shell.exec and curl here + // as version-infos returns its result synchronously... + var cdnResult = shell.exec('curl http://ajax.googleapis.com/ajax/libs/angularjs/' + version + '/angular.min.js ' + + '--head --write-out "%{http_code}" -o /dev/null -silent', + {silent: true}); + if (cdnResult.code === 0) { + var statusCode = cdnResult.output.trim(); + if (statusCode === '200') { + cdnVersion = version; + } } } } @@ -204,3 +213,13 @@ exports.gitRepoInfo = gitRepoInfo = getGitRepoInfo(); exports.previousVersions = previousVersions = getPreviousVersions(); exports.cdnVersion = cdnVersion = getCdnVersion(); exports.currentVersion = getTaggedVersion() || getSnapshotVersion(); + +if (NO_REMOTE_REQUESTS) { + console.log('=============================================================================================='); + console.log('Running with no remote requests for version data:'); + console.log(' - this is due to the "NG1_BUILD_NO_REMOTE_VERSION_REQUESTS" environment variable being defined.'); + console.log(' - be aware that the generated docs may not have valid or the most recent version information.'); + console.log('=============================================================================================='); +} +console.log('CDN version:', cdnVersion.raw); +console.log('Current version:', exports.currentVersion.raw); \ No newline at end of file