From 167dc8aeefcc47f143f7945ae0262c4b30cafa19 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 31 Aug 2017 00:46:57 +0300 Subject: [PATCH 1/6] Migrate to "platformio-node-helpers" --- .eslintrc.js | 14 +- .vscode/launch.json | 4 +- CHANGELOG.md | 2 + package.json | 11 +- src/commands/init.js | 7 +- src/constants.js | 26 -- src/home.js | 51 +-- src/installer/helpers.js | 160 -------- src/installer/manager.js | 17 +- src/installer/python-install-confirm.js | 37 -- src/installer/python-prompt.js | 47 +++ src/installer/stages/base.js | 59 --- src/installer/stages/platformio-core.js | 355 ------------------ ...obal-state-storage.js => state-storage.js} | 2 +- src/main.js | 14 +- src/maintenance.js | 58 --- src/project/indexer.js | 10 +- src/utils.js | 63 ---- 18 files changed, 113 insertions(+), 824 deletions(-) delete mode 100644 src/installer/helpers.js delete mode 100644 src/installer/python-install-confirm.js create mode 100644 src/installer/python-prompt.js delete mode 100644 src/installer/stages/base.js delete mode 100644 src/installer/stages/platformio-core.js rename src/installer/{vscode-global-state-storage.js => state-storage.js} (94%) delete mode 100644 src/maintenance.js diff --git a/.eslintrc.js b/.eslintrc.js index 0d6abaa..3713a16 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,12 +5,24 @@ module.exports = { 'node': true, 'jasmine': true, }, - 'extends': ['eslint:recommended'], + 'plugins': [ + 'import' + ], + 'extends': [ + 'eslint:recommended', + 'plugin:import/errors', + 'plugin:import/warnings' + ], 'parser': 'babel-eslint', 'parserOptions': { 'ecmaVersion': 6, 'sourceType': 'module' }, + 'settings': { + 'import/core-modules': [ + 'vscode' + ] + }, 'rules': { 'comma-dangle': [ 'error', diff --git a/.vscode/launch.json b/.vscode/launch.json index 38a70bc..0b1daee 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "request": "launch", "runtimeExecutable": "${execPath}", "args": ["--extensionDevelopmentPath=${workspaceRoot}"], - "preLaunchTask": "npm: run build", + "preLaunchTask": "npm: build", "stopOnEntry": false }, { @@ -17,7 +17,7 @@ "request": "launch", "runtimeExecutable": "${execPath}", "args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/test"], - "preLaunchTask": "npm: run build", + "preLaunchTask": "npm: build", "stopOnEntry": false } ] diff --git a/CHANGELOG.md b/CHANGELOG.md index 62069e3..f5228c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Release Notes +## 0.7.0 (2017-??-??) + ## 0.6.0 (2017-08-10) * Integrate new PIO Home 2.0 diff --git a/package.json b/package.json index ebcd7d8..4a7f377 100644 --- a/package.json +++ b/package.json @@ -220,22 +220,17 @@ "babel-cli": "^6.24.1", "babel-eslint": "^7.2.3", "babel-plugin-transform-class-properties": "^6.24.1", - "babel-preset-env": "^1.5.2", + "babel-preset-env": "^1.6.0", "esformatter": "^0.10.0", "eslint": "^4.1.1", + "eslint-plugin-import": "^2.7.0", "vsce": "^1.27.0", "vscode": "^1.1.1" }, "dependencies": { - "cross-spawn": "^5.1.0", "fs-plus": "^3.0.0", "ini": "^1.3.4", - "open": "^0.0.5", - "request": "^2.81.0", - "semver": "^5.3.0", - "tar": "3.1.8", - "tcp-port-used": "^0.1.2", - "tmp": "^0.0.31" + "platformio-node-helpers": "^0.1.0" }, "extensionDependencies": [ "ms-vscode.cpptools", diff --git a/src/commands/init.js b/src/commands/init.js index 8fcec0c..b476d07 100644 --- a/src/commands/init.js +++ b/src/commands/init.js @@ -6,7 +6,8 @@ * the root directory of this source tree. */ -import { runPIOCommand } from '../utils'; +import * as pioNodeHelpers from 'platformio-node-helpers'; + import vscode from 'vscode'; @@ -27,7 +28,7 @@ export default async function initCommand() { try { const data = JSON.parse(await new Promise((resolve, reject) => { - runPIOCommand(['boards', '--json-output'], (code, stdout, stderr) => { + pioNodeHelpers.core.runPIOCommand(['boards', '--json-output'], (code, stdout, stderr) => { if (code !== 0) { reject(stderr); } else { @@ -58,7 +59,7 @@ export default async function initCommand() { }); await new Promise((resolve, reject) => { - runPIOCommand(['init', '--ide', 'vscode', '--board', selectedBoard.boardId, '--project-dir', vscode.workspace.rootPath], (code, stdout, stderr) => { + pioNodeHelpers.core.runPIOCommand(['init', '--ide', 'vscode', '--board', selectedBoard.boardId, '--project-dir', vscode.workspace.rootPath], (code, stdout, stderr) => { if (code !== 0) { reject(stderr); } else { diff --git a/src/constants.js b/src/constants.js index 8096e49..3417812 100644 --- a/src/constants.js +++ b/src/constants.js @@ -6,32 +6,6 @@ * the root directory of this source tree. */ -import fs from 'fs-plus'; -import path from 'path'; - -export const DEFAULT_PIO_ARGS = ['-f', '-c', 'vscode']; export const AUTO_REBUILD_DELAY = 3000; export const IS_WINDOWS = process.platform.startsWith('win'); -export const PIO_HOME_DIR = _getPioHomeDir(process.env.PLATFORMIO_HOME_DIR || path.join(fs.getHomeDirectory() || '~', '.platformio')); -export const CACHE_DIR = path.join(PIO_HOME_DIR, '.cache-ide'); -export const ENV_DIR = path.join(PIO_HOME_DIR, 'penv'); -export const ENV_BIN_DIR = path.join(ENV_DIR, IS_WINDOWS ? 'Scripts' : 'bin'); export const PIO_CORE_MIN_VERSION = '3.5.0-a.4'; - - -function _getPioHomeDir(pioHomeDir) { - if (IS_WINDOWS) { - // Make sure that all path characters have valid ASCII codes. - for (const char of pioHomeDir) { - if (char.charCodeAt(0) > 127) { - // If they don't, put the pio home directory into the root of the disk. - const homeDirPathFormat = path.parse(pioHomeDir); - return path.format({ - dir: homeDirPathFormat.root, - base: '.platformio', - }); - } - } - } - return pioHomeDir; -} diff --git a/src/home.js b/src/home.js index 2da8249..0bab38a 100644 --- a/src/home.js +++ b/src/home.js @@ -6,55 +6,32 @@ * the root directory of this source tree. */ -import request from 'request'; -import spawn from 'cross-spawn'; -import tcpPortUsed from 'tcp-port-used'; +import * as pioNodeHelpers from 'platformio-node-helpers'; + +import vscode from 'vscode'; export class HomeContentProvider { - static HTTP_HOST = 'localhost'; - static HTTP_PORT = 8008; + static shutdownServer() { + pioNodeHelpers.home.shutdownServer(); + } async provideTextDocumentContent(uri) { - await HomeContentProvider.ensureServerStarted(); + const params = await pioNodeHelpers.home.ensureServerStarted({ + onIDECommand: (command, params) => { + if (command === 'open_project') { + vscode.commands.executeCommand('vscode.openFolder', vscode.Uri.file(params)); + } + } + }); return ` -