pinokiod 3.19.62 → 3.19.63
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 +24 -19
- package/package.json +1 -1
package/kernel/util.js
CHANGED
|
@@ -159,27 +159,32 @@ const exists= (abspath) => {
|
|
|
159
159
|
return new Promise(r=>fs.access(abspath, fs.constants.F_OK, e => r(!e)))
|
|
160
160
|
}
|
|
161
161
|
const log = async (filepath, str, session) => {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
162
|
+
if (str && str.trim().length > 0) {
|
|
163
|
+
try {
|
|
164
|
+
await fs.promises.mkdir(filepath, { recursive: true })
|
|
165
|
+
} catch (e) {
|
|
166
|
+
}
|
|
166
167
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
168
|
+
let output = '';
|
|
169
|
+
for (let line of str.split('\n')) {
|
|
170
|
+
line = line.split('\r').pop(); // handle overwriting lines
|
|
171
|
+
output += line + '\n';
|
|
172
|
+
}
|
|
172
173
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
174
|
+
const pattern = [
|
|
175
|
+
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
|
|
176
|
+
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-Za-z=><~]))'
|
|
177
|
+
].join('|');
|
|
178
|
+
const regex = new RegExp(pattern, 'gi')
|
|
179
|
+
let stripped = str.replaceAll(regex, '');
|
|
180
|
+
let logpath = path.resolve(filepath, session)
|
|
181
|
+
console.log("> write log", logpath)
|
|
182
|
+
await fs.promises.writeFile(logpath, stripped)
|
|
183
|
+
let latest_logpath = path.resolve(filepath, "latest")
|
|
184
|
+
console.log("> write latest log", latest_logpath)
|
|
185
|
+
await fs.promises.writeFile(latest_logpath, stripped)
|
|
186
|
+
console.log("> all logs written")
|
|
187
|
+
}
|
|
183
188
|
}
|
|
184
189
|
const run = (cmd, cwd, kernel) => {
|
|
185
190
|
// console.log("Util.run", { cmd, cwd })
|