Skip to content

Commit

Permalink
feat: use split manifest files (#487)
Browse files Browse the repository at this point in the history
* feat: use split manifest files

* fix: ignore artifacts files on npm run build

* fix: remove browser_specific_settings from common manifest

* test: add manifest step on ci

* fix: generate both manifests on ci matrix
  • Loading branch information
victal authored May 5, 2024
1 parent 6cfbf54 commit 9f503d0
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
steps:
- name: Checkout
uses: actions/[email protected]
- name: Build manifest
run: npm run manifest
- name: Cypress run
uses: cypress-io/github-action@v6
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ tests/integration/videos

# Webextension build files
web-ext-artifacts/
manifest.json
manifest-*
3 changes: 3 additions & 0 deletions manifests/chrome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"manifest_version": 3
}
7 changes: 1 addition & 6 deletions manifest.json → manifests/common.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"manifest_version": 2,
"name": "Tapas RSS Button",
"version": "1.1.0",
"description": "A webextension that adds an RSS feed button on tapas.io webcomic pages",
Expand Down Expand Up @@ -33,10 +32,6 @@
],
"options_ui": {
"page": "src/options/index.html"
},
"browser_specific_settings": {
"gecko": {
"id": "{395c081e-9f3b-4218-9587-bcbfa467c3b6}"
}
}
}

8 changes: 8 additions & 0 deletions manifests/firefox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"manifest_version": 2,
"browser_specific_settings": {
"gecko": {
"id": "{395c081e-9f3b-4218-9587-bcbfa467c3b6}"
}
}
}
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
"description": "A webextension to add an rss button to tapas.io webcomics pages",
"main": "",
"scripts": {
"build": "web-ext build -o -i tests/ cypress/ images/ node_modules/ package.json README.md package-lock.json cypress.json",
"dev": "web-ext run -f ${FIREFOX:-firefox}",
"build": "npm run build:firefox && npm run build:chrome",
"build:firefox": "npm run manifest:firefox && web-ext build -a web-ext-artifacts/firefox",
"build:chrome": "npm run manifest:chrome && web-ext build -a web-ext-artifacts/chrome",
"dev": "npm run manifest:firefox && web-ext run -f ${FIREFOX:-firefox}",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"manifest": "npm run manifest:firefox && npm run manifest:chrome",
"manifest:firefox": "node scripts/merge_manifests.js manifests/common.json manifests/firefox.json && cp manifest.json manifest-firefox.json",
"manifest:chrome": "node scripts/merge_manifests.js manifests/common.json manifests/chrome.json && cp manifest.json manifest-chrome.json",
"test": "npm run test:unit && npm run test:cypress",
"test:unit": "mocha tests/unit/**/*.spec.js",
"test:cypress": "cypress run -b ${BROWSER:-firefox}",
"cypress:open": "cypress open"
"test:cypress": "npm run manifest:firefox && cypress run -b ${BROWSER:-firefox}",
"cypress:open": "npm run manifest && cypress open"
},
"repository": {
"type": "git",
Expand Down
15 changes: 15 additions & 0 deletions scripts/merge_manifests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const fs = require('fs')
const { dirname, join } = require('path')
const { argv } = require('process')

const root = dirname(__dirname)
const manifest = Object.assign({},
...argv.slice(2)
.map(file => fs.readFileSync(join(root, file)))
.map(JSON.parse.bind(JSON))
)

fs.writeFileSync(
join(root, 'manifest.json'),
JSON.stringify(manifest, null, 2)
)
5 changes: 3 additions & 2 deletions tests/integration/copy.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const { testPages } = require('../utils/series')

describe('Cypress tests for extension UI changes', () => {
const extensionAlias = `tapas-rss-${Cypress.browser.name}`
beforeEach(async () => {
return cy.setExtensionStorage('sync', { rssAction: 'copy' })
return cy.setExtensionStorage('sync', { rssAction: 'copy' }, { alias: extensionAlias })
})
afterEach(() => {
return cy.clearExtensionStorage('sync')
return cy.clearExtensionStorage('sync', { alias: extensionAlias })
})

for (const info of testPages) {
Expand Down
10 changes: 9 additions & 1 deletion tests/integration/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ const extensionLoader = require('@victal/cypress-extensions-plugin/loader')
module.exports = (on, config) => {
on('before:browser:launch', extensionLoader.load({
source: path.join(__dirname, '..', '..', '..'),
alias: 'tapas-rss-firefox',
manifest: 'manifest-firefox.json',
watch: false,
validBrowsers: ['chrome', 'firefox']
validBrowsers: ['firefox']
}, {
source: path.join(__dirname, '..', '..', '..'),
alias: 'tapas-rss-chrome',
manifest: 'manifest-chrome.json',
watch: false,
validBrowsers: ['chrome']
}))
}
22 changes: 22 additions & 0 deletions web-ext-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
ignoreFiles: [
'web-ext-config.js',
'web-ext-artifacts',
'tests/',
'cypress/',
'cypress.config.js',
'images/',
'node_modules/',
'package.json',
'README.md',
'package-lock.json',
'cypress.json',
'manifests/',
'scripts',
'manifest-chrome.json',
'manifest-firefox.json'
],
build: {
overwriteDest: true
}
}

0 comments on commit 9f503d0

Please sign in to comment.