Skip to content

Commit

Permalink
Test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mrruby committed Dec 17, 2023
1 parent f2a8a90 commit 2634334
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 14 deletions.
13 changes: 13 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CHROME_ID=your_chrome_id
CHROME_CLIENT_ID=your_chrome_client_id
CHROME_CLIENT_SECRET=your_chrome_client_secret
CHROME_REFRESH_TOKEN=your_chrome_refresh_token
EDGE_ID=your_edge_id
EDGE_CLIENT_ID=your_edge_client_id
EDGE_CLIENT_SECRET=your_edge_client_secret
EDGE_ACCESS_TOKEN_URL=your_edge_access_token_url
FF_ID=your_firefox_id
FF_JWT_ISSUER=your_firefox_jwt_issuer
FF_JWT_SECRET=your_firefox_jwt_secret


8 changes: 4 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: pnpm install

- name: Build extension
run: pnpm run build
run: FF_ID=${{ env.FF_ID }} pnpm build:prod

- name: Zip the build
run: |
Expand All @@ -41,21 +41,21 @@ jobs:
client_id: ${{ secrets.CHROME_CLIENT_ID }}
client_secret: ${{ secrets.CHROME_CLIENT_SECRET }}
refresh_token: ${{ secrets.CHROME_REFRESH_TOKEN }}
extension_id: eggfhkdnfdhdpmkfpihjjbnncgmhihce
extension_id: ${{ env.CHROME_ID }}
zip_file: build.zip

- name: Firefox upload & release
uses: cardinalby/[email protected]
with:
zipFilePath: build.zip
extensionId: [email protected]
extensionId: ${{ env.FF_ID }}
jwtIssuer: ${{ secrets.FF_JWT_ISSUER }}
jwtSecret: ${{ secrets.FF_JWT_SECRET }}

- name: Edge upload & release
uses: wdzeng/[email protected]
with:
product-id: 70d8655d-2c91-4b81-99b1-35afa863ea8c
product-id: ${{ env.EDGE_ID }}
zip-path: build.zip
client-id: ${{ secrets.EDGE_CLIENT_ID }}
client-secret: ${{ secrets.EDGE_CLIENT_SECRET }}
Expand Down
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
"version": "0.0.3",
"private": true,
"scripts": {
"dev": "vite build --watch",
"build": "vite build && node removeInlineScript.cjs",
"build": "pnpm build:vite && pnpm build:script && pnpm build:removeExport && pnpm build:removeInline",
"build:prod": "pnpm build:replaceGeckoId -- FF_ID && pnpm build:dev",
"build:vite": "vite build",
"build:script": "tsc --p scripts/extension/tsconfig.json",
"build:removeExport": "node scripts/project/removeExportFromScript.cjs",
"build:removeInline": "node scripts/project/removeInlineScript.cjs",
"build:replaceGeckoId": "node scripts/project/replaceGeckoId.cjs",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
Expand All @@ -15,6 +20,7 @@
"devDependencies": {
"@sveltejs/adapter-static": "^2.0.3",
"@sveltejs/kit": "^1.27.7",
"@tsconfig/node-lts": "^20.1.0",
"@types/chrome": "^0.0.254",
"@types/file-saver": "^2.0.7",
"@typescript-eslint/eslint-plugin": "^6.13.2",
Expand Down
22 changes: 22 additions & 0 deletions scripts/extension/background.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Message } from '../../types/index';

console.log('background script loaded');

chrome.runtime.onMessageExternal.addListener((message: Message, sender, sendResponse) => {
if (message.action === 'openWindow') {
try {
chrome.windows.create({
url: 'sign.html',
type: 'popup',
height: 600,
width: 375,
top: 0,
left: screen.width - 375
});
} catch (error) {
console.error('Error creating window:', error);
return;
}
sendResponse({ success: true, message: 'Window opened' });
}
});
13 changes: 13 additions & 0 deletions scripts/extension/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"outDir": "../../build/scripts",
"allowJs": true,
"checkJs": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"strict": true,
"target": "esnext",
"types": ["chrome"]
},
"include": ["background.ts"]
}
18 changes: 18 additions & 0 deletions scripts/project/removeExportFromScript.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* eslint-disable @typescript-eslint/no-var-requires */
// removeExportFromScript.cjs
const path = require('path');
const fs = require('fs');

function removeExportStatement(directory, fileName) {
console.log('Removing "export {};" from script');
const filePath = path.join(directory, fileName);
let fileContent = fs.readFileSync(filePath, 'utf8');

// Replace "export {};" with an empty string
fileContent = fileContent.replace('export {};', '');

fs.writeFileSync(filePath, fileContent);
console.log(`"export {};" removed from: ${filePath}`);
}

removeExportStatement(path.resolve(__dirname, '../../build/scripts'), 'background.js');
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ async function removeInlineScript(directory) {
});
}

removeInlineScript(path.resolve(__dirname, 'build'));
removeInlineScript(path.resolve(__dirname, '../../build'));
41 changes: 41 additions & 0 deletions scripts/project/replaceGeckoId.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* eslint-disable @typescript-eslint/no-var-requires */
// replaceGeckoId.js
const fs = require('fs');
const path = require('path');

const manifestPath = path.resolve(__dirname, '../../static/manifest.json');

const args = process.argv.slice(2);
const geckoId = args[0];

if (!geckoId) {
console.error('Gecko ID is not provided as an argument.');
process.exit(1);
}

fs.readFile(manifestPath, 'utf8', (err, data) => {
if (err) {
console.error('Error reading the manifest file:', err);
return;
}

const manifest = JSON.parse(data);
const updatedManifest = {
...manifest,
browser_specific_settings: {
...manifest.browser_specific_settings,
gecko: {
id: geckoId
}
}
};

fs.writeFile(manifestPath, JSON.stringify(updatedManifest, null, 2), 'utf8', (err) => {
if (err) {
console.error('Error writing the manifest file:', err);
return;
}

console.log('Manifest file updated successfully.');
});
});
15 changes: 8 additions & 7 deletions static/manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
{
"name": "Holo key manager",
"description": "A browser extension to manage holo keys",
"version": "0.0.27",
"version": "0.0.28",
"manifest_version": 3,
"browser_specific_settings": {
"gecko": {
"id": "[email protected]"
}
},
"action": {
"default_title": "Holo key manager",
"default_icon": "favicon.png",
Expand All @@ -16,5 +11,11 @@
"content_security_policy": {
"extension_pages": "default-src 'self' 'wasm-unsafe-eval'"
},
"permissions": ["storage"]
"background": {
"service_worker": "scripts/background.js"
},
"permissions": ["activeTab", "storage", "tabs", "nativeMessaging"],
"externally_connectable": {
"matches": ["*://localhost/*"]
}
}

0 comments on commit 2634334

Please sign in to comment.