Skip to content

Commit d0d9c0f

Browse files
committed
refactor: Switch to using SEA for creating standalong binaries
1 parent af84a83 commit d0d9c0f

27 files changed

+902
-683
lines changed

src/butler-sheet-icons.js

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,25 @@ const program = new Command();
7979
'--port <port>',
8080
'Qlik Sense http/https port. 443 is default for https, 80 for http'
8181
)
82-
.requiredOption('--schemaversion <string>', 'Qlik Sense engine schema version', '12.612.0')
83-
.requiredOption('--appid <id>', 'Qlik Sense app whose sheet icons should be modified.', '')
82+
.addOption(
83+
new Option('--schemaversion <version>', 'Qlik Sense engine schema version')
84+
.choices([
85+
'12.170.2',
86+
'12.612.0',
87+
'12.936.0',
88+
'12.1306.0',
89+
'12.1477.0',
90+
'12.1657.0',
91+
'12.1823.0',
92+
'12.2015.0',
93+
])
94+
.default('12.612.0')
95+
)
8496
.requiredOption(
8597
'--certfile <file>',
8698
'Qlik Sense certificate file (exported from QMC)',
8799
'./cert/client.pem'
88100
)
89-
.option(
90-
'--qliksensetag <value>',
91-
'Used to control which Sense apps should have their sheets updated with new icons. All apps with this tag will be updated.',
92-
''
93-
)
94101
.requiredOption(
95102
'--certkeyfile <file>',
96103
'Qlik Sense certificate key file (exported from QMC)',
@@ -101,7 +108,6 @@ const program = new Command();
101108
'Ignore warnings when Sense certificate does not match the --host paramater',
102109
false
103110
)
104-
.requiredOption('--prefix <prefix>', 'Qlik Sense virtual proxy prefix', '')
105111
.requiredOption(
106112
'--secure <true|false>',
107113
'Connection to Qlik Sense engine is via https',
@@ -124,6 +130,13 @@ const program = new Command();
124130
'User ID for user to connect with when logging into web UI'
125131
)
126132
.requiredOption('--logonpwd <password>', 'password for user to connect with')
133+
.requiredOption('--appid <id>', 'Qlik Sense app whose sheet icons should be modified.', '')
134+
.option(
135+
'--qliksensetag <value>',
136+
'Used to control which Sense apps should have their sheets updated with new icons. All apps with this tag will be updated.',
137+
''
138+
)
139+
.requiredOption('--prefix <prefix>', 'Qlik Sense virtual proxy prefix', '')
127140
.requiredOption(
128141
'--headless <true|false>',
129142
'Headless (=not visible) browser (true, false)',
@@ -260,7 +273,20 @@ const program = new Command();
260273
'--port <port>',
261274
'Qlik Sense http/https port. 443 is default for https, 80 for http'
262275
)
263-
.requiredOption('--schemaversion <string>', 'Qlik Sense engine schema version', '12.612.0')
276+
.addOption(
277+
new Option('--schemaversion <version>', 'Qlik Sense engine schema version')
278+
.choices([
279+
'12.170.2',
280+
'12.612.0',
281+
'12.936.0',
282+
'12.1306.0',
283+
'12.1477.0',
284+
'12.1657.0',
285+
'12.1823.0',
286+
'12.2015.0',
287+
])
288+
.default('12.612.0')
289+
)
264290
.requiredOption('--appid <id>', 'Qlik Sense app whose sheet icons should be modified.', '')
265291
.option(
266292
'--qliksensetag <value>',
@@ -342,10 +368,19 @@ const program = new Command();
342368
.choices(['error', 'warn', 'info', 'verbose', 'debug', 'silly'])
343369
.default('info')
344370
)
345-
.requiredOption(
346-
'--schemaversion <string>',
347-
'Qlik Sense engine schema version',
348-
'12.612.0'
371+
.addOption(
372+
new Option('--schemaversion <version>', 'Qlik Sense engine schema version')
373+
.choices([
374+
'12.170.2',
375+
'12.612.0',
376+
'12.936.0',
377+
'12.1306.0',
378+
'12.1477.0',
379+
'12.1657.0',
380+
'12.1823.0',
381+
'12.2015.0',
382+
])
383+
.default('12.612.0')
349384
)
350385
.requiredOption(
351386
'--tenanturl <url>',
@@ -506,10 +541,19 @@ const program = new Command();
506541
.choices(['error', 'warn', 'info', 'verbose', 'debug', 'silly'])
507542
.default('info')
508543
)
509-
.requiredOption(
510-
'--schemaversion <string>',
511-
'Qlik Sense engine schema version',
512-
'12.612.0'
544+
.addOption(
545+
new Option('--schemaversion <version>', 'Qlik Sense engine schema version')
546+
.choices([
547+
'12.170.2',
548+
'12.612.0',
549+
'12.936.0',
550+
'12.1306.0',
551+
'12.1477.0',
552+
'12.1657.0',
553+
'12.1823.0',
554+
'12.2015.0',
555+
])
556+
.default('12.612.0')
513557
)
514558
.requiredOption(
515559
'--tenanturl <url>',

src/globals.js

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
11
const winston = require('winston');
22
const upath = require('upath');
3+
const sea = require('node:sea');
4+
const { readFileSync } = require('node:fs');
35

46
// Get app version from package.json file
5-
const appVersion = require('./package.json').version;
7+
const filenamePackage = `./src/package.json`;
8+
let a;
9+
let b;
10+
let c;
11+
let appVersion;
12+
13+
// Are we running as a packaged app?
14+
if (sea.isSea()) {
15+
// Get contents of package.json file
16+
packageJson = sea.getAsset('package.json', 'utf8');
17+
const version = JSON.parse(packageJson).version;
18+
19+
appVersion = version;
20+
} else {
21+
// Get path to JS file
22+
a = __filename;
23+
24+
// Strip off the filename
25+
b = upath.dirname(a);
26+
27+
// Add path to package.json file
28+
c = upath.join(b, '..', filenamePackage);
29+
30+
const { version } = JSON.parse(readFileSync(c));
31+
appVersion = version;
32+
}
633

734
// Set up logger with timestamps and colors, and optional logging to disk file
835
const logTransports = [];
@@ -31,7 +58,7 @@ const logger = winston.createLogger({
3158
});
3259

3360
// Suppported Chromium version: https://pptr.dev/chromium-support
34-
// Correlate with Correlate with https://chromium.woolyss.com to get revision number to get revision number
61+
// Correlate with https://chromium.woolyss.com to get revision number
3562
// const chromiumRevision = '1056772';
3663
// const chromiumRevisionLinux = '1056772';
3764
const chromiumRevisionLinux = '1109227';
@@ -67,18 +94,20 @@ const getChromiumRevision = () => {
6794
const getLoggingLevel = () => logTransports.find((transport) => transport.name === 'console').level;
6895

6996
/**
70-
*
97+
* Set the console logging level
7198
* @param {*} newLevel
7299
*/
73100
const setLoggingLevel = (newLevel) => {
74101
logTransports.find((transport) => transport.name === 'console').level = newLevel;
75102
};
76103

77-
const isPkg = typeof process.pkg !== 'undefined';
78-
const bsiExecutablePath = isPkg ? upath.dirname(process.execPath) : __dirname;
104+
/**
105+
* Booleann to indicate if we are running as a standalone app or not
106+
*/
107+
const isSea = sea.isSea();
108+
const bsiExecutablePath = isSea ? upath.dirname(process.execPath) : process.cwd();
79109

80110
function sleep(ms) {
81-
// eslint-disable-next-line no-promise-executor-return
82111
return new Promise((resolve) => setTimeout(resolve, ms));
83112
}
84113

@@ -87,7 +116,7 @@ module.exports = {
87116
appVersion,
88117
getLoggingLevel,
89118
setLoggingLevel,
90-
isPkg,
119+
isSea,
91120
bsiExecutablePath,
92121
getChromiumRevision,
93122
sleep,

src/img/do-not-delete

Lines changed: 0 additions & 1 deletion
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/lib/browser/browser-install.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const path = require('path');
88
const { homedir } = require('os');
99
const cliProgress = require('cli-progress');
1010

11-
const { logger, setLoggingLevel, bsiExecutablePath, isPkg } = require('../../globals');
11+
const { logger, setLoggingLevel, bsiExecutablePath, isSea } = require('../../globals');
1212
const { getMostRecentUsableChromeBuildId } = require('./browser-list-available');
1313

1414
/**
@@ -43,7 +43,7 @@ const browserInstall = async (options, _command) => {
4343
setLoggingLevel(options.loglevel);
4444

4545
logger.verbose('Starting browser install');
46-
logger.verbose(`Running as standalone app: ${isPkg}`);
46+
logger.verbose(`Running as standalone app: ${isSea}`);
4747
logger.debug(`BSI executable path: ${bsiExecutablePath}`);
4848
logger.debug(`Options: ${JSON.stringify(options, null, 2)}`);
4949

src/lib/browser/browser-installed.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { getInstalledBrowsers } = require('@puppeteer/browsers');
22
const path = require('path');
33
const { homedir } = require('os');
44

5-
const { logger, setLoggingLevel, bsiExecutablePath, isPkg } = require('../../globals');
5+
const { logger, setLoggingLevel, bsiExecutablePath, isSea } = require('../../globals');
66

77
/**
88
* List all installed browsers.
@@ -27,7 +27,7 @@ async function browserInstalled(options) {
2727
setLoggingLevel(options.loglevel);
2828

2929
logger.verbose('Starting check for installed browser');
30-
logger.verbose(`Running as standalone app: ${isPkg}`);
30+
logger.verbose(`Running as standalone app: ${isSea}`);
3131
logger.debug(`BSI executable path: ${bsiExecutablePath}`);
3232
logger.debug(`Options: ${JSON.stringify(options, null, 2)}`);
3333

src/lib/browser/browser-list-available.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const path = require('path');
33
const { homedir } = require('os');
44
const axios = require('axios');
55

6-
const { logger, setLoggingLevel, bsiExecutablePath, isPkg } = require('../../globals');
6+
const { logger, setLoggingLevel, bsiExecutablePath, isSea } = require('../../globals');
77

88
/**
99
* Maps Puppeteer's platform values to corresponding Chrome version history API platform values.
@@ -52,7 +52,7 @@ async function browserListAvailable(options) {
5252
setLoggingLevel(options.loglevel);
5353

5454
logger.verbose('Starting check for available browser versions');
55-
logger.verbose(`Running as standalone app: ${isPkg}`);
55+
logger.verbose(`Running as standalone app: ${isSea}`);
5656
logger.debug(`BSI executable path: ${bsiExecutablePath}`);
5757
logger.debug(`Options: ${JSON.stringify(options, null, 2)}`);
5858

0 commit comments

Comments
 (0)