Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Commit

Permalink
fix(ecl-diff): regex improved, other fixes - TWIG-206 (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
planctus authored and papegaill committed Jan 17, 2020
1 parent 19f89c6 commit 23fee8e
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions php/php_storybook/scripts/ecl-diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,26 @@
no-param-reassign, no-restricted-syntax, no-await-in-loop */

const fs = require('fs');
const htmlDiffer = require('html-differ');
const logger = require('html-differ/lib/logger');
const puppeteer = require('puppeteer');
const decode = require('decode-html');
const yargsInteractive = require('yargs-interactive');
const { HtmlDiffer } = require('html-differ');

const diffOptions = {
ignoreAttributes: ['href'],
compareAttributesAsJSON: [],
ignoreWhitespaces: true,
ignoreComments: true,
ignoreEndTags: false,
ignoreDuplicateAttributes: false,
};

const htmlDiffer = new HtmlDiffer(diffOptions);
let packages = require('../../../../src/ec/.storybook/ec-packages.js').list;

const system = 'ec';
const domain = 'https://ec.europa.eu';
const rootFolder = process.cwd();
const distFolder = `${rootFolder}/php`;
const systemFolder = `${distFolder}/packages/${system}`;
Expand Down Expand Up @@ -68,15 +80,6 @@ const options = {
},
};

const diffOptions = {
ignoreAttributes: ['xlink:href', 'href'],
compareAttributesAsJSON: [],
ignoreWhitespaces: true,
ignoreComments: true,
ignoreEndTags: false,
ignoreDuplicateAttributes: false,
};

yargsInteractive()
.usage('$0 <command> [args]')
.interactive(options)
Expand Down Expand Up @@ -158,13 +161,13 @@ yargsInteractive()
.replace(
/xlink:href="\/?icons(-social)?\.svg#/g,
'xlink:href="{{.*icons.*.svg#}}'
// Booleans.
)
.replace(
/(data-ecl-)(?!auto-init)([^\n\r =]+)(="(true|false)")?/g,
'$1$2="{{true|false}}"'
// Logo.
)
// Booleans.
// Inline attributes.
.replace(/(data-ecl-)([^ =|]+) /g, '$1$2="{{true|false}}" ')
// Standalone attributes.
.replace(/(data-ecl-)([^\s|]+)=""/g, '$1$2="{{true|false}}"')
// Logo
.replace(/\/logo--(en|fr).svg/g, '{{(.*?)logo--(en|fr).*.svg}}');
// Now we process the story in ECL, we try to retrieve all the stories available
// and see if any of them matches the requested one, if none does we return the
Expand Down Expand Up @@ -222,7 +225,7 @@ yargsInteractive()
if (eclSubSection !== 'none') {
eclGluePath = `${eclSection}-${eclSubSection}`;
}
const eclPath = `https://ec.europa.eu/component-library/playground/ec/?path=/story/${eclGluePath}-`;
const eclPath = `${domain}/component-library/playground/ec/?path=/story/${eclGluePath}-`;
const eclFinalUrl = `${eclPath + eclComponent}--${eclStory}`;
// Puppeteer will go to the url and try to click on the link in the left sidebar
// to reveal the available stories.
Expand All @@ -249,7 +252,7 @@ yargsInteractive()
story
);
// Try to match the urls found with the one built in this script.
if (eclFinalUrl === `https://ec.europa.eu${href}`) {
if (eclFinalUrl === `${domain}${href}`) {
hrefs = false;
break;
}
Expand Down

0 comments on commit 23fee8e

Please sign in to comment.