mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-18 18:41:52 +08:00
chore(server): set script flavor instead of NODE_ENV (#10121)
This commit is contained in:
@@ -15,8 +15,8 @@
|
|||||||
"test:copilot": "ava \"src/__tests__/**/copilot-*.spec.ts\"",
|
"test:copilot": "ava \"src/__tests__/**/copilot-*.spec.ts\"",
|
||||||
"test:coverage": "c8 ava --concurrency 1 --serial",
|
"test:coverage": "c8 ava --concurrency 1 --serial",
|
||||||
"test:copilot:coverage": "c8 ava --timeout=5m \"src/__tests__/**/copilot-*.spec.ts\"",
|
"test:copilot:coverage": "c8 ava --timeout=5m \"src/__tests__/**/copilot-*.spec.ts\"",
|
||||||
"data-migration": "cross-env NODE_ENV=script r ./src/data/index.ts",
|
"data-migration": "cross-env NODE_ENV=development r ./src/data/index.ts",
|
||||||
"predeploy": "yarn prisma migrate deploy && NODE_ENV=script node --import ./scripts/register.js ./dist/data/index.js run",
|
"predeploy": "yarn prisma migrate deploy && node --import ./scripts/register.js ./dist/data/index.js run",
|
||||||
"postinstall": "prisma generate"
|
"postinstall": "prisma generate"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ test.before('start app', async t => {
|
|||||||
sync: false,
|
sync: false,
|
||||||
renderer: false,
|
renderer: false,
|
||||||
doc: true,
|
doc: true,
|
||||||
|
script: false,
|
||||||
} satisfies typeof AFFiNE.flavor;
|
} satisfies typeof AFFiNE.flavor;
|
||||||
const app = await createTestingApp({
|
const app = await createTestingApp({
|
||||||
imports: [buildAppModule()],
|
imports: [buildAppModule()],
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ test.before('start app', async t => {
|
|||||||
sync: false,
|
sync: false,
|
||||||
renderer: false,
|
renderer: false,
|
||||||
doc: false,
|
doc: false,
|
||||||
|
script: false,
|
||||||
} satisfies typeof AFFiNE.flavor;
|
} satisfies typeof AFFiNE.flavor;
|
||||||
const app = await createTestingApp({
|
const app = await createTestingApp({
|
||||||
imports: [buildAppModule()],
|
imports: [buildAppModule()],
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ test.before('start app', async t => {
|
|||||||
sync: false,
|
sync: false,
|
||||||
renderer: true,
|
renderer: true,
|
||||||
doc: false,
|
doc: false,
|
||||||
|
script: false,
|
||||||
} satisfies typeof AFFiNE.flavor;
|
} satisfies typeof AFFiNE.flavor;
|
||||||
const app = await createTestingApp({
|
const app = await createTestingApp({
|
||||||
imports: [buildAppModule()],
|
imports: [buildAppModule()],
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ test.before('start app', async t => {
|
|||||||
sync: true,
|
sync: true,
|
||||||
renderer: false,
|
renderer: false,
|
||||||
doc: false,
|
doc: false,
|
||||||
|
script: false,
|
||||||
} satisfies typeof AFFiNE.flavor;
|
} satisfies typeof AFFiNE.flavor;
|
||||||
const app = await createTestingApp({
|
const app = await createTestingApp({
|
||||||
imports: [buildAppModule()],
|
imports: [buildAppModule()],
|
||||||
|
|||||||
@@ -2,9 +2,16 @@ import type { LeafPaths } from '../utils/types';
|
|||||||
import { AppStartupConfig } from './types';
|
import { AppStartupConfig } from './types';
|
||||||
|
|
||||||
export type EnvConfigType = 'string' | 'int' | 'float' | 'boolean';
|
export type EnvConfigType = 'string' | 'int' | 'float' | 'boolean';
|
||||||
export type ServerFlavor = 'allinone' | 'graphql' | 'sync' | 'renderer' | 'doc';
|
export type ServerFlavor =
|
||||||
|
| 'allinone'
|
||||||
|
| 'graphql'
|
||||||
|
| 'sync'
|
||||||
|
| 'renderer'
|
||||||
|
| 'doc'
|
||||||
|
| 'script';
|
||||||
|
|
||||||
export type AFFINE_ENV = 'dev' | 'beta' | 'production';
|
export type AFFINE_ENV = 'dev' | 'beta' | 'production';
|
||||||
export type NODE_ENV = 'development' | 'test' | 'production' | 'script';
|
export type NODE_ENV = 'development' | 'test' | 'production';
|
||||||
|
|
||||||
export enum DeploymentType {
|
export enum DeploymentType {
|
||||||
Affine = 'affine',
|
Affine = 'affine',
|
||||||
@@ -29,7 +36,6 @@ export interface PreDefinedAFFiNEConfig {
|
|||||||
prod: boolean;
|
prod: boolean;
|
||||||
dev: boolean;
|
dev: boolean;
|
||||||
test: boolean;
|
test: boolean;
|
||||||
script: boolean;
|
|
||||||
};
|
};
|
||||||
readonly deploy: boolean;
|
readonly deploy: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,15 @@ import {
|
|||||||
import { readEnv } from './env';
|
import { readEnv } from './env';
|
||||||
import { defaultStartupConfig } from './register';
|
import { defaultStartupConfig } from './register';
|
||||||
|
|
||||||
|
function expectFlavor(flavor: ServerFlavor, expected: ServerFlavor) {
|
||||||
|
return flavor === expected || flavor === 'allinone';
|
||||||
|
}
|
||||||
|
|
||||||
function getPredefinedAFFiNEConfig(): PreDefinedAFFiNEConfig {
|
function getPredefinedAFFiNEConfig(): PreDefinedAFFiNEConfig {
|
||||||
const NODE_ENV = readEnv<NODE_ENV>('NODE_ENV', 'production', [
|
const NODE_ENV = readEnv<NODE_ENV>('NODE_ENV', 'production', [
|
||||||
'development',
|
'development',
|
||||||
'test',
|
'test',
|
||||||
'production',
|
'production',
|
||||||
'script',
|
|
||||||
]);
|
]);
|
||||||
const AFFINE_ENV = readEnv<AFFINE_ENV>('AFFINE_ENV', 'production', [
|
const AFFINE_ENV = readEnv<AFFINE_ENV>('AFFINE_ENV', 'production', [
|
||||||
'dev',
|
'dev',
|
||||||
@@ -31,6 +34,7 @@ function getPredefinedAFFiNEConfig(): PreDefinedAFFiNEConfig {
|
|||||||
'sync',
|
'sync',
|
||||||
'renderer',
|
'renderer',
|
||||||
'doc',
|
'doc',
|
||||||
|
'script',
|
||||||
]);
|
]);
|
||||||
const deploymentType = readEnv<DeploymentType>(
|
const deploymentType = readEnv<DeploymentType>(
|
||||||
'DEPLOYMENT_TYPE',
|
'DEPLOYMENT_TYPE',
|
||||||
@@ -49,7 +53,6 @@ function getPredefinedAFFiNEConfig(): PreDefinedAFFiNEConfig {
|
|||||||
prod: NODE_ENV === 'production',
|
prod: NODE_ENV === 'production',
|
||||||
dev: NODE_ENV === 'development',
|
dev: NODE_ENV === 'development',
|
||||||
test: NODE_ENV === 'test',
|
test: NODE_ENV === 'test',
|
||||||
script: NODE_ENV === 'script',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -64,10 +67,11 @@ function getPredefinedAFFiNEConfig(): PreDefinedAFFiNEConfig {
|
|||||||
flavor: {
|
flavor: {
|
||||||
type: flavor,
|
type: flavor,
|
||||||
allinone: flavor === 'allinone',
|
allinone: flavor === 'allinone',
|
||||||
graphql: flavor === 'graphql' || flavor === 'allinone',
|
graphql: expectFlavor(flavor, 'graphql'),
|
||||||
sync: flavor === 'sync' || flavor === 'allinone',
|
sync: expectFlavor(flavor, 'sync'),
|
||||||
renderer: flavor === 'renderer' || flavor === 'allinone',
|
renderer: expectFlavor(flavor, 'renderer'),
|
||||||
doc: flavor === 'doc' || flavor === 'allinone',
|
doc: expectFlavor(flavor, 'doc'),
|
||||||
|
script: expectFlavor(flavor, 'script'),
|
||||||
},
|
},
|
||||||
affine,
|
affine,
|
||||||
node,
|
node,
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import '../prelude';
|
|
||||||
|
|
||||||
import { Logger } from '@nestjs/common';
|
import { Logger } from '@nestjs/common';
|
||||||
import { CommandFactory } from 'nest-commander';
|
import { CommandFactory } from 'nest-commander';
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
AFFiNE.metrics.enabled = false;
|
process.env.SERVER_FLAVOR = 'script';
|
||||||
AFFiNE.doc.manager.enableUpdateAutoMerging = false;
|
|
||||||
|
await import('../prelude');
|
||||||
const { CliAppModule } = await import('./app');
|
const { CliAppModule } = await import('./app');
|
||||||
await CommandFactory.run(CliAppModule, new Logger()).catch(e => {
|
await CommandFactory.run(CliAppModule, new Logger()).catch(e => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user