From 6f584bf5d6db2e8ea768ee729770ad05dd3a224e Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Mon, 6 May 2019 22:00:44 +0200 Subject: [PATCH] Fixed the `electron` build. - Switched from `grpc` to `@grpc/grpc-js`. - Use electron `4.x` due to `@grpc/grpc-js`. - Enabled the build on Azure Pipelines. - From now on, the TS/JS generation is manual. Signed-off-by: Akos Kitta --- arduino-ide-extension/package.json | 5 +- .../scripts/patch-grpc-js.js | 25 ++++++ .../node/cli-protocol/commands_grpc_pb.d.ts | 2 +- .../src/node/cli-protocol/commands_grpc_pb.js | 2 +- .../src/node/core-client-provider-impl.ts | 2 +- arduino-ide-extension/src/node/util.ts | 16 ---- azure-pipelines.yml | 82 +++++++++++++++++++ electron/README.md | 2 +- electron/build/template-package.json | 12 +++ electron/packager/cli | 3 + package.json | 4 +- yarn.lock | 12 +++ 12 files changed, 143 insertions(+), 24 deletions(-) create mode 100644 arduino-ide-extension/scripts/patch-grpc-js.js delete mode 100644 arduino-ide-extension/src/node/util.ts create mode 100644 azure-pipelines.yml diff --git a/arduino-ide-extension/package.json b/arduino-ide-extension/package.json index 56dd4ead..d03c2638 100644 --- a/arduino-ide-extension/package.json +++ b/arduino-ide-extension/package.json @@ -4,6 +4,7 @@ "description": "An extension for Theia building the Arduino IDE", "license": "MIT", "dependencies": { + "@grpc/grpc-js": "^0.4.0", "@theia/core": "next", "@theia/editor": "next", "@theia/filesystem": "next", @@ -14,8 +15,8 @@ "p-queue": "^5.0.0" }, "scripts": { - "generate-protoc": "./scripts/generate-protoc.sh", - "prepare": "yarn run clean && yarn generate-protoc && yarn run build", + "generate-protoc": "./scripts/generate-protoc.sh && node ./scripts/patch-grpc-js.js", + "prepare": "yarn run clean && yarn run build", "clean": "rimraf lib", "lint": "tslint -c ./tslint.json --project ./tsconfig.json", "build": "tsc && cp -rf src/node/cli-protocol lib/node && yarn lint", diff --git a/arduino-ide-extension/scripts/patch-grpc-js.js b/arduino-ide-extension/scripts/patch-grpc-js.js new file mode 100644 index 00000000..d51dd863 --- /dev/null +++ b/arduino-ide-extension/scripts/patch-grpc-js.js @@ -0,0 +1,25 @@ +// Use `@grpc/grpc-js` instead of `grpc` at runtime. +// https://github.com/grpc/grpc-node/issues/624 +(() => { + const fs = require('fs'); + const path = require('path'); + const roots = ['src']; // XXX: patch the `lib` instead? + console.info("🔧 >>> Patching code. Switching from 'grpc' to '@grpc/grpc-js'..."); + for (const root of roots) { + const cliProtocolPath = path.resolve(__dirname, '..', root, 'node', 'cli-protocol'); + for (const fileName of fs.readdirSync(cliProtocolPath)) { + const filePath = path.resolve(cliProtocolPath, fileName); + let content = fs.readFileSync(filePath, { encoding: 'utf8' }); + if (content.indexOf("require('grpc')") !== -1) { + console.info(`Updated require('grpc') to require('@grpc/grpc-js') in ${filePath}.`); + fs.writeFileSync(filePath, content.replace("require('grpc')", "require('@grpc/grpc-js')")); + } + content = fs.readFileSync(filePath, { encoding: 'utf8' }); + if (content.indexOf('import * as grpc from "grpc"') !== -1) { + console.info(`Updated import * as grpc from "grpc" to import * as grpc from "@grpc/grpc-js" in ${filePath}.`); + fs.writeFileSync(filePath, content.replace('import * as grpc from "grpc"', 'import * as grpc from "@grpc/grpc-js"')); + } + } + } + console.info('👌 <<< Done. The code has been patched.'); +})(); diff --git a/arduino-ide-extension/src/node/cli-protocol/commands_grpc_pb.d.ts b/arduino-ide-extension/src/node/cli-protocol/commands_grpc_pb.d.ts index 81af22d5..0464a31b 100644 --- a/arduino-ide-extension/src/node/cli-protocol/commands_grpc_pb.d.ts +++ b/arduino-ide-extension/src/node/cli-protocol/commands_grpc_pb.d.ts @@ -3,7 +3,7 @@ /* tslint:disable */ -import * as grpc from "grpc"; +import * as grpc from "@grpc/grpc-js"; import * as commands_pb from "./commands_pb"; import * as common_pb from "./common_pb"; import * as board_pb from "./board_pb"; diff --git a/arduino-ide-extension/src/node/cli-protocol/commands_grpc_pb.js b/arduino-ide-extension/src/node/cli-protocol/commands_grpc_pb.js index a7da5b71..e1c31286 100644 --- a/arduino-ide-extension/src/node/cli-protocol/commands_grpc_pb.js +++ b/arduino-ide-extension/src/node/cli-protocol/commands_grpc_pb.js @@ -19,7 +19,7 @@ // // 'use strict'; -var grpc = require('grpc'); +var grpc = require('@grpc/grpc-js'); var commands_pb = require('./commands_pb.js'); var common_pb = require('./common_pb.js'); var board_pb = require('./board_pb.js'); diff --git a/arduino-ide-extension/src/node/core-client-provider-impl.ts b/arduino-ide-extension/src/node/core-client-provider-impl.ts index 4d75cadd..880dbb27 100644 --- a/arduino-ide-extension/src/node/core-client-provider-impl.ts +++ b/arduino-ide-extension/src/node/core-client-provider-impl.ts @@ -1,5 +1,5 @@ import { inject, injectable } from 'inversify'; -import * as grpc from 'grpc'; +import * as grpc from '@grpc/grpc-js'; import { ArduinoCoreClient } from './cli-protocol/commands_grpc_pb'; import { InitResp, InitReq, Configuration, UpdateIndexReq, UpdateIndexResp } from './cli-protocol/commands_pb'; import { WorkspaceServiceExt } from '../browser/workspace-service-ext'; diff --git a/arduino-ide-extension/src/node/util.ts b/arduino-ide-extension/src/node/util.ts deleted file mode 100644 index cb0ce91d..00000000 --- a/arduino-ide-extension/src/node/util.ts +++ /dev/null @@ -1,16 +0,0 @@ -import * as grpc from "grpc"; -import * as jspb from "google-protobuf"; - -export type GrpcMethod = (request: Req, callback: (error: grpc.ServiceError | null, response: Resp) => void) => grpc.ClientUnaryCall - -export function promisify, Req, Resp extends jspb.Message>(m: M, req: Req): Promise { - return new Promise((resolve, reject) => { - m(req, (err, resp) => { - if (!!err) { - reject(err); - } else { - resolve(resp); - } - }); - }); -} \ No newline at end of file diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 00000000..79b8ae6d --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,82 @@ +trigger: + batch: true + branches: + include: + - master + - electron # TODO: remove this! + +pr: +- master + +jobs: +- job: Build + strategy: + matrix: + linux: + imageName: 'ubuntu-16.04' + mac: + imageName: 'macos-10.13' + windows: + imageName: 'vs2017-win2016' + pool: + vmImage: $(imageName) + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: '2.7' + architecture: 'x64' + displayName: '[Config] Use - Python 2.7' + - task: NodeTool@0 + inputs: + versionSpec: '10.x' + displayName: '[Config] Use - Node.js 10.x' + - script: yarn + displayName: Build + env: + GITHUB_TOKEN: $(Personal.GitHub.Token) + - bash: | + yarn --cwd ./electron/packager/ + yarn --cwd ./electron/packager/ package + displayName: Package + env: + GITHUB_TOKEN: $(Personal.GitHub.Token) + RELEASE_TAG: $(Release.Tag) + - bash: | + export ARDUINO_POC_NAME=$(./electron/packager/cli name) + echo "##vso[task.setvariable variable=ArduinoPoC.AppName]$ARDUINO_POC_NAME" + env: + RELEASE_TAG: $(Release.Tag) + displayName: '[Config] Use - ARDUINO_POC_NAME env' + - task: PublishBuildArtifacts@1 + inputs: + pathtoPublish: electron/build/dist/$(ArduinoPoC.AppName) + artifactName: 'Arduino-PoC - Applications' + displayName: Publish +- job: Release + pool: + vmImage: ubuntu-16.04 + dependsOn: + - Build + condition: and(in(variables['Build.Reason'], 'Manual', 'Schedule'), startsWith(variables['Release.Tag'], 'v')) + steps: + - task: DownloadBuildArtifacts@0 + displayName: Download + inputs: + artifactName: 'Arduino-PoC - Applications' + downloadPath: 'gh-release' + - task: GithubRelease@0 + inputs: + gitHubConnection: personal-access-token-service-connection + repositoryName: bcmi-labs/arduino-editor + assets: | + gh-release/Arduino-PoC - Applications/*.zip + gh-release/Arduino-PoC - Applications/*.dmg + gh-release/Arduino-PoC - Applications/*.tar.xz + target: $(Build.SourceVersion) + action: Edit + tagSource: auto + tag: $(Release.Tag) + assetUploadMode: delete + isDraft: true + addChangeLog: false + displayName: Release diff --git a/electron/README.md b/electron/README.md index d591b0e3..f52d2e5e 100644 --- a/electron/README.md +++ b/electron/README.md @@ -34,7 +34,7 @@ One can create a GitHub release draft, tag the source, and upload the artifacts ### Publishing the Release Draft: One has to manually publish the GitHub release. - - Go to the [release page](https://github.com/TypeFox/arduino-poc/releases) of the arduino-poc repository. + - Go to the [release page](https://github.com/bcmi-labs/arduino-editor.git/releases) of the `arduino-editor` repository. - Select your release draft. - Click on `Edit`. diff --git a/electron/build/template-package.json b/electron/build/template-package.json index 7c1d32ed..8a26ff1a 100644 --- a/electron/build/template-package.json +++ b/electron/build/template-package.json @@ -4,6 +4,7 @@ "main": "src-gen/frontend/electron-main.js", "author": "TypeFox", "dependencies": { + "google-protobuf": "^3.5.0", "arduino-ide-extension": "file:../working-copy/arduino-ide-extension" }, "devDependencies": { @@ -22,9 +23,14 @@ "type": "git", "url": "git+https://github.com/TypeFox/arduino-poc.git" }, + "// Notes:" : [ + "The `electronVersion` version was pinned for `@grpc/grpc-js` -> Node.js version constraints.", + "`google-protobuf` was declared as it is not picked up by the `electron-builder` as a runtime dependency." + ], "build": { "productName": "Arduino-PoC", "appId": "arduino.PoC", + "electronVersion": "4.0.0", "asar": false, "directories": { "buildResources": "resources" @@ -55,6 +61,12 @@ "artifactName": "${productName}-${env.ARDUINO_VERSION}-${os}.${ext}", "darkModeSupport": true }, + "linux": { + "target": [ + "tar.xz" + ], + "artifactName": "${productName}-${env.ARDUINO_VERSION}-${os}.${ext}" + }, "dmg": { "icon": "resources/icon.icns", "iconSize": 128, diff --git a/electron/packager/cli b/electron/packager/cli index 0df45515..203ca8db 100755 --- a/electron/packager/cli +++ b/electron/packager/cli @@ -18,6 +18,9 @@ const yargs = require('yargs'); } else if (platform === 'win32') { ext = 'zip'; os = 'win'; + } else if (platform === 'linux') { + ext = 'tar.xz'; + os = 'linux'; } else { process.stderr.write(`Unexpected platform: ${platform}.`); process.exit(1); diff --git a/package.json b/package.json index 61e4ee25..db6704da 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "arduino-poc", "version": "0.0.1", - "description": "A proof-of-concent demonstrating an Arduino IDE built using Theia", + "description": "A PoC demonstrating an Arduino IDE built using Eclipse Theia", "main": "index.js", - "repository": "https://github.com/TypeFox/arduino-poc.git", + "repository": "https://github.com/bcmi-labs/arduino-editor.git", "author": "Christian Weichel ", "license": "MIT", "private": true, diff --git a/yarn.lock b/yarn.lock index 526985e5..9f5cb5b6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -25,6 +25,13 @@ dependencies: regenerator-runtime "^0.13.2" +"@grpc/grpc-js@^0.4.0": + version "0.4.0" + resolved "https://registry.yarnpkg.com/@grpc/grpc-js/-/grpc-js-0.4.0.tgz#b20a6abf1346ce7fd696a042f83d10c94e143881" + integrity sha512-UbGDPnstJamJrSiHzCSwSavIX260IfLOZLRJYDqRKJA/jmVZa3hPMWDjhFrcCKDq2MLc/O/nauFED3r4khcZrA== + dependencies: + semver "^6.0.0" + "@lerna/add@3.13.3": version "3.13.3" resolved "https://registry.yarnpkg.com/@lerna/add/-/add-3.13.3.tgz#f4c1674839780e458f0426d4f7b6d0a77b9a2ae9" @@ -9738,6 +9745,11 @@ self-closing-tags@^1.0.1: resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.0.tgz#790a7cf6fea5459bac96110b29b60412dc8ff96b" integrity sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA== +semver@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/semver/-/semver-6.0.0.tgz#05e359ee571e5ad7ed641a6eec1e547ba52dea65" + integrity sha512-0UewU+9rFapKFnlbirLi3byoOuhrSsli/z/ihNnvM24vgF+8sNBiI1LZPBSH9wJKUwaUbw+s3hToDLCXkrghrQ== + semver@~5.3.0: version "5.3.0" resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"