Skip to content

Commit

Permalink
🏗 Share utility to convert amp- names to bento- (#36359)
Browse files Browse the repository at this point in the history
Closes #36351
  • Loading branch information
alanorozco committed Oct 14, 2021
1 parent 5fed125 commit 759e265
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
9 changes: 9 additions & 0 deletions build-system/tasks/bento-helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @param {string} name
* @return {string}
*/
function getBentoName(name) {
return `bento-${name.replace(/^amp-/, '')}`;
}

module.exports = {getBentoName};
4 changes: 2 additions & 2 deletions build-system/tasks/css/bento-css.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const CssSelectorTokenizer = require('css-selector-tokenizer');
const postcss = require('postcss');
const {getBentoName} = require('../bento-helpers');

/**
* @param {string} selector
Expand All @@ -14,8 +15,7 @@ function renameTagNamesInSelector(selector) {
continue;
}
if (node.type === 'element') {
// TODO(https://go.amp.dev/issue/36351): Use shared utility function
node.name = node.name.replace(/^amp-/, 'bento-');
node.name = getBentoName(node.name);
}
if (Array.isArray(node.nodes)) {
nodes.push(...node.nodes);
Expand Down
5 changes: 3 additions & 2 deletions build-system/tasks/extension-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const {
const {analyticsVendorConfigs} = require('./analytics-vendor-configs');
const {compileJison} = require('./compile-jison');
const {cyan, green, red} = require('kleur/colors');
const {getBentoName} = require('./bento-helpers');
const {isCiBuild} = require('../common/ci');
const {jsifyCssAsync} = require('./css/jsify-css');
const {jssOptions} = require('../babel-config/jss-config');
Expand Down Expand Up @@ -625,7 +626,7 @@ async function buildExtensionCss(extDir, name, version, options) {
* @return {!Promise}
*/
async function buildBentoCss(name, version, minifiedAmpCss) {
const bentoName = name.replace(/^amp-/, 'bento-');
const bentoName = getBentoName(name);
const renamedCss = await renameSelectorsToBentoTagNames(minifiedAmpCss);
await fs.outputFile(`build/${bentoName}-${version}.css`, renamedCss);
await fs.outputFile(`dist/v0/${bentoName}-${version}.css`, renamedCss);
Expand Down Expand Up @@ -713,7 +714,7 @@ function buildBinaries(extDir, binaries, options) {
* @return {!Promise}
*/
async function buildBentoExtensionJs(dir, name, options) {
const bentoName = name.replace(/^amp-/, 'bento-');
const bentoName = getBentoName(name);
return buildExtensionJs(dir, bentoName, {
...options,
wrapper: 'none',
Expand Down

0 comments on commit 759e265

Please sign in to comment.