mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-24 22:09:08 +08:00
refactor(server): better selfhost deployment (#9036)
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
"@radix-ui/react-tooltip": "^1.1.1",
|
||||
"@sentry/react": "^8.9.0",
|
||||
"@tanstack/react-table": "^8.19.3",
|
||||
"@toeverything/infra": "workspace:*",
|
||||
"cmdk": "^1.0.0",
|
||||
"embla-carousel-react": "^8.1.5",
|
||||
"input-otp": "^1.2.4",
|
||||
|
||||
@@ -1,5 +1,20 @@
|
||||
import { Toaster } from '@affine/admin/components/ui/sonner';
|
||||
import {
|
||||
configureCloudModule,
|
||||
DefaultServerService,
|
||||
} from '@affine/core/modules/cloud';
|
||||
import { configureLocalStorageStateStorageImpls } from '@affine/core/modules/storage';
|
||||
import { configureUrlModule } from '@affine/core/modules/url';
|
||||
import { wrapCreateBrowserRouter } from '@sentry/react';
|
||||
import {
|
||||
configureGlobalContextModule,
|
||||
configureGlobalStorageModule,
|
||||
configureLifecycleModule,
|
||||
Framework,
|
||||
FrameworkRoot,
|
||||
FrameworkScope,
|
||||
LifecycleService,
|
||||
} from '@toeverything/infra';
|
||||
import { useEffect } from 'react';
|
||||
import {
|
||||
createBrowserRouter as reactRouterCreateBrowserRouter,
|
||||
@@ -109,18 +124,38 @@ export const router = _createBrowserRouter(
|
||||
}
|
||||
);
|
||||
|
||||
const framework = new Framework();
|
||||
configureLifecycleModule(framework);
|
||||
configureLocalStorageStateStorageImpls(framework);
|
||||
configureGlobalStorageModule(framework);
|
||||
configureGlobalContextModule(framework);
|
||||
configureUrlModule(framework);
|
||||
configureCloudModule(framework);
|
||||
const frameworkProvider = framework.provider();
|
||||
|
||||
// setup application lifecycle events, and emit application start event
|
||||
window.addEventListener('focus', () => {
|
||||
frameworkProvider.get(LifecycleService).applicationFocus();
|
||||
});
|
||||
frameworkProvider.get(LifecycleService).applicationStart();
|
||||
const serverService = frameworkProvider.get(DefaultServerService);
|
||||
|
||||
export const App = () => {
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<SWRConfig
|
||||
value={{
|
||||
revalidateOnFocus: false,
|
||||
revalidateOnMount: false,
|
||||
}}
|
||||
>
|
||||
<RouterProvider router={router} />
|
||||
</SWRConfig>
|
||||
<Toaster />
|
||||
</TooltipProvider>
|
||||
<FrameworkRoot framework={frameworkProvider}>
|
||||
<FrameworkScope scope={serverService.server.scope}>
|
||||
<TooltipProvider>
|
||||
<SWRConfig
|
||||
value={{
|
||||
revalidateOnFocus: false,
|
||||
revalidateOnMount: false,
|
||||
}}
|
||||
>
|
||||
<RouterProvider router={router} />
|
||||
</SWRConfig>
|
||||
<Toaster />
|
||||
</TooltipProvider>
|
||||
</FrameworkScope>
|
||||
</FrameworkRoot>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
"verbatimModuleSyntax": false,
|
||||
"jsx": "react-jsx"
|
||||
},
|
||||
"references": [{ "path": "../core" }, { "path": "../graphql" }],
|
||||
"references": [
|
||||
{ "path": "../core" },
|
||||
{ "path": "../graphql" },
|
||||
{ "path": "../../common/infra" }
|
||||
],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
import crypto from 'node:crypto';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
const filenamesMapping = {
|
||||
all: 'latest.yml',
|
||||
macos: 'latest-mac.yml',
|
||||
linux: 'latest-linux.yml',
|
||||
};
|
||||
|
||||
const releaseFiles = ['zip', 'exe', 'dmg', 'appimage', 'deb', 'flatpak'];
|
||||
|
||||
const generateYml = platform => {
|
||||
const yml = {
|
||||
version: process.env.RELEASE_VERSION ?? '0.0.0',
|
||||
files: [],
|
||||
};
|
||||
|
||||
const regex =
|
||||
// we involves all distribution files in one release file to enforce we handle auto updater correctly
|
||||
platform === 'all'
|
||||
? new RegExp(`.(${releaseFiles.join('|')})$`)
|
||||
: new RegExp(`.+-${platform}-.+.(${releaseFiles.join('|')})$`);
|
||||
|
||||
const files = fs.readdirSync(process.cwd()).filter(file => regex.test(file));
|
||||
const outputFileName = filenamesMapping[platform];
|
||||
|
||||
files.forEach(fileName => {
|
||||
const filePath = path.join(process.cwd(), './', fileName);
|
||||
try {
|
||||
const fileData = fs.readFileSync(filePath);
|
||||
const hash = crypto
|
||||
.createHash('sha512')
|
||||
.update(fileData)
|
||||
.digest('base64');
|
||||
const size = fs.statSync(filePath).size;
|
||||
|
||||
yml.files.push({
|
||||
url: fileName,
|
||||
sha512: hash,
|
||||
size: size,
|
||||
});
|
||||
} catch {}
|
||||
});
|
||||
yml.releaseDate = new Date().toISOString();
|
||||
|
||||
// NOTE(@forehalo): make sure old windows x64 won't fetch windows arm64 by default
|
||||
// maybe we need to separate arm64 builds to separated yml file `latest-arm64.yml`, `latest-linux-arm64.yml`
|
||||
// check https://github.com/electron-userland/electron-builder/blob/master/packages/electron-updater/src/providers/Provider.ts#L30
|
||||
// and packages/frontend/apps/electron/src/main/updater/affine-update-provider.ts#L100
|
||||
yml.files.sort(a => (a.url.includes('windows-arm64') ? 1 : -1));
|
||||
|
||||
const ymlStr =
|
||||
`version: ${yml.version}\n` +
|
||||
`files:\n` +
|
||||
yml.files
|
||||
.map(file => {
|
||||
return (
|
||||
` - url: ${file.url}\n` +
|
||||
` sha512: ${file.sha512}\n` +
|
||||
` size: ${file.size}\n`
|
||||
);
|
||||
})
|
||||
.join('') +
|
||||
`releaseDate: ${yml.releaseDate}\n`;
|
||||
|
||||
fs.writeFileSync(outputFileName, ymlStr);
|
||||
};
|
||||
|
||||
generateYml('macos');
|
||||
generateYml('linux');
|
||||
generateYml('all');
|
||||
@@ -9,7 +9,7 @@ import type { GraphQLError } from 'graphql';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import type { SWRConfiguration, SWRResponse } from 'swr';
|
||||
import useSWR from 'swr';
|
||||
import useSWRImutable from 'swr/immutable';
|
||||
import useSWRImmutable from 'swr/immutable';
|
||||
import useSWRInfinite from 'swr/infinite';
|
||||
|
||||
/**
|
||||
@@ -60,7 +60,7 @@ const createUseQuery =
|
||||
);
|
||||
const graphqlService = useService(GraphQLService);
|
||||
|
||||
const useSWRFn = immutable ? useSWRImutable : useSWR;
|
||||
const useSWRFn = immutable ? useSWRImmutable : useSWR;
|
||||
return useSWRFn(
|
||||
options ? () => ['cloud', options.query.id, options.variables] : null,
|
||||
options ? () => graphqlService.gql(options) : null,
|
||||
|
||||
Reference in New Issue
Block a user