pinokiod 3.315.0 → 3.316.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/kernel/util.js +27 -23
- package/package.json +1 -1
package/kernel/util.js
CHANGED
|
@@ -322,36 +322,40 @@ const exists= (abspath) => {
|
|
|
322
322
|
return new Promise(r=>fs.access(abspath, fs.constants.F_OK, e => r(!e)))
|
|
323
323
|
}
|
|
324
324
|
const log = async (filepath, str, session) => {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
325
|
+
try {
|
|
326
|
+
if (str && str.trim().length > 0) {
|
|
327
|
+
let e = await exists(filepath)
|
|
328
|
+
if (!e) {
|
|
329
|
+
await fs.promises.mkdir(filepath, { recursive: true })
|
|
330
|
+
}
|
|
330
331
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
332
|
+
let output = '';
|
|
333
|
+
for (let line of str.split('\n')) {
|
|
334
|
+
line = line.split('\r').pop(); // handle overwriting lines
|
|
335
|
+
output += line + '\n';
|
|
336
|
+
}
|
|
336
337
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
338
|
+
const pattern = [
|
|
339
|
+
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
|
|
340
|
+
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-Za-z=><~]))'
|
|
341
|
+
].join('|');
|
|
342
|
+
const regex = new RegExp(pattern, 'gi')
|
|
343
|
+
let stripped = str.replaceAll(regex, '');
|
|
343
344
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
345
|
+
// write to session
|
|
346
|
+
let logpath = path.resolve(filepath, session)
|
|
347
|
+
await fs.promises.writeFile(logpath, stripped)
|
|
347
348
|
|
|
348
|
-
|
|
349
|
+
// create latest from last 10 sessions
|
|
349
350
|
|
|
350
|
-
|
|
351
|
+
let dirpath = path.dirname(filepath)
|
|
351
352
|
|
|
352
353
|
|
|
353
|
-
|
|
354
|
-
|
|
354
|
+
let latest_logpath = path.resolve(filepath, "latest")
|
|
355
|
+
await fs.promises.writeFile(latest_logpath, stripped)
|
|
356
|
+
}
|
|
357
|
+
} catch (e) {
|
|
358
|
+
console.log(">> Util.log error", { filepath, str, session}, e)
|
|
355
359
|
}
|
|
356
360
|
}
|
|
357
361
|
const run = (cmd, cwd, kernel) => {
|