@altronix/cli 0.7.11 → 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 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
- name: `${board}-${name}-${config}-${version}`
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).name;
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
- subscriber.next({ item, complete: true });
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", (data) => subscriber.next({ item, output: data.toString() }));
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", name };
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).name;
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,10 +296,10 @@ 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();
@@ -304,7 +312,7 @@ function cmakeConfigure(opts) {
304
312
  }
305
313
  function cmakeBuild(opts) {
306
314
  const { buildDir, outputFile, errorFile, } = opts;
307
- const item = cmakeItem(opts).name;
315
+ const { item } = cmakeItem(opts);
308
316
  return of([`--build`, `${buildDir}`, `--target`, ` wasm`]).pipe(mergeMap((cmakeArgs) => new Observable((subscriber) => {
309
317
  const wasm = cp.spawn("cmake", cmakeArgs, {
310
318
  cwd: buildDir,
@@ -317,10 +325,10 @@ function cmakeBuild(opts) {
317
325
  wasm.stdout.pipe(out);
318
326
  wasm.stderr.pipe(ferr);
319
327
  wasm.on("error", (e) => {
320
- subscriber.error(e);
321
328
  fout.close();
322
329
  ferr.close();
323
330
  out.destroy();
331
+ subscriber.error(new BuildError(item, "wasm", e.name));
324
332
  });
325
333
  wasm.on("exit", () => {
326
334
  fout.close();
@@ -332,8 +340,8 @@ function cmakeBuild(opts) {
332
340
  })));
333
341
  }
334
342
  function cmake(opts) {
335
- const { name: item } = cmakeItem(opts);
336
- return concat(cmakeConfigure(opts), cmakeBuild(opts), of({ item, complete: true }));
343
+ const { item } = cmakeItem(opts);
344
+ return concat(cmakeConfigure(opts), cmakeBuild(opts), of({ item, complete: true })).pipe(catchError(e => of(e)));
337
345
  }
338
346
  function emulateBytePages(board) {
339
347
  return (board.startsWith("atsame54_xpro") ||
@@ -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
- name: string;
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,22 +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(({ name }) => name));
24
+ const progress = useBuildEffect(progress$, items.map(({ item }) => item));
7
25
  useLayoutEffect(() => {
8
26
  const width = items
9
- .map(({ name }) => name)
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.name },
31
+ return (React.createElement(Box, { flexDirection: "column" }, items.map(({ item, kind }) => (React.createElement(Box, { key: item },
14
32
  React.createElement(Box, { width: width, marginRight: 1 },
15
- React.createElement(Text, { wrap: "truncate", bold: true }, item.name.padStart(width))),
33
+ React.createElement(Text, { wrap: "truncate", bold: true }, item.padStart(width))),
16
34
  React.createElement(Box, { width: 4, marginRight: 1 },
17
- React.createElement(Text, { wrap: "truncate", bold: true, color: buildColor(item.kind) }, item.kind.toUpperCase().padStart(4))),
18
- React.createElement(Box, { width: 2, marginRight: 1 }, progress[item.name] && React.createElement(Text, { color: "cyan" }, "=>")),
19
- React.createElement(Text, { dimColor: !progressComplete(progress[item.name]), color: progressColor(progress[item.name]) }, progress[item.name]))))));
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])))))));
20
39
  }
21
40
  function buildColor(kind) {
22
41
  return kind === "west" ? "blue" : "magenta";
@@ -25,7 +44,10 @@ function progressComplete(progress) {
25
44
  return progress === "OK!";
26
45
  }
27
46
  function progressColor(progress) {
28
- return progressComplete(progress) ? "green" : "white";
47
+ return (!progress || (progress.charAt(0) == "|" ||
48
+ progress.charAt(0) == "/" ||
49
+ progress.charAt(0) == "-" ||
50
+ progress.charAt(0) == "\\")) ? "white" : progressComplete(progress) ? "green" : "red";
29
51
  }
30
52
  function initProgress(items) {
31
53
  return items.reduce((acc, curr) => ({ ...acc, [curr]: "" }), {});
@@ -48,7 +70,11 @@ function progressInc(progress) {
48
70
  }
49
71
  }
50
72
  function progressReducer(acc, next) {
51
- acc[next.item] = next.complete ? "OK!" : progressInc(acc[next.item]);
73
+ acc[next.item] = next.complete
74
+ ? "OK!"
75
+ : next.error
76
+ ? next.error.replace(/\r?\n/g, "")
77
+ : progressInc(acc[next.item]);
52
78
  return acc;
53
79
  }
54
80
  function useBuildEffect(obs$, items) {
@@ -61,3 +87,15 @@ function useBuildEffect(obs$, items) {
61
87
  }, [obs$, items]);
62
88
  return progress;
63
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altronix/cli",
3
- "version": "0.7.11",
3
+ "version": "0.7.12",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "atx": "./dist/index.js"