Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit e7c0d76

Browse files
starpitk8s-ci-robot
authored andcommitted
feat: use webpack to build headless bundles
1 parent afb8574 commit e7c0d76

File tree

15 files changed

+577
-76
lines changed

15 files changed

+577
-76
lines changed

bin/kubectl-kui

Lines changed: 85 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,90 @@
1-
#!/usr/bin/env node
1+
#!/usr/bin/env bash
2+
# -*- mode: shell-script
23

3-
/**
4-
* Note: this kubectl plugin wrapper is intended only for use while
5-
* developing Kui plugins. The kubectl plugin used by production
6-
* builds will be different, because, in that case, we need to launch
7-
* the built Kui electron app, rather than (as we do here) launching
8-
* Kui by requiring from the unpackaged node_modules.
9-
*
10-
*/
4+
#
5+
# Note: this kubectl plugin wrapper is intended only for use while
6+
# developing Kui plugins. The kubectl plugin used by production
7+
# builds will be different, because, in that case, we need to launch
8+
# the built Kui electron app, rather than (as we do here) launching
9+
# Kui by requiring from the unpackaged node_modules.
10+
#
11+
#
1112

12-
// get node off the argv
13-
process.argv.shift()
13+
# export KUI_HEADLESS=true
14+
export NODE_NO_WARNINGS=1
15+
# export ELECTRON_RUN_AS_NODE=true
16+
export NODE_OPTIONS="--no-warnings"
1417

15-
// insert 'kubectl' into argv
16-
process.argv.splice(1, 0, 'kubectl')
18+
# This tells the core Kui plugin resolver that we are using webpack to
19+
# build our headless bundles, not the old headless hacks
20+
# export KUI_HEADLESS_WEBPACK=true
1721

18-
process.env.KUI_POPUP_WINDOW_RESIZE = true
22+
SCRIPTDIR=$(cd $(dirname "$0") && pwd)
1923

20-
require('@kui-shell/core').main(process.argv)
24+
if [ -f ./node_modules/electron/dist/Electron.app/Contents/MacOS/Electron ]; then
25+
# development mode
26+
NODE=./node_modules/electron/dist/Electron.app/Contents/MacOS/Electron
27+
HEADLESS=./dist/headless
28+
elif [ -f /Applications/Kui.app/Contents/MacOS/Kui ]; then
29+
# Kui installed in /Applications on macOS
30+
BASE=/Applications/Kui.app
31+
NODE="$BASE/Contents/MacOS/Kui"
32+
HEADLESS=$BASE/Contents/Resources/headless
33+
elif [ -f ./Kui.app/Contents/MacOS/Kui ]; then
34+
# Kui installed in CWD on macOS
35+
BASE="$PWD/Kui.app"
36+
NODE="$BASE/Contents/MacOS/Kui"
37+
HEADLESS="$BASE/Contents/Resources/headless"
38+
elif [ -f /usr/local/bin/Kui/Kui ]; then
39+
# Kui installed in /usr/local/bin on Linux or Windows
40+
BASE=/usr/local/bin/Kui
41+
NODE="$BASE/Kui"
42+
HEADLESS="$BASE/headless"
43+
elif [ -f ./Kui/Kui ]; then
44+
# Kui installed in CWD on Linux or Windows
45+
BASE="$PWD/Kui"
46+
NODE="$BASE/Kui"
47+
HEADLESS="$BASE/headless"
48+
elif [ -f ./Kui ]; then
49+
# Kui installed in CWD on Linux or Windows (variant)
50+
BASE="$PWD"
51+
NODE="$BASE/Kui"
52+
HEADLESS="$BASE/headless"
53+
elif [ -f "$SCRIPTDIR/Kui.app/Contents/MacOS/Kui" ]; then
54+
# Kui installed in SCRIPTDIR on macOS
55+
BASE="$SCRIPTDIR/Kui.app"
56+
NODE="$BASE/Contents/MacOS/Kui"
57+
HEADLESS="$BASE/Contents/Resources/headless"
58+
elif [ -f "$SCRIPTDIR/Kui/Kui" ]; then
59+
# Kui installed in SCRIPTDIR on Linux or Windows
60+
BASE="$SCRIPTDIR/Kui"
61+
NODE="$BASE/Kui"
62+
HEADLESS="$BASE/headless"
63+
elif [ -f "$SCRIPTDIR/Kui" ]; then
64+
# Kui installed in SCRIPTDIR on Linux or Windows (variant)
65+
BASE="$SCRIPTDIR"
66+
NODE="$BASE/Kui"
67+
HEADLESS="$BASE/headless"
68+
elif [ -f "$KUI_HOME/Kui.app/Contents/MacOS/Kui" ]; then
69+
# Kui installed in KUI_HOME on macOS
70+
BASE="$KUI_HOME/Kui.app"
71+
NODE="$BASE/Contents/MacOS/Kui"
72+
HEADLESS="$BASE/Contents/Resources/headless"
73+
elif [ -f "$KUI_HOME/Kui" ]; then
74+
# Kui installed in KUI_HOME on Linux or Windows
75+
BASE="$KUI_HOME"
76+
NODE="$BASE/Kui"
77+
HEADLESS="$BASE/headless"
78+
else
79+
echo "Error: Could not find Kui. Try setting KUI_HOME=/path/to/Kui"
80+
exit 1
81+
fi
82+
83+
# This points the headless->electron launcher to our Electron
84+
export KUI_ELECTRON_HOME="${KUI_ELECTRON_HOME-$NODE}"
85+
86+
# for when we switch over to webpack headless builds:
87+
# exec "$NODE" -e 'require("'$HEADLESS'/kui.min.js").kiwi.main(process.argv)' . -- kubectl $@
88+
89+
# for now
90+
exec "$NODE" . -- kubectl $@

bin/kui

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,81 @@
1-
#!/usr/bin/env node
1+
#!/usr/bin/env sh
2+
# -*- mode: shell-script
23

3-
// get node off the argv
4-
process.argv.shift()
4+
# export KUI_HEADLESS=true
5+
export NODE_NO_WARNINGS=1
6+
# export ELECTRON_RUN_AS_NODE=true
7+
export NODE_OPTIONS="--no-warnings"
58

6-
process.env.KUI_HEADLESS = true
9+
# This tells the core Kui plugin resolver that we are using webpack to
10+
# build our headless bundles, not the old headless hacks
11+
# export KUI_HEADLESS_WEBPACK=true
712

8-
require('@kui-shell/core').main(process.argv)
13+
SCRIPTDIR=$(cd $(dirname "$0") && pwd)
14+
15+
if [ -f ./node_modules/electron/dist/Electron.app/Contents/MacOS/Electron ]; then
16+
# development mode
17+
NODE=./node_modules/electron/dist/Electron.app/Contents/MacOS/Electron
18+
HEADLESS=./dist/headless
19+
elif [ -f /Applications/Kui.app/Contents/MacOS/Kui ]; then
20+
# Kui installed in /Applications on macOS
21+
BASE=/Applications/Kui.app
22+
NODE="$BASE/Contents/MacOS/Kui"
23+
HEADLESS=$BASE/Contents/Resources/headless
24+
elif [ -f ./Kui.app/Contents/MacOS/Kui ]; then
25+
# Kui installed in CWD on macOS
26+
BASE="$PWD/Kui.app"
27+
NODE="$BASE/Contents/MacOS/Kui"
28+
HEADLESS="$BASE/Contents/Resources/headless"
29+
elif [ -f /usr/local/bin/Kui/Kui ]; then
30+
# Kui installed in /usr/local/bin on Linux or Windows
31+
BASE=/usr/local/bin/Kui
32+
NODE="$BASE/Kui"
33+
HEADLESS="$BASE/headless"
34+
elif [ -f ./Kui/Kui ]; then
35+
# Kui installed in CWD on Linux or Windows
36+
BASE="$PWD/Kui"
37+
NODE="$BASE/Kui"
38+
HEADLESS="$BASE/headless"
39+
elif [ -f ./Kui ]; then
40+
# Kui installed in CWD on Linux or Windows (variant)
41+
BASE="$PWD"
42+
NODE="$BASE/Kui"
43+
HEADLESS="$BASE/headless"
44+
elif [ -f "$SCRIPTDIR/Kui.app/Contents/MacOS/Kui" ]; then
45+
# Kui installed in SCRIPTDIR on macOS
46+
BASE="$SCRIPTDIR/Kui.app"
47+
NODE="$BASE/Contents/MacOS/Kui"
48+
HEADLESS="$BASE/Contents/Resources/headless"
49+
elif [ -f "$SCRIPTDIR/Kui/Kui" ]; then
50+
# Kui installed in SCRIPTDIR on Linux or Windows
51+
BASE="$SCRIPTDIR/Kui"
52+
NODE="$BASE/Kui"
53+
HEADLESS="$BASE/headless"
54+
elif [ -f "$SCRIPTDIR/Kui" ]; then
55+
# Kui installed in SCRIPTDIR on Linux or Windows (variant)
56+
BASE="$SCRIPTDIR"
57+
NODE="$BASE/Kui"
58+
HEADLESS="$BASE/headless"
59+
elif [ -f "$KUI_HOME/Kui.app/Contents/MacOS/Kui" ]; then
60+
# Kui installed in KUI_HOME on macOS
61+
BASE="$KUI_HOME/Kui.app"
62+
NODE="$BASE/Contents/MacOS/Kui"
63+
HEADLESS="$BASE/Contents/Resources/headless"
64+
elif [ -f "$KUI_HOME/Kui" ]; then
65+
# Kui installed in KUI_HOME on Linux or Windows
66+
BASE="$KUI_HOME"
67+
NODE="$BASE/Kui"
68+
HEADLESS="$BASE/headless"
69+
else
70+
echo "Error: Could not find Kui. Try setting KUI_HOME=/path/to/Kui"
71+
exit 1
72+
fi
73+
74+
# This points the headless->electron launcher to our Electron
75+
export KUI_ELECTRON_HOME="${KUI_ELECTRON_HOME-$NODE}"
76+
77+
# for when we switch over to webpack headless builds:
78+
# exec "$NODE" -e 'require("'$HEADLESS'/kui.min.js").kiwi.main(process.argv)' . shell
79+
80+
# for now:
81+
exec "$NODE" . shell

packages/builder/dist/electron/build.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ CORE_HOME="$STAGING"/node_modules/@kui-shell/core
3737
THEME="$CLIENT_HOME"/node_modules/@kui-shell/client
3838
export BUILDER_HOME="$STAGING"/node_modules/@kui-shell/builder
3939
export BUILDDIR="$CLIENT_HOME"/dist/electron
40+
export HEADLESS_BUILDDIR="$STAGING"/dist/headless
4041

4142
#
4243
# ignore these files when bundling the ASAR (this is a regexp, not glob pattern)
@@ -191,6 +192,11 @@ Start-Process -NoNewWindow $ScriptDir/Kui.exe -ArgumentList $argv' >> kubectl-ku
191192
cp "$KUI_LAUNCHER" "$BUILDDIR/${CLIENT_NAME}-win32-$ARCH"
192193
fi
193194

195+
# copy in the headless build
196+
if [ -n "$KUI_HEADLESS_WEBPACK" ]; then
197+
cp -a "$HEADLESS_BUILDDIR" "$BUILDDIR/${CLIENT_NAME}-win32-$ARCH"
198+
fi
199+
194200
#
195201
# deal with win32 packaging
196202
#
@@ -280,6 +286,11 @@ fi
280286
cp "$KUI_LAUNCHER" "$BUILDDIR/${CLIENT_NAME}-darwin-$ARCH"
281287
fi
282288

289+
# copy in the headless build
290+
if [ -n "$KUI_HEADLESS_WEBPACK" ]; then
291+
cp -a "$HEADLESS_BUILDDIR" "$BUILDDIR/${CLIENT_NAME}-darwin-$ARCH/${PRODUCT_NAME}.app/Contents/Resources"
292+
fi
293+
283294
echo "TGZ build for darwin"
284295
tar -C "$BUILDDIR" -jcf "$BUILDDIR/${CLIENT_NAME}-darwin-$ARCH.tar.bz2" "${CLIENT_NAME}-darwin-$ARCH" &
285296
MAC_TAR_PID=$!
@@ -323,6 +334,11 @@ SCRIPTDIR=$(cd $(dirname "$0") && pwd)
323334
cp "$KUI_LAUNCHER" "$BUILDDIR/${CLIENT_NAME}-linux-$ARCH"
324335
fi
325336

337+
# copy in the headless build
338+
if [ -n "$KUI_HEADLESS_WEBPACK" ]; then
339+
cp -a "$HEADLESS_BUILDDIR" "$BUILDDIR/${CLIENT_NAME}-linux-$ARCH"
340+
fi
341+
326342
if [ -z "$NO_INSTALLER" ]; then
327343
echo "Zip build for linux"
328344
(cd $BUILDDIR && zip -q -r "${CLIENT_NAME}-linux-$ARCH" "${CLIENT_NAME}-linux-$ARCH" -x \*~) &
@@ -402,7 +418,16 @@ function initWebpack {
402418
function webpack {
403419
pushd "$STAGING" > /dev/null
404420
rm -f "$BUILDDIR"/*.js*
405-
TARGET=electron-renderer MODE=${MODE-production} CLIENT_HOME="$CLIENT_HOME" KUI_STAGE="$STAGING" KUI_BUILDDIR="$BUILDDIR" KUI_BUILDER_HOME="$BUILDER_HOME" npx --no-install webpack-cli
421+
422+
if [ -n "$KUI_HEADLESS_WEBPACK" ]; then
423+
echo "Building headless bundles via webpack"
424+
MODE=${MODE-production} CLIENT_HOME="$CLIENT_HOME" KUI_STAGE="$STAGING" KUI_BUILDDIR="$BUILDDIR" KUI_BUILDER_HOME="$BUILDER_HOME" npx --no-install webpack-cli --config ./node_modules/@kui-shell/webpack/headless-webpack.config.js --mode=${MODE-production} &
425+
fi
426+
427+
# echo "Building electron bundles via webpack"
428+
TARGET=electron-renderer MODE=${MODE-production} CLIENT_HOME="$CLIENT_HOME" KUI_STAGE="$STAGING" KUI_BUILDDIR="$BUILDDIR" KUI_BUILDER_HOME="$BUILDER_HOME" npx --no-install webpack-cli --mode=${MODE-production}
429+
430+
wait
406431
popd > /dev/null
407432
}
408433

packages/core/src/main/main.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ export const main = async (argv: string[], env = process.env, execOptions?: Exec
4242
// then spawn the electron graphics
4343
debug('shortcut to graphics')
4444
const { getCommand, initElectron } = await import('./spawn-electron')
45-
const { argv: strippedArgv, subwindowPlease, subwindowPrefs } = getCommand(
46-
argv,
47-
async () => (await import('electron')).screen
48-
)
45+
const { argv: strippedArgv, subwindowPlease, subwindowPrefs } = getCommand(argv, async () => import('electron'))
4946
initElectron(
5047
strippedArgv,
5148
{ isRunningHeadless },

0 commit comments

Comments
 (0)