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

543 #547

Merged
merged 15 commits into from
Nov 19, 2024
Merged

543 #547

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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p align="center"><img src="docs/ctrl-q_2.png"><p>
<p align="center"><img src="docs/ctrl-q.png"><p>

<h1 align="center">Ctrl-Q makes life easier for Qlik Sense admins and developers.<br><br>

Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 2 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"license": "MIT",
"type": "module",
"dependencies": {
"@qlik/api": "^1.24.0",
"@qlik/api": "^1.25.0",
"axios": "^1.7.7",
"commander": "^12.1.0",
"csv-parse": "^5.5.6",
Expand Down Expand Up @@ -58,26 +58,12 @@
"devDependencies": {
"@babel/eslint-parser": "^7.25.9",
"@babel/plugin-syntax-import-assertions": "^7.26.0",
"@eslint/js": "^9.14.0",
"@eslint/js": "^9.15.0",
"@jest/globals": "^29.7.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"jest": "^29.7.0",
"prettier": "^3.3.3",
"snyk": "^1.1294.0"
},
"pkg": {
"assets": [
"node_modules/axios/**/*",
"node_modules/fsevents/fsevents.node",
"node_modules/csv-stringify/dist/cjs",
"node_modules/enigma.js/**/*.json",
"src/static",
"package.json"
],
"scripts": [
"node_modules/enigma.js/**/*.json",
"node_modules/js-yaml/**/*.js"
]
}
}
2 changes: 0 additions & 2 deletions release-please-config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"last-release-sha": "7b1d7a8f1b05f8b3b9d56f79abae725016a0ee82",
"release-as": "4.0.0",
"draft": true,
"release-search-depth": 10,
"commit-search-depth": 200,
Expand Down
11 changes: 11 additions & 0 deletions sea-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
"disableExperimentalSEAWarning": true,
"assets": {
"package.json": "./package.json",
"/404.html": "./src/static/404.html",
"/android-chrome-192x192.png": "./src/static/android-chrome-192x192.png",
"/android-chrome-512x512.png": "./src/static/android-chrome-512x512.png",
"/apple-touch-icon.png": "./src/static/apple-touch-icon.png",
"/ctrl-q.png": "./src/static/ctrl-q.png",
"/favicon-16x16.png": "./src/static/favicon-16x16.png",
"/favicon-32x32.png": "./src/static/favicon-32x32.png",
"/favicon.ico": "./src/static/favicon.ico",
"/index.html": "./src/static/index.html",
"/vis-network.min.js": "./src/static/vis-network.min.js",
"/vis-network.min.js.map": "./src/static/vis-network.min.js",
"enigma_schema_12.170.2.json": "./node_modules/enigma.js/schemas/12.170.2.json",
"enigma_schema_12.612.0.json": "./node_modules/enigma.js/schemas/12.612.0.json",
"enigma_schema_12.936.0.json": "./node_modules/enigma.js/schemas/12.936.0.json",
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/app_export_cert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { jest, test, expect, describe } from '@jest/globals';

import fs from 'node:fs';
import path from 'node:path';
import exportAppToFile from '../lib/cmd/qseow/exportapp.js';
import { exportAppToFile } from '../lib/cmd/qseow/exportapp.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/app_export_jwt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { jest, test, expect, describe } from '@jest/globals';

import fs from 'node:fs';
import path from 'node:path';
import exportAppToFile from '../lib/cmd/qseow/exportapp.js';
import { exportAppToFile } from '../lib/cmd/qseow/exportapp.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/app_import_cert.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
import { jest, test, expect, describe } from '@jest/globals';

import importAppFromFile from '../lib/cmd/qseow/importapp.js';
import { importAppFromFile } from '../lib/cmd/qseow/importapp.js';
import { appExistById, deleteAppById } from '../lib/util/qseow/app.js';

const options = {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/app_import_jwt.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
import { jest, test, expect, describe } from '@jest/globals';

import importAppFromFile from '../lib/cmd/qseow/importapp.js';
import { importAppFromFile } from '../lib/cmd/qseow/importapp.js';
import { appExistById, deleteAppById } from '../lib/util/qseow/app.js';

const options = {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/app_jwt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { jest, test, expect, describe } from '@jest/globals';

import { getApps, getAppById, appExistById, deleteAppById } from '../lib/util/qseow/app.js';
import importAppFromFile from '../lib/cmd/qseow/importapp.js';
import { importAppFromFile } from '../lib/cmd/qseow/importapp.js';
import { sleep } from '../globals.js';

const options = {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/bookmark_get_cert.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
import { jest, test, expect, describe } from '@jest/globals';

import getBookmark from '../lib/cmd/qseow/getbookmark.js';
import { getBookmark } from '../lib/cmd/qseow/getbookmark.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/bookmark_get_jwt.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import getBookmark from '../lib/cmd/qseow/getbookmark.js';
import { getBookmark } from '../lib/cmd/qseow/getbookmark.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/connection_test_cert.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import testConnection from '../lib/cmd/qseow/testconnection.js';
import { testConnection } from '../lib/cmd/qseow/testconnection.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/connection_test_jwt.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import testConnection from '../lib/cmd/qseow/testconnection.js';
import { testConnection } from '../lib/cmd/qseow/testconnection.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/script_get_cert.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import getScript from '../lib/cmd/qseow/getscript.js';
import { getScript } from '../lib/cmd/qseow/getscript.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/script_get_jwt.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import getScript from '../lib/cmd/qseow/getscript.js';
import { getScript } from '../lib/cmd/qseow/getscript.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/task_custom_property_set_cert.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import setTaskCustomProperty from '../lib/cmd/qseow/settaskcp.js';
import { setTaskCustomProperty } from '../lib/cmd/qseow/settaskcp.js';
import { getTaskById } from '../lib/util/qseow/task.js';

const options = {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/task_custom_property_set_jwt.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import setTaskCustomProperty from '../lib/cmd/qseow/settaskcp.js';
import { setTaskCustomProperty } from '../lib/cmd/qseow/settaskcp.js';
import { getTaskById } from '../lib/util/qseow/task.js';

const options = {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/task_get_cert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { jest, test, expect, describe } from '@jest/globals';

import fs from 'node:fs';
import path from 'node:path';
import getTask from '../lib/cmd/qseow/gettask.js';
import { getTask } from '../lib/cmd/qseow/gettask.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/task_get_jwt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { jest, test, expect, describe } from '@jest/globals';

import fs from 'node:fs';
import path from 'node:path';
import getTask from '../lib/cmd/qseow/gettask.js';
import { getTask } from '../lib/cmd/qseow/gettask.js';

const options = {
logLevel: process.env.CTRL_Q_LOG_LEVEL || 'info',
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/task_import_cert.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import importTaskFromFile from '../lib/cmd/qseow/importtask.js';
import { importTaskFromFile } from '../lib/cmd/qseow/importtask.js';
import { getTaskById, deleteExternalProgramTaskById, deleteReloadTaskById } from '../lib/util/qseow/task.js';
import { mapTaskType } from '../lib/util/qseow/lookups.js';

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/task_import_jwt.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest, test, expect, describe } from '@jest/globals';

import importTaskFromFile from '../lib/cmd/qseow/importtask.js';
import { importTaskFromFile } from '../lib/cmd/qseow/importtask.js';
import { getTaskById, deleteExternalProgramTaskById, deleteReloadTaskById } from '../lib/util/qseow/task.js';
import { mapTaskType } from '../lib/util/qseow/lookups.js';

Expand Down
76 changes: 29 additions & 47 deletions src/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,7 @@ let c;
export let appVersion;

// Are we running as a packaged app?
if (process.pkg) {
// Get path to JS file
a = process.pkg.defaultEntrypoint;

// Strip off the filename
b = upath.dirname(a);

// Add path to package.json file
c = upath.join(b, filenamePackage);

const { version } = JSON.parse(readFileSync(c));
appVersion = version;
} else if (sea.isSea()) {
if (sea.isSea()) {
// Get contents of package.json file
packageJson = sea.getAsset('package.json', 'utf8');
const version = JSON.parse(packageJson).version;
Expand Down Expand Up @@ -75,8 +63,8 @@ export const logger = winston.createLogger({
});

// Are we running as standalone app or not?
export const isPkg = typeof process.pkg !== 'undefined';
export const execPath = isPkg ? upath.dirname(process.execPath) : process.cwd();
export const isSea = sea.isSea();
export const execPath = isSea ? upath.dirname(process.execPath) : process.cwd();

// Functions to get/set current console logging level
export const getLoggingLevel = () => logTransports.find((transport) => transport.name === 'console').level;
Expand All @@ -85,25 +73,16 @@ export const setLoggingLevel = (newLevel) => {
logTransports.find((transport) => transport.name === 'console').level = newLevel;
};

export const verifyFileExists = async (file, silent = false) => {
// Separate handling is needed depending on if we are running as a packaged SEA app or not
// SEA apps cannot list bundled assets as directories, so we need to use a different approach
export async function verifyFileSystemExists(file, silent = false) {
let exists = false;
try {
await Fs.stat(file);
exists = true;
} catch (err) {
if (!silent) {
if (isPkg) {
if (err.message) {
// Make message a bit nicer than what's returned from stat()
if (err.message.includes('no such file or directory')) {
logger.error(`File "${file}" does not exist.`);
} else {
logger.error(`Error while checking if file ${file} exists: ${err.message}`);
}
} else {
logger.error(`Error while checking if file ${file} exists: ${err}`);
}
} else if (err.message) {
if (err.message) {
if (err.message.includes('no such file or directory')) {
logger.error(`File "${file}" does not exist.`);
} else {
Expand All @@ -116,13 +95,33 @@ export const verifyFileExists = async (file, silent = false) => {
}
}
}
return exists;
}

export function verifySeaAssetExists(file, silent = false) {
let exists = false;
try {
sea.getAsset(file, 'utf8');
exists = true;
} catch (err) {
if (!silent) {
if (err.message) {
if (err.message.includes('no such file or directory')) {
logger.error(`Asset "${file}" does not exist.`);
} else {
logger.error(`Error while checking if asset ${file} exists: ${err.message}`);
}
} else {
logger.error(`Error while checking if asset ${file} exists: ${err}`);
}
}
}
return exists;
};
}

export const mergeDirFilePath = (pathElements) => {
let fullPath = '';
if (isPkg) {
if (isSea) {
fullPath = upath.resolve(upath.dirname(process.execPath), ...pathElements);
} else {
// fullPath = upath.resolve(__dirname, ...pathElements);
Expand Down Expand Up @@ -179,20 +178,3 @@ export const setCliOptions = (options) => {

// Function to get CLI options
export const getCliOptions = () => cliOptions;

// export default {
// logger,
// appVersion,
// getLoggingLevel,
// setLoggingLevel,
// execPath,
// isPkg,
// verifyFileExists,
// generateXrfKey,
// readCert,
// isNumeric,
// mergeDirFilePath,
// sleep,
// getCliOptions,
// setCliOptions,
// };
Loading