/
boards.js
74 lines (62 loc) · 1.88 KB
/
boards.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* eslint-disable no-param-reassign */
import { exit } from 'process';
import {
compose,
concat,
filter,
map,
none,
pluck,
prop,
sortBy,
startsWith,
} from 'ramda';
import asTable from 'as-table';
import * as xdb from 'xod-deploy-bin';
import BaseCommand from '../baseCommand';
import { resolveBundledWorkspacePath } from '../paths';
const mergeAvailableInstalled = (available, installed) => {
const fqbns = pluck('fqbn', installed);
return concat(
installed,
compose(filter(el => none(startsWith(el.package))(fqbns)))(available)
);
};
class BoardsCommand extends BaseCommand {
async run() {
this.parseArgv(BoardsCommand);
await this.ensureWorkspace();
const { workspace, quiet } = this.flags;
try {
const sketchDir = await xdb.prepareSketchDir();
const aCli = await xdb.createCli(
resolveBundledWorkspacePath(),
workspace,
sketchDir
);
const boards = compose(
map(el => ({
'Board Name': el.name,
FQBN: el.fqbn || `${el.package} [not installed]`,
})),
sortBy(prop('name')),
b => mergeAvailableInstalled(b.available, b.installed)
)(await xdb.listBoards(resolveBundledWorkspacePath(), workspace, aCli));
const rows = quiet ? map(b => [b['Board Name'], b.FQBN])(boards) : boards;
const table = process.stdout.columns
? asTable.configure({ maxTotalWidth: process.stdout.columns })(rows)
: asTable(rows);
process.stdout.write(`${table}\n`);
return exit(0);
} catch (err) {
this.printError(this.patchArduinoCliError(err));
return exit((err.payload || err).code || 100);
}
}
}
BoardsCommand.description = 'show available boards';
BoardsCommand.usage = 'boards [options]';
BoardsCommand.flags = BaseCommand.flags;
BoardsCommand.args = [];
BoardsCommand.strict = false;
export default BoardsCommand;