bimba-cli 0.4.6 → 0.4.7
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/package.json +1 -1
- package/plugin.js +6 -16
- package/serve.js +20 -15
package/package.json
CHANGED
package/plugin.js
CHANGED
|
@@ -55,7 +55,7 @@ export const imbaPlugin = {
|
|
|
55
55
|
|
|
56
56
|
// the file has been successfully compiled
|
|
57
57
|
if (!out.errors?.length) {
|
|
58
|
-
console.log(theme.action("compiling: ") + theme.folder(dir.join(f.dir,'/')) + theme.filename(f.base) + " - " + theme.success("
|
|
58
|
+
console.log(theme.action("compiling: ") + theme.folder(dir.join(f.dir,'/')) + theme.filename(f.base) + " - " + theme.success("compiled"));
|
|
59
59
|
stats.bundled++;
|
|
60
60
|
stats.compiled++;
|
|
61
61
|
contents = out.js;
|
|
@@ -89,28 +89,18 @@ plugin(imbaPlugin);
|
|
|
89
89
|
|
|
90
90
|
// print an error generated by the imba compiler
|
|
91
91
|
export function printerr(err) {
|
|
92
|
-
|
|
92
|
+
|
|
93
93
|
// halper function to produce empty strings
|
|
94
94
|
const fill = (len = 0) => {return new Array(len + 1).join(' ')}
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
|
|
96
|
+
// gather the needed information from the compiler error
|
|
97
97
|
const snippet = err.toSnippet().split("\n");
|
|
98
|
-
const errs = snippet[2] ? snippet[2].indexOf('^') : -1;
|
|
99
|
-
|
|
100
|
-
// no source context available — print compact fallback
|
|
101
|
-
if (!snippet[1] || errs === -1) {
|
|
102
|
-
console.log('');
|
|
103
|
-
console.log(fill(10) + theme.error(" " + err.message + " "));
|
|
104
|
-
console.log('');
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
98
|
const display = {
|
|
109
99
|
error: " " + err.message + " ",
|
|
110
100
|
outdent: fill(10),
|
|
111
101
|
source: snippet[1] + " ",
|
|
112
|
-
margin: " line " +
|
|
113
|
-
errs:
|
|
102
|
+
margin: " line " + err.range.start.line + " ",
|
|
103
|
+
errs: snippet[2].indexOf('^'),
|
|
114
104
|
erre: snippet[2].lastIndexOf('^') + 1,
|
|
115
105
|
};
|
|
116
106
|
|
package/serve.js
CHANGED
|
@@ -184,9 +184,10 @@ export function serve(entrypoint, flags) {
|
|
|
184
184
|
const sockets = new Set()
|
|
185
185
|
let importMapTag = null
|
|
186
186
|
|
|
187
|
+
let _lastLines = 0
|
|
187
188
|
let _fadeTimers = []
|
|
188
189
|
let _fadeId = 0
|
|
189
|
-
let
|
|
190
|
+
let _cursorOnLine = false
|
|
190
191
|
|
|
191
192
|
function cancelFade() {
|
|
192
193
|
_fadeTimers.forEach(t => clearTimeout(t))
|
|
@@ -195,18 +196,22 @@ export function serve(entrypoint, flags) {
|
|
|
195
196
|
|
|
196
197
|
function printStatus(file, state, errors) {
|
|
197
198
|
cancelFade()
|
|
198
|
-
if (
|
|
199
|
-
process.stdout.write('\x1b[
|
|
200
|
-
|
|
199
|
+
if (_cursorOnLine) {
|
|
200
|
+
process.stdout.write('\x1b[1G\x1b[J')
|
|
201
|
+
_lastLines = 0
|
|
202
|
+
_cursorOnLine = false
|
|
203
|
+
} else if (_lastLines > 0) {
|
|
204
|
+
process.stdout.write(`\x1b[${_lastLines}A\x1b[J`)
|
|
205
|
+
_lastLines = 0
|
|
201
206
|
}
|
|
202
207
|
const now = new Date().toLocaleTimeString('ru-RU', { hour: '2-digit', minute: '2-digit', second: '2-digit' })
|
|
203
208
|
const status = state === 'ok' ? theme.success(' ok ') : theme.failure(' fail ')
|
|
204
|
-
process.stdout.write('\x1b[s')
|
|
205
|
-
_statusSaved = true
|
|
206
209
|
if (errors?.length) {
|
|
207
210
|
process.stdout.write(` ${theme.folder(now)} ${theme.filename(file)} ${status}\n`)
|
|
211
|
+
_lastLines = 1
|
|
208
212
|
for (const err of errors) {
|
|
209
|
-
|
|
213
|
+
printerr(err)
|
|
214
|
+
_lastLines += 5
|
|
210
215
|
}
|
|
211
216
|
} else {
|
|
212
217
|
const myId = ++_fadeId
|
|
@@ -216,13 +221,16 @@ export function serve(entrypoint, flags) {
|
|
|
216
221
|
const charDelay = 22
|
|
217
222
|
|
|
218
223
|
process.stdout.write(` ${theme.folder(now)} ${theme.filename(file)} ${status}`)
|
|
224
|
+
_lastLines = 1
|
|
225
|
+
_cursorOnLine = true
|
|
219
226
|
|
|
220
227
|
for (let i = 1; i <= totalLen; i++) {
|
|
221
228
|
_fadeTimers.push(setTimeout(() => {
|
|
222
|
-
if (_fadeId !== myId) return
|
|
223
|
-
process.stdout.write('\x1b[1D
|
|
229
|
+
if (_fadeId !== myId || _lastLines !== 1) return
|
|
230
|
+
process.stdout.write('\x1b[1D\x1b[K')
|
|
224
231
|
if (i === totalLen) {
|
|
225
|
-
|
|
232
|
+
_lastLines = 0
|
|
233
|
+
_cursorOnLine = false
|
|
226
234
|
}
|
|
227
235
|
}, startDelay + i * charDelay))
|
|
228
236
|
}
|
|
@@ -266,7 +274,7 @@ export function serve(entrypoint, flags) {
|
|
|
266
274
|
if (out.errors?.length) {
|
|
267
275
|
if (!out.cached) {
|
|
268
276
|
printStatus(file, 'fail', out.errors)
|
|
269
|
-
const payload = JSON.stringify({ type: 'error', file, errors: out.errors.map(e => ({ message: e.message, line: e.range?.start?.line, snippet: e.toSnippet()
|
|
277
|
+
const payload = JSON.stringify({ type: 'error', file, errors: out.errors.map(e => ({ message: e.message, line: e.range?.start?.line, snippet: e.toSnippet() })) })
|
|
270
278
|
for (const socket of sockets) socket.send(payload)
|
|
271
279
|
}
|
|
272
280
|
return new Response(out.errors.map(e => e.message).join('\n'), { status: 500 })
|
|
@@ -277,10 +285,7 @@ export function serve(entrypoint, flags) {
|
|
|
277
285
|
}
|
|
278
286
|
return new Response(out.js, { headers: { 'Content-Type': 'application/javascript' } })
|
|
279
287
|
} catch (e) {
|
|
280
|
-
|
|
281
|
-
printStatus(file, 'fail', [{ message: e.message }])
|
|
282
|
-
const payload = JSON.stringify({ type: 'error', file, errors: [{ message: e.message }] })
|
|
283
|
-
for (const socket of sockets) socket.send(payload)
|
|
288
|
+
console.error(theme.failure('Compile error: ') + theme.filename(pathname) + '\n' + e.message)
|
|
284
289
|
return new Response(e.message, { status: 500 })
|
|
285
290
|
}
|
|
286
291
|
}
|