Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinmombay committed Dec 30, 2015
2 parents ed3b071 + 8eec93e commit 562506d
Show file tree
Hide file tree
Showing 151 changed files with 5,994 additions and 2,710 deletions.
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
"no-throw-literal": 2,
"no-trailing-spaces": 2,
"no-unused-expressions": 0,
"no-unused-vars": [2, {
"argsIgnorePattern": "^var_|opt_|unused",
"varsIgnorePattern": "AmpElement|Def|Interface$"
}],
"no-useless-call": 2,
"no-useless-concat": 2,
"no-var": 2,
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ script:
- gulp build
- gulp dist
- gulp presubmit
- gulp compile
# Unit tests with Travis' default chromium
- gulp test
# Integration tests with all saucelabs browsers
Expand Down
5 changes: 1 addition & 4 deletions 3p/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// TODO(malteubl) Move somewhere else since this is not an ad.

import {loadScript} from '../src/3p';
import {setStyles} from '../src/style';

/**
* Produces the Twitter API object for the passed in callback. If the current
Expand Down Expand Up @@ -52,8 +51,6 @@ function getTwttr(global, cb) {
export function twitter(global, data) {
const tweet = document.createElement('div');
tweet.id = 'tweet';
const width = data.initialWindowWidth;
const height = data.initialWindowHeight;
tweet.style.width = '100%';
global.document.getElementById('c').appendChild(tweet);
getTwttr(global, function(twttr) {
Expand All @@ -65,7 +62,7 @@ export function twitter(global, data) {
// Unfortunately the tweet isn't really done at this time.
// We listen for resize to learn when things are
// really done.
iframe.contentWindow.addEventListener('resize', function(e) {
iframe.contentWindow.addEventListener('resize', function() {
render();
}, true);
render();
Expand Down
2 changes: 1 addition & 1 deletion ads/adsense.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {writeScript, checkData} from '../src/3p';
import {checkData} from '../src/3p';

/**
* @param {!Window} global
Expand Down
1 change: 0 additions & 1 deletion ads/doubleclick.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export function doubleclick(global, data) {
}
});

const canvas = global.document.getElementById('c');
// Exported for testing.
c.slot = slot;
googletag.display('c');
Expand Down
25 changes: 24 additions & 1 deletion build-system/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* files and list directories for use with the gulp live server
*/
var app = require('connect')();
var bodyParser = require('body-parser');
var clr = require('connect-livereload');
var finalhandler = require('finalhandler');
var path = require('path');
Expand All @@ -29,9 +30,31 @@ var args = Array.prototype.slice.call(process.argv, 2, 4);
var paths = args[0];
var port = args[1];

app.use(bodyParser.json());

app.use('/api/show', function(req, res) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({
showNotification: true
}));
});

app.use('/api/dont-show', function(req, res) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({
showNotification: false
}));
});


app.use('/api/echo/post', function(req, res) {
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(req.body, null, 2));
});

app.use(clr());

paths.split(",").forEach(function(pth){
paths.split(',').forEach(function(pth) {
// Serve static files that exist
app.use(serveStatic(path.join(process.cwd(), pth)));
// Serve directory listings
Expand Down
90 changes: 90 additions & 0 deletions build-system/tasks/compile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* Copyright 2015 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

var closureCompiler = require('gulp-closure-compiler');
var gulp = require('gulp');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');

// Compiles AMP with the closure compiler. This is intended only for
// production use. During development we intent to continue using
// babel, as it has much faster incremental compilation.
// This currently only works for the main AMP JS binary, but should be
// straight forward to extend to the rest of our code base.
gulp.task('compile', function() {
/*eslint "google-camelcase/google-camelcase": 0*/
return gulp.src([
'ads/**/*.js',
'extensions/**/*.js',
'build/css.js',
'src/**/*.js',
// We do not want to load the entry point that loads the babel helpers.
'!src/amp-babel.js',
'builtins/**.js',
'third_party/caja/html-sanitizer.js',
'third_party/closure-library/sha384-generated.js',
'third_party/mustache/**/*.js',
'node_modules/document-register-element/build/' +
'document-register-element.max.js',
'node_modules/core-js/modules/**.js',
// Not sure what these files are, but they seem to duplicate code
// one level below and confuse the compiler.
'!node_modules/core-js/modules/library/**.js',
// Don't include tests.
'!**_test.js',
'!**/test-*.js',
])
.pipe(closureCompiler({
// Temporary shipping with our own compiler that has a single patch
// applied
compilerPath: 'third_party/closure-compiler/compiler.jar',
fileName: 'build/cc-amp.js',
compilerFlags: {
// Transpile from ES6 to ES5.
language_in: 'ECMASCRIPT6',
language_out: 'ECMASCRIPT5',
js_module_root: 'node_modules/',
common_js_entry_module: 'src/amp.js',
process_common_js_modules: true,
// This strips all files from the input set that aren't explicitly
// required.
only_closure_dependencies: true,
output_wrapper: '(function(){var process={env:{}};%output%})();'
}
}))
.on('error', function(err) {
if (/0 error\(s\)/.test(err.message)) {
// emit warning
console./*OK*/warn(err.message);
this.emit('end');
} else {
throw err;
}
})
.on('end', function() {
console./*OK*/log('Minify closure compiler result');
// Somewhat ironically we use uglify to further minify the result.
// This is needed because we currently use only very basic optimizations
// in closure compiler and it doesn't minify global variables at this
// stage.
return gulp.src(['build/cc-amp.js'])
.pipe(uglify({
preserveComments: 'some'
}))
.pipe(rename('cc-v0.js'))
.pipe(gulp.dest('dist'))
});
});
1 change: 1 addition & 0 deletions build-system/tasks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
require('./babel-helpers');
require('./changelog');
require('./clean');
require('./compile');
require('./lint');
require('./make-golden');
require('./presubmit-checks');
Expand Down
71 changes: 55 additions & 16 deletions build-system/tasks/presubmit-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,50 @@ var forbiddenTerms = {
]
},
// Service factories that should only be installed once.
'installActionService': {
message: privateServiceFactory,
whitelist: [
'src/service/action-impl.js',
'src/amp-core-service.js',
],
},
'installActionHandler': {
message: privateServiceFactory,
whitelist: [
'src/service/action-impl.js',
'extensions/amp-access/0.1/amp-access.js',
],
},
'installCidService': {
message: privateServiceFactory,
whitelist: [
'src/service/cid-impl.js',
'extensions/amp-analytics/0.1/amp-analytics.js',
'extensions/amp-analytics/0.1/test/test-amp-analytics.js',
'test/functional/test-cid.js',
'test/functional/test-url-replacements.js'
],
},
'installViewerService': {
message: privateServiceFactory,
whitelist: [
'src/amp-core-service.js',
'src/service/history-impl.js',
'src/service/viewer-impl.js',
'src/service/viewport-impl.js',
'src/service/vsync-impl.js',
],
},
'installViewportService': {
message: privateServiceFactory,
whitelist: [
'src/amp-core-service.js',
'src/service/viewport-impl.js',
],
},
'installVsyncService': {
message: privateServiceFactory,
whitelist: [
'src/amp-core-service.js',
'src/service/viewport-impl.js',
'src/service/vsync-impl.js',
],
},
// Privacy sensitive
Expand All @@ -66,25 +102,21 @@ var forbiddenTerms = {
'src/cid.js',
'src/service/cid-impl.js',
'src/url-replacements.js',
'test/functional/test-cid.js',
'extensions/amp-user-notification/0.1/amp-user-notification.js',
],
},
'getBaseCid': {
message: requiresReviewPrivacy,
whitelist: [
'src/service/cid-impl.js',
'src/viewer.js',
'test/functional/test-cid.js',
'src/service/viewer-impl.js',
],
},
'cookie\\W': {
message: requiresReviewPrivacy,
whitelist: [
'src/cookies.js',
'src/service/cid-impl.js',
'test/functional/test-cid.js',
'test/functional/test-cookies.js',
'test/functional/test-experiments.js',
],
},
'getCookie\\W': {
Expand All @@ -93,7 +125,6 @@ var forbiddenTerms = {
'src/service/cid-impl.js',
'src/cookies.js',
'src/experiments.js',
'test/functional/test-cookies.js',
'tools/experiments/experiments.js',
]
},
Expand All @@ -102,19 +133,14 @@ var forbiddenTerms = {
whitelist: [
'src/cookies.js',
'src/experiments.js',
'test/functional/test-cookies.js',
'test/functional/test-url-replacements.js',
'tools/experiments/experiments.js',
]
},
'eval\\(': '',
'localStorage': {
message: requiresReviewPrivacy,
whitelist: [
'extensions/amp-analytics/0.1/test/test-amp-analytics.js',
'test/_init_tests.js',
'src/service/cid-impl.js',
'test/functional/test-cid.js',
],
},
'sessionStorage': requiresReviewPrivacy,
Expand Down Expand Up @@ -227,6 +253,18 @@ var requiredTerms = {
dedicatedCopyrightNoteSources,
};


/**
* Check if root of path is test/ or file is in a folder named test.
* @param {string} path
* @return {boolean}
*/
function isInTestFolder(path) {
var dirs = path.split('/');
var folder = dirs[dirs.length - 2];
return path.startsWith('test/') || folder == 'test';
}

/**
* Logs any issues found in the contents of file based on terms (regex
* patterns), and provides any possible fix information for matched terms if
Expand All @@ -247,7 +285,8 @@ function matchTerms(file, terms) {
var whitelist = terms[term].whitelist;
// NOTE: we could do a glob test instead of exact check in the future
// if needed but that might be too permissive.
if (Array.isArray(whitelist) && whitelist.indexOf(relative) != -1) {
if (Array.isArray(whitelist) && (whitelist.indexOf(relative) != -1 ||
isInTestFolder(relative))) {
return false;
}
// we can't optimize building the `RegExp` objects early unless we build
Expand Down
9 changes: 9 additions & 0 deletions css/amp.css
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,12 @@ amp-analytics {
overflow: hidden !important;
visibility: hidden;
}


/**
* Minimal AMP Access CSS. This part has to be here so that the correct UI
* can be provided before AMP Access JS has been loaded.
*/
[amp-access][amp-access-off] {
display: none;
}
2 changes: 1 addition & 1 deletion examples/analytics.amp.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<script type="application/json">
{
"vars": {
"account": "UA-XXXX-Y"
"account": "UA-YYYY-Y"
},
"triggers": {
"default pageview": {
Expand Down
Loading

0 comments on commit 562506d

Please sign in to comment.