Skip to content

Commit

Permalink
Build all ad extensions with amp-ad (#17291)
Browse files Browse the repository at this point in the history
* build all ad extensions

* approach 2

* add comment
  • Loading branch information
zhouyx committed Aug 13, 2018
1 parent 4711b23 commit 837db4c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions gulpfile.js
Expand Up @@ -57,6 +57,9 @@ const hostname3p = argv.hostname3p || '3p.ampproject.net';
const extensions = {};
const extensionAliasFilePath = {};

// All a4a extensions.
const adVendors = [];

const {green, red, cyan} = colors;

const minifiedRuntimeTarget = 'dist/v0.js';
Expand Down Expand Up @@ -139,6 +142,12 @@ function declareExtension(name, version, options) {
extensions[`${name}-${v}`] =
Object.assign({name, version: v}, defaultOptions, options);
});
if (name.startsWith('amp-ad-network-')) {
// Get the ad network name. All ad network extensions are named
// in the format `amp-ad-network-${name}-impl`
name = name.slice(15, -5);
adVendors.push(name);
}
}

/**
Expand Down Expand Up @@ -260,10 +269,22 @@ function getExtensionsFromArg(examples) {
const html = fs.readFileSync(example, 'utf8');
const customElementTemplateRe = /custom-(element|template)="([^"]+)"/g;
const extensionNameMatchIndex = 2;
let hasAd = false;
let match;
while ((match = customElementTemplateRe.exec(html))) {
if (match[extensionNameMatchIndex] == 'amp-ad') {
hasAd = true;
}
extensions.push(match[extensionNameMatchIndex]);
}
if (hasAd) {
for (let i = 0; i < adVendors.length; i++) {
if (html.includes(`type="${adVendors[i]}"`)) {
extensions.push('amp-a4a');
extensions.push(`amp-ad-network-${adVendors[i]}-impl`);
}
}
}
});

return dedupe(extensions);
Expand Down

0 comments on commit 837db4c

Please sign in to comment.