@altronix/cli 0.8.0 → 0.9.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
@@ -10,64 +10,69 @@ import { render } from 'ink';
10
10
  import React from 'react';
11
11
  import Ui, { BuildError } from './build.ui.js';
12
12
  import { keys } from './keys.js';
13
- const schemaBuild = {
13
+ const schemaBoard = {
14
14
  type: 'object',
15
- required: [],
16
- patternProperties: {
17
- '.*': {
15
+ required: ['images'],
16
+ properties: {
17
+ version: { type: 'string', nullable: true },
18
+ soc: { type: 'string', nullable: true },
19
+ cpu: { type: 'string', nullable: true },
20
+ variant: { type: 'string', nullable: true },
21
+ images: {
18
22
  type: 'object',
19
- required: ['sourceDir', 'binaryDir', 'installDir', 'boards'],
20
- properties: {
21
- sourceDir: { type: 'string' },
22
- binaryDir: { type: 'string' },
23
- installDir: { type: 'string' },
24
- boards: {
25
- type: 'object',
26
- required: [],
27
- patternProperties: {
28
- '.*': {
29
- type: 'object',
30
- required: [],
31
- patternProperties: {
32
- '.*': {
33
- type: 'object',
34
- properties: {
35
- configs: {
36
- type: 'array',
37
- items: { type: 'string' },
38
- nullable: true
39
- },
40
- overlays: {
41
- type: 'array',
42
- items: { type: 'string' },
43
- nullable: true
44
- }
45
- }
46
- }
47
- }
48
- }
23
+ required: [],
24
+ additionalProperties: {
25
+ type: 'object',
26
+ properties: {
27
+ configs: {
28
+ type: 'array',
29
+ items: { type: 'string' },
30
+ nullable: true
31
+ },
32
+ overlays: {
33
+ type: 'array',
34
+ items: { type: 'string' },
35
+ nullable: true
49
36
  }
50
37
  }
51
38
  }
52
39
  }
53
40
  }
54
41
  };
55
- const schemaSeedle = {
42
+ const schemaBuild = {
56
43
  type: 'object',
57
44
  required: [],
58
- patternProperties: {
59
- '.*': {
60
- type: 'object',
61
- required: ['installDir', 'files'],
62
- properties: {
63
- namespace: { type: 'string', nullable: true },
64
- prefix: { type: 'string', nullable: true },
65
- installDir: { type: 'string' },
66
- files: { type: 'array', items: { type: 'string' } }
45
+ additionalProperties: {
46
+ type: 'object',
47
+ required: ['sourceDir', 'binaryDir', 'installDir', 'boards'],
48
+ properties: {
49
+ sourceDir: { type: 'string' },
50
+ binaryDir: { type: 'string' },
51
+ installDir: { type: 'string' },
52
+ boards: {
53
+ type: 'object',
54
+ required: [],
55
+ additionalProperties: {
56
+ anyOf: [{ ...schemaBoard }, { type: 'array', items: schemaBoard }]
57
+ }
67
58
  }
68
59
  }
69
60
  }
70
61
  };
62
+ const schemaSeedle = {
63
+ type: 'object',
64
+ required: [],
65
+ additionalProperties: {
66
+ type: 'object',
67
+ required: ['installDir', 'files'],
68
+ properties: {
69
+ namespace: { type: 'string', nullable: true },
70
+ prefix: { type: 'string', nullable: true },
71
+ installDir: { type: 'string' },
72
+ files: { type: 'array', items: { type: 'string' } }
73
+ }
74
+ }
75
+ };
71
76
  const schema = {
72
77
  type: 'object',
73
78
  required: ['applications', 'bootloaders', 'wasm'],
@@ -143,9 +148,12 @@ function formatVersion(ver) {
143
148
  async function westOptionsNormalize(board, config, build, cwd, verbose) {
144
149
  const resolve = await resolver(cwd);
145
150
  const name = build.__key;
151
+ const boardTarget = [board.__key, board.soc, board.cpu, board.variant]
152
+ .filter((item) => !!item)
153
+ .join('/');
146
154
  const installDir = resolve(build.installDir);
147
155
  const sourceDir = resolve(build.sourceDir);
148
- const binaryDir = path.join(resolve(build.binaryDir), board, config.__key);
156
+ const binaryDir = path.join(resolve(build.binaryDir), boardTarget.replaceAll('/', '-'), config.__key);
149
157
  const versionFile = path.join(sourceDir, 'VERSION');
150
158
  const version = formatVersion(await parseAppVersion(versionFile));
151
159
  const confs = config.configs
@@ -156,7 +164,8 @@ async function westOptionsNormalize(board, config, build, cwd, verbose) {
156
164
  : [];
157
165
  return {
158
166
  name,
159
- board,
167
+ board: boardTarget.replaceAll('/', '-'),
168
+ boardTarget,
160
169
  config: config.__key,
161
170
  cwd,
162
171
  version,
@@ -178,12 +187,12 @@ function westItem(opts) {
178
187
  };
179
188
  }
180
189
  function west(args) {
181
- const { cwd, board, sourceDir, binaryDir, confs, overlays } = args;
190
+ const { cwd, boardTarget, sourceDir, binaryDir, confs, overlays } = args;
182
191
  const { item } = westItem(args);
183
192
  const expect = path.join(binaryDir, 'zephyr', 'zephyr.bin');
184
193
  return of([
185
194
  `build`,
186
- `-b ${board}`,
195
+ `-b ${boardTarget}`,
187
196
  `-s ${sourceDir}`,
188
197
  `-d ${binaryDir}`,
189
198
  `--`,
@@ -347,13 +356,8 @@ function cmake(opts) {
347
356
  return concat(cmakeConfigure(opts), cmakeBuild(opts), of({ item, complete: true })).pipe(catchError(of));
348
357
  }
349
358
  function emulateBytePages(board) {
350
- return (board.startsWith('atsame54_xpro') ||
351
- board.startsWith('netwaysp4b') ||
352
- board.startsWith('netwaysp4bt') ||
353
- board.startsWith('netway4eb') ||
354
- board.startsWith('netway4ebt') ||
355
- board.startsWith('netway5pq') ||
356
- board.startsWith('netway5btq') ||
359
+ return (board.startsWith('same54_xpro') ||
360
+ board.startsWith('netway') ||
357
361
  board.startsWith('oa2b'));
358
362
  }
359
363
  function extraAppConfs(extraConfs, config) {
@@ -444,7 +448,9 @@ function tovoid() {
444
448
  export async function build() {
445
449
  const config = this.opts()['config'] || path.resolve('./', 'atx.json');
446
450
  const verbose = this.optsWithGlobals()['verbose'];
447
- const matches = new RegExp(this.opts()['matches'] || '(.*)');
451
+ const mBoard = new RegExp(this.opts()['matchesBoard'] || '(.*)');
452
+ const mApplication = new RegExp(this.opts()['matchesApplication'] || '(.*)');
453
+ const mConfig = new RegExp(this.opts()['matchesConfig'] || '(.*)');
448
454
  const cwd = path.resolve(path.dirname(config));
449
455
  const data = await fs.promises.readFile(config, 'ascii');
450
456
  const atx = JSON.parse(data);
@@ -454,18 +460,24 @@ export async function build() {
454
460
  throw validate.errors;
455
461
  const env = path.resolve(cwd, '.env');
456
462
  dotenv.config({ path: env });
457
- const apps = keys(atx.applications).flatMap((app) => {
463
+ const apps = keys(atx.applications)
464
+ .filter(({ __key }) => __key.match(mApplication))
465
+ .flatMap((app) => {
458
466
  return keys(app.boards)
459
- .filter(({ __key }) => __key.match(matches))
467
+ .filter(({ __key }) => __key.match(mBoard))
460
468
  .flatMap((board) => {
461
- return keys(board).map((config) => westOptionsNormalize(board.__key, config, app, cwd, verbose));
469
+ return keys(board.images)
470
+ .filter(({ __key }) => __key.match(mConfig))
471
+ .map((config) => {
472
+ return westOptionsNormalize(board, config, app, cwd, verbose);
473
+ });
462
474
  });
463
475
  });
464
476
  const bootloaders = keys(atx.bootloaders).flatMap((app) => {
465
477
  return keys(app.boards)
466
- .filter(({ __key }) => __key.match(matches))
478
+ .filter(({ __key }) => __key.match(mBoard))
467
479
  .flatMap((board) => {
468
- return keys(board).map((config) => westOptionsNormalize(board.__key, config, app, cwd, verbose));
480
+ return keys(board.images).map((config) => westOptionsNormalize(board, config, app, cwd, verbose));
469
481
  });
470
482
  });
471
483
  const wasm = keys(atx.wasm).map((w) => seedleOptionsNormalize(w, cwd, verbose));
@@ -500,13 +512,17 @@ export async function build() {
500
512
  dst: path.join(d, `${board}-${name}-${config}.bin`)
501
513
  };
502
514
  }))).pipe(copy(), tovoid());
503
- await lastValueFrom(ready$);
504
- const items = await lastValueFrom(items$);
505
- const renderer = render(React.createElement(Ui, { items: items, "progress$": build$, onComplete: () => renderer.unmount() }));
506
- await renderer.waitUntilExit();
507
- renderer.cleanup();
508
- return lastValueFrom(install$).catch((e) => {
515
+ try {
516
+ await lastValueFrom(ready$);
517
+ const items = await lastValueFrom(items$);
518
+ const renderer = render(React.createElement(Ui, { items: items, "progress$": build$, onComplete: () => renderer.unmount() }));
519
+ await renderer.waitUntilExit();
520
+ renderer.cleanup();
521
+ return lastValueFrom(install$);
522
+ }
523
+ catch (e) {
509
524
  if (!(e instanceof EmptyError))
510
525
  throw e;
511
- });
526
+ console.log('nothing to build');
527
+ }
512
528
  }
package/dist/index.js CHANGED
@@ -46,7 +46,9 @@ program
46
46
  .option('-A, --application', 'build applications')
47
47
  .option('-B, --bootloader', 'build bootloaders')
48
48
  .option('-W, --wasm', 'build wasm')
49
- .option('-M, --matches [regex]', 'board regex match expr')
49
+ .option('--matches-board [regex]', 'board regex match expr')
50
+ .option('--matches-application [regex]', 'application regex match expr')
51
+ .option('--matches-config [regex]', 'config regex match expr')
50
52
  .option('-y, --yes', 'answer yes automatically')
51
53
  .action(build);
52
54
  const device = program
package/dist/keys.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export type WithKey<T> = T & {
2
2
  __key: string;
3
3
  };
4
+ export type FlattenWithKey<Type> = Type extends Array<infer Item> ? Array<WithKey<Item>> : Array<WithKey<Type>>;
4
5
  export declare function keys<T>(map: {
5
6
  [key: string]: T;
6
- }): WithKey<T>[];
7
+ }): FlattenWithKey<T>;
package/dist/keys.js CHANGED
@@ -1,5 +1,14 @@
1
1
  export function keys(map) {
2
- return Object.keys(map)
2
+ let ret = [];
3
+ Object.keys(map)
3
4
  .filter((key) => key !== '__key')
4
- .map((key) => ({ ...map[key], __key: key }));
5
+ .forEach((key) => {
6
+ if (Array.isArray(map[key])) {
7
+ map[key].forEach((item) => ret.push({ ...item, __key: key }));
8
+ }
9
+ else {
10
+ ret.push({ ...map[key], __key: key });
11
+ }
12
+ });
13
+ return ret;
5
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altronix/cli",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "bin": {
package/dist/app.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import React from 'react';
2
- type Props = {
3
- name: string | undefined;
4
- };
5
- export default function App({ name }: Props): React.JSX.Element;
6
- export {};
package/dist/app.js DELETED
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
- import { Text } from 'ink';
3
- export default function App({ name = 'Stranger' }) {
4
- return (React.createElement(Text, null,
5
- "Hello, ",
6
- React.createElement(Text, { color: "green" }, name)));
7
- }
package/dist/cli.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
package/dist/cli.js DELETED
@@ -1,24 +0,0 @@
1
- #!/usr/bin/env node
2
- import React from 'react';
3
- import { render } from 'ink';
4
- import meow from 'meow';
5
- import App from './app.js';
6
- const cli = meow(`
7
- Usage
8
- $ cli
9
-
10
- Options
11
- --name Your name
12
-
13
- Examples
14
- $ cli --name=Jane
15
- Hello, Jane
16
- `, {
17
- importMeta: import.meta,
18
- flags: {
19
- name: {
20
- type: 'string',
21
- },
22
- },
23
- });
24
- render(React.createElement(App, { name: cli.flags.name }));
@@ -1,3 +0,0 @@
1
- import { OperatorFunction } from 'rxjs';
2
- import { ResponseBody } from '@altronix/device';
3
- export default function (): OperatorFunction<ResponseBody, void>;
package/dist/stress.ui.js DELETED
@@ -1,31 +0,0 @@
1
- import React, { useLayoutEffect, useState } from 'react';
2
- import { Observable, scan } from 'rxjs';
3
- import { Box, render, Text } from 'ink';
4
- export default function () {
5
- return (obs$) => new Observable((subscriber) => {
6
- const renderer = render(React.createElement(View, { "response$": obs$, onComplete: () => {
7
- renderer.unmount();
8
- subscriber.next();
9
- subscriber.complete();
10
- } }));
11
- });
12
- }
13
- function View({ response$, onComplete }) {
14
- const responses = useResponses(response$, onComplete);
15
- return (React.createElement(Box, null,
16
- React.createElement(Text, null, "Response count:"),
17
- React.createElement(Text, null, responses.length)));
18
- }
19
- function useResponses(obs$, onComplete) {
20
- const [responses, setResponses] = useState([]);
21
- useLayoutEffect(() => {
22
- const s = obs$
23
- .pipe(scan((acc, next) => [...acc, next], responses))
24
- .subscribe({
25
- next: (responses) => setResponses(responses),
26
- complete: onComplete
27
- });
28
- return () => s.unsubscribe();
29
- }, [obs$]);
30
- return responses;
31
- }