Skip to content

Commit

Permalink
also fix lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
foxriver76 committed Sep 27, 2024
1 parent ebc00bc commit 0cbb82f
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 19 deletions.
18 changes: 0 additions & 18 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
import config from '@iobroker/eslint-config';

// disable temporary the rule 'jsdoc/require-param' and enable 'jsdoc/require-jsdoc'
config.forEach(rule => {
if (rule?.plugins?.jsdoc) {
rule.rules['jsdoc/require-jsdoc'] = 'off';
rule.rules['jsdoc/require-param'] = 'off';
}
});

export default [
...config,
{
languageOptions: {
parserOptions: {
projectService: {
allowDefaultProject: ['*.js', '*.mjs'],
},
tsconfigRootDir: import.meta.dirname,
},
},
},
];
13 changes: 13 additions & 0 deletions src/controllerTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,31 @@ function getAdapterDir(adapter: string): string | null {
return controllerToolsInternal.getAdapterDir(adapter);
}

/** Information about Host */
export interface InstalledInfo {
/** If it is the js-controller */
controller?: boolean;
/** Version of adapter */
version?: string;
/** Path to adapter icon */
icon?: string;
/** Title of adapter */
title?: string;
/** I18n title of adapter */
titleLang?: ioBroker.Translated;
/** I18n adapter description */
desc?: ioBroker.Translated;
/** Supported adapter platform */
platform?: string;
/** The keywords */
keywords?: string[];
/** Path to ReadMe */
readme?: string;
/** Running version of adapter */
runningVersion?: string;
/** The license */
license?: string;
/** The url of the license */
licenseUrl?: string;
}
/**
Expand Down
36 changes: 36 additions & 0 deletions src/exitCodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,76 @@
// Keep this in sync when a new exit code is added

export type ExitCodes = Readonly<{
/** Exit without error */
NO_ERROR: number;
/** Exit because js-controller is stopped */
JS_CONTROLLER_STOPPED: number;
/** Exit because Adapter config is invalid */
INVALID_ADAPTER_CONFIG: number;
/** Exit because no adapter config was found */
NO_ADAPTER_CONFIG_FOUND: number;
/** Exit because the config is invalid */
INVALID_CONFIG_OBJECT: number;
/** Exit because the adapter id is invalid */
INVALID_ADAPTER_ID: number;
/** Exit because an uncaught exception occurred */
UNCAUGHT_EXCEPTION: number;
/** Exit because the adapter is already running */
ADAPTER_ALREADY_RUNNING: number;
/** Exit because instance is disabled */
INSTANCE_IS_DISABLED: number;
/** Exit because directory cannot be compressed */
CANNOT_GZIP_DIRECTORY: number;
/** Exit because adapter directory could not be found */
CANNOT_FIND_ADAPTER_DIR: number;
/** Exit because adapter requested it */
ADAPTER_REQUESTED_TERMINATION: number;
/** Exit because the packet name is not known */
UNKNOWN_PACKET_NAME: number;
/** Exit because the adapters requested a rebuild */
ADAPTER_REQUESTED_REBUILD: number;
/** Exit because instances could not be read */
CANNOT_READ_INSTANCES: number;
/** Exit because only one instance is allowed globally */
NO_MULTIPLE_INSTANCES_ALLOWED: number;
/** Exit because only one instance is allowed on this host */
NO_MULTIPLE_INSTANCES_ALLOWED_ON_HOST: number;
/** Exit because no connection to objects database could be established */
NO_CONNECTION_TO_OBJ_DB: number;
/** Exit because no connection to states database could be established */
NO_CONNECTION_TO_STATES_DB: number;
/** Exit because the instance already exists */
INSTANCE_ALREADY_EXISTS: number;
/** Exit because the npm package could not be installed */
CANNOT_INSTALL_NPM_PACKET: number;
/** Exit because the zip could not be extracted */
CANNOT_EXTRACT_FROM_ZIP: number;
/** Exit because the io-package.json is invalid */
INVALID_IO_PACKAGE_JSON: number;
/** Exit because directory could not be copied */
CANNOT_COPY_DIR: number;
/** Exit because adapter files are missing */
MISSING_ADAPTER_FILES: number;
/** Exit because the npm version is invalid */
INVALID_NPM_VERSION: number;
/** Exit because the node version is invalid */
INVALID_NODE_VERSION: number;
/** Exit because the operating system is invalid */
INVALID_OS: number;
/** Exit because the dependency version is invalid */
INVALID_DEPENDENCY_VERSION: number;
/** Exit because the passed arguments are invalid */
INVALID_ARGUMENTS: number;
/** Exit because the password is invalid */
INVALID_PASSWORD: number;
/** Exit because the iobroker.json is missing */
MISSING_CONFIG_JSON: number;
/** Exit because a non-deletable object cannot be deleted */
CANNOT_DELETE_NON_DELETABLE: number;
/** Exit because states could not be retrieved */
CANNOT_GET_STATES: number;
/** Exit because repository list could not be retrieved */
CANNOT_GET_REPO_LIST: number;
/** Exit because direct restart is requested after stop */
START_IMMEDIATELY_AFTER_STOP: number;
}>;
6 changes: 6 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const thisDir = fileURLToPath(new URL('.', import.meta.url || `file://${__filena
/**
* Tries to resolve a package using Node.js resolution.
* Directory names differing from the package name and alternate lookup paths can be passed.
*
* @param possiblePaths all possible paths the package can be resolved from
* @param lookupPaths lookup paths passed to `require.resolve`
*/
export function tryResolvePackage(possiblePaths: string[], lookupPaths?: string[]): string | undefined {
for (const pkg of possiblePaths) {
Expand All @@ -31,6 +34,9 @@ export function tryResolvePackage(possiblePaths: string[], lookupPaths?: string[
/**
* Scans for a package by walking up the directory tree and inspecting package.json
* Directory names differing from the package name and an alternate start dir can be passed.
*
* @param possiblePaths All possible paths to check
* @param startDir Optional start directory where we scan for the package
*/
export function scanForPackage(possiblePaths: string[], startDir: string = thisDir): string | undefined {
// We start in the node_modules subfolder of adapter-core,
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export function getAbsoluteDefaultDataDir(): string {
/**
* Returns the absolute path of the data directory for the current adapter instance.
* On linux, this is usually `/opt/iobroker/iobroker-data/<adapterName>.<instanceNr>`
*
* @param adapterObject The adapter instance
*/
export function getAbsoluteInstanceDataDir(adapterObject: ioBroker.Adapter): string {
return join(getAbsoluteDefaultDataDir(), adapterObject.namespace);
Expand Down
3 changes: 2 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ function resolveAdapterConstructor(): any {
}

throw new Error('Cannot resolve adapter class');
return process.exit(10);
}

/** Reads the configuration file of JS-Controller */
Expand All @@ -116,7 +115,9 @@ export interface AdapterInstance<
HasObjectsCache extends boolean | undefined = undefined,
HasStatesCache extends boolean | undefined = undefined,
> extends ioBroker.Adapter {
/** Objects cache */
oObjects: HasObjectsCache extends true ? Exclude<ioBroker.Adapter['oObjects'], undefined> : undefined;
/** States cache */
oStates: HasStatesCache extends true ? Exclude<ioBroker.Adapter['oStates'], undefined> : undefined;
}

Expand Down

0 comments on commit 0cbb82f

Please sign in to comment.