mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
refactor: use esbuild instead of vite (#2672)
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
#!/usr/bin/env zx
|
||||
import 'zx/globals';
|
||||
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { resolve } from 'node:path';
|
||||
|
||||
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';
|
||||
@@ -20,11 +17,8 @@ async function buildLayers() {
|
||||
const common = config();
|
||||
await esbuild.build(common.preload);
|
||||
|
||||
console.log('build plugins');
|
||||
spawnSync('yarn', ['build'], {
|
||||
cwd: resolve(rootDir, './plugins/bookmark-block'),
|
||||
stdio: 'inherit',
|
||||
});
|
||||
console.log('Build plugins');
|
||||
await import('./plugins/build-plugins.mjs');
|
||||
|
||||
await esbuild.build({
|
||||
...common.main,
|
||||
|
||||
@@ -1,12 +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 { 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,15 +68,8 @@ function spawnOrReloadElectron() {
|
||||
|
||||
const common = config();
|
||||
|
||||
function watchPlugins() {
|
||||
const cp = spawn('yarn', ['dev'], {
|
||||
cwd: resolve(rootDir, './plugins/bookmark-block'),
|
||||
stdio: 'inherit',
|
||||
});
|
||||
|
||||
process.once('beforeExit', () => {
|
||||
cp.kill();
|
||||
});
|
||||
async function watchPlugins() {
|
||||
await import('./plugins/dev-plugins.mjs');
|
||||
}
|
||||
|
||||
async function watchPreload() {
|
||||
@@ -136,7 +129,7 @@ async function watchMain() {
|
||||
}
|
||||
|
||||
async function main() {
|
||||
watchPlugins();
|
||||
await watchPlugins();
|
||||
await watchMain();
|
||||
await watchPreload();
|
||||
|
||||
|
||||
9
apps/electron/scripts/plugins/build-plugins.mjs
Executable file
9
apps/electron/scripts/plugins/build-plugins.mjs
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env node
|
||||
import { build } from 'esbuild';
|
||||
|
||||
import { definePluginServerConfig } from './utils.mjs';
|
||||
|
||||
await build({
|
||||
...definePluginServerConfig('bookmark-block'),
|
||||
external: ['cheerio', 'electron'],
|
||||
});
|
||||
11
apps/electron/scripts/plugins/dev-plugins.mjs
Executable file
11
apps/electron/scripts/plugins/dev-plugins.mjs
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env node
|
||||
import { context } from 'esbuild';
|
||||
|
||||
import { definePluginServerConfig } from './utils.mjs';
|
||||
|
||||
const plugin = await context({
|
||||
...definePluginServerConfig('bookmark-block'),
|
||||
external: ['cheerio', 'electron'],
|
||||
});
|
||||
|
||||
await plugin.watch();
|
||||
29
apps/electron/scripts/plugins/utils.mjs
Normal file
29
apps/electron/scripts/plugins/utils.mjs
Normal file
@@ -0,0 +1,29 @@
|
||||
import { resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
export const rootDir = fileURLToPath(new URL('../../../..', import.meta.url));
|
||||
export const electronOutputDir = resolve(
|
||||
rootDir,
|
||||
'apps',
|
||||
'electron',
|
||||
'dist',
|
||||
'plugins'
|
||||
);
|
||||
export const pluginDir = resolve(rootDir, 'plugins');
|
||||
|
||||
/**
|
||||
*
|
||||
* @param pluginDirName {string}
|
||||
* @return {import('esbuild').BuildOptions}
|
||||
*/
|
||||
export function definePluginServerConfig(pluginDirName) {
|
||||
const pluginRootDir = resolve(pluginDir, pluginDirName);
|
||||
const serverEntryFile = resolve(pluginRootDir, 'src/server.ts');
|
||||
const serverOutputDir = resolve(electronOutputDir, pluginDirName);
|
||||
return {
|
||||
entryPoints: [serverEntryFile],
|
||||
platform: 'node',
|
||||
outdir: serverOutputDir,
|
||||
bundle: true,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user