Skip to content

Commit d56f8d8

Browse files
fix: lowercase appName, correct iobroker.js path, and pass default node args where necessary (#2144)
* fix: lowercase appName and pass default node args where necessary * fix logging for cmdExec * found a few more * we only have a lowercase conf file --------- Co-authored-by: foxriver76 <[email protected]>
1 parent 862b755 commit d56f8d8

File tree

8 files changed

+67
-46
lines changed

8 files changed

+67
-46
lines changed

packages/cli/src/lib/setup.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -627,9 +627,12 @@ async function processCommand(
627627
// And try to install each of them
628628
for (const instance of initialInstances) {
629629
try {
630-
const adapterInstalled = !!require.resolve(`${tools.appName}.${instance}`, {
631-
paths: tools.getDefaultRequireResolvePaths(module)
632-
});
630+
const adapterInstalled = !!require.resolve(
631+
`${tools.appName.toLowerCase()}.${instance}`,
632+
{
633+
paths: tools.getDefaultRequireResolvePaths(module)
634+
}
635+
);
633636

634637
if (adapterInstalled) {
635638
let otherInstanceExists = false;
@@ -2124,8 +2127,8 @@ async function processCommand(
21242127
dependencies: {} as Record<string, string>,
21252128
author: 'bluefox <[email protected]>'
21262129
};
2127-
json.dependencies[`${tools.appName}.js-controller`] = '*';
2128-
json.dependencies[`${tools.appName}.admin`] = '*';
2130+
json.dependencies[`${tools.appName.toLowerCase()}.js-controller`] = '*';
2131+
json.dependencies[`${tools.appName.toLowerCase()}.admin`] = '*';
21292132

21302133
// @ts-expect-error todo fix it
21312134
tools.getRepositoryFile(null, null, (_err, sources, _sourcesHash) => {
@@ -2488,7 +2491,7 @@ async function processCommand(
24882491
let pckg;
24892492
if (adapter) {
24902493
try {
2491-
pckg = require(`${tools.appName}.${adapter}/package.json`);
2494+
pckg = require(`${tools.appName.toLowerCase()}.${adapter}/package.json`);
24922495
} catch {
24932496
pckg = { version: `"${adapter}" not found` };
24942497
}
@@ -2581,7 +2584,7 @@ async function processCommand(
25812584
if (repoUrlOrCommand === 'add' || repoUrlOrCommand === 'addset') {
25822585
if (!repoUrl) {
25832586
console.warn(
2584-
`Please define repository URL or path: ${tools.appName} add <repoName> <repoUrlOrPath>`
2587+
`Please define repository URL or path: ${tools.appName.toLowerCase()} add <repoName> <repoUrlOrPath>`
25852588
);
25862589
return void callback(EXIT_CODES.INVALID_ARGUMENTS);
25872590
} else {
@@ -2808,7 +2811,7 @@ async function processCommand(
28082811
let pckg;
28092812
if (command) {
28102813
try {
2811-
pckg = require(`${tools.appName}.${command}/package.json`);
2814+
pckg = require(`${tools.appName.toLowerCase()}.${command}/package.json`);
28122815
} catch {
28132816
pckg = { version: `"${command}" not found` };
28142817
}

packages/cli/src/lib/setup/setupBackup.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,11 @@ export class BackupRestore {
556556
}
557557

558558
// if installed as npm
559-
if (fs.existsSync(path.join(controllerDir, '..', '..', 'node_modules', `${tools.appName}.js-controller`))) {
559+
if (
560+
fs.existsSync(
561+
path.join(controllerDir, '..', '..', 'node_modules', `${tools.appName.toLowerCase()}.js-controller`)
562+
)
563+
) {
560564
const p = path.join(controllerDir, '..');
561565
_modules = fs.readdirSync(p).filter(dir => fs.existsSync(`${p}/${dir}/io-package.json`));
562566
const regEx_ = new RegExp(`^${tools.appName}\\.`, 'i');

packages/cli/src/lib/setup/setupInstall.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ export class Install {
206206
if (
207207
url &&
208208
packetName === 'js-controller' &&
209-
fs.pathExistsSync(`${tools.getControllerDir()}/../../node_modules/${tools.appName}.js-controller`)
209+
fs.pathExistsSync(
210+
`${tools.getControllerDir()}/../../node_modules/${tools.appName.toLowerCase()}.js-controller`
211+
)
210212
) {
211213
url = null;
212214
}
@@ -249,7 +251,7 @@ export class Install {
249251
} else if (!url) {
250252
// Adapter
251253
console.warn(
252-
`host.${hostname} Adapter "${packetName}" can be updated only together with ${tools.appName}.js-controller`
254+
`host.${hostname} Adapter "${packetName}" can be updated only together with ${tools.appName.toLowerCase()}.js-controller`
253255
);
254256
return { packetName, stoppedList };
255257
}
@@ -1433,7 +1435,7 @@ export class Install {
14331435
const _uninstallNpm = async (): Promise<void> => {
14341436
try {
14351437
// find the adapter's io-package.json
1436-
const adapterNpm = `${tools.appName}.${adapter}`;
1438+
const adapterNpm = `${tools.appName.toLowerCase()}.${adapter}`;
14371439
// eslint-disable-next-line @typescript-eslint/no-var-requires
14381440
const ioPack = require(`${adapterNpm}/io-package.json`); // yep, it's that easy
14391441

packages/cli/src/lib/setup/setupMultihost.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ export class Multihost {
3939
if (fs.existsSync(this.configName)) {
4040
config = fs.readJsonSync(this.configName);
4141
} else {
42-
config = fs.readJsonSync(path.join(tools.getControllerDir(), 'conf', `${tools.appName}-dist.json`));
42+
config = fs.readJsonSync(
43+
path.join(tools.getControllerDir(), 'conf', `${tools.appName.toLowerCase()}-dist.json`)
44+
);
4345
}
4446
} catch {
45-
config = fs.readJsonSync(path.join(tools.getControllerDir(), 'conf', `${tools.appName}-dist.json`));
47+
config = fs.readJsonSync(
48+
path.join(tools.getControllerDir(), 'conf', `${tools.appName.toLowerCase()}-dist.json`)
49+
);
4650
}
4751
return config;
4852
}

packages/cli/src/lib/setup/setupSetup.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ Please DO NOT copy files manually into ioBroker storage directories!`
545545
console.log(`Backup created: ${filePath}`);
546546
await this.resetDbConnect();
547547

548-
console.log(`updating conf/${tools.appName}.json`);
548+
console.log(`updating conf/${tools.appName.toLowerCase()}.json`);
549549
fs.writeFileSync(`${tools.getConfigFileName()}.bak`, JSON.stringify(oldConfig, null, 2));
550550
fs.writeFileSync(tools.getConfigFileName(), JSON.stringify(newConfig, null, 2));
551551

@@ -566,7 +566,7 @@ Please DO NOT copy files manually into ioBroker storage directories!`
566566
`New Database could not be connected. Please check your settings. No settings have been changed.${COLOR_RESET}`
567567
);
568568

569-
console.log(`restoring conf/${tools.appName}.json`);
569+
console.log(`restoring conf/${tools.appName.toLowerCase()}.json`);
570570
fs.writeFileSync(tools.getConfigFileName(), JSON.stringify(oldConfig, null, 2));
571571
fs.unlinkSync(`${tools.getConfigFileName()}.bak`);
572572

@@ -587,7 +587,7 @@ Please DO NOT copy files manually into ioBroker storage directories!`
587587
if (exitCode) {
588588
console.log(`Error happened during restore. Exit-Code: ${exitCode}`);
589589
console.log();
590-
console.log(`restoring conf/${tools.appName}.json`);
590+
console.log(`restoring conf/${tools.appName.toLowerCase()}.json`);
591591
fs.writeFileSync(tools.getConfigFileName(), JSON.stringify(oldConfig, null, 2));
592592
fs.unlinkSync(tools.getConfigFileName() + '.bak');
593593
} else {
@@ -612,7 +612,7 @@ Please DO NOT copy files manually into ioBroker storage directories!`
612612
console.log('');
613613
}
614614
}
615-
console.log(`updating conf/${tools.appName}.json`);
615+
console.log(`updating conf/${tools.appName.toLowerCase()}.json`);
616616
fs.writeFileSync(tools.getConfigFileName(), JSON.stringify(newConfig, null, 2));
617617
return EXIT_CODES.NO_ERROR;
618618
}
@@ -626,10 +626,10 @@ Please DO NOT copy files manually into ioBroker storage directories!`
626626
config = fs.readJsonSync(tools.getConfigFileName());
627627
originalConfig = deepClone(config);
628628
} else {
629-
config = fs.readJsonSync(path.join(CONTROLLER_DIR, 'conf', `${tools.appName}-dist.json`));
629+
config = fs.readJsonSync(path.join(CONTROLLER_DIR, 'conf', `${tools.appName.toLowerCase()}-dist.json`));
630630
}
631631
} catch {
632-
config = fs.readJsonSync(path.join(CONTROLLER_DIR, 'conf', `${tools.appName}-dist.json`));
632+
config = fs.readJsonSync(path.join(CONTROLLER_DIR, 'conf', `${tools.appName.toLowerCase()}-dist.json`));
633633
}
634634

635635
const currentObjectsType = originalConfig.objects.type || 'jsonl';
@@ -1135,12 +1135,9 @@ require('${path.normalize(__dirname + '/..')}/setup').execute();`;
11351135
// only change config if non existing - else setup custom has to be used
11361136
if (!fs.existsSync(configFileName)) {
11371137
isCreated = true;
1138-
if (fs.existsSync(path.join(CONTROLLER_DIR, 'conf', `${tools.appName}-dist.json`))) {
1139-
config = fs.readJsonSync(path.join(CONTROLLER_DIR, 'conf', `${tools.appName}-dist.json`));
1140-
} else {
1141-
config = fs.readJsonSync(path.join(CONTROLLER_DIR, 'conf', `${tools.appName.toLowerCase()}-dist.json`));
1142-
}
1143-
console.log(`creating conf/${tools.appName}.json`);
1138+
config = fs.readJsonSync(path.join(CONTROLLER_DIR, 'conf', `${tools.appName.toLowerCase()}-dist.json`));
1139+
1140+
console.log(`creating conf/${tools.appName.toLowerCase()}.json`);
11441141
config.objects.host = this.params.objects || '127.0.0.1';
11451142
config.states.host = this.params.states || '127.0.0.1';
11461143
if (useRedis) {
@@ -1167,7 +1164,10 @@ require('${path.normalize(__dirname + '/..')}/setup').execute();`;
11671164
try {
11681165
// Create
11691166
if (
1170-
__dirname.toLowerCase().replace(/\\/g, '/').includes(`node_modules/${tools.appName}.js-controller`)
1167+
__dirname
1168+
.toLowerCase()
1169+
.replace(/\\/g, '/')
1170+
.includes(`node_modules/${tools.appName.toLowerCase()}.js-controller`)
11711171
) {
11721172
const parts = config.dataDir.split('/');
11731173
// Remove appName-data/

packages/cli/src/lib/setup/setupVisDebug.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ export class VisDebug {
8686
// correct appName.json
8787
// correct config.js
8888
const controllerDir = tools.getControllerDir();
89-
let visDir = `${controllerDir}/node_modules/${tools.appName}.vis`;
89+
let visDir = `${controllerDir}/node_modules/${tools.appName.toLowerCase()}.vis`;
9090
if (!fs.existsSync(visDir)) {
9191
visDir = `${controllerDir}/node_modules/${tools.appName.toLowerCase()}.vis`;
9292
if (!fs.existsSync(visDir)) {
93-
visDir = `${controllerDir}/../${tools.appName}.vis`;
93+
visDir = `${controllerDir}/../${tools.appName.toLowerCase()}.vis`;
9494
if (!fs.existsSync(visDir)) {
9595
visDir = `${controllerDir}/../${tools.appName.toLowerCase()}.vis`;
9696
if (!fs.existsSync(visDir)) {
97-
console.error(`Cannot find ${tools.appName}.vis`);
97+
console.error(`Cannot find ${tools.appName.toLowerCase()}.vis`);
9898
return void this.processExit(EXIT_CODES.MISSING_ADAPTER_FILES);
9999
}
100100
}

packages/controller/src/lib/zipFiles.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export async function readDirAsZip(
103103

104104
// try to load processor of adapter
105105
try {
106-
options.stringify = (await import(`${tools.appName}.${adapter}/lib/convert.js`)).stringify;
106+
options.stringify = (await import(`${tools.appName.toLowerCase()}.${adapter}/lib/convert.js`)).stringify;
107107
} catch {
108108
// OK
109109
}
@@ -202,7 +202,7 @@ export async function writeDirAsZip(
202202

203203
// try to load processor of adapter
204204
try {
205-
options.parse = (await import(`${tools.appName}.${adapter}/lib/convert.js`)).parse;
205+
options.parse = (await import(`${tools.appName.toLowerCase()}.${adapter}/lib/convert.js`)).parse;
206206
} catch {
207207
// OK
208208
}
@@ -244,7 +244,7 @@ export async function readObjectsAsZip(
244244
if (adapter) {
245245
// try to load processor of adapter
246246
try {
247-
options.stringify = (await import(`${tools.appName}.${adapter}/lib/convert.js`)).stringify;
247+
options.stringify = (await import(`${tools.appName.toLowerCase()}.${adapter}/lib/convert.js`)).stringify;
248248
} catch {
249249
// OK
250250
}
@@ -351,7 +351,7 @@ export async function writeObjectsAsZip(
351351
if (adapter) {
352352
// try to load processor of adapter
353353
try {
354-
options.parse = (await import(`${tools.appName}.${adapter}/lib/convert.js`)).parse;
354+
options.parse = (await import(`${tools.appName.toLowerCase()}.${adapter}/lib/convert.js`)).parse;
355355
} catch {
356356
// OK
357357
}

packages/controller/src/main.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import type { Client as StatesClient } from '@iobroker/db-states-redis';
2929
import { Upload } from '@iobroker/js-controller-cli';
3030
import decache from 'decache';
3131
import type { PluginHandlerSettings } from '@iobroker/plugin-base/types';
32+
import { getDefaultNodeArgs } from './lib/tools';
3233

3334
type TaskObject = ioBroker.SettableObject & { state?: ioBroker.SettableState };
3435
type DiagInfoType = 'extended' | 'normal' | 'no-city' | 'none';
@@ -204,7 +205,9 @@ function getConfig(): Record<string, any> | never {
204205
} else {
205206
logger = toolsLogger('info', [tools.appName]);
206207
}
207-
logger.error(`${hostLogPrefix} conf/${tools.appName}.json missing - call node ${tools.appName}.js setup`);
208+
logger.error(
209+
`${hostLogPrefix} conf/${tools.appName.toLowerCase()}.json missing - call node ${tools.appName.toLowerCase()}.js setup`
210+
);
208211
process.exit(EXIT_CODES.MISSING_CONFIG_JSON);
209212
} else {
210213
// TODO: adjust return type as soon as #2120 merged and we have the type
@@ -2410,14 +2413,17 @@ async function processMessage(msg: ioBroker.SendableMessage): Promise<null | voi
24102413
});
24112414
} else {
24122415
logger.warn(
2413-
`${hostLogPrefix} ${tools.appName} cannot execute shell command "${msg.message}" because not enabled in ${tools.appName}.json file`
2416+
`${hostLogPrefix} ${tools.appName} cannot execute shell command "${
2417+
msg.message
2418+
}" because not enabled in ${tools.appName.toLowerCase()}.json file`
24142419
);
24152420
}
24162421

24172422
break;
24182423

24192424
case 'cmdExec': {
2420-
const args = [`${__dirname}/${tools.appName}.js`];
2425+
const mainFile = path.join(__dirname, '..', `${tools.appName.toLowerCase()}.js`);
2426+
const args = [...getDefaultNodeArgs(mainFile), mainFile];
24212427
if (!msg.message.data || typeof msg.message.data !== 'string') {
24222428
logger.warn(
24232429
`${hostLogPrefix} ${
@@ -2427,11 +2433,9 @@ async function processMessage(msg: ioBroker.SendableMessage): Promise<null | voi
24272433
)}`
24282434
);
24292435
} else {
2430-
const cmd = msg.message.data.split(' ');
2431-
for (let i = 0; i < cmd.length; i++) {
2432-
args.push(cmd[i]);
2433-
}
2434-
logger.info(`${hostLogPrefix} ${tools.appName} ${args.slice(1).join(' ')}`);
2436+
const extraArgs = msg.message.data.split(' ');
2437+
args.push(...extraArgs);
2438+
logger.info(`${hostLogPrefix} ${tools.appName.toLowerCase()} ${extraArgs.join(' ')}`);
24352439

24362440
try {
24372441
const child = spawn('node', args, { windowsHide: true });
@@ -3759,6 +3763,7 @@ function installAdapters(): void {
37593763
);
37603764
}
37613765

3766+
const mainFile = path.join(__dirname, '..', `${tools.appName.toLowerCase()}.js`);
37623767
const installArgs = [];
37633768
const installOptions = { windowsHide: true };
37643769
if (!task.rebuild && task.installedFrom && proc.downloadRetry < 3) {
@@ -3789,13 +3794,14 @@ function installAdapters(): void {
37893794
}
37903795
}
37913796
logger.info(
3792-
`${hostLogPrefix} ${tools.appName} ${installArgs.join(' ')}${
3797+
`${hostLogPrefix} ${tools.appName.toLowerCase()} ${installArgs.join(' ')}${
37933798
task.rebuild
37943799
? ''
37953800
: ` using ${proc.downloadRetry < 3 && task.installedFrom ? 'installedFrom' : 'installedVersion'}`
37963801
}`
37973802
);
3798-
installArgs.unshift(`${__dirname}/${tools.appName}.js`);
3803+
3804+
installArgs.unshift(...getDefaultNodeArgs(mainFile), mainFile);
37993805

38003806
try {
38013807
task.inProgress = true;
@@ -3864,7 +3870,9 @@ function installAdapters(): void {
38643870
});
38653871
child.on('error', err => {
38663872
logger.error(
3867-
`${hostLogPrefix} Cannot execute "${__dirname}/${tools.appName}.js ${commandScope} ${name}: ${err.message}`
3873+
`${hostLogPrefix} Cannot execute "${__dirname}/${tools.appName.toLowerCase()}.js ${commandScope} ${name}: ${
3874+
err.message
3875+
}`
38683876
);
38693877
setTimeout(() => {
38703878
installQueue.shift();
@@ -3873,7 +3881,7 @@ function installAdapters(): void {
38733881
});
38743882
} catch (err) {
38753883
logger.error(
3876-
`${hostLogPrefix} Cannot execute "${__dirname}/${tools.appName}.js ${commandScope} ${name}: ${err}`
3884+
`${hostLogPrefix} Cannot execute "${__dirname}/${tools.appName.toLowerCase()}.js ${commandScope} ${name}: ${err}`
38773885
);
38783886
setTimeout(() => {
38793887
installQueue.shift();

0 commit comments

Comments
 (0)