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

Add compress script to apply gzip to assets not packed by webpack #658

Merged
merged 2 commits into from
Jan 31, 2025
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to the Zlux App Manager will be documented in this file.

## `3.2.0`

- Enhacement: Zowe v3 Desktop assets are now compressed so that the Desktop can load faster on slow internet. (#658)

## `3.0.0`

- Enhancement: Updated the Desktop Angular version from 12 to 18. This makes V2 Angular apps incompatible with V3. Iframe and React is unaffected.
Expand Down
49 changes: 49 additions & 0 deletions virtual-desktop/gzip.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
This program and the accompanying materials are
made available under the terms of the Eclipse Public License v2.0 which accompanies
this distribution, and is available at https://www.eclipse.org/legal/epl-v20.html

SPDX-License-Identifier: EPL-2.0

Copyright Contributors to the Zowe Project.
*/

import * as fs from 'node:fs';
import * as path from 'node:path';
import { execSync } from 'node:child_process';

const GZIP_SIZE_MIN = 50000; //50 KB
const GZIP_ATTEMPT_MAX = 1000000000; //1 GB. Don't try compressing large files, these likely are incompressible binary.
const KEEP_RATIO = 0.85; // Items not compressed below this will not be kept as compressed

function recurse(directory) {
const listing = fs.readdirSync(directory, {withFileTypes: true});
listing.forEach((dirent)=> {
let itemPath = path.join(directory, dirent.name);
if (dirent.isDirectory()) {
recurse(itemPath);
} else {
let stat = fs.statSync(itemPath);
if ((stat.size >= GZIP_SIZE_MIN) && (stat.size <= GZIP_ATTEMPT_MAX)) {
execSync('gzip -k '+dirent.name, {cwd: directory});
let itemPathGz = path.join(directory, dirent.name+'.gz');
let statGz = fs.statSync(itemPathGz);
//keep only one file: compressed file is kept if meaningfully smaller.
if ((stat.size*KEEP_RATIO) < statGz.size) {
fs.unlinkSync(itemPathGz);
} else {
fs.unlinkSync(itemPath);
}
}
}
});
}

try {
const listing = fs.readdirSync('web');
} catch (e) {
console.log('Could not read web directory, run build first.');
process.exit(1);
}

recurse('web');
1 change: 1 addition & 0 deletions virtual-desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"start": "ng build --watch",
"build": "ng build && npm run copy",
"build:externals": "exit 0",
"compress": "node gzip.mjs",
"copy": "cpx node_modules/requirejs/require.js web/",
"i18n": "ng-xi18n -p tsconfig.ngx-i18n.json --i18nFormat=xlf --outFile=messages.xlf && xliffmerge -p xliffmerge.json",
"lint": "tslint -c tslint.json \"src/**/*.ts\""
Expand Down
Loading