diff --git a/packages/xod-cli/src/commands/boards.js b/packages/xod-cli/src/commands/boards.js index 61d5591a..743c2476 100644 --- a/packages/xod-cli/src/commands/boards.js +++ b/packages/xod-cli/src/commands/boards.js @@ -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; diff --git a/packages/xod-cli/src/listrTasks.js b/packages/xod-cli/src/listrTasks.js index 2035e0bb..56690076 100644 --- a/packages/xod-cli/src/listrTasks.js +++ b/packages/xod-cli/src/listrTasks.js @@ -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 diff --git a/packages/xod-client-electron/src/app/arduinoCli.js b/packages/xod-client-electron/src/app/arduinoCli.js index 026e7168..d4aee8e4 100644 --- a/packages/xod-client-electron/src/app/arduinoCli.js +++ b/packages/xod-client-electron/src/app/arduinoCli.js @@ -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 ); diff --git a/packages/xod-deploy-bin/package.json b/packages/xod-deploy-bin/package.json index c62826d5..fc941e15 100644 --- a/packages/xod-deploy-bin/package.json +++ b/packages/xod-deploy-bin/package.json @@ -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": { diff --git a/packages/xod-deploy-bin/src/arduinoCli.js b/packages/xod-deploy-bin/src/arduinoCli.js index 75927771..fe68db0e 100644 --- a/packages/xod-deploy-bin/src/arduinoCli.js +++ b/packages/xod-deploy-bin/src/arduinoCli.js @@ -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; };