mirror of
https://github.com/xodio/xod.git
synced 2026-03-07 01:06:53 +01:00
fix(xod-deploy-bin, xod-cli, xod-client-electron): always ensure workspace on list boards or updating indexes
This commit is contained in:
@@ -45,7 +45,7 @@ class BoardsCommand extends BaseCommand {
|
||||
})),
|
||||
sortBy(prop('name')),
|
||||
b => mergeAvailableInstalled(b.available, b.installed)
|
||||
)(await xdb.listBoards(workspace, aCli));
|
||||
)(await xdb.listBoards(resolveBundledWorkspacePath(), workspace, aCli));
|
||||
|
||||
const rows = quiet ? map(b => [b['Board Name'], b.FQBN])(boards) : boards;
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ import { loadProject } from 'xod-fs';
|
||||
import { createError, foldEither } from 'xod-func-tools';
|
||||
import * as xdb from 'xod-deploy-bin';
|
||||
|
||||
import { resolveBundledWorkspacePath } from './paths';
|
||||
|
||||
export const loadProjectTask = (workspaces, projectPath) => ({
|
||||
title: 'Project loading',
|
||||
task: ctx =>
|
||||
@@ -45,7 +47,11 @@ export const transpileTask = () => ({
|
||||
export const checkBoardTask = (workspace, fqbn) => ({
|
||||
title: 'Check board',
|
||||
task: async ctx => {
|
||||
const boards = await xdb.listBoards(workspace, ctx.arduinoCli);
|
||||
const boards = await xdb.listBoards(
|
||||
resolveBundledWorkspacePath(),
|
||||
workspace,
|
||||
ctx.arduinoCli
|
||||
);
|
||||
const board = last(filter(el => el.fqbn === fqbn, boards.installed));
|
||||
|
||||
// toolchain not installed - handle it
|
||||
|
||||
@@ -3,6 +3,7 @@ import * as xdb from 'xod-deploy-bin';
|
||||
|
||||
import subscribeIpc from './subscribeIpc';
|
||||
import { loadWorkspacePath } from './workspaceActions';
|
||||
import { getPathToBundledWorkspace } from './utils';
|
||||
import {
|
||||
LIST_BOARDS,
|
||||
UPLOAD_TO_ARDUINO,
|
||||
@@ -34,7 +35,10 @@ export const upload = (onProgress, cli, payload) => {
|
||||
// =============================================================================
|
||||
export const subscribeListBoards = cli =>
|
||||
subscribeIpc(
|
||||
() => loadWorkspacePath().then(ws => xdb.listBoards(ws, cli)),
|
||||
() =>
|
||||
loadWorkspacePath().then(ws =>
|
||||
xdb.listBoards(getPathToBundledWorkspace(), ws, cli)
|
||||
),
|
||||
LIST_BOARDS
|
||||
);
|
||||
|
||||
@@ -46,7 +50,10 @@ export const subscribeUpload = cli =>
|
||||
|
||||
export const subscribeUpdateIndexes = cli =>
|
||||
subscribeIpc(
|
||||
() => loadWorkspacePath().then(ws => xdb.updateIndexes(ws, cli)),
|
||||
() =>
|
||||
loadWorkspacePath().then(ws =>
|
||||
xdb.updateIndexes(getPathToBundledWorkspace(), ws, cli)
|
||||
),
|
||||
UPDATE_INDEXES
|
||||
);
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
"fs-extra": "^7.0.1",
|
||||
"ramda": "0.24.1",
|
||||
"which": "^1.3.1",
|
||||
"xod-fs": "^0.36.0",
|
||||
"xod-func-tools": "^0.34.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -5,6 +5,7 @@ import * as R from 'ramda';
|
||||
import * as fse from 'fs-extra';
|
||||
import arduinoCli from 'arduino-cli';
|
||||
import { createError } from 'xod-func-tools';
|
||||
import { isWorkspaceValid, spawnWorkspaceFile } from 'xod-fs';
|
||||
|
||||
import {
|
||||
ARDUINO_LIBRARIES_DIRNAME,
|
||||
@@ -407,6 +408,21 @@ const updateIndexesInternal = (wsPath, cli) =>
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* It creates a workspace file and packages directory if needed.
|
||||
*
|
||||
* :: Path -> Path -> Promise Path Error
|
||||
*/
|
||||
const ensureWorkspace = (wsBundledPath, wsPath) =>
|
||||
isWorkspaceValid(wsPath).catch(async e => {
|
||||
if (e.errorCode === 'WORKSPACE_DIR_NOT_EXIST_OR_EMPTY') {
|
||||
await prepareWorkspacePackagesDir(wsBundledPath, wsPath);
|
||||
await spawnWorkspaceFile(wsPath);
|
||||
return wsPath;
|
||||
}
|
||||
throw e;
|
||||
});
|
||||
|
||||
/**
|
||||
* Returns map of installed boards and boards that could be installed:
|
||||
* - Installed boards (boards, which are ready for deploy)
|
||||
@@ -414,9 +430,10 @@ const updateIndexesInternal = (wsPath, cli) =>
|
||||
* - Available boards (boards, which packages could be installed)
|
||||
* { name :: String, package :: String, version :: String }
|
||||
*
|
||||
* :: Path -> ArduinoCli -> Promise { installed :: [InstalledBoard], available :: [AvailableBoard] } Error
|
||||
* :: Path -> Path -> ArduinoCli -> Promise { installed :: [InstalledBoard], available :: [AvailableBoard] } Error
|
||||
*/
|
||||
export const listBoards = async (wsPath, cli) => {
|
||||
export const listBoards = async (wsBundledPath, wsPath, cli) => {
|
||||
await ensureWorkspace(wsBundledPath, wsPath);
|
||||
await syncAdditionalPackages(wsPath, cli);
|
||||
|
||||
return Promise.all([
|
||||
@@ -455,9 +472,10 @@ export const listBoards = async (wsPath, cli) => {
|
||||
* Updates package index json files.
|
||||
* Returns a list of just added URLs
|
||||
*
|
||||
* :: Path -> ArduinoCli -> Promise [URL] Error
|
||||
* :: Path -> Path -> ArduinoCli -> Promise [URL] Error
|
||||
*/
|
||||
export const updateIndexes = async (wsPath, cli) => {
|
||||
export const updateIndexes = async (wsBundledPath, wsPath, cli) => {
|
||||
await ensureWorkspace(wsBundledPath, wsPath);
|
||||
const addedUrls = await syncAdditionalPackages(wsPath, cli);
|
||||
|
||||
await updateIndexesInternal(wsPath, cli);
|
||||
@@ -466,7 +484,7 @@ export const updateIndexes = async (wsPath, cli) => {
|
||||
// all new index files are valid, because `updateIndex`
|
||||
// only downloads index files without validating
|
||||
// Bug reported: https://github.com/arduino/arduino-cli/issues/81
|
||||
await listBoards(wsPath, cli);
|
||||
await listBoards(wsBundledPath, wsPath, cli);
|
||||
|
||||
return addedUrls;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user