Skip to content

Commit

Permalink
enable osxNotarize (#7)
Browse files Browse the repository at this point in the history
* enable osxNotarize

fix a small bug in recognising ports for board check

* use correct store
  • Loading branch information
xiduzo authored Aug 23, 2024
1 parent f48cd96 commit 5a90e43
Show file tree
Hide file tree
Showing 27 changed files with 122 additions and 96 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/make.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ jobs:
- name: Make application
run: yarn make
env:
APPLE_IDENTITY: ${{ env.APPLE_IDENTITY }}
APPLE_IDENTITY: ${{ vars.APPLE_IDENTITY }}
APPLE_ID: ${{ vars.APPLE_ID }}
APPLE_TEAM_ID: ${{ vars.APPLE_TEAM_ID }}
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}

- name: Clean up keychain and provisioning profile
if: runner.os == 'macOS'
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,12 @@ jobs:
run: yarn publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
APPLE_API_KEY: AuthKey_${{ env.APPLE_API_KEY_ID }}.p8
APPLE_IDENTITY: ${{ vars.APPLE_IDENTITY }}
APPLE_ID: ${{ vars.APPLE_ID }}
APPLE_TEAM_ID: ${{ vars.APPLE_TEAM_ID }}
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}

- name: Clean up keychain and provisioning profile
if: runner.os == 'macOS'
run: |
security delete-keychain $RUNNER_TEMP/app-signing.keychain-db
76 changes: 56 additions & 20 deletions apps/electron-app/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

const fs = require('fs/promises');
const path = require('path');

/** @type {Arborist} */
// @ts-ignore missing types for @npmcli/arborist
const arborist = require('@npmcli/arborist');
Expand All @@ -30,6 +31,8 @@ const { findRoot } = require('@manypkg/find-root');
* location: string;
* realpath: string;
* target: Node;
* name: string;
* version: string;
* edgesOut: Map<string, Edge>;
* }} Node
*/
Expand All @@ -47,7 +50,8 @@ const getWorkspaceByPath = (node, realPath) =>
/** @type {(node: Node) => Node[]} */
const collectProdDeps = node => {
const stack = [node];
const result = new Set(); // Using a set to avoid duplicates and track visited nodes
/** @type {Map<string, Node>} */
const result = new Map(); // Using a set to avoid duplicates and track visited nodes

while (stack.length > 0) {
const currentNode = stack.pop();
Expand All @@ -63,9 +67,11 @@ const collectProdDeps = node => {
continue;
}

const depEdges = [...currentNode.edgesOut.values()].filter(
depEdge => depEdge.type === 'prod',
);
const depEdges = [...currentNode.edgesOut.values()]
.filter(depEdge => depEdge.type === 'prod')
.filter(
depEdge => !depEdge.to.location.startsWith('node_modules/@types'),
);

// Show dependencies
// console.debug(
Expand All @@ -76,14 +82,36 @@ const collectProdDeps = node => {
for (const depEdge of depEdges) {
const depNode = resolveLink(depEdge.to);

if (!result.has(depNode)) {
result.add(depNode);
const addedNode = result.get(depNode.name);
if (addedNode) {
const addedVersion = Number(addedNode.version.replace(/[.]/g, ''));
const depVersion = Number(depNode.version.replace(/[.]/g, ''));

if (depVersion > addedVersion) {
console.log(
'newer version detected',
'from',
addedNode.name,
addedNode.location,
addedVersion,
'to',
depNode.name,
depNode.location,
depVersion,
);

stack.push(depNode);
}
} else {
stack.push(depNode);
}

console.log('adding module', depNode.name, depNode.version);
result.set(depNode.name, depNode);
}
}

return Array.from(result); // Convert the set to an array if necessary
return Array.from(result.values()); // Convert the set to an array if necessary
};

/** @type {(source: string, destination: string) => Promise<void>} */
Expand All @@ -99,25 +127,33 @@ const bundle = async (source, destination) => {
const prodDeps = collectProdDeps(sourceNode);

for (const dep of prodDeps) {
const dest = path.join(destination, dep.location);

let bundlePath = dest;
if (dep.location.startsWith('packages')) {
switch (dep.location) {
case 'packages/components':
bundlePath = dest.replace('packages', 'node_modules/@microflow');
break;
default:
continue;
}
const dest = dep.location.startsWith('packages')
? path.join(destination, 'node_modules', '@microflow', dep.name)
: path.join(destination, 'node_modules', dep.name);

if (dep.name.startsWith('@types')) {
// console.debug(`IGNORE ${dep.name}`);
continue;
}

console.log(`${dep.location} --> ${bundlePath}`);
// console.log(dep.name, `${dep.location} --> ${dest}`);

await fs.cp(dep.realpath, bundlePath, {
await fs.cp(dep.realpath, dest, {
recursive: true,
errorOnExist: false,
dereference: true,
filter: source => {
console.log('>> copying', source);
return true;
},
});

// if (dest.includes('@serialport/bindings-cpp')) {
// // Check if folder exists
// const folder = path.join(dest, 'build', 'node_gyp_bins');
// const exists = await fs.readdir(folder).catch(() => false);
// console.log('!!!! patching serialport', dest, exists);
// }
}
};

Expand Down
52 changes: 20 additions & 32 deletions apps/electron-app/forge.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { bundle } = require('./bundler');
require('dotenv').config();
const fs = require('fs/promises');

/** @type {import('@electron-forge/shared-types').ForgeConfig} */
module.exports = {
Expand All @@ -11,38 +12,24 @@ module.exports = {
strictVerify: false,
identity: process.env.APPLE_IDENTITY, // https://github.com/electron/forge/issues/3131#issuecomment-2237818679
ignore: filePath => {
if (filePath.includes('build/node_gyp_bins/python3')) {
// https://github.com/nodejs/node-gyp/issues/2713
if (filePath.includes('build/node_gyp_bins')) {
console.log('>> ignore signing', filePath);
fs.rm(filePath, { recursive: true })
.then(() => {
console.log('>> removed folder', filePath);
})
.catch(console.error);
return true;
}
return false;
},
// optionsForFile: filePath => {
// if (!filePath.includes('node_gyp_bins/python3')) {
// return;
// }

// console.log('>> extra options', filePath);

// return {
// additionalArguments: ['--deep'],
// };
// },
// ignore: filePath => {
// if (!filePath.includes('node_gyp_bins/python3')) {
// return false;
// }

// console.log('>> ignore', filePath);
// return true;
// },
},
// osxNotarize: {
// tool: 'notarytool',
// appleId: process.env.APPLE_ID,
// appleIdPassword: process.env.APPLE_PASSWORD,
// teamId: process.env.APPLE_TEAM_ID,
// },
osxNotarize: {
appleId: process.env.APPLE_ID,
appleIdPassword: process.env.APPLE_PASSWORD,
teamId: process.env.APPLE_TEAM_ID,
},
prune: false, // Requires for monorepo
protocols: [
{
Expand All @@ -53,20 +40,21 @@ module.exports = {
},
hooks: {
packageAfterCopy: async (
forgeConfig,
_forgeConfig,
buildPath,
electronVersion,
platform,
arch,
_electronVersion,
_platform,
_arch,
) => {
console.log(forgeConfig, buildPath, electronVersion, platform, arch);
// https://gist.github.com/robin-hartmann/ad6ffc19091c9e661542fbf178647047
// this is a workaround until we find a proper solution
// for running electron-forge in a mono repository
await bundle(__dirname, buildPath);
},
},
rebuildConfig: {},
rebuildConfig: {
disablePreGypCopy: true,
},
makers: [
{
name: '@electron-forge/maker-squirrel', // Windows
Expand Down
4 changes: 2 additions & 2 deletions apps/electron-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "git",
"url": "https://github.com/xiduzo/microflow"
},
"version": "0.1.4",
"version": "0.1.5",
"description": "An application which allows you to create flow-based logic for micro-controllers",
"author": {
"name": "Sander Boer",
Expand Down Expand Up @@ -54,7 +54,7 @@
"dependencies": {
"@microflow/components": "workspaces:*",
"@microflow/flasher": "workspaces:*",
"@microflow/mqtt": "workspaces:*",
"@microflow/mqtt-provider": "workspaces:*",
"@microflow/ui": "workspaces:*",
"@microflow/utils": "workspaces:*",
"@xyflow/react": "^12.0.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/electron-app/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
FigmaProvider,
MqttConfig,
MqttProvider,
} from '@microflow/mqtt/client';
} from '@microflow/mqtt-provider/client';
import { Toaster } from '@microflow/ui';
import { Edge, Node, ReactFlowProvider } from '@xyflow/react';
import { useEffect, useState } from 'react';
Expand Down
13 changes: 6 additions & 7 deletions apps/electron-app/src/main/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,17 @@ ipcMain.on('ipc-menu', (_event, action, ...args) => {
ipcMain.on('ipc-check-board', async event => {
childProcess?.kill();

const boardsAndPorts = await getKnownBoardsWithPorts();

const filePath = join(__dirname, 'workers', 'check.js');

let connectedPort: PortInfo | null = null;

const [lastBoard, ports] = boardsAndPorts.at(-1);
const lastPort = ports.at(-1);
// Check board on all ports which match the known product IDs
const boardsAndPorts = await getKnownBoardsWithPorts();

log.debug('Checking boards and ports', {
boardsAndPorts: JSON.stringify(boardsAndPorts),
});

// Check board on all ports which match the known product IDs
const filePath = join(__dirname, 'workers', 'check.js');

checkBoard: for (const [board, ports] of boardsAndPorts) {
for (const port of ports) {
log.debug(`checking board ${board} on path ${port.path}`, { filePath });
Expand Down Expand Up @@ -111,6 +108,8 @@ ipcMain.on('ipc-check-board', async event => {
} satisfies BoardCheckResult);
break checkBoard; // board is flashed with firmata, no need to check other ports
} catch (error) {
const [lastBoard, ports] = boardsAndPorts.at(-1);
const lastPort = ports.at(-1);
log.warn('Error flashing board', { error });
// we should not return as we still want to sniff the ports 🐕
if (board === lastBoard && port.path === lastPort.path) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MqttConfig } from '@microflow/mqtt/client';
import { MqttConfig } from '@microflow/mqtt-provider/client';
import {
Button,
Form,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
FigmaVariable,
useFigmaVariable,
useMqtt,
} from '@microflow/mqtt/client';
} from '@microflow/mqtt-provider/client';
import {
Badge,
Icons,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
MqttDirection,
MqttValueType,
} from '@microflow/components';
import { useMqtt } from '@microflow/mqtt/client';
import { useMqtt } from '@microflow/mqtt-provider/client';
import {
Badge,
Icons,
Expand Down
15 changes: 8 additions & 7 deletions apps/electron-app/workers/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ try {
process.parentPort.postMessage({
type: 'ready',
port: board.port,
pins: Object.entries(board.pins).reduce((acc, [key, value]) => {
acc.push({
pin: Number(key),
...value,
});
return acc;
}, []),
pins:
Object.entries(board.pins)?.reduce((acc, [key, value]) => {
acc.push({
pin: Number(key),
...value,
});
return acc;
}, []) ?? [],
});
});

Expand Down
4 changes: 2 additions & 2 deletions apps/figma-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@microflow/figma-plugin",
"private": true,
"version": "0.1.4",
"version": "0.1.5",
"scripts": {
"dev": "concurrently \"yarn watch:ui\" \"yarn watch:plugin\"",
"dev:ui-only": "vite -c ./vite.config.ui.ts",
Expand All @@ -17,7 +17,7 @@
"build:plugin": "vite build -c ./vite.config.plugin.ts"
},
"dependencies": {
"@microflow/mqtt": "workspaces:*",
"@microflow/mqtt-provider": "workspaces:*",
"@microflow/ui": "workspaces:*",
"mqtt": "^5.8.0",
"react": "^18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/figma-plugin/src/ui/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MqttProvider } from '@microflow/mqtt/client';
import { MqttProvider } from '@microflow/mqtt-provider/client';
import '@microflow/ui/global.css';
import { RouterProvider, createMemoryRouter } from 'react-router-dom';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMqtt } from '@microflow/mqtt/client';
import { useMqtt } from '@microflow/mqtt-provider/client';
import { useEffect, useRef } from 'react';
import { MESSAGE_TYPE, SetLocalValiable } from '../../common/types/Message';
import { useMessageListener } from '../hooks/useMessageListener';
Expand Down
2 changes: 1 addition & 1 deletion apps/figma-plugin/src/ui/pages/home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, cva, Icons } from '@microflow/ui';
import { PageContent } from '../../components/Page';

import { ConnectionStatus, useMqtt } from '@microflow/mqtt/client';
import { ConnectionStatus, useMqtt } from '@microflow/mqtt-provider/client';
import { Link } from 'react-router-dom';
import { useSetWindowSize } from '../../hooks/useSetWindowSize';

Expand Down
2 changes: 1 addition & 1 deletion apps/figma-plugin/src/ui/pages/mqtt/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MqttConfig } from '@microflow/mqtt/client';
import { MqttConfig } from '@microflow/mqtt-provider/client';
import {
Button,
Form,
Expand Down
Loading

0 comments on commit 5a90e43

Please sign in to comment.