diff --git a/.eslintrc b/.eslintrc index 177fe664..a3f23853 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,5 +1,8 @@ { "parser": "babel-eslint", + "plugins": [ + "react" + ], "rules": { "max-len": 0, "comma-dangle": 0, @@ -13,7 +16,8 @@ "arrow-parens": 0, "consistent-return": 0, "no-useless-escape": 0, - "no-underscore-dangle": 0 + "no-underscore-dangle": 0, + "react/jsx-uses-vars": 2 }, "extends": "airbnb-base", "env": { diff --git a/demo/app.jsx b/demo/app.jsx index 64cf4cb7..b9f73a22 100644 --- a/demo/app.jsx +++ b/demo/app.jsx @@ -22,7 +22,7 @@ import React from 'react'; import Daemon from '../src'; import { HEX } from './serial_mirror'; -// import V2 from './v2/v2.jsx'; +import V2 from './v2/v2.jsx'; const chromeExtensionID = 'hfejhkbipnickajaidoppbadcomekkde'; @@ -274,9 +274,9 @@ class App extends React.Component { <textarea aria-label="Serial Monitor output" id="serial-textarea" value={ this.state.serialMonitorContent } readOnly/> </div> - {/* <div className="v2"> + <div className="v2"> <V2 daemon={daemon}></V2> - </div> */} + </div> <div className="section"> <h2>Upload a sample sketch on a MKR1000 at /dev/ttyACM0</h2> diff --git a/package-lock.json b/package-lock.json index 07ba1204..2159039f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "arduino-create-agent-js-client", - "version": "2.2.2", + "version": "2.2.3", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1801,12 +1801,12 @@ } }, "clean-webpack-plugin": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/clean-webpack-plugin/-/clean-webpack-plugin-1.0.1.tgz", - "integrity": "sha512-gvwfMsqu3HBgTVvaBa1H3AZKO03CHpr5uP92SPIktP3827EovAitwW+1xoqXyTxCuXnLYpMHG5ytS4AoukHDWA==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/clean-webpack-plugin/-/clean-webpack-plugin-2.0.1.tgz", + "integrity": "sha512-vway5pXGVd91bicwjaf8j188Al6VMf9R9Ekl6q0qeiaWStRsOOXuh4qtjX1UrUvmz5XevQVCdjBuzr4Tzsnpog==", "dev": true, "requires": { - "rimraf": "^2.6.1" + "del": "^4.0.0" } }, "cli-cursor": { @@ -2246,6 +2246,49 @@ } } }, + "del": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/del/-/del-4.1.0.tgz", + "integrity": "sha512-C4kvKNlYrwXhKxz97BuohF8YoGgQ23Xm9lvoHmgT7JaPGprSEjk3+XFled74Yt/x0ZABUHg2D67covzAPUKx5Q==", + "dev": true, + "requires": { + "globby": "^6.1.0", + "is-path-cwd": "^2.0.0", + "is-path-in-cwd": "^2.0.0", + "p-map": "^2.0.0", + "pify": "^4.0.1", + "rimraf": "^2.6.3" + }, + "dependencies": { + "is-path-cwd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-path-cwd/-/is-path-cwd-2.0.0.tgz", + "integrity": "sha512-m5dHHzpOXEiv18JEORttBO64UgTEypx99vCxQLjbBvGhOJxnTNglYoFXxwo6AbsQb79sqqycQEHv2hWkHZAijA==", + "dev": true + }, + "is-path-in-cwd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-path-in-cwd/-/is-path-in-cwd-2.0.0.tgz", + "integrity": "sha512-6Vz5Gc9s/sDA3JBVu0FzWufm8xaBsqy1zn8Q6gmvGP6nSDMw78aS4poBNeatWjaRpTpxxLn1WOndAiOlk+qY8A==", + "dev": true, + "requires": { + "is-path-inside": "^1.0.0" + } + }, + "p-map": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/p-map/-/p-map-2.1.0.tgz", + "integrity": "sha512-y3b8Kpd8OAN444hxfBbFfj1FY/RjtTd8tzYwhUqNYXx0fXx2iX4maP4Qr6qhIKbQXI02wTLAda4fYUbDagTUFw==", + "dev": true + }, + "pify": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz", + "integrity": "sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==", + "dev": true + } + } + }, "depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", @@ -2269,9 +2312,9 @@ "dev": true }, "detect-browser": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/detect-browser/-/detect-browser-4.1.0.tgz", - "integrity": "sha512-YKQf1QQDXXJrwNE07xHujoD+meBnjhsYFdPwxFEXS1ylJWD9GKd21lKBjuqtXzAkz4CQjwBO3DYXBU/wWwZCGA==" + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/detect-browser/-/detect-browser-4.4.0.tgz", + "integrity": "sha512-wD1RDItw/aCnQ3fYSZNXZ/AVFwrqFDgLEsnSorLpgH3HC9YOjTC6Of+IeERrv28KbJ3B4bQd5ru1UFsGVCJM+g==" }, "detect-file": { "version": "1.0.0", @@ -2852,9 +2895,9 @@ } }, "eslint-plugin-import": { - "version": "2.17.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.17.1.tgz", - "integrity": "sha512-lzD9uvRvW4MsHzIOMJEDSb5MOV9LzgxRPBaovvOhJqzgxRHYfGy9QOrMuwHIh5ehKFJ7Z3DcrcGKDQ0IbP0EdQ==", + "version": "2.17.2", + "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.17.2.tgz", + "integrity": "sha512-m+cSVxM7oLsIpmwNn2WXTJoReOF9f/CtLMo7qOVmKd1KntBy0hEcuNZ3erTmWjx+DxRO0Zcrm5KwAvI9wHcV5g==", "dev": true, "requires": { "array-includes": "^3.0.3", @@ -2927,6 +2970,56 @@ } } }, + "eslint-plugin-react": { + "version": "7.12.4", + "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.12.4.tgz", + "integrity": "sha512-1puHJkXJY+oS1t467MjbqjvX53uQ05HXwjqDgdbGBqf5j9eeydI54G3KwiJmWciQ0HTBacIKw2jgwSBSH3yfgQ==", + "dev": true, + "requires": { + "array-includes": "^3.0.3", + "doctrine": "^2.1.0", + "has": "^1.0.3", + "jsx-ast-utils": "^2.0.1", + "object.fromentries": "^2.0.0", + "prop-types": "^15.6.2", + "resolve": "^1.9.0" + }, + "dependencies": { + "doctrine": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", + "integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==", + "dev": true, + "requires": { + "esutils": "^2.0.2" + } + }, + "has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dev": true, + "requires": { + "function-bind": "^1.1.1" + } + }, + "path-parse": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", + "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", + "dev": true + }, + "resolve": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.0.tgz", + "integrity": "sha512-3sUr9aq5OfSg2S9pNtPA9hL1FVEAjvfOC4leW0SNf/mpnaakz2a9femSd6LqAww2RaFctwyf1lCqnTHuF1rxDg==", + "dev": true, + "requires": { + "path-parse": "^1.0.6" + } + } + } + }, "eslint-restricted-globals": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/eslint-restricted-globals/-/eslint-restricted-globals-0.1.1.tgz", @@ -3716,14 +3809,14 @@ "dev": true }, "fsevents": { - "version": "1.2.7", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.7.tgz", - "integrity": "sha512-Pxm6sI2MeBD7RdD12RYsqaP0nMiwx8eZBXCa6z2L+mRHm2DYrOYwihmhjpkdjUHwQhslWQjRpEgNq4XvBmaAuw==", + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.8.tgz", + "integrity": "sha512-tPvHgPGB7m40CZ68xqFGkKuzN+RnpGmSV+hgeKxhRpbxdqKXUFJGC3yonBOLzQBcJyGpdZFDfCsdOC2KFsXzeA==", "dev": true, "optional": true, "requires": { - "nan": "^2.9.2", - "node-pre-gyp": "^0.10.0" + "nan": "^2.12.1", + "node-pre-gyp": "^0.12.0" }, "dependencies": { "abbrev": { @@ -3801,12 +3894,12 @@ "optional": true }, "debug": { - "version": "2.6.9", + "version": "4.1.1", "bundled": true, "dev": true, "optional": true, "requires": { - "ms": "2.0.0" + "ms": "^2.1.1" } }, "deep-extend": { @@ -3977,24 +4070,24 @@ } }, "ms": { - "version": "2.0.0", + "version": "2.1.1", "bundled": true, "dev": true, "optional": true }, "needle": { - "version": "2.2.4", + "version": "2.3.0", "bundled": true, "dev": true, "optional": true, "requires": { - "debug": "^2.1.2", + "debug": "^4.1.0", "iconv-lite": "^0.4.4", "sax": "^1.2.4" } }, "node-pre-gyp": { - "version": "0.10.3", + "version": "0.12.0", "bundled": true, "dev": true, "optional": true, @@ -4022,13 +4115,13 @@ } }, "npm-bundled": { - "version": "1.0.5", + "version": "1.0.6", "bundled": true, "dev": true, "optional": true }, "npm-packlist": { - "version": "1.2.0", + "version": "1.4.1", "bundled": true, "dev": true, "optional": true, @@ -4167,7 +4260,7 @@ "optional": true }, "semver": { - "version": "5.6.0", + "version": "5.7.0", "bundled": true, "dev": true, "optional": true @@ -4362,6 +4455,19 @@ "integrity": "sha512-S0nG3CLEQiY/ILxqtztTWH/3iRRdyBLw6KMDxnKMchrtbj2OFmehVh0WUCfW3DUrIgx/qFrJPICrq4Z4sTR9UQ==", "dev": true }, + "globby": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-6.1.0.tgz", + "integrity": "sha1-9abXDoOV4hyFj7BInWTfAkJNUGw=", + "dev": true, + "requires": { + "array-union": "^1.0.1", + "glob": "^7.0.3", + "object-assign": "^4.0.1", + "pify": "^2.0.0", + "pinkie-promise": "^2.0.0" + } + }, "graceful-fs": { "version": "4.1.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", @@ -5325,6 +5431,15 @@ "integrity": "sha1-Hq3nrMASA0rYTiOWdn6tn6VJWCE=", "dev": true }, + "jsx-ast-utils": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-2.0.1.tgz", + "integrity": "sha1-6AGxs5mF4g//yHtA43SAgOLcrH8=", + "dev": true, + "requires": { + "array-includes": "^3.0.3" + } + }, "killable": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/killable/-/killable-1.0.1.tgz", @@ -6077,6 +6192,18 @@ } } }, + "object.fromentries": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/object.fromentries/-/object.fromentries-2.0.0.tgz", + "integrity": "sha512-9iLiI6H083uiqUuvzyY6qrlmc/Gz8hLQFOcb/Ri/0xXFkSNS3ctV+CbE6yM2+AnkYfOB3dGjdzC0wrMLIhQICA==", + "dev": true, + "requires": { + "define-properties": "^1.1.2", + "es-abstract": "^1.11.0", + "function-bind": "^1.1.1", + "has": "^1.0.1" + } + }, "object.getownpropertydescriptors": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.0.3.tgz", diff --git a/package.json b/package.json index 4b9d63fd..fb0ad6b4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "arduino-create-agent-js-client", - "version": "2.2.2", + "version": "2.2.3", "description": "JS module providing discovery of the Arduino Create Plugin and communication with it", "main": "lib/index.js", "module": "es/index.js", @@ -15,7 +15,7 @@ "lib": "lib" }, "dependencies": { - "detect-browser": "^4.1.0", + "detect-browser": "^4.4.0", "rxjs": "^6.4.0", "semver-compare": "^1.0.0", "socket.io-client": "2.2.0" @@ -29,11 +29,12 @@ "babel-preset-env": "^1.7.0", "babel-preset-es2015": "^6.24.1", "babel-preset-react": "^6.24.1", - "clean-webpack-plugin": "^1.0.1", + "clean-webpack-plugin": "^2.0.1", "cross-env": "^5.2.0", "eslint": "^5.16.0", "eslint-config-airbnb-base": "^13.1.0", - "eslint-plugin-import": "^2.17.1", + "eslint-plugin-import": "^2.17.2", + "eslint-plugin-react": "^7.12.4", "html-webpack-plugin": "^3.2.0", "react": "^16.8.6", "react-dom": "^16.8.6", @@ -51,6 +52,7 @@ }, "scripts": { "test": "", + "https": "webpack-dev-server --https", "dev": "webpack-dev-server", "lint": "./node_modules/.bin/eslint src", "lint-fix": "./node_modules/.bin/eslint --fix src --ext .js", diff --git a/src/socket-daemon.js b/src/socket-daemon.js index c89eb78d..f7b1b47d 100644 --- a/src/socket-daemon.js +++ b/src/socket-daemon.js @@ -26,7 +26,7 @@ import { timer, BehaviorSubject } from 'rxjs'; import { filter, takeUntil, first } from 'rxjs/operators'; import Daemon from './daemon'; -// import V2 from './socket-daemon.v2'; +import V2 from './socket-daemon.v2'; // Required agent version const browser = detect(); @@ -63,17 +63,17 @@ export default class SocketDaemon extends Daemon { this.openChannel(() => this.socket.emit('command', 'list')); - // this.agentV2Found = new BehaviorSubject(null); + this.agentV2Found = new BehaviorSubject(null); this.agentFound .subscribe(agentFound => { if (agentFound) { this._wsConnect(); - /* const v2 = new V2(this.pluginURL); + const v2 = new V2(this.pluginURL); v2.init().then(() => { this.v2 = v2; this.agentV2Found.next(this.v2); - }); */ + }); } else { this.findAgent(); @@ -279,10 +279,7 @@ export default class SocketDaemon extends Daemon { */ update() { return fetch(`${this.agentInfo[this.selectedProtocol]}/update`, { - method: 'POST', - headers: { - 'Content-Type': 'text/plain; charset=utf-8' - } + method: 'POST' }) .then(result => result.json()) .then(response => { @@ -307,10 +304,7 @@ export default class SocketDaemon extends Daemon { stopPlugin() { if (this.agentFound.getValue()) { return fetch(`${this.agentInfo[this.selectedProtocol]}/pause`, { - method: 'POST', - headers: { - 'Content-Type': 'text/plain; charset=utf-8' - } + method: 'POST' }); } } @@ -434,9 +428,6 @@ export default class SocketDaemon extends Daemon { daemonUpload(data) { fetch(`${this.pluginURL}/upload`, { method: 'POST', - headers: { - 'Content-Type': 'text/plain; charset=utf-8' - }, body: JSON.stringify(data) }) .then(result => { @@ -471,15 +462,15 @@ export default class SocketDaemon extends Daemon { _upload(uploadPayload, uploadCommandInfo) { if (Array.isArray(uploadCommandInfo.tools)) { uploadCommandInfo.tools.forEach(tool => { - // if (this.v2) { - // this.downloading.next({ status: this.DOWNLOAD_IN_PROGRESS }); - // this.v2.installTool(tool).then(() => { - // this.downloading.next({ status: this.DOWNLOAD_DONE }); - // }); - // } - // else { - this.downloadTool(tool.name, tool.version, tool.packager); - // } + if (this.v2) { + this.downloading.next({ status: this.DOWNLOAD_IN_PROGRESS }); + this.v2.installTool(tool).then(() => { + this.downloading.next({ status: this.DOWNLOAD_DONE }); + }); + } + else { + this.downloadTool(tool.name, tool.version, tool.packager); + } }); } diff --git a/src/socket-daemon.v2.js b/src/socket-daemon.v2.js index ea2fbafb..e5a6690d 100644 --- a/src/socket-daemon.v2.js +++ b/src/socket-daemon.v2.js @@ -34,10 +34,7 @@ export default class SocketDaemonV2 { // } installTool(payload) { return fetch(`${this.daemonURL}/pkgs/tools/installed`, { - method: 'PUT', - headers: { - 'Content-Type': 'text/plain; charset=utf-8' - }, + method: 'POST', body: JSON.stringify(payload) }).then(res => res.json() .then((json) => {