@akc42/server-utils 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/debug.js +23 -15
- package/package.json +2 -4
- package/version.js +10 -10
package/debug.js
CHANGED
|
@@ -26,7 +26,7 @@ let cachelimit = 50;
|
|
|
26
26
|
export function Debug (topic) {
|
|
27
27
|
const t = topic;
|
|
28
28
|
let timestamp = new Date().getTime();
|
|
29
|
-
return function (...args) {
|
|
29
|
+
return async function (...args) {
|
|
30
30
|
let enabled = false;
|
|
31
31
|
if (config) {
|
|
32
32
|
const topics = config.split(':');
|
|
@@ -44,16 +44,18 @@ export function Debug (topic) {
|
|
|
44
44
|
//eslint-disable-next-line no-console
|
|
45
45
|
console.log(output);
|
|
46
46
|
} else {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
})
|
|
47
|
+
try {
|
|
48
|
+
await fs.appendFile(process.env.LOG_FILE, output + '\n',{flush: true})
|
|
49
|
+
} catch(err) {
|
|
50
|
+
console.warn('Failed to write following message to log file', output);
|
|
51
|
+
}
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
54
|
cache.push(output);
|
|
53
55
|
if (cache.length > cachelimit) cache.splice(0,cache.length - cachelimit); //prevent it getting too big
|
|
54
56
|
}
|
|
55
57
|
};
|
|
56
|
-
export function dumpDebugCache() {
|
|
58
|
+
export async function dumpDebugCache() {
|
|
57
59
|
const output = chalk.white.bgBlue('Above are all the debug calls (most recent first) which lead up to, and then followed on from, the error above');
|
|
58
60
|
cache.reverse();
|
|
59
61
|
for(const line of cache) {
|
|
@@ -61,9 +63,11 @@ export function dumpDebugCache() {
|
|
|
61
63
|
//eslint-disable-next-line no-console
|
|
62
64
|
console.log(line);
|
|
63
65
|
} else {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
})
|
|
66
|
+
try {
|
|
67
|
+
await fs.appendFile(process.env.LOG_FILE, line + '\n',{flush: true});
|
|
68
|
+
} catch (err) {
|
|
69
|
+
console.warn('Failed to write following message to log file', line);
|
|
70
|
+
}
|
|
67
71
|
}
|
|
68
72
|
}
|
|
69
73
|
cache.reverse();
|
|
@@ -71,12 +75,14 @@ export function dumpDebugCache() {
|
|
|
71
75
|
//eslint-disable-next-line no-console
|
|
72
76
|
console.log(output);
|
|
73
77
|
} else {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
})
|
|
78
|
+
try {
|
|
79
|
+
await fs.appendFile(process.env.LOG_FILE, output + '\n',{flush: true});
|
|
80
|
+
} catch(err) {
|
|
81
|
+
console.warn('Failed to write following message to log file', output);
|
|
82
|
+
}
|
|
77
83
|
}
|
|
78
84
|
};
|
|
79
|
-
export function setDebugConfig(con, limit = 50) {
|
|
85
|
+
export async function setDebugConfig(con, limit = 50) {
|
|
80
86
|
cachelimit = limit;
|
|
81
87
|
if (con !== config) {
|
|
82
88
|
config = con;
|
|
@@ -85,9 +91,11 @@ export function setDebugConfig(con, limit = 50) {
|
|
|
85
91
|
//eslint-disable-next-line no-console
|
|
86
92
|
console.log(output);
|
|
87
93
|
} else {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
})
|
|
94
|
+
try {
|
|
95
|
+
await fs.appendFile(process.env.LOG_FILE, output + '\n',{flush: true})
|
|
96
|
+
} catch (err) {
|
|
97
|
+
console.warn('Failed to write following message to log file', output);
|
|
98
|
+
}
|
|
91
99
|
}
|
|
92
100
|
}
|
|
93
101
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akc42/server-utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A Set of Utilities to use on the Server Side of a Project",
|
|
6
6
|
"main": "./utils.js",
|
|
@@ -22,8 +22,6 @@
|
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://github.com/akc42/server-utils#readme",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"
|
|
26
|
-
"chalk": "^5.3.0",
|
|
27
|
-
"debug": "^4.3.4"
|
|
25
|
+
"chalk": "^5.3.0"
|
|
28
26
|
}
|
|
29
27
|
}
|
package/version.js
CHANGED
|
@@ -25,16 +25,16 @@ import { exec } from 'node:child_process';
|
|
|
25
25
|
|
|
26
26
|
const debug = Debug('version');
|
|
27
27
|
|
|
28
|
-
function shCmd(cmd, root) {
|
|
29
|
-
debug('About to execute Command ', cmd);
|
|
30
|
-
return new Promise((accept, reject) => {
|
|
31
|
-
exec(cmd, { cwd: root }, (err, stdout, stderr) => {
|
|
28
|
+
async function shCmd(cmd, root) {
|
|
29
|
+
await debug('About to execute Command ', cmd);
|
|
30
|
+
return new Promise(async (accept, reject) => {
|
|
31
|
+
exec(cmd, { cwd: root }, async (err, stdout, stderr) => {
|
|
32
32
|
if (stderr) {
|
|
33
|
-
debug('Command ', cmd, 'about to fail with ', err);
|
|
33
|
+
await debug('Command ', cmd, 'about to fail with ', err);
|
|
34
34
|
reject(err);
|
|
35
35
|
} else {
|
|
36
36
|
const out = stdout.trim();
|
|
37
|
-
debug('Command ', cmd, 'Success with ', out);
|
|
37
|
+
await debug('Command ', cmd, 'Success with ', out);
|
|
38
38
|
accept(out);
|
|
39
39
|
}
|
|
40
40
|
});
|
|
@@ -46,9 +46,9 @@ export default async function(root) {
|
|
|
46
46
|
let vtime;
|
|
47
47
|
|
|
48
48
|
try {
|
|
49
|
-
debug('Look for git')
|
|
49
|
+
await debug('Look for git')
|
|
50
50
|
await access(resolve(root, '.git'));
|
|
51
|
-
debug('Git found, so use it to get data')
|
|
51
|
+
await debug('Git found, so use it to get data')
|
|
52
52
|
//we get here if there is a git directory, so we can look up version and latest commit from them
|
|
53
53
|
version = await shCmd('git describe --abbrev=0 --tags');
|
|
54
54
|
//git is installed and we found a tag
|
|
@@ -60,7 +60,7 @@ export default async function(root) {
|
|
|
60
60
|
} catch (e) {
|
|
61
61
|
//no git, or no tag, so we must look for a version file
|
|
62
62
|
try {
|
|
63
|
-
debug('Git approach failed, so look for release info');
|
|
63
|
+
await debug('Git approach failed, so look for release info');
|
|
64
64
|
version = await readFile(resolve(root, 'release.info'), 'utf8');
|
|
65
65
|
try {
|
|
66
66
|
const { mtime } = await stat(resolve(root, 'release.info'));
|
|
@@ -88,7 +88,7 @@ export default async function(root) {
|
|
|
88
88
|
} finally {
|
|
89
89
|
const finalversion = version.replace(/\s+/g, ' ').trim(); //trim out new lines and multiple spaces just one.
|
|
90
90
|
const copyrightTime = new Date(vtime);
|
|
91
|
-
debug('Resolving with Git copyright Year is ', copyrightTime.getUTCFullYear());
|
|
91
|
+
await debug('Resolving with Git copyright Year is ', copyrightTime.getUTCFullYear());
|
|
92
92
|
return({ version: finalversion, year: copyrightTime.getUTCFullYear() });
|
|
93
93
|
}
|
|
94
94
|
};
|