@altronix/cli 0.7.20 → 0.8.0

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
@@ -348,9 +348,12 @@ function cmake(opts) {
348
348
  }
349
349
  function emulateBytePages(board) {
350
350
  return (board.startsWith('atsame54_xpro') ||
351
- board.startsWith('netway4e1bt') ||
351
+ board.startsWith('netwaysp4b') ||
352
+ board.startsWith('netwaysp4bt') ||
352
353
  board.startsWith('netway4eb') ||
354
+ board.startsWith('netway4ebt') ||
353
355
  board.startsWith('netway5pq') ||
356
+ board.startsWith('netway5btq') ||
354
357
  board.startsWith('oa2b'));
355
358
  }
356
359
  function extraAppConfs(extraConfs, config) {
@@ -441,6 +444,7 @@ function tovoid() {
441
444
  export async function build() {
442
445
  const config = this.opts()['config'] || path.resolve('./', 'atx.json');
443
446
  const verbose = this.optsWithGlobals()['verbose'];
447
+ const matches = new RegExp(this.opts()['matches'] || '(.*)');
444
448
  const cwd = path.resolve(path.dirname(config));
445
449
  const data = await fs.promises.readFile(config, 'ascii');
446
450
  const atx = JSON.parse(data);
@@ -451,12 +455,16 @@ export async function build() {
451
455
  const env = path.resolve(cwd, '.env');
452
456
  dotenv.config({ path: env });
453
457
  const apps = keys(atx.applications).flatMap((app) => {
454
- return keys(app.boards).flatMap((board) => {
458
+ return keys(app.boards)
459
+ .filter(({ __key }) => __key.match(matches))
460
+ .flatMap((board) => {
455
461
  return keys(board).map((config) => westOptionsNormalize(board.__key, config, app, cwd, verbose));
456
462
  });
457
463
  });
458
464
  const bootloaders = keys(atx.bootloaders).flatMap((app) => {
459
- return keys(app.boards).flatMap((board) => {
465
+ return keys(app.boards)
466
+ .filter(({ __key }) => __key.match(matches))
467
+ .flatMap((board) => {
460
468
  return keys(board).map((config) => westOptionsNormalize(board.__key, config, app, cwd, verbose));
461
469
  });
462
470
  });
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare function concurrent(this: Command, count: string): Promise<void>;
@@ -0,0 +1,26 @@
1
+ import { Linq } from '@altronix/device';
2
+ import logger from './logger.js';
3
+ import { select, first } from './select.js';
4
+ import progress from './progress.js';
5
+ import { defer, EmptyError, finalize, merge, lastValueFrom, switchMap } from 'rxjs';
6
+ export async function concurrent(count) {
7
+ logger(this.optsWithGlobals()['verbose'] ? 'silly' : 'info');
8
+ const linq = new Linq();
9
+ // const request = {
10
+ // path: '/api/v1/about',
11
+ // meth: METH_CONSTANTS.GET,
12
+ // retry: 20,
13
+ // timeout: 10000
14
+ // };
15
+ const obs$ = linq.connections().pipe(this.optsWithGlobals()['first'] ? first() : select(), switchMap((serial) => {
16
+ const n = parseInt(count);
17
+ const requests = new Array(n)
18
+ .fill(0)
19
+ .map(() => defer(() => linq.get(serial, '/api/v1/about')));
20
+ return merge(...requests).pipe(progress(n));
21
+ }), finalize(() => linq.shutdown()));
22
+ return lastValueFrom(obs$).catch((e) => {
23
+ if (!(e instanceof EmptyError))
24
+ throw e;
25
+ });
26
+ }
package/dist/index.js CHANGED
@@ -11,6 +11,8 @@ import { getCloud, setCloud } from './cloud.js';
11
11
  import { stress } from './stress.js';
12
12
  import { update } from './update.js';
13
13
  import { listen } from './listen.js';
14
+ import { getDemo, getHello } from './sample.js';
15
+ import { concurrent } from './concurrent.js';
14
16
  // https://stackoverflow.com/questions/8817423/why-is-dirname-not-defined-in-node-repl
15
17
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
16
18
  // Parse package.json to get version
@@ -44,6 +46,7 @@ program
44
46
  .option('-A, --application', 'build applications')
45
47
  .option('-B, --bootloader', 'build bootloaders')
46
48
  .option('-W, --wasm', 'build wasm')
49
+ .option('-M, --matches [regex]', 'board regex match expr')
47
50
  .option('-y, --yes', 'answer yes automatically')
48
51
  .action(build);
49
52
  const device = program
@@ -116,6 +119,25 @@ device
116
119
  .description('listen for alerts and heartbeats')
117
120
  .argument('<duration>', 'how long to listen')
118
121
  .action(listen);
122
+ device
123
+ .command('concurrent')
124
+ .description('make a number of requests concurrently')
125
+ .argument('<count>', 'how many requests to make concurrently')
126
+ .action(concurrent);
127
+ const sample = program
128
+ .command('sample')
129
+ .description('manage zephyr device settings')
130
+ .option('-p, --port <PORT>', 'listen port for incoming device connections')
131
+ .option('-v, --verbose', 'print extra debug informating during request')
132
+ .option('-f, --first', 'perform request on first device we see (any device)');
133
+ sample
134
+ .command('get-demo')
135
+ .description('read the demo data from the sample')
136
+ .action(getDemo);
137
+ sample
138
+ .command('get-hello')
139
+ .description('read the hello data from the sample')
140
+ .action(getHello);
119
141
  // Load plugins
120
142
  // (await plugins()).forEach(({ plugin: _, path: __, description: ___ }) => {});
121
143
  program.parseAsync().catch((e) => console.error(e));
@@ -10,14 +10,19 @@ export default function Progress({ total, response$, onComplete }) {
10
10
  return (React.createElement(Box, null,
11
11
  React.createElement(Box, null,
12
12
  React.createElement(Text, null, "["),
13
- new Array(progress).fill(0).map((_, idx) => (React.createElement(Text, { key: idx }, "#"))),
14
- new Array(empty).fill(0).map((_, idx) => (React.createElement(Text, { key: idx }, "-"))),
13
+ progress > 0 && new Array(progress).fill(0).map(mapper('#')),
14
+ empty > 0 && new Array(empty).fill(0).map(mapper('-')),
15
15
  React.createElement(Text, null, "]")),
16
16
  React.createElement(Box, { marginLeft: 1 },
17
17
  React.createElement(Text, null,
18
- Math.ceil((100 * progress) / width),
18
+ Math.min(Math.ceil((100 * progress) / width), 100),
19
19
  "%"))));
20
20
  }
21
+ function mapper(char) {
22
+ return function (_item, idx) {
23
+ return React.createElement(Text, { key: idx }, char);
24
+ };
25
+ }
21
26
  function useProgress(obs$, total, width, onComplete) {
22
27
  const [progress, setProgress] = useState([0, width]);
23
28
  useLayoutEffect(() => {
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ export declare function getDemo(this: Command): Promise<void>;
3
+ export declare function getHello(this: Command): Promise<void>;
package/dist/sample.js ADDED
@@ -0,0 +1,30 @@
1
+ // sample.tsx
2
+ import { Demo } from '@altronix/zdk/sample';
3
+ import { Linq } from '@altronix/device';
4
+ import { EmptyError, finalize, firstValueFrom, map, switchMap } from 'rxjs';
5
+ import logger from './logger.js';
6
+ import { select, first } from './select.js';
7
+ export async function getDemo() {
8
+ logger(this.optsWithGlobals()['verbose'] ? 'silly' : 'info');
9
+ const linq = new Linq();
10
+ const path = '/sample/demo';
11
+ const obs = linq.connections().pipe(this.optsWithGlobals()['first'] ? first() : select(), switchMap((sid) => linq.get(sid, path)), map((resp) => Demo.fromCbor(resp.body)), finalize(() => linq.shutdown()));
12
+ return firstValueFrom(obs)
13
+ .then((about) => console.log(JSON.stringify(about.toJson(), null, 2)))
14
+ .catch((e) => {
15
+ if (!(e instanceof EmptyError))
16
+ throw e;
17
+ });
18
+ }
19
+ export async function getHello() {
20
+ logger(this.optsWithGlobals()['verbose'] ? 'silly' : 'info');
21
+ const linq = new Linq();
22
+ const path = '/sample/hello';
23
+ const obs = linq.connections().pipe(this.optsWithGlobals()['first'] ? first() : select(), switchMap((sid) => linq.get(sid, path)), map((resp) => JSON.parse(new TextDecoder().decode(resp.body))), finalize(() => linq.shutdown()));
24
+ return firstValueFrom(obs)
25
+ .then((about) => console.log(JSON.stringify(about, null, 2)))
26
+ .catch((e) => {
27
+ if (!(e instanceof EmptyError))
28
+ throw e;
29
+ });
30
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altronix/cli",
3
- "version": "0.7.20",
3
+ "version": "0.8.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "bin": {
@@ -22,8 +22,8 @@
22
22
  "react": "^18.2.0",
23
23
  "rxjs": "^7.8.1",
24
24
  "winston": "^3.13.0",
25
- "@altronix/zdk": "0.7.2",
26
- "@altronix/device": "0.7.1"
25
+ "@altronix/device": "0.7.2",
26
+ "@altronix/zdk": "0.7.3"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@sindresorhus/tsconfig": "^3.0.1",