Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add build script to pali canary #649

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,19 @@ jobs:
- name: Build project for Chrome
run: yarn run build:chrome

- name: Build project for Canary
run: yarn run build:canary

- name: List files in build directory
run: ls -l ./build

- name: Set asset name
id: set_asset_name
run: echo "ASSET_NAME=$(ls build | grep 'pali-wallet-chrome' | grep '.zip')" >> $GITHUB_ENV
- name: Set asset name for Chrome
id: set_asset_name_chrome
run: echo "ASSET_NAME_CHROME=$(ls build | grep 'pali-wallet-' | grep 'chrome' | grep '.zip' | grep -v 'canary')" >> $GITHUB_ENV

- name: Set asset name for Canary
id: set_asset_name_canary
run: echo "ASSET_NAME_CANARY=$(ls build | grep 'pali-wallet-' | grep 'chrome' | grep 'canary' | grep '.zip')" >> $GITHUB_ENV

- name: Get package version
id: get_version
Expand All @@ -51,12 +58,22 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload zip to release
- name: Upload Chrome zip to release
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./build/${{ env.ASSET_NAME }}
asset_name: ${{ env.ASSET_NAME }}
asset_path: ./build/${{ env.ASSET_NAME_CHROME }}
asset_name: ${{ env.ASSET_NAME_CHROME }}
asset_content_type: application/zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload Canary zip to release
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./build/${{ env.ASSET_NAME_CANARY }}
asset_name: ${{ env.ASSET_NAME_CANARY }}
asset_content_type: application/zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
},
"scripts": {
"generate-manifest": "node ./source/config/generateManifest.js",
"set-env": "node ./source/config/setEnvAndRun.js",
"dev:chrome": "yarn generate-manifest && cross-env NODE_ENV=development cross-env TARGET_BROWSER=chrome webpack --config source/config/webpack.dev.js --watch",
"build:chrome": "yarn generate-manifest && cross-env NODE_ENV=production cross-env TARGET_BROWSER=chrome webpack --config source/config/webpack.prod.js",
"build:chrome": "yarn set-env production chrome 'yarn generate-manifest && webpack --config source/config/webpack.prod.js'",
"build:canary": "yarn set-env canary chrome 'yarn generate-manifest && webpack --config source/config/webpack.prod.js'",
"dev-watch-requests:chrome": "jq '.permissions = if .permissions then (if (.permissions | index(\"webRequest\")) == null then .permissions + [\"webRequest\"] else .permissions end) else [\"webRequest\"] end | .environment = {\"WATCH_REQUESTS\": \"active\"}' manifest.json > modified_manifest.json && mv modified_manifest.json manifest.json && cross-env NODE_ENV=development cross-env TARGET_BROWSER=chrome webpack --watch",
"dev:firefox": "jq '.permissions = if .permissions then (if (.permissions | index(\"webRequest\")) == null then .permissions + [\"webRequest\"] else .permissions end) else [\"webRequest\"] end' manifest.json > modified_manifest.json && mv modified_manifest.json manifest.json && cross-env NODE_ENV=development cross-env TARGET_BROWSER=firefox webpack --watch",
"dev:opera": "jq '.permissions = if .permissions then (if (.permissions | index(\"webRequest\")) == null then .permissions + [\"webRequest\"] else .permissions end) else [\"webRequest\"] end' manifest.json > modified_manifest.json && mv modified_manifest.json manifest.json && cross-env NODE_ENV=development cross-env TARGET_BROWSER=opera webpack --watch",
Expand Down Expand Up @@ -185,4 +187,4 @@
},
"homepage": "https://github.com/syscoin/pali_wallet#readme",
"author": "pollum labs"
}
}
18 changes: 13 additions & 5 deletions source/config/generateManifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

const dotenv = require('dotenv');
const fs = require('fs');
const path = require('path');

const { MV2_OPTIONS, MV3_OPTIONS } = require('./consts.js');

dotenv.config();

function generateManifest() {
console.log(process.env.MANIFEST_TYPE);
const manifestOptions =
process.env.MANIFEST_TYPE === 'MV2' ? MV2_OPTIONS : MV3_OPTIONS;

Expand All @@ -27,14 +25,24 @@ function generateManifest() {
// prod
if (process.env.NODE_ENV === 'production') {
if (manifestOptions.permissions) {
manifestOptions.permissions = manifestOptions.permissions.filter(
(permission) => permission !== 'webRequest'
);
manifestOptions.permissions = filterWebRequest(manifestOptions.permissions);
}
}

// canary
if (process.env.NODE_ENV === 'canary') {
manifestOptions.name = manifestOptions.name.replace('Pali Wallet', 'Pali Wallet Canary');
if (manifestOptions.permissions) {
manifestOptions.permissions = filterWebRequest(manifestOptions.permissions);
}
}

const manifestContent = JSON.stringify(manifestOptions, null, 2);
fs.writeFileSync('manifest.json', manifestContent);
}

const filterWebRequest = (permissions) => {
return permissions.filter((permission) => permission !== 'webRequest');
}

generateManifest();
15 changes: 15 additions & 0 deletions source/config/setEnvAndRun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable */

const { execSync } = require('child_process');

const env = process.argv[2];
const targetBrowser = process.argv[3];
const command = process.argv.slice(4).join(' ');

process.env.NODE_ENV = env;
process.env.TARGET_BROWSER = targetBrowser;

console.log(`NODE_ENV: ${process.env.NODE_ENV}`);
console.log(`TARGET_BROWSER: ${process.env.TARGET_BROWSER}`);

execSync(command, { stdio: 'inherit' });
3 changes: 2 additions & 1 deletion source/config/webpack.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ const common = require('./webpack.common');
const version = require('../../package.json').version;

const targetBrowser = process.env.TARGET_BROWSER || 'chrome';
const environment = process.env.NODE_ENV;

module.exports = merge(common, {
mode: 'production',
devtool: 'source-map',
plugins: [
new ZipPlugin({
filename: `pali-wallet-${targetBrowser}-${version}`,
filename: `pali-wallet-${environment}-${targetBrowser}-${version}`,
path: path.join(__dirname, '../../build'),
extension: `${
targetBrowser === 'opera'
Expand Down
Loading