@altronix/cli 0.7.10 → 0.7.12
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/build.js +23 -16
- package/dist/build.ui.d.ts +6 -1
- package/dist/build.ui.js +51 -12
- package/package.json +1 -1
package/dist/build.js
CHANGED
|
@@ -4,11 +4,11 @@ import path from "node:path";
|
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import cp from "node:child_process";
|
|
6
6
|
import inquirer from "@inquirer/confirm";
|
|
7
|
-
import { concat, concatMap, EMPTY, from, last, lastValueFrom, map, merge, mergeMap, Observable, of, share, tap, toArray, } from "rxjs";
|
|
7
|
+
import { catchError, concat, concatMap, EMPTY, from, last, lastValueFrom, map, merge, mergeMap, Observable, of, share, tap, toArray, } from "rxjs";
|
|
8
8
|
import { PassThrough } from "node:stream";
|
|
9
9
|
import { render } from "ink";
|
|
10
10
|
import React from "react";
|
|
11
|
-
import Ui from "./build.ui.js";
|
|
11
|
+
import Ui, { BuildError } from "./build.ui.js";
|
|
12
12
|
import { keys } from "./keys.js";
|
|
13
13
|
const schemaBuild = {
|
|
14
14
|
type: "object",
|
|
@@ -174,12 +174,12 @@ function westItem(opts) {
|
|
|
174
174
|
const { board, name, config, version } = opts;
|
|
175
175
|
return {
|
|
176
176
|
kind: "west",
|
|
177
|
-
|
|
177
|
+
item: `${board}-${name}-${config}-${version}`
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
180
|
function west(args) {
|
|
181
181
|
const { cwd, board, sourceDir, binaryDir, confs, overlays } = args;
|
|
182
|
-
const item = westItem(args)
|
|
182
|
+
const { item } = westItem(args);
|
|
183
183
|
return of([
|
|
184
184
|
`build`,
|
|
185
185
|
`-b ${board}`,
|
|
@@ -193,23 +193,31 @@ function west(args) {
|
|
|
193
193
|
const fout = fs.createWriteStream(args.outputFile);
|
|
194
194
|
const ferr = fs.createWriteStream(args.errorFile);
|
|
195
195
|
const out = new PassThrough();
|
|
196
|
+
const err = new PassThrough();
|
|
197
|
+
let error = "";
|
|
196
198
|
west.stdout.pipe(fout);
|
|
197
199
|
west.stdout.pipe(out);
|
|
198
200
|
west.stderr.pipe(ferr);
|
|
201
|
+
west.stderr.pipe(err);
|
|
199
202
|
west.on("error", (e) => {
|
|
200
|
-
subscriber.error(e);
|
|
201
203
|
fout.close();
|
|
202
204
|
ferr.close();
|
|
203
205
|
out.destroy();
|
|
206
|
+
err.destroy();
|
|
207
|
+
subscriber.next({ item, error: e.name });
|
|
204
208
|
});
|
|
205
209
|
west.on("exit", () => {
|
|
206
210
|
fout.close();
|
|
207
211
|
ferr.close();
|
|
208
212
|
out.destroy();
|
|
209
|
-
|
|
213
|
+
err.destroy();
|
|
214
|
+
error.length ?
|
|
215
|
+
subscriber.next({ item, error }) :
|
|
216
|
+
subscriber.next({ item, complete: true });
|
|
210
217
|
subscriber.complete();
|
|
211
218
|
});
|
|
212
|
-
out.on("data", (
|
|
219
|
+
out.on("data", (d) => subscriber.next({ item, output: d.toString() }));
|
|
220
|
+
err.on("data", (d) => error += d);
|
|
213
221
|
})));
|
|
214
222
|
}
|
|
215
223
|
async function seedleOptionsNormalize(seedle, cwd, verbose) {
|
|
@@ -270,12 +278,12 @@ function seedle(opts) {
|
|
|
270
278
|
})));
|
|
271
279
|
}
|
|
272
280
|
function cmakeItem(opts) {
|
|
273
|
-
const { name } = opts;
|
|
274
|
-
return { kind: "wasm",
|
|
281
|
+
const { name: item } = opts;
|
|
282
|
+
return { kind: "wasm", item };
|
|
275
283
|
}
|
|
276
284
|
function cmakeConfigure(opts) {
|
|
277
285
|
const { buildDir, outputFile, errorFile, } = opts;
|
|
278
|
-
const item = cmakeItem(opts)
|
|
286
|
+
const { item } = cmakeItem(opts);
|
|
279
287
|
return of([`-B${buildDir}`, `-S${buildDir}`]).pipe(mergeMap((cmakeArgs) => new Observable((subscriber) => {
|
|
280
288
|
const wasm = cp.spawn("cmake", cmakeArgs, {
|
|
281
289
|
cwd: buildDir,
|
|
@@ -288,16 +296,15 @@ function cmakeConfigure(opts) {
|
|
|
288
296
|
wasm.stdout.pipe(out);
|
|
289
297
|
wasm.stderr.pipe(ferr);
|
|
290
298
|
wasm.on("error", (e) => {
|
|
291
|
-
subscriber.error(e);
|
|
292
299
|
fout.close();
|
|
293
300
|
ferr.close();
|
|
294
301
|
out.destroy();
|
|
302
|
+
subscriber.error(new BuildError(item, "wasm", e.name));
|
|
295
303
|
});
|
|
296
304
|
wasm.on("exit", () => {
|
|
297
305
|
fout.close();
|
|
298
306
|
ferr.close();
|
|
299
307
|
out.destroy();
|
|
300
|
-
subscriber.next({ item, complete: true });
|
|
301
308
|
subscriber.complete();
|
|
302
309
|
});
|
|
303
310
|
out.on("data", (data) => subscriber.next({ item, output: data.toString() }));
|
|
@@ -305,7 +312,7 @@ function cmakeConfigure(opts) {
|
|
|
305
312
|
}
|
|
306
313
|
function cmakeBuild(opts) {
|
|
307
314
|
const { buildDir, outputFile, errorFile, } = opts;
|
|
308
|
-
const item = cmakeItem(opts)
|
|
315
|
+
const { item } = cmakeItem(opts);
|
|
309
316
|
return of([`--build`, `${buildDir}`, `--target`, ` wasm`]).pipe(mergeMap((cmakeArgs) => new Observable((subscriber) => {
|
|
310
317
|
const wasm = cp.spawn("cmake", cmakeArgs, {
|
|
311
318
|
cwd: buildDir,
|
|
@@ -318,23 +325,23 @@ function cmakeBuild(opts) {
|
|
|
318
325
|
wasm.stdout.pipe(out);
|
|
319
326
|
wasm.stderr.pipe(ferr);
|
|
320
327
|
wasm.on("error", (e) => {
|
|
321
|
-
subscriber.error(e);
|
|
322
328
|
fout.close();
|
|
323
329
|
ferr.close();
|
|
324
330
|
out.destroy();
|
|
331
|
+
subscriber.error(new BuildError(item, "wasm", e.name));
|
|
325
332
|
});
|
|
326
333
|
wasm.on("exit", () => {
|
|
327
334
|
fout.close();
|
|
328
335
|
ferr.close();
|
|
329
336
|
out.destroy();
|
|
330
|
-
subscriber.next({ item, complete: true });
|
|
331
337
|
subscriber.complete();
|
|
332
338
|
});
|
|
333
339
|
out.on("data", (data) => subscriber.next({ item, output: data.toString() }));
|
|
334
340
|
})));
|
|
335
341
|
}
|
|
336
342
|
function cmake(opts) {
|
|
337
|
-
|
|
343
|
+
const { item } = cmakeItem(opts);
|
|
344
|
+
return concat(cmakeConfigure(opts), cmakeBuild(opts), of({ item, complete: true })).pipe(catchError(e => of(e)));
|
|
338
345
|
}
|
|
339
346
|
function emulateBytePages(board) {
|
|
340
347
|
return (board.startsWith("atsame54_xpro") ||
|
package/dist/build.ui.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
+
export declare class BuildError extends Error implements BuildItem {
|
|
4
|
+
item: string;
|
|
5
|
+
kind: "west" | "wasm";
|
|
6
|
+
constructor(item: string, kind: "west" | "wasm", message: string);
|
|
7
|
+
}
|
|
3
8
|
export interface BuildItem {
|
|
4
|
-
|
|
9
|
+
item: string;
|
|
5
10
|
kind: "west" | "wasm";
|
|
6
11
|
}
|
|
7
12
|
export interface BuildProgress<K extends string = string> {
|
package/dist/build.ui.js
CHANGED
|
@@ -1,21 +1,41 @@
|
|
|
1
|
-
import React, { useLayoutEffect, useState } from 'react';
|
|
2
|
-
import { Box, Text } from "ink";
|
|
1
|
+
import React, { useLayoutEffect, useEffect, useState } from 'react';
|
|
2
|
+
import { Box, Text, useStdout } from "ink";
|
|
3
3
|
import { scan } from 'rxjs';
|
|
4
|
+
export class BuildError extends Error {
|
|
5
|
+
constructor(item, kind, message) {
|
|
6
|
+
super(message);
|
|
7
|
+
Object.defineProperty(this, "item", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: item
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(this, "kind", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: kind
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
4
21
|
export default function ({ items, progress$ }) {
|
|
22
|
+
const [col, _rows] = useStdoutDimensions();
|
|
5
23
|
const [width, setWidth] = useState(0);
|
|
6
|
-
const progress = useBuildEffect(progress$, items.map(({
|
|
24
|
+
const progress = useBuildEffect(progress$, items.map(({ item }) => item));
|
|
7
25
|
useLayoutEffect(() => {
|
|
8
26
|
const width = items
|
|
9
|
-
.map(({
|
|
27
|
+
.map(({ item }) => item)
|
|
10
28
|
.reduce(calculateItemWidth, 0);
|
|
11
29
|
setWidth(width);
|
|
12
30
|
}, [items]);
|
|
13
|
-
return (React.createElement(Box, { flexDirection: "column" }, items.map((item) => (React.createElement(Box, { key: item
|
|
14
|
-
React.createElement(Box, { width: width, marginRight:
|
|
15
|
-
React.createElement(Text, { wrap: "truncate", bold: true }, item.
|
|
16
|
-
React.createElement(Box, { width: 4, marginRight:
|
|
17
|
-
React.createElement(Text, { wrap: "truncate", bold: true, color: buildColor(
|
|
18
|
-
React.createElement(
|
|
31
|
+
return (React.createElement(Box, { flexDirection: "column" }, items.map(({ item, kind }) => (React.createElement(Box, { key: item },
|
|
32
|
+
React.createElement(Box, { width: width, marginRight: 1 },
|
|
33
|
+
React.createElement(Text, { wrap: "truncate", bold: true }, item.padStart(width))),
|
|
34
|
+
React.createElement(Box, { width: 4, marginRight: 1 },
|
|
35
|
+
React.createElement(Text, { wrap: "truncate", bold: true, color: buildColor(kind) }, kind.toUpperCase().padStart(4))),
|
|
36
|
+
React.createElement(Box, { width: 2, marginRight: 1 }, progress[item] && React.createElement(Text, { color: "cyan" }, "=>")),
|
|
37
|
+
React.createElement(Box, { width: col - width - 4 - 2 - 1 - 1 - 1 },
|
|
38
|
+
React.createElement(Text, { wrap: "truncate", dimColor: !progressComplete(progress[item]), color: progressColor(progress[item]) }, progress[item])))))));
|
|
19
39
|
}
|
|
20
40
|
function buildColor(kind) {
|
|
21
41
|
return kind === "west" ? "blue" : "magenta";
|
|
@@ -24,7 +44,10 @@ function progressComplete(progress) {
|
|
|
24
44
|
return progress === "OK!";
|
|
25
45
|
}
|
|
26
46
|
function progressColor(progress) {
|
|
27
|
-
return
|
|
47
|
+
return (!progress || (progress.charAt(0) == "|" ||
|
|
48
|
+
progress.charAt(0) == "/" ||
|
|
49
|
+
progress.charAt(0) == "-" ||
|
|
50
|
+
progress.charAt(0) == "\\")) ? "white" : progressComplete(progress) ? "green" : "red";
|
|
28
51
|
}
|
|
29
52
|
function initProgress(items) {
|
|
30
53
|
return items.reduce((acc, curr) => ({ ...acc, [curr]: "" }), {});
|
|
@@ -47,7 +70,11 @@ function progressInc(progress) {
|
|
|
47
70
|
}
|
|
48
71
|
}
|
|
49
72
|
function progressReducer(acc, next) {
|
|
50
|
-
acc[next.item] = next.complete
|
|
73
|
+
acc[next.item] = next.complete
|
|
74
|
+
? "OK!"
|
|
75
|
+
: next.error
|
|
76
|
+
? next.error.replace(/\r?\n/g, "")
|
|
77
|
+
: progressInc(acc[next.item]);
|
|
51
78
|
return acc;
|
|
52
79
|
}
|
|
53
80
|
function useBuildEffect(obs$, items) {
|
|
@@ -60,3 +87,15 @@ function useBuildEffect(obs$, items) {
|
|
|
60
87
|
}, [obs$, items]);
|
|
61
88
|
return progress;
|
|
62
89
|
}
|
|
90
|
+
function useStdoutDimensions() {
|
|
91
|
+
const { stdout } = useStdout();
|
|
92
|
+
const [dimensions, setDimensions] = useState([stdout.columns, stdout.rows]);
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
const handler = () => setDimensions([stdout.columns, stdout.rows]);
|
|
95
|
+
stdout.on('resize', handler);
|
|
96
|
+
return () => {
|
|
97
|
+
stdout.off('resize', handler);
|
|
98
|
+
};
|
|
99
|
+
}, [stdout]);
|
|
100
|
+
return dimensions;
|
|
101
|
+
}
|