Skip to content

Commit 3a2a516

Browse files
committed
Adjust install script
1 parent b00510e commit 3a2a516

File tree

5 files changed

+101
-68
lines changed

5 files changed

+101
-68
lines changed

index.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,10 @@ declare module "addon-tools-raub" {
404404
export const getLoggers: () => Readonly<Record<string, TGlobalLogger>>
405405

406406
/**
407-
* Get a logger by name, returns null if not found
407+
* Get a logger by name.
408+
*
409+
* If there is no logger by that name,
410+
* it will create a new one with default parameters.
408411
*/
409-
export const getLogger: () => (TGlobalLogger | null)
412+
export const getLogger: () => (TGlobalLogger)
410413
}

package-lock.json

Lines changed: 70 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"author": "Luis Blanco <[email protected]>",
33
"name": "addon-tools-raub",
4-
"version": "9.0.0",
4+
"version": "9.1.0",
55
"description": "Helpers for Node.js addons and dependency packages",
66
"license": "MIT",
77
"main": "index.js",

utils/install.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ const exec = util.promisify(require('node:child_process').exec);
55

66
const { getBin, getPlatform } = require('../include');
77
const { mkdir, rmdir, rm, exists } = require('./files');
8+
const { getLogger } = require('./logger');
89

10+
const logger = getLogger('addon-tools');
911

1012
const download = async (url) => {
1113
const { stderr } = await exec([
@@ -14,7 +16,15 @@ const download = async (url) => {
1416
url,
1517
].join(' '));
1618
if (stderr) {
17-
console.warn(stderr);
19+
logger.warn(stderr);
20+
}
21+
};
22+
23+
24+
const unpack = async (gzPath, binPath) => {
25+
const { stderr } = await exec(`tar -xzf ${gzPath} --directory ${binPath}`);
26+
if (stderr) {
27+
logger.warn(stderr);
1828
}
1929
};
2030

@@ -27,18 +37,19 @@ const install = async (folderUrl) => {
2737
await rmdir(binPath);
2838
await mkdir(binPath);
2939

30-
await download(urlPath);
31-
32-
if (!(await exists(gzPath))) {
33-
console.warn(`Could not download "${urlPath}" to "${gzPath}"`);
40+
try {
41+
await download(urlPath);
42+
43+
if (!(await exists(gzPath))) {
44+
logger.warn(`Could not download "${urlPath}" to "${gzPath}"`);
45+
return false;
46+
}
47+
48+
await unpack(gzPath, binPath);
49+
} catch (error) {
50+
logger.warn(error);
3451
return false;
3552
}
36-
37-
const { stderr } = await exec(`tar -xzf ${gzPath} --directory ${binPath}`);
38-
if (stderr) {
39-
console.warn(stderr);
40-
}
41-
4253
await rm(gzPath);
4354
return true;
4455
};

utils/logger.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const getLevel = () => currentLevel;
5757

5858
const getLoggers = () => ({ ...loggers });
5959

60-
const getLogger = (name) => loggers[name] || null;
60+
const getLogger = (name) => loggers[name] || createLogger({ name });
6161

6262
if (!global.AddonTools.log) {
6363
global.AddonTools.log = (name, level, ...args) => {
@@ -69,6 +69,8 @@ if (!global.AddonTools.log) {
6969
};
7070
}
7171

72+
createLogger({ name: 'addon-tools' });
73+
7274
module.exports = {
7375
createLogger, setLevel, getLevel, getLoggers, getLogger,
7476
};

0 commit comments

Comments
 (0)