@niceties/draftlog-appender 1.2.0 → 1.2.3
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/dist/core.cjs +52 -52
- package/dist/core.d.ts +1 -1
- package/dist/core.mjs +52 -52
- package/dist/details/canvas.d.ts +1 -1
- package/dist/details/model.d.ts +1 -1
- package/package.json +7 -7
package/dist/core.cjs
CHANGED
|
@@ -9,11 +9,18 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
9
9
|
|
|
10
10
|
var draftlog__default = /*#__PURE__*/_interopDefaultLegacy(draftlog);
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
const createCanvas = (spinner, formatter, ident) => {
|
|
13
13
|
draftlog__default["default"](console);
|
|
14
14
|
draftlog__default["default"].defaults.canReWrite = false;
|
|
15
15
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
16
|
const updaters = [];
|
|
17
|
+
const getPrefix = (status, tick) => {
|
|
18
|
+
// status is truthy when it is inprogress
|
|
19
|
+
const prefix = status ? spinner.frames[tick] :
|
|
20
|
+
// status not null when it is finished
|
|
21
|
+
status != null;
|
|
22
|
+
return prefix;
|
|
23
|
+
};
|
|
17
24
|
return (model) => {
|
|
18
25
|
if (model.skipLines_) {
|
|
19
26
|
updaters.splice(0, model.skipLines_);
|
|
@@ -55,42 +62,12 @@ function createCanvas(spinner, formatter, ident) {
|
|
|
55
62
|
}
|
|
56
63
|
}
|
|
57
64
|
};
|
|
58
|
-
|
|
59
|
-
// status is truthy when it is inprogress
|
|
60
|
-
const prefix = status ? spinner.frames[tick] :
|
|
61
|
-
// status not null when it is finished
|
|
62
|
-
status != null;
|
|
63
|
-
return prefix;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
65
|
+
};
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
const createModel = (logAboveSpinners) => {
|
|
68
68
|
const model = new list.List();
|
|
69
|
-
model.tick_ = model.skipLines_ = model.spinning_ = 0;
|
|
70
69
|
const itemById = Object.create(null);
|
|
71
|
-
|
|
72
|
-
// item has status undefined, so it is static by default
|
|
73
|
-
const item = { text_: text, loglevel_: loglevel, ref_: ref, parentId_: parentId, dirty_: true, context_: context, tag_: tag };
|
|
74
|
-
if (action === 0 /* start */) {
|
|
75
|
-
item.status_ = 1 /* inprogress */;
|
|
76
|
-
}
|
|
77
|
-
if (action === 2 /* finish */) {
|
|
78
|
-
item.status_ = 0 /* finished */;
|
|
79
|
-
}
|
|
80
|
-
if (action !== 3 /* log */) {
|
|
81
|
-
// if status still empty in the original item or item does not exists it will remain empty and static
|
|
82
|
-
updateModel(inputId, item);
|
|
83
|
-
}
|
|
84
|
-
cleanupModel();
|
|
85
|
-
if (action === 3 /* log */) {
|
|
86
|
-
appendToModel(item, logAboveSpinners);
|
|
87
|
-
}
|
|
88
|
-
return model;
|
|
89
|
-
}, () => {
|
|
90
|
-
cleanupModel();
|
|
91
|
-
return model;
|
|
92
|
-
}];
|
|
93
|
-
function appendToModel(item, head) {
|
|
70
|
+
const appendToModel = (item, head) => {
|
|
94
71
|
if (head) {
|
|
95
72
|
list.prepend(model, item);
|
|
96
73
|
}
|
|
@@ -98,8 +75,8 @@ function createModel(logAboveSpinners) {
|
|
|
98
75
|
list.append(model, item);
|
|
99
76
|
}
|
|
100
77
|
model.spinning_ += (item.status_ || 0);
|
|
101
|
-
}
|
|
102
|
-
|
|
78
|
+
};
|
|
79
|
+
const updateModel = (inputId, options) => {
|
|
103
80
|
const modelItem = itemById[inputId];
|
|
104
81
|
if (!modelItem) {
|
|
105
82
|
const item = Object.assign({ inputId_: inputId }, options);
|
|
@@ -128,8 +105,8 @@ function createModel(logAboveSpinners) {
|
|
|
128
105
|
putIntoChildren(modelItem.parentId_, modelItem, lastLeaf);
|
|
129
106
|
}
|
|
130
107
|
}
|
|
131
|
-
}
|
|
132
|
-
|
|
108
|
+
};
|
|
109
|
+
const putIntoChildren = (itemParentId, begin, end) => {
|
|
133
110
|
let parent = itemById[itemParentId];
|
|
134
111
|
if (!parent) {
|
|
135
112
|
parent = { inputId_: itemParentId, text_: '', loglevel_: 0, ref_: new WeakRef(model) };
|
|
@@ -139,8 +116,8 @@ function createModel(logAboveSpinners) {
|
|
|
139
116
|
list.appendRange((parent.lastLeaf_ || parent), begin, end);
|
|
140
117
|
parent.lastLeaf_ = begin;
|
|
141
118
|
model.spinning_ += (begin.status_ || 0);
|
|
142
|
-
}
|
|
143
|
-
|
|
119
|
+
};
|
|
120
|
+
const cleanupModel = () => {
|
|
144
121
|
var _a;
|
|
145
122
|
for (const item of model) {
|
|
146
123
|
if (!((_a = item.ref_) === null || _a === void 0 ? void 0 : _a.deref())) {
|
|
@@ -152,18 +129,37 @@ function createModel(logAboveSpinners) {
|
|
|
152
129
|
break;
|
|
153
130
|
}
|
|
154
131
|
}
|
|
155
|
-
}
|
|
156
|
-
|
|
132
|
+
};
|
|
133
|
+
model.tick_ = model.skipLines_ = model.spinning_ = 0;
|
|
134
|
+
return [({ message: text, inputId, action, loglevel, ref, parentId, context, tag }) => {
|
|
135
|
+
// item has status undefined, so it is static by default
|
|
136
|
+
const item = { text_: text, loglevel_: loglevel, ref_: ref, parentId_: parentId, dirty_: true, context_: context, tag_: tag };
|
|
137
|
+
if (action === 0 /* start */) {
|
|
138
|
+
item.status_ = 1 /* inprogress */;
|
|
139
|
+
}
|
|
140
|
+
if (action === 2 /* finish */) {
|
|
141
|
+
item.status_ = 0 /* finished */;
|
|
142
|
+
}
|
|
143
|
+
if (action !== 3 /* log */) {
|
|
144
|
+
// if status still empty in the original item or item does not exists it will remain empty and static
|
|
145
|
+
updateModel(inputId, item);
|
|
146
|
+
}
|
|
147
|
+
cleanupModel();
|
|
148
|
+
if (action === 3 /* log */) {
|
|
149
|
+
appendToModel(item, logAboveSpinners);
|
|
150
|
+
}
|
|
151
|
+
return model;
|
|
152
|
+
}, () => {
|
|
153
|
+
cleanupModel();
|
|
154
|
+
return model;
|
|
155
|
+
}];
|
|
156
|
+
};
|
|
157
157
|
|
|
158
|
-
|
|
158
|
+
const createDraftlogAppender = (spinner, formatter, logAboveSpinners, ident) => {
|
|
159
159
|
let interval;
|
|
160
160
|
const [updateModel, getModel] = createModel(logAboveSpinners);
|
|
161
161
|
const renderModel = createCanvas(spinner, formatter, ident);
|
|
162
|
-
|
|
163
|
-
renderModel(updateModel(message));
|
|
164
|
-
checkTimeout();
|
|
165
|
-
};
|
|
166
|
-
function checkTimeout() {
|
|
162
|
+
const checkTimeout = () => {
|
|
167
163
|
const spinning = getModel().spinning_;
|
|
168
164
|
if (spinning && !interval) {
|
|
169
165
|
interval = setInterval(updateSpinners, spinner.interval);
|
|
@@ -173,13 +169,17 @@ function createDraftlogAppender(spinner, formatter, logAboveSpinners, ident) {
|
|
|
173
169
|
clearInterval(interval);
|
|
174
170
|
interval = undefined;
|
|
175
171
|
}
|
|
176
|
-
}
|
|
177
|
-
|
|
172
|
+
};
|
|
173
|
+
const updateSpinners = () => {
|
|
178
174
|
const model = getModel();
|
|
179
175
|
model.tick_++;
|
|
180
176
|
model.tick_ %= spinner.frames.length;
|
|
181
177
|
renderModel(model);
|
|
182
|
-
}
|
|
183
|
-
|
|
178
|
+
};
|
|
179
|
+
return (message) => {
|
|
180
|
+
renderModel(updateModel(message));
|
|
181
|
+
checkTimeout();
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
184
|
|
|
185
185
|
exports.createDraftlogAppender = createDraftlogAppender;
|
package/dist/core.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Formatter, LogMessage } from '@niceties/logger/types';
|
|
2
2
|
import { Spinner } from './spinners';
|
|
3
|
-
export declare
|
|
3
|
+
export declare const createDraftlogAppender: (spinner: Spinner, formatter: Formatter, logAboveSpinners: boolean, ident: number) => (message: LogMessage) => void;
|
package/dist/core.mjs
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import draftlog from 'draftlog';
|
|
2
2
|
import { List, prepend, append, removeRange, appendRange, remove } from '@slimlib/list';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
const createCanvas = (spinner, formatter, ident) => {
|
|
5
5
|
draftlog(console);
|
|
6
6
|
draftlog.defaults.canReWrite = false;
|
|
7
7
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
8
|
const updaters = [];
|
|
9
|
+
const getPrefix = (status, tick) => {
|
|
10
|
+
// status is truthy when it is inprogress
|
|
11
|
+
const prefix = status ? spinner.frames[tick] :
|
|
12
|
+
// status not null when it is finished
|
|
13
|
+
status != null;
|
|
14
|
+
return prefix;
|
|
15
|
+
};
|
|
9
16
|
return (model) => {
|
|
10
17
|
if (model.skipLines_) {
|
|
11
18
|
updaters.splice(0, model.skipLines_);
|
|
@@ -47,42 +54,12 @@ function createCanvas(spinner, formatter, ident) {
|
|
|
47
54
|
}
|
|
48
55
|
}
|
|
49
56
|
};
|
|
50
|
-
|
|
51
|
-
// status is truthy when it is inprogress
|
|
52
|
-
const prefix = status ? spinner.frames[tick] :
|
|
53
|
-
// status not null when it is finished
|
|
54
|
-
status != null;
|
|
55
|
-
return prefix;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
57
|
+
};
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
const createModel = (logAboveSpinners) => {
|
|
60
60
|
const model = new List();
|
|
61
|
-
model.tick_ = model.skipLines_ = model.spinning_ = 0;
|
|
62
61
|
const itemById = Object.create(null);
|
|
63
|
-
|
|
64
|
-
// item has status undefined, so it is static by default
|
|
65
|
-
const item = { text_: text, loglevel_: loglevel, ref_: ref, parentId_: parentId, dirty_: true, context_: context, tag_: tag };
|
|
66
|
-
if (action === 0 /* start */) {
|
|
67
|
-
item.status_ = 1 /* inprogress */;
|
|
68
|
-
}
|
|
69
|
-
if (action === 2 /* finish */) {
|
|
70
|
-
item.status_ = 0 /* finished */;
|
|
71
|
-
}
|
|
72
|
-
if (action !== 3 /* log */) {
|
|
73
|
-
// if status still empty in the original item or item does not exists it will remain empty and static
|
|
74
|
-
updateModel(inputId, item);
|
|
75
|
-
}
|
|
76
|
-
cleanupModel();
|
|
77
|
-
if (action === 3 /* log */) {
|
|
78
|
-
appendToModel(item, logAboveSpinners);
|
|
79
|
-
}
|
|
80
|
-
return model;
|
|
81
|
-
}, () => {
|
|
82
|
-
cleanupModel();
|
|
83
|
-
return model;
|
|
84
|
-
}];
|
|
85
|
-
function appendToModel(item, head) {
|
|
62
|
+
const appendToModel = (item, head) => {
|
|
86
63
|
if (head) {
|
|
87
64
|
prepend(model, item);
|
|
88
65
|
}
|
|
@@ -90,8 +67,8 @@ function createModel(logAboveSpinners) {
|
|
|
90
67
|
append(model, item);
|
|
91
68
|
}
|
|
92
69
|
model.spinning_ += (item.status_ || 0);
|
|
93
|
-
}
|
|
94
|
-
|
|
70
|
+
};
|
|
71
|
+
const updateModel = (inputId, options) => {
|
|
95
72
|
const modelItem = itemById[inputId];
|
|
96
73
|
if (!modelItem) {
|
|
97
74
|
const item = Object.assign({ inputId_: inputId }, options);
|
|
@@ -120,8 +97,8 @@ function createModel(logAboveSpinners) {
|
|
|
120
97
|
putIntoChildren(modelItem.parentId_, modelItem, lastLeaf);
|
|
121
98
|
}
|
|
122
99
|
}
|
|
123
|
-
}
|
|
124
|
-
|
|
100
|
+
};
|
|
101
|
+
const putIntoChildren = (itemParentId, begin, end) => {
|
|
125
102
|
let parent = itemById[itemParentId];
|
|
126
103
|
if (!parent) {
|
|
127
104
|
parent = { inputId_: itemParentId, text_: '', loglevel_: 0, ref_: new WeakRef(model) };
|
|
@@ -131,8 +108,8 @@ function createModel(logAboveSpinners) {
|
|
|
131
108
|
appendRange((parent.lastLeaf_ || parent), begin, end);
|
|
132
109
|
parent.lastLeaf_ = begin;
|
|
133
110
|
model.spinning_ += (begin.status_ || 0);
|
|
134
|
-
}
|
|
135
|
-
|
|
111
|
+
};
|
|
112
|
+
const cleanupModel = () => {
|
|
136
113
|
var _a;
|
|
137
114
|
for (const item of model) {
|
|
138
115
|
if (!((_a = item.ref_) === null || _a === void 0 ? void 0 : _a.deref())) {
|
|
@@ -144,18 +121,37 @@ function createModel(logAboveSpinners) {
|
|
|
144
121
|
break;
|
|
145
122
|
}
|
|
146
123
|
}
|
|
147
|
-
}
|
|
148
|
-
|
|
124
|
+
};
|
|
125
|
+
model.tick_ = model.skipLines_ = model.spinning_ = 0;
|
|
126
|
+
return [({ message: text, inputId, action, loglevel, ref, parentId, context, tag }) => {
|
|
127
|
+
// item has status undefined, so it is static by default
|
|
128
|
+
const item = { text_: text, loglevel_: loglevel, ref_: ref, parentId_: parentId, dirty_: true, context_: context, tag_: tag };
|
|
129
|
+
if (action === 0 /* start */) {
|
|
130
|
+
item.status_ = 1 /* inprogress */;
|
|
131
|
+
}
|
|
132
|
+
if (action === 2 /* finish */) {
|
|
133
|
+
item.status_ = 0 /* finished */;
|
|
134
|
+
}
|
|
135
|
+
if (action !== 3 /* log */) {
|
|
136
|
+
// if status still empty in the original item or item does not exists it will remain empty and static
|
|
137
|
+
updateModel(inputId, item);
|
|
138
|
+
}
|
|
139
|
+
cleanupModel();
|
|
140
|
+
if (action === 3 /* log */) {
|
|
141
|
+
appendToModel(item, logAboveSpinners);
|
|
142
|
+
}
|
|
143
|
+
return model;
|
|
144
|
+
}, () => {
|
|
145
|
+
cleanupModel();
|
|
146
|
+
return model;
|
|
147
|
+
}];
|
|
148
|
+
};
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
const createDraftlogAppender = (spinner, formatter, logAboveSpinners, ident) => {
|
|
151
151
|
let interval;
|
|
152
152
|
const [updateModel, getModel] = createModel(logAboveSpinners);
|
|
153
153
|
const renderModel = createCanvas(spinner, formatter, ident);
|
|
154
|
-
|
|
155
|
-
renderModel(updateModel(message));
|
|
156
|
-
checkTimeout();
|
|
157
|
-
};
|
|
158
|
-
function checkTimeout() {
|
|
154
|
+
const checkTimeout = () => {
|
|
159
155
|
const spinning = getModel().spinning_;
|
|
160
156
|
if (spinning && !interval) {
|
|
161
157
|
interval = setInterval(updateSpinners, spinner.interval);
|
|
@@ -165,13 +161,17 @@ function createDraftlogAppender(spinner, formatter, logAboveSpinners, ident) {
|
|
|
165
161
|
clearInterval(interval);
|
|
166
162
|
interval = undefined;
|
|
167
163
|
}
|
|
168
|
-
}
|
|
169
|
-
|
|
164
|
+
};
|
|
165
|
+
const updateSpinners = () => {
|
|
170
166
|
const model = getModel();
|
|
171
167
|
model.tick_++;
|
|
172
168
|
model.tick_ %= spinner.frames.length;
|
|
173
169
|
renderModel(model);
|
|
174
|
-
}
|
|
175
|
-
|
|
170
|
+
};
|
|
171
|
+
return (message) => {
|
|
172
|
+
renderModel(updateModel(message));
|
|
173
|
+
checkTimeout();
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
176
|
|
|
177
177
|
export { createDraftlogAppender };
|
package/dist/details/canvas.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Formatter } from '@niceties/logger/types';
|
|
2
2
|
import { Model } from './model';
|
|
3
3
|
import { Spinner } from '../spinners';
|
|
4
|
-
export declare
|
|
4
|
+
export declare const createCanvas: (spinner: Spinner, formatter: Formatter, ident: number) => (model: Model) => void;
|
package/dist/details/model.d.ts
CHANGED
|
@@ -21,4 +21,4 @@ export declare type Model = List<ModelItem> & {
|
|
|
21
21
|
tick_: number;
|
|
22
22
|
spinning_: number;
|
|
23
23
|
};
|
|
24
|
-
export declare
|
|
24
|
+
export declare const createModel: (logAboveSpinners: boolean) => [(logMessage: LogMessage) => Model, () => Model];
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.2.
|
|
2
|
+
"version": "1.2.3",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "@niceties/draftlog-appender",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Konstantin Shutkin"
|
|
7
7
|
},
|
|
8
|
-
"funding": "https://www.donationalerts.com/r/excitingcode",
|
|
9
8
|
"type": "module",
|
|
10
9
|
"exports": {
|
|
11
10
|
".": {
|
|
@@ -19,7 +18,8 @@
|
|
|
19
18
|
"./spinners": {
|
|
20
19
|
"require": "./dist/spinners.cjs",
|
|
21
20
|
"default": "./dist/spinners.mjs"
|
|
22
|
-
}
|
|
21
|
+
},
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
23
|
},
|
|
24
24
|
"main": "./dist/index.cjs",
|
|
25
25
|
"module": "./dist/index.mjs",
|
|
@@ -63,15 +63,15 @@
|
|
|
63
63
|
"semantic-release": "18.0.0",
|
|
64
64
|
"semantic-release-monorepo": "7.0.5",
|
|
65
65
|
"ts-jest": "27.1.3",
|
|
66
|
-
"typescript": "4.
|
|
66
|
+
"typescript": "4.6.x",
|
|
67
67
|
"update-monorepo-package-json": "0.2.0",
|
|
68
|
-
"pkgbld": "1.1
|
|
68
|
+
"pkgbld": "1.2.1"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"@niceties/logger": "^1.1.
|
|
71
|
+
"@niceties/logger": "^1.1.4"
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"draftlog": "^1.0.13",
|
|
75
|
-
"@slimlib/list": "^1.0.
|
|
75
|
+
"@slimlib/list": "^1.0.3"
|
|
76
76
|
}
|
|
77
77
|
}
|