build(electron): use nx (#2942)

This commit is contained in:
Alex Yang 2023-06-30 16:10:35 +08:00 committed by GitHub
parent 9e90242ddb
commit 38a2aa9d17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 134 additions and 148 deletions

View File

@ -374,8 +374,8 @@ jobs:
run: yarn nx test @affine/monorepo
env:
NATIVE_TEST: 'true'
- name: Build layers
run: yarn workspace @affine/electron build
- name: Build AFFiNE Desktop
run: yarn nx build @affine/electron
- name: Download static resource artifact
uses: actions/download-artifact@v3
with:
@ -384,13 +384,13 @@ jobs:
- name: Run desktop tests
if: ${{ matrix.spec.test && matrix.spec.os == 'ubuntu-latest' }}
run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- yarn workspace @affine/electron test
run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- yarn nx test @affine/electron
env:
COVERAGE: true
- name: Run desktop tests
if: ${{ matrix.spec.test && matrix.spec.os != 'ubuntu-latest' }}
run: yarn workspace @affine/electron test
run: yarn nx test @affine/electron
env:
COVERAGE: true

View File

@ -125,7 +125,7 @@ jobs:
run: yarn nx run-many -t build -p plugin-infra infra
- name: Build layers
run: yarn workspace @affine/electron build
run: yarn nx build @affine/electron
- name: Signing By Apple Developer ID
if: ${{ matrix.spec.platform == 'darwin' }}

View File

@ -126,8 +126,8 @@ jobs:
- name: Build Infra
run: yarn nx run-many -t build -p plugin-infra infra
- name: Build layers
run: yarn workspace @affine/electron build
- name: Build AFFiNE Desktop
run: yarn nx build @affine/electron
- name: Signing By Apple Developer ID
if: ${{ matrix.spec.platform == 'darwin' }}

View File

@ -11,8 +11,7 @@
"homepage": "https://github.com/toeverything/AFFiNE",
"scripts": {
"dev": "yarn cross-env DEV_SERVER_URL=http://localhost:8080 node scripts/dev.mjs",
"watch": "yarn cross-env DEV_SERVER_URL=http://localhost:8080 node scripts/dev.mjs --watch",
"prod": "yarn node scripts/dev.mjs",
"dev:prod": "yarn node scripts/dev.mjs",
"build": "zx scripts/build-layers.mjs",
"generate-assets": "zx scripts/generate-assets.mjs",
"package": "electron-forge package",
@ -23,11 +22,9 @@
"forge": "./forge.config.js"
},
"main": "./dist/main.js",
"exports": {
"./scripts/plugins/build-plugins.mjs": "./scripts/plugins/build-plugins.mjs"
},
"devDependencies": {
"@affine-test/kit": "workspace:*",
"@affine/bookmark-block": "workspace:*",
"@affine/native": "workspace:*",
"@blocksuite/blocks": "0.0.0-20230629103121-76e6587d-nightly",
"@blocksuite/editor": "0.0.0-20230629103121-76e6587d-nightly",
@ -50,7 +47,7 @@
"electron-log": "^5.0.0-beta.24",
"electron-squirrel-startup": "1.0.0",
"electron-window-state": "^5.0.3",
"esbuild": "^0.18.9",
"esbuild": "^0.18.10",
"fs-extra": "^11.1.1",
"jotai": "^2.2.1",
"playwright": "=1.33.0",

View File

@ -1,12 +1,9 @@
#!/usr/bin/env zx
import 'zx/globals';
import { resolve } from 'node:path';
import { spawnSync } from 'child_process';
import * as esbuild from 'esbuild';
import { config, rootDir } from './common.mjs';
import { config } from './common.mjs';
const NODE_ENV =
process.env.NODE_ENV === 'development' ? 'development' : 'production';
@ -18,20 +15,10 @@ if (process.platform === 'win32') {
async function buildLayers() {
const common = config();
console.log('Build plugin infra');
spawnSync('yarn', ['build'], {
stdio: 'inherit',
cwd: resolve(rootDir, './packages/plugin-infra'),
});
console.log('Build plugins');
await import('./plugins/build-plugins.mjs');
await esbuild.build(common.workers);
await esbuild.build({
...common.layers,
define: {
...common.define,
'process.env.NODE_ENV': `"${NODE_ENV}"`,
'process.env.BUILD_TYPE': `"${process.env.BUILD_TYPE || 'stable'}"`,
},

View File

@ -15,16 +15,9 @@ const DEV_SERVER_URL = process.env.DEV_SERVER_URL;
/** @type 'production' | 'development'' */
const mode = (process.env.NODE_ENV = process.env.NODE_ENV || 'development');
// List of env that will be replaced by esbuild
const ENV_MACROS = ['AFFINE_GOOGLE_CLIENT_ID', 'AFFINE_GOOGLE_CLIENT_SECRET'];
/** @return {{layers: import('esbuild').BuildOptions, workers: import('esbuild').BuildOptions}} */
export const config = () => {
const define = Object.fromEntries([
...ENV_MACROS.map(key => [
'process.env.' + key,
JSON.stringify(process.env[key] ?? ''),
]),
['process.env.NODE_ENV', `"${mode}"`],
['process.env.USE_WORKER', '"true"'],
]);

View File

@ -1,13 +1,12 @@
/* eslint-disable no-async-promise-executor */
import { spawn } from 'node:child_process';
import { readFileSync } from 'node:fs';
import path, { resolve } from 'node:path';
import path from 'node:path';
import electronPath from 'electron';
import * as esbuild from 'esbuild';
import which from 'which';
import { config, electronDir, rootDir } from './common.mjs';
import { config, electronDir } from './common.mjs';
// this means we don't spawn electron windows, mainly for testing
const watchMode = process.argv.includes('--watch');
@ -68,14 +67,6 @@ function spawnOrReloadElectron() {
}
const common = config();
const yarnPath = which.sync('yarn');
async function watchPlugins() {
spawn(yarnPath, ['dev'], {
stdio: 'inherit',
cwd: resolve(rootDir, './packages/plugin-infra'),
});
await import('./plugins/dev-plugins.mjs');
}
async function watchLayers() {
return new Promise(async resolve => {
@ -134,7 +125,6 @@ async function watchWorkers() {
}
async function main() {
await watchPlugins();
await watchLayers();
await watchWorkers();

View File

@ -9,5 +9,5 @@
"allowSyntheticDefaultImports": true,
"noEmit": false
},
"include": ["./scripts"]
"include": ["./scripts", "esbuild.main.config.ts", "esbuild.plugin.config.ts"]
}

View File

@ -97,7 +97,7 @@
"dependsOn": ["build"]
},
"dev": {
"dependsOn": ["^build"]
"dependsOn": ["^dev"]
},
"e2e:coverage": {
"dependsOn": ["^build"]

View File

@ -17,10 +17,10 @@
"dev": "dev-web",
"dev:electron": "yarn workspace @affine/electron dev:app",
"dev:plugins": "./apps/electron/scripts/plugins/dev-plugins.mjs",
"build": "nx build @affine/web",
"build:infra": "yarn workspace @toeverything/plugin-infra build && yarn workspace @toeverything/infra build",
"build:storybook": "nx build @affine/storybook",
"build:plugins": "./apps/electron/scripts/plugins/build-plugins.mjs",
"build": "yarn nx build @affine/web",
"build:electron": "yarn nx build @affine/electron",
"build:infra": "yarn nx run-many -t build -p plugin-infra infra",
"build:storybook": "yarn nx build @affine/storybook",
"start:web": "yarn workspace @affine/web start",
"start:web-static": "yarn exec serve apps/web/out -l 8080",
"start:storybook": "yarn exec serve apps/storybook/storybook-static -l 6006",

View File

@ -8,7 +8,8 @@
"./*": "./src/components/*/index.tsx"
},
"scripts": {
"build": "yarn workspace @affine/i18n build"
"build": "yarn workspace @affine/i18n build",
"dev": "yarn workspace @affine/i18n dev"
},
"peerDependencies": {
"@blocksuite/blocks": "*",

12
packages/i18n/dev.mjs Normal file
View File

@ -0,0 +1,12 @@
import { runCli } from '@magic-works/i18n-codegen';
import { fileURLToPath } from 'url';
runCli(
{
config: fileURLToPath(new URL('../../.i18n-codegen.json', import.meta.url)),
watch: true,
},
error => {
console.error(error);
}
);

View File

@ -16,6 +16,7 @@
},
"scripts": {
"build": "node build.mjs",
"dev": "node dev.mjs",
"sync-languages": "NODE_OPTIONS=--experimental-fetch ts-node-esm src/scripts/sync.ts",
"sync-languages:check": "yarn run sync-languages --check",
"download-resources": "NODE_OPTIONS=--experimental-fetch ts-node-esm src/scripts/download.ts"

View File

@ -7,6 +7,10 @@
".": "./src/index.ts",
"./server": "./src/server.ts"
},
"scripts": {
"build": "node ./scripts/build.mjs",
"dev": "node ./scripts/dev.mjs"
},
"dependencies": {
"@affine/component": "workspace:*",
"@toeverything/plugin-infra": "workspace:*",

View File

@ -1,7 +1,7 @@
import { resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
export const rootDir = fileURLToPath(new URL('../../../..', import.meta.url));
export const rootDir = fileURLToPath(new URL('../../..', import.meta.url));
export const electronOutputDir = resolve(
rootDir,
'apps',

189
yarn.lock
View File

@ -50,7 +50,7 @@ __metadata:
languageName: unknown
linkType: soft
"@affine/bookmark-block@workspace:plugins/bookmark-block":
"@affine/bookmark-block@workspace:*, @affine/bookmark-block@workspace:plugins/bookmark-block":
version: 0.0.0-use.local
resolution: "@affine/bookmark-block@workspace:plugins/bookmark-block"
dependencies:
@ -207,6 +207,7 @@ __metadata:
resolution: "@affine/electron@workspace:apps/electron"
dependencies:
"@affine-test/kit": "workspace:*"
"@affine/bookmark-block": "workspace:*"
"@affine/native": "workspace:*"
"@blocksuite/blocks": 0.0.0-20230629103121-76e6587d-nightly
"@blocksuite/editor": 0.0.0-20230629103121-76e6587d-nightly
@ -232,7 +233,7 @@ __metadata:
electron-squirrel-startup: 1.0.0
electron-updater: ^5.3.0
electron-window-state: ^5.0.3
esbuild: ^0.18.9
esbuild: ^0.18.10
fs-extra: ^11.1.1
jotai: ^2.2.1
link-preview-js: ^3.0.4
@ -4848,9 +4849,9 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/android-arm64@npm:0.18.9":
version: 0.18.9
resolution: "@esbuild/android-arm64@npm:0.18.9"
"@esbuild/android-arm64@npm:0.18.10":
version: 0.18.10
resolution: "@esbuild/android-arm64@npm:0.18.10"
conditions: os=android & cpu=arm64
languageName: node
linkType: hard
@ -4869,9 +4870,9 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/android-arm@npm:0.18.9":
version: 0.18.9
resolution: "@esbuild/android-arm@npm:0.18.9"
"@esbuild/android-arm@npm:0.18.10":
version: 0.18.10
resolution: "@esbuild/android-arm@npm:0.18.10"
conditions: os=android & cpu=arm
languageName: node
linkType: hard
@ -4890,9 +4891,9 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/android-x64@npm:0.18.9":
version: 0.18.9
resolution: "@esbuild/android-x64@npm:0.18.9"
"@esbuild/android-x64@npm:0.18.10":
version: 0.18.10
resolution: "@esbuild/android-x64@npm:0.18.10"
conditions: os=android & cpu=x64
languageName: node
linkType: hard
@ -4911,9 +4912,9 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/darwin-arm64@npm:0.18.9":
version: 0.18.9
resolution: "@esbuild/darwin-arm64@npm:0.18.9"
"@esbuild/darwin-arm64@npm:0.18.10":
version: 0.18.10
resolution: "@esbuild/darwin-arm64@npm:0.18.10"
conditions: os=darwin & cpu=arm64
languageName: node
linkType: hard
@ -4932,9 +4933,9 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/darwin-x64@npm:0.18.9":
version: 0.18.9
resolution: "@esbuild/darwin-x64@npm:0.18.9"
"@esbuild/darwin-x64@npm:0.18.10":
version: 0.18.10
resolution: "@esbuild/darwin-x64@npm:0.18.10"
conditions: os=darwin & cpu=x64
languageName: node
linkType: hard
@ -4953,9 +4954,9 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/freebsd-arm64@npm:0.18.9":
version: 0.18.9
resolution: "@esbuild/freebsd-arm64@npm:0.18.9"
"@esbuild/freebsd-arm64@npm:0.18.10":
version: 0.18.10
resolution: "@esbuild/freebsd-arm64@npm:0.18.10"
conditions: os=freebsd & cpu=arm64
languageName: node
linkType: hard
@ -4974,9 +4975,9 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/freebsd-x64@npm:0.18.9":
version: 0.18.9
resolution: "@esbuild/freebsd-x64@npm:0.18.9"
"@esbuild/freebsd-x64@npm:0.18.10":
version: 0.18.10
resolution: "@esbuild/freebsd-x64@npm:0.18.10"
conditions: os=freebsd & cpu=x64
languageName: node
linkType: hard
@ -4995,9 +4996,9 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/linux-arm64@npm:0.18.9":
version: 0.18.9
resolution: "@esbuild/linux-arm64@npm:0.18.9"
"@esbuild/linux-arm64@npm:0.18.10":
version: 0.18.10
resolution: "@esbuild/linux-arm64@npm:0.18.10"
conditions: os=linux & cpu=arm64
languageName: node
linkType: hard
@ -5016,9 +5017,9 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/linux-arm@npm:0.18.9":
version: 0.18.9
resolution: "@esbuild/linux-arm@npm:0.18.9"
"@esbuild/linux-arm@npm:0.18.10":
version: 0.18.10
resolution: "@esbuild/linux-arm@npm:0.18.10"
conditions: os=linux & cpu=arm
languageName: node
linkType: hard
@ -5037,9 +5038,9 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/linux-ia32@npm:0.18.9":
version: 0.18.9
resolution: "@esbuild/linux-ia32@npm:0.18.9"
"@esbuild/linux-ia32@npm:0.18.10":
version: 0.18.10
resolution: "@esbuild/linux-ia32@npm:0.18.10"
conditions: os=linux & cpu=ia32
languageName: node
linkType: hard
@ -5058,9 +5059,9 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/linux-loong64@npm:0.18.9":
version: 0.18.9
resolution: "@esbuild/linux-loong64@npm:0.18.9"
"@esbuild/linux-loong64@npm:0.18.10":
version: 0.18.10
resolution: "@esbuild/linux-loong64@npm:0.18.10"
conditions: os=linux & cpu=loong64
languageName: node
linkType: hard
@ -5079,9 +5080,9 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/linux-mips64el@npm:0.18.9":
version: 0.18.9
resolution: "@esbuild/linux-mips64el@npm:0.18.9"
"@esbuild/linux-mips64el@npm:0.18.10":
version: 0.18.10
resolution: "@esbuild/linux-mips64el@npm:0.18.10"
conditions: os=linux & cpu=mips64el
languageName: node
linkType: hard
@ -5100,9 +5101,9 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/linux-ppc64@npm:0.18.9":
version: 0.18.9
resolution: "@esbuild/linux-ppc64@npm:0.18.9"
"@esbuild/linux-ppc64@npm:0.18.10":
version: 0.18.10
resolution: "@esbuild/linux-ppc64@npm:0.18.10"
conditions: os=linux & cpu=ppc64
languageName: node
linkType: hard
@ -5121,9 +5122,9 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/linux-riscv64@npm:0.18.9":
version: 0.18.9
resolution: "@esbuild/linux-riscv64@npm:0.18.9"
"@esbuild/linux-riscv64@npm:0.18.10":
version: 0.18.10
resolution: "@esbuild/linux-riscv64@npm:0.18.10"
conditions: os=linux & cpu=riscv64
languageName: node
linkType: hard
@ -5142,9 +5143,9 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/linux-s390x@npm:0.18.9":
version: 0.18.9
resolution: "@esbuild/linux-s390x@npm:0.18.9"
"@esbuild/linux-s390x@npm:0.18.10":
version: 0.18.10
resolution: "@esbuild/linux-s390x@npm:0.18.10"
conditions: os=linux & cpu=s390x
languageName: node
linkType: hard
@ -5163,9 +5164,9 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/linux-x64@npm:0.18.9":
version: 0.18.9
resolution: "@esbuild/linux-x64@npm:0.18.9"
"@esbuild/linux-x64@npm:0.18.10":
version: 0.18.10
resolution: "@esbuild/linux-x64@npm:0.18.10"
conditions: os=linux & cpu=x64
languageName: node
linkType: hard
@ -5184,9 +5185,9 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/netbsd-x64@npm:0.18.9":
version: 0.18.9
resolution: "@esbuild/netbsd-x64@npm:0.18.9"
"@esbuild/netbsd-x64@npm:0.18.10":
version: 0.18.10
resolution: "@esbuild/netbsd-x64@npm:0.18.10"
conditions: os=netbsd & cpu=x64
languageName: node
linkType: hard
@ -5205,9 +5206,9 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/openbsd-x64@npm:0.18.9":
version: 0.18.9
resolution: "@esbuild/openbsd-x64@npm:0.18.9"
"@esbuild/openbsd-x64@npm:0.18.10":
version: 0.18.10
resolution: "@esbuild/openbsd-x64@npm:0.18.10"
conditions: os=openbsd & cpu=x64
languageName: node
linkType: hard
@ -5226,9 +5227,9 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/sunos-x64@npm:0.18.9":
version: 0.18.9
resolution: "@esbuild/sunos-x64@npm:0.18.9"
"@esbuild/sunos-x64@npm:0.18.10":
version: 0.18.10
resolution: "@esbuild/sunos-x64@npm:0.18.10"
conditions: os=sunos & cpu=x64
languageName: node
linkType: hard
@ -5247,9 +5248,9 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/win32-arm64@npm:0.18.9":
version: 0.18.9
resolution: "@esbuild/win32-arm64@npm:0.18.9"
"@esbuild/win32-arm64@npm:0.18.10":
version: 0.18.10
resolution: "@esbuild/win32-arm64@npm:0.18.10"
conditions: os=win32 & cpu=arm64
languageName: node
linkType: hard
@ -5268,9 +5269,9 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/win32-ia32@npm:0.18.9":
version: 0.18.9
resolution: "@esbuild/win32-ia32@npm:0.18.9"
"@esbuild/win32-ia32@npm:0.18.10":
version: 0.18.10
resolution: "@esbuild/win32-ia32@npm:0.18.10"
conditions: os=win32 & cpu=ia32
languageName: node
linkType: hard
@ -5289,9 +5290,9 @@ __metadata:
languageName: node
linkType: hard
"@esbuild/win32-x64@npm:0.18.9":
version: 0.18.9
resolution: "@esbuild/win32-x64@npm:0.18.9"
"@esbuild/win32-x64@npm:0.18.10":
version: 0.18.10
resolution: "@esbuild/win32-x64@npm:0.18.10"
conditions: os=win32 & cpu=x64
languageName: node
linkType: hard
@ -17550,32 +17551,32 @@ __metadata:
languageName: node
linkType: hard
"esbuild@npm:^0.18.9":
version: 0.18.9
resolution: "esbuild@npm:0.18.9"
"esbuild@npm:^0.18.10":
version: 0.18.10
resolution: "esbuild@npm:0.18.10"
dependencies:
"@esbuild/android-arm": 0.18.9
"@esbuild/android-arm64": 0.18.9
"@esbuild/android-x64": 0.18.9
"@esbuild/darwin-arm64": 0.18.9
"@esbuild/darwin-x64": 0.18.9
"@esbuild/freebsd-arm64": 0.18.9
"@esbuild/freebsd-x64": 0.18.9
"@esbuild/linux-arm": 0.18.9
"@esbuild/linux-arm64": 0.18.9
"@esbuild/linux-ia32": 0.18.9
"@esbuild/linux-loong64": 0.18.9
"@esbuild/linux-mips64el": 0.18.9
"@esbuild/linux-ppc64": 0.18.9
"@esbuild/linux-riscv64": 0.18.9
"@esbuild/linux-s390x": 0.18.9
"@esbuild/linux-x64": 0.18.9
"@esbuild/netbsd-x64": 0.18.9
"@esbuild/openbsd-x64": 0.18.9
"@esbuild/sunos-x64": 0.18.9
"@esbuild/win32-arm64": 0.18.9
"@esbuild/win32-ia32": 0.18.9
"@esbuild/win32-x64": 0.18.9
"@esbuild/android-arm": 0.18.10
"@esbuild/android-arm64": 0.18.10
"@esbuild/android-x64": 0.18.10
"@esbuild/darwin-arm64": 0.18.10
"@esbuild/darwin-x64": 0.18.10
"@esbuild/freebsd-arm64": 0.18.10
"@esbuild/freebsd-x64": 0.18.10
"@esbuild/linux-arm": 0.18.10
"@esbuild/linux-arm64": 0.18.10
"@esbuild/linux-ia32": 0.18.10
"@esbuild/linux-loong64": 0.18.10
"@esbuild/linux-mips64el": 0.18.10
"@esbuild/linux-ppc64": 0.18.10
"@esbuild/linux-riscv64": 0.18.10
"@esbuild/linux-s390x": 0.18.10
"@esbuild/linux-x64": 0.18.10
"@esbuild/netbsd-x64": 0.18.10
"@esbuild/openbsd-x64": 0.18.10
"@esbuild/sunos-x64": 0.18.10
"@esbuild/win32-arm64": 0.18.10
"@esbuild/win32-ia32": 0.18.10
"@esbuild/win32-x64": 0.18.10
dependenciesMeta:
"@esbuild/android-arm":
optional: true
@ -17623,7 +17624,7 @@ __metadata:
optional: true
bin:
esbuild: bin/esbuild
checksum: 2580d38d2e90dd094fd30e922ae68cead86976ac339a6481a4d07d2c3909548a4aa297724fafca67245ce9e8b4f2cd06f6be71c2d2ae88dce435c0a0d50db5fc
checksum: 895c9457579dda46cc0f992c13d660c27d55f03c063f3da042de1b0ac60a24df9d33c400ba97e2fd5c454914a23edfc95444690301b5a07b0ec1901fa699e51c
languageName: node
linkType: hard