Skip to content

Commit

Permalink
Issue 6375 - UI - Update cockpit.js code to the latest version (#6376)
Browse files Browse the repository at this point in the history
Description: Update src/cockpit/389-console/pkg/lib/cockpit.js to the latest version.
Update the entire src/cockpit/389-console/pkg/lib directory from Cockpit's repository.
Update package.json.
Update 389 DS UI components to PF5.

Fixes: #6375

Reviewed by: @progier389, @mreynolds389 (Thanks!!)
  • Loading branch information
droideck committed Jan 8, 2025
1 parent 1e4ce02 commit 77294b7
Show file tree
Hide file tree
Showing 188 changed files with 23,126 additions and 10,727 deletions.
38 changes: 19 additions & 19 deletions src/cockpit/389-console/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import os from 'node:os';

import copy from 'esbuild-plugin-copy';
Expand All @@ -11,16 +12,20 @@ import { cockpitCompressPlugin } from './pkg/lib/esbuild-compress-plugin.js';
import { cockpitPoEsbuildPlugin } from './pkg/lib/cockpit-po-plugin.js';
import { cockpitRsyncEsbuildPlugin } from './pkg/lib/cockpit-rsync-plugin.js';
import { esbuildStylesPlugins } from './pkg/lib/esbuild-common.js';
import { eslintPlugin } from './pkg/lib/esbuild-eslint-plugin.js';
import { stylelintPlugin } from './pkg/lib/esbuild-stylelint-plugin.js';

const production = process.env.NODE_ENV === 'production';
const useWasm = os.arch() !== 'x64';
const esbuild = (await import(useWasm ? 'esbuild-wasm' : 'esbuild')).default;

const production = process.env.NODE_ENV === 'production';
const watchMode = process.env.ESBUILD_WATCH === "true";
// linters dominate the build time, so disable them for production builds by default, but enable in watch mode
const lint = process.env.LINT ? (process.env.LINT !== 0) : (watchMode || !production);
const parser = (await import('argparse')).default.ArgumentParser();
parser.add_argument('-r', '--rsync', { help: "rsync bundles to ssh target after build", metavar: "HOST" });
parser.add_argument('-w', '--watch', { action: 'store_true', help: "Enable watch mode", default: process.env.ESBUILD_WATCH === "true" });
parser.add_argument('-m', '--metafile', { help: "Enable bundle size information file", metavar: "FILE" });
const args = parser.parse_args();

if (args.rsync)
process.env.RSYNC = args.rsync;

// List of directories to use when using import statements
const nodePaths = ['pkg/lib'];
const outdir = 'dist';
Expand All @@ -47,15 +52,12 @@ function notifyEndPlugin() {
};
}

const cwd = process.cwd();

// similar to fs.watch(), but recursively watches all subdirectories
function watch_dirs(dir, on_change) {
const callback = (ev, dir, fname) => {
// only listen for "change" events, as renames are noisy
// ignore hidden files
const isHidden = /^\./.test(fname);
if (ev !== "change" || isHidden) {
if (ev !== "change" || fname.startsWith('.')) {
return;
}
on_change(path.join(dir, fname));
Expand All @@ -81,18 +83,13 @@ const context = await esbuild.context({
external: ['*.woff', '*.woff2', '*.jpg', '*.svg', '../../assets*'], // Allow external font files which live in ../../static/fonts
legalComments: 'external', // Move all legal comments to a .LEGAL.txt file
loader: { ".js": "jsx" },
metafile: !!args.metafile,
minify: production,
nodePaths,
outdir,
target: ['es2020'],
plugins: [
cleanPlugin(),
...lint
? [
stylelintPlugin({ filter: new RegExp(cwd + '\/src\/.*\.(css?|scss?)$') }),
eslintPlugin({ filter: new RegExp(cwd + '\/src\/.*\.(jsx?|js?)$') })
]
: [],
// Esbuild will only copy assets that are explicitly imported and used
// in the code. This is a problem for index.html and manifest.json which are not imported
copy({
Expand All @@ -110,14 +107,17 @@ const context = await esbuild.context({
});

try {
await context.rebuild();
const result = await context.rebuild();
if (args.metafile) {
fs.writeFileSync(args.metafile, JSON.stringify(result.metafile));
}
} catch (e) {
if (!watchMode)
if (!args.watch)
process.exit(1);
// ignore errors in watch mode
}

if (watchMode) {
if (args.watch) {
const on_change = async path => {
console.log("change detected:", path);
await context.cancel();
Expand Down
2 changes: 1 addition & 1 deletion src/cockpit/389-console/buildAndRun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ if [ $? != 0 ]; then
fi

printf "\nBuilding and watching ...\n"
ESBUILD_WATCH=true ./build.js
./build.js --watch
# npm run watch
Loading

0 comments on commit 77294b7

Please sign in to comment.