mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 13:25:12 +00:00
feat: plugin system with isolated bundles (#2660)
(cherry picked from commit 94d20f1bdc)
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
/* eslint-disable no-async-promise-executor */
|
||||
import { spawn } from 'node:child_process';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import path, { resolve } from 'node:path';
|
||||
|
||||
import electronPath from 'electron';
|
||||
import * as esbuild from 'esbuild';
|
||||
|
||||
import { config, root } from './common.mjs';
|
||||
import { config, electronDir, rootDir } from './common.mjs';
|
||||
|
||||
// this means we don't spawn electron windows, mainly for testing
|
||||
const watchMode = process.argv.includes('--watch');
|
||||
@@ -21,7 +21,10 @@ const stderrFilterPatterns = [
|
||||
|
||||
// these are set before calling `config`, so we have a chance to override them
|
||||
try {
|
||||
const devJson = readFileSync(path.resolve(root, './dev.json'), 'utf-8');
|
||||
const devJson = readFileSync(
|
||||
path.resolve(electronDir, './dev.json'),
|
||||
'utf-8'
|
||||
);
|
||||
const devEnv = JSON.parse(devJson);
|
||||
Object.assign(process.env, devEnv);
|
||||
} catch (err) {
|
||||
@@ -65,7 +68,18 @@ function spawnOrReloadElectron() {
|
||||
|
||||
const common = config();
|
||||
|
||||
function watchPreload() {
|
||||
function watchPlugins() {
|
||||
const cp = spawn('yarn', ['dev'], {
|
||||
cwd: resolve(rootDir, './plugins/bookmark-block'),
|
||||
stdio: 'inherit',
|
||||
});
|
||||
|
||||
process.once('beforeExit', () => {
|
||||
cp.kill();
|
||||
});
|
||||
}
|
||||
|
||||
async function watchPreload() {
|
||||
return new Promise(async resolve => {
|
||||
let initialBuild = false;
|
||||
const preloadBuild = await esbuild.context({
|
||||
@@ -122,6 +136,7 @@ async function watchMain() {
|
||||
}
|
||||
|
||||
async function main() {
|
||||
watchPlugins();
|
||||
await watchMain();
|
||||
await watchPreload();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user