From ae41291e702f5c8ddd1eef8a351a7ec5090dfce5 Mon Sep 17 00:00:00 2001 From: Jalil Arfaoui Date: Sat, 30 Oct 2021 16:17:10 +0200 Subject: [PATCH] feat: Adapt manifest.json to LMEL facet --- manifest/base.js | 98 ++++++++++--------- manifest/development/chromium.js | 35 ++++--- manifest/development/firefox.js | 29 +++--- manifest/index.js | 8 +- manifest/proding/chromium.js | 47 ++++----- manifest/proding/firefox.js | 17 ++-- manifest/production/chromium.js | 6 +- manifest/production/firefox.js | 9 +- manifest/staging/chromium.js | 47 ++++----- manifest/staging/firefox.js | 17 ++-- .../molecules/Popin/PopinBottomBar.tsx | 61 ++++++------ src/libs/facets/dismoi.facet.ts | 1 + src/libs/facets/lmel.facet.ts | 1 + src/libs/facets/useFacetName.hook.ts | 11 +++ webpack/config.plugins.js | 2 +- 15 files changed, 218 insertions(+), 171 deletions(-) create mode 100644 src/libs/facets/dismoi.facet.ts create mode 100644 src/libs/facets/lmel.facet.ts create mode 100644 src/libs/facets/useFacetName.hook.ts diff --git a/manifest/base.js b/manifest/base.js index 72fef65de..3358f1d50 100644 --- a/manifest/base.js +++ b/manifest/base.js @@ -8,51 +8,55 @@ const version = require('../package.json').version; const icons = require('./icons'); -module.exports = Object.freeze({ - name: 'Dismoi', - description: - 'Amis, media, experts vous informent directement sur les pages web visitées. ', - version, - manifest_version: 2, - icons, - background: { - page: 'background.html' - }, - content_scripts: [ - { - exclude_globs: [ - '*.pdf*', - '*.Pdf*', - '*.PDF*', - '*.jpeg*', - '*.jpg*', - '*.png*', - '*.gif*' - ], - matches: ['*://*/*'], - exclude_matches: [ - '*://*.googleusercontent.com/viewer/secure/pdf/*', - '*://*.cdn.mozilla.net/*', - '*://*.accounts.firefox.com/*', - '*://*.addons.mozilla.org/*', - '*://*.input.mozilla.org/*', - '*://*.install.mozilla.org/*', - '*://*.support.mozilla.org/*', - '*://*.services.mozilla.org/*', - '*://*.testpilot.firefox.com/*' - ], - js: ['js/browser-polyfill.js', 'js/content.bundle.js'], - run_at: 'document_end' - } - ], - browser_action: { - default_icon: { - '16': 'img/logo/16x16.png', - '48': 'img/logo/48x48.png', - '128': 'img/logo/128x128.png' +module.exports = facet => { + const facetName = facet === 'lmel' ? 'Le Même en Local' : 'Dismoi'; + + return Object.freeze({ + name: facetName, + description: + 'Amis, media, experts vous informent directement sur les pages web visitées. ', + version, + manifest_version: 2, + icons, + background: { + page: 'background.html' + }, + content_scripts: [ + { + exclude_globs: [ + '*.pdf*', + '*.Pdf*', + '*.PDF*', + '*.jpeg*', + '*.jpg*', + '*.png*', + '*.gif*' + ], + matches: ['*://*/*'], + exclude_matches: [ + '*://*.googleusercontent.com/viewer/secure/pdf/*', + '*://*.cdn.mozilla.net/*', + '*://*.accounts.firefox.com/*', + '*://*.addons.mozilla.org/*', + '*://*.input.mozilla.org/*', + '*://*.install.mozilla.org/*', + '*://*.support.mozilla.org/*', + '*://*.services.mozilla.org/*', + '*://*.testpilot.firefox.com/*' + ], + js: ['js/browser-polyfill.js', 'js/content.bundle.js'], + run_at: 'document_end' + } + ], + browser_action: { + default_icon: { + '16': 'img/logo/16x16.png', + '48': 'img/logo/48x48.png', + '128': 'img/logo/128x128.png' + }, + default_title: facetName }, - default_title: 'Dismoi' - }, - permissions: ['activeTab', 'storage', 'contextMenus'], - web_accessible_resources: ['img/*', 'fonts/*'], -}); + permissions: ['activeTab', 'storage', 'contextMenus'], + web_accessible_resources: ['img/*', 'fonts/*'] + }); +}; diff --git a/manifest/development/chromium.js b/manifest/development/chromium.js index 5010f5144..cdf320a52 100644 --- a/manifest/development/chromium.js +++ b/manifest/development/chromium.js @@ -1,21 +1,24 @@ const csp = require('content-security-policy-builder'); const base = require('../base'); -module.exports = { - ...base, - name: `${base.name} - development`, - content_security_policy: csp({ - directives: { - 'script-src': ["'self'", "'unsafe-eval'"], - 'object-src': ["'self'"] +module.exports = facet => { + const facetBase = base(facet); + return { + ...facetBase, + name: `${facetBase.name} - development`, + content_security_policy: csp({ + directives: { + 'script-src': ["'self'", "'unsafe-eval'"], + 'object-src': ["'self'"] + } + }), + browser_action: { + ...facetBase.browser_action, + default_title: `${facetBase.browser_action.default_title} - development` + }, + externally_connectable: { + matches: ['*://localhost/*'], + accepts_tls_channel_id: false } - }), - browser_action: { - ...base.browser_action, - default_title: `${base.browser_action.default_title} - development` - }, - externally_connectable: { - matches: ['*://localhost/*'], - accepts_tls_channel_id: false - } + }; }; diff --git a/manifest/development/firefox.js b/manifest/development/firefox.js index 65ff91475..75246c00c 100644 --- a/manifest/development/firefox.js +++ b/manifest/development/firefox.js @@ -1,18 +1,21 @@ const csp = require('content-security-policy-builder'); const base = require('../base'); -module.exports = { - ...base, - name: `${base.name} - development`, - permissions: [...base.permissions, '*://*/*'], - content_security_policy: csp({ - directives: { - 'script-src': ["'self'", "'unsafe-eval'"], - 'object-src': ["'self'"] +module.exports = facet => { + const facetBase = base(facet); + return { + ...facetBase, + name: `${facetBase.name} - development`, + permissions: [...facetBase.permissions, '*://*/*'], + content_security_policy: csp({ + directives: { + 'script-src': ["'self'", "'unsafe-eval'"], + 'object-src': ["'self'"] + } + }), + browser_action: { + ...facetBase.browser_action, + default_title: `${facetBase.browser_action.default_title} - development` } - }), - browser_action: { - ...base.browser_action, - default_title: `${base.browser_action.default_title} - development` - } + }; }; diff --git a/manifest/index.js b/manifest/index.js index 80276ea4d..cb16fb206 100644 --- a/manifest/index.js +++ b/manifest/index.js @@ -1,8 +1,12 @@ const getManifestFilepath = (env, platform) => `./${env}/${platform}.js`; -const getManifest = (env, platform) => { +const getManifest = (env, platform, facet) => { console.log(getManifestFilepath(env, platform)); - return JSON.stringify(require(getManifestFilepath(env, platform)), null, 2); + return JSON.stringify( + require(getManifestFilepath(env, platform))(facet), + null, + 2 + ); }; module.exports = getManifest; diff --git a/manifest/proding/chromium.js b/manifest/proding/chromium.js index 5d53bae32..eb28d3b95 100644 --- a/manifest/proding/chromium.js +++ b/manifest/proding/chromium.js @@ -2,27 +2,30 @@ const csp = require('content-security-policy-builder'); const production = require('../production/chromium'); const base = require('../base'); -module.exports = { - ...production, - name: `${base.name} - proding`, - content_security_policy: csp({ - directives: { - 'default-src': ['https://api.dismoi.io'], - 'connect-src': [ - 'https://api.dismoi.io', - 'https://sentry.io', - 'https://stats.lmem.net', - 'https://app.posthog.com' - ], - 'script-src': ["'self'", "'unsafe-eval'"], - 'object-src': ["'self'"], - 'img-src': ["'self'", 'https://api.dismoi.io', 'data:'], - 'font-src': ["'self'", 'data:'], - 'style-src': ["'unsafe-inline'"] +module.exports = facet => { + const facetBase = base(facet); + return { + ...production(facet), + name: `${facetBase.name} - proding`, + content_security_policy: csp({ + directives: { + 'default-src': ['https://api.dismoi.io'], + 'connect-src': [ + 'https://api.dismoi.io', + 'https://sentry.io', + 'https://stats.lmem.net', + 'https://app.posthog.com' + ], + 'script-src': ["'self'", "'unsafe-eval'"], + 'object-src': ["'self'"], + 'img-src': ["'self'", 'https://api.dismoi.io', 'data:'], + 'font-src': ["'self'", 'data:'], + 'style-src': ["'unsafe-inline'"] + } + }), + browser_action: { + ...facetBase.browser_action, + default_title: `${facetBase.browser_action.default_title} - proding` } - }), - browser_action: { - ...base.browser_action, - default_title: `${base.browser_action.default_title} - proding` - } + }; }; diff --git a/manifest/proding/firefox.js b/manifest/proding/firefox.js index d125b6766..26cdb76f5 100644 --- a/manifest/proding/firefox.js +++ b/manifest/proding/firefox.js @@ -1,11 +1,14 @@ const production = require('../production/firefox'); const base = require('../base'); -module.exports = { - ...production, - name: `${base.name} - proding`, - browser_action: { - ...base.browser_action, - default_title: `${base.browser_action.default_title} - proding` - } +module.exports = facet => { + const facetBase = base(facet); + return { + ...production(facet), + name: `${facetBase.name} - proding`, + browser_action: { + ...facetBase.browser_action, + default_title: `${facetBase.browser_action.default_title} - proding` + } + }; }; diff --git a/manifest/production/chromium.js b/manifest/production/chromium.js index c4471ec0d..bfa9afdc6 100644 --- a/manifest/production/chromium.js +++ b/manifest/production/chromium.js @@ -1,8 +1,8 @@ const csp = require('content-security-policy-builder'); const base = require('../base'); -module.exports = { - ...base, +module.exports = facet => ({ + ...base(facet), content_security_policy: csp({ directives: { 'default-src': ['https://api.dismoi.io'], @@ -23,4 +23,4 @@ module.exports = { matches: ['https://*.dismoi.io/*'], accepts_tls_channel_id: false } -}; +}); diff --git a/manifest/production/firefox.js b/manifest/production/firefox.js index 213d18f63..e5e83a19d 100644 --- a/manifest/production/firefox.js +++ b/manifest/production/firefox.js @@ -1,6 +1,9 @@ const base = require('../base'); -module.exports = { - ...base, - permissions: [...base.permissions, '*://*/*'] +module.exports = facet => { + const facetBase = base(facet); + return { + ...facetBase, + permissions: [...facetBase.permissions, '*://*/*'] + }; }; diff --git a/manifest/staging/chromium.js b/manifest/staging/chromium.js index 670a4f1f9..effe35815 100644 --- a/manifest/staging/chromium.js +++ b/manifest/staging/chromium.js @@ -2,27 +2,30 @@ const csp = require('content-security-policy-builder'); const proding = require('../proding/chromium'); const base = require('../base'); -module.exports = { - ...proding, - name: `${base.name} - staging`, - content_security_policy: csp({ - directives: { - 'default-src': ['https://staging.dismoi.io'], - 'connect-src': [ - 'https://staging.dismoi.io', - 'https://sentry.io', - 'https://stats.lmem.net', - 'https://app.posthog.com' - ], - 'script-src': ["'self'", "'unsafe-eval'"], - 'object-src': ["'self'"], - 'img-src': ["'self'", 'https://staging.dismoi.io', 'data:'], - 'font-src': ["'self'", 'data:'], - 'style-src': ["'unsafe-inline'"] +module.exports = facet => { + const facetBase = base(facet); + return { + ...proding(facet), + name: `${facetBase.name} - staging`, + content_security_policy: csp({ + directives: { + 'default-src': ['https://staging.dismoi.io'], + 'connect-src': [ + 'https://staging.dismoi.io', + 'https://sentry.io', + 'https://stats.lmem.net', + 'https://app.posthog.com' + ], + 'script-src': ["'self'", "'unsafe-eval'"], + 'object-src': ["'self'"], + 'img-src': ["'self'", 'https://staging.dismoi.io', 'data:'], + 'font-src': ["'self'", 'data:'], + 'style-src': ["'unsafe-inline'"] + } + }), + browser_action: { + ...facetBase.browser_action, + default_title: `${facetBase.browser_action.default_title} - staging` } - }), - browser_action: { - ...base.browser_action, - default_title: `${base.browser_action.default_title} - staging` - } + }; }; diff --git a/manifest/staging/firefox.js b/manifest/staging/firefox.js index 0e6a55574..3ed141b13 100644 --- a/manifest/staging/firefox.js +++ b/manifest/staging/firefox.js @@ -1,11 +1,14 @@ const proding = require('../proding/firefox'); const base = require('../base'); -module.exports = { - ...proding, - name: `${base.name} - staging`, - browser_action: { - ...base.browser_action, - default_title: `${base.browser_action.default_title} - staging` - } +module.exports = facet => { + const facetBase = base(facet); + return { + ...proding(facet), + name: `${facetBase.name} - staging`, + browser_action: { + ...facetBase.browser_action, + default_title: `${facetBase.browser_action.default_title} - staging` + } + }; }; diff --git a/src/components/molecules/Popin/PopinBottomBar.tsx b/src/components/molecules/Popin/PopinBottomBar.tsx index d5fd86f48..101eac7ba 100644 --- a/src/components/molecules/Popin/PopinBottomBar.tsx +++ b/src/components/molecules/Popin/PopinBottomBar.tsx @@ -9,6 +9,7 @@ import LogoLesInrocks from 'assets/img/contributors/logo-les-inrocks.png'; import LogoMicode from 'assets/img/contributors/logo-micode.png'; import LogoQueChoisir from 'assets/img/contributors/logo-que-choisir.png'; import { WEBSITE_DOMAIN } from 'libs/domain'; +import { useFacetName } from 'libs/facets/useFacetName.hook'; const Link = styled(ExternalLink)` color: ${props => props.theme.text}; @@ -45,33 +46,37 @@ const ContributorItem = styled.li` } `; -const PopinBottomBar = () => ( - - - En savoir plus sur DisMoi{' '} - et ses sources - - - - - - - - - - - - - - - - - - - - - - -); +const PopinBottomBar = () => { + const facetName = useFacetName(); + return ( + + + En savoir plus sur{' '} + {facetName} et ses + sources + + + + + + + + + + + + + + + + + + + + + + + ); +}; export default PopinBottomBar; diff --git a/src/libs/facets/dismoi.facet.ts b/src/libs/facets/dismoi.facet.ts new file mode 100644 index 000000000..276c500db --- /dev/null +++ b/src/libs/facets/dismoi.facet.ts @@ -0,0 +1 @@ +export const facetName = 'DisMoi'; diff --git a/src/libs/facets/lmel.facet.ts b/src/libs/facets/lmel.facet.ts new file mode 100644 index 000000000..14c409792 --- /dev/null +++ b/src/libs/facets/lmel.facet.ts @@ -0,0 +1 @@ +export const facetName = 'Le Même en Local'; diff --git a/src/libs/facets/useFacetName.hook.ts b/src/libs/facets/useFacetName.hook.ts new file mode 100644 index 000000000..8ef0d0d90 --- /dev/null +++ b/src/libs/facets/useFacetName.hook.ts @@ -0,0 +1,11 @@ +import { facetName as lmelName } from './lmel.facet'; +import { facetName as dismoiName } from './dismoi.facet'; + +export function useFacetName() { + switch (process.env.FACET) { + case 'lmel': + return lmelName; + } + + return dismoiName; +} diff --git a/webpack/config.plugins.js b/webpack/config.plugins.js index 2032e9133..3eb6a7104 100644 --- a/webpack/config.plugins.js +++ b/webpack/config.plugins.js @@ -88,7 +88,7 @@ module.exports = (env = {}, argv = {}, buildPath) => { plugins.push( new AddAssetWebpackPlugin( 'manifest.json', - getManifest(NODE_ENV, PLATFORM) + getManifest(NODE_ENV, PLATFORM, FACET) ) ); }