mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-02 02:00:49 +08:00
chore: bump deps (#14777)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Migration and config commands now feature interactive prompts for required inputs. * **Bug Fixes** * Enhanced error handling in CLI operations. * **Chores** * Updated GraphQL Code Generator toolchain to v6. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
"@fal-ai/serverless-client": "^0.15.0",
|
||||
"@google-cloud/opentelemetry-cloud-trace-exporter": "^3.0.0",
|
||||
"@google-cloud/opentelemetry-resource-util": "^3.0.0",
|
||||
"@inquirer/prompts": "^7.10.1",
|
||||
"@nestjs-cls/transactional": "^3.2.0",
|
||||
"@nestjs-cls/transactional-adapter-prisma": "^1.3.4",
|
||||
"@nestjs/apollo": "^13.0.4",
|
||||
@@ -65,6 +66,7 @@
|
||||
"@react-email/components": "^0.5.7",
|
||||
"@socket.io/redis-adapter": "^8.3.0",
|
||||
"bullmq": "^5.40.2",
|
||||
"commander": "^13.1.0",
|
||||
"cookie-parser": "^1.4.7",
|
||||
"cross-env": "^10.1.0",
|
||||
"date-fns": "^4.0.0",
|
||||
@@ -88,7 +90,6 @@
|
||||
"lodash-es": "^4.17.23",
|
||||
"mustache": "^4.2.0",
|
||||
"nanoid": "^5.1.6",
|
||||
"nest-commander": "^3.15.0",
|
||||
"nest-winston": "^1.9.7",
|
||||
"nestjs-cls": "^6.0.0",
|
||||
"nodemailer": "^8.0.4",
|
||||
|
||||
@@ -1,12 +1,102 @@
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { CommandFactory } from 'nest-commander';
|
||||
import { basename } from 'node:path';
|
||||
|
||||
import { type INestApplicationContext, Logger } from '@nestjs/common';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { Command, CommanderError } from 'commander';
|
||||
|
||||
import { CliAppModule } from './data/app';
|
||||
import { CreateCommand } from './data/commands/create';
|
||||
import { ImportConfigCommand } from './data/commands/import';
|
||||
import { RevertCommand, RunCommand } from './data/commands/run';
|
||||
|
||||
function getProgramName() {
|
||||
return process.env.npm_lifecycle_event ?? basename(process.argv[1] ?? 'cli');
|
||||
}
|
||||
|
||||
async function withCliApp(
|
||||
logger: Logger,
|
||||
callback: (app: INestApplicationContext) => Promise<void>
|
||||
) {
|
||||
const app = await NestFactory.createApplicationContext(CliAppModule, {
|
||||
logger,
|
||||
});
|
||||
|
||||
try {
|
||||
await callback(app);
|
||||
} finally {
|
||||
await app.close();
|
||||
}
|
||||
}
|
||||
|
||||
function buildProgram(logger: Logger) {
|
||||
const program = new Command();
|
||||
|
||||
program
|
||||
.name(getProgramName())
|
||||
.description('AFFiNE server CLI')
|
||||
.showHelpAfterError()
|
||||
.showSuggestionAfterError();
|
||||
|
||||
program
|
||||
.command('create [name]')
|
||||
.description('create a data migration script')
|
||||
.action(async name => {
|
||||
await withCliApp(logger, async app => {
|
||||
await app.get(CreateCommand).execute(name);
|
||||
});
|
||||
});
|
||||
|
||||
program
|
||||
.command('run')
|
||||
.description('Run all pending data migrations')
|
||||
.action(async () => {
|
||||
await withCliApp(logger, async app => {
|
||||
await app.get(RunCommand).execute();
|
||||
});
|
||||
});
|
||||
|
||||
program
|
||||
.command('revert [name]')
|
||||
.description('Revert one data migration with given name')
|
||||
.action(async name => {
|
||||
await withCliApp(logger, async app => {
|
||||
await app.get(RevertCommand).execute(name);
|
||||
});
|
||||
});
|
||||
|
||||
program
|
||||
.command('import-config [path]')
|
||||
.description('import config from a file')
|
||||
.action(async path => {
|
||||
await withCliApp(logger, async app => {
|
||||
await app.get(ImportConfigCommand).execute(path);
|
||||
});
|
||||
});
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
export async function run() {
|
||||
await CommandFactory.run(CliAppModule, new Logger()).catch(e => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
process.exit(0);
|
||||
const logger = new Logger('Cli');
|
||||
|
||||
try {
|
||||
const program = buildProgram(logger);
|
||||
program.exitOverride();
|
||||
|
||||
const argv =
|
||||
process.argv.length > 2 ? process.argv : [...process.argv, '--help'];
|
||||
await program.parseAsync(argv);
|
||||
} catch (error) {
|
||||
if (error instanceof CommanderError) {
|
||||
process.exitCode = error.exitCode;
|
||||
return;
|
||||
}
|
||||
|
||||
if (error instanceof Error) {
|
||||
logger.error(error.message, error.stack);
|
||||
} else {
|
||||
logger.error(String(error));
|
||||
}
|
||||
process.exitCode = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,18 +2,12 @@ import { Module } from '@nestjs/common';
|
||||
|
||||
import { FunctionalityModules } from '../app.module';
|
||||
import { IndexerModule } from '../plugins/indexer';
|
||||
import { CreateCommand, NameQuestion } from './commands/create';
|
||||
import { CreateCommand } from './commands/create';
|
||||
import { ImportConfigCommand } from './commands/import';
|
||||
import { RevertCommand, RunCommand } from './commands/run';
|
||||
|
||||
@Module({
|
||||
imports: [...FunctionalityModules, IndexerModule],
|
||||
providers: [
|
||||
NameQuestion,
|
||||
CreateCommand,
|
||||
RunCommand,
|
||||
RevertCommand,
|
||||
ImportConfigCommand,
|
||||
],
|
||||
providers: [CreateCommand, RunCommand, RevertCommand, ImportConfigCommand],
|
||||
})
|
||||
export class CliAppModule {}
|
||||
|
||||
@@ -2,54 +2,37 @@ import { appendFileSync, writeFileSync } from 'node:fs';
|
||||
import { join, parse } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { input } from '@inquirer/prompts';
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { camelCase, kebabCase, upperFirst } from 'lodash-es';
|
||||
import {
|
||||
Command,
|
||||
CommandRunner,
|
||||
InquirerService,
|
||||
Question,
|
||||
QuestionSet,
|
||||
} from 'nest-commander';
|
||||
|
||||
@QuestionSet({ name: 'name-questions' })
|
||||
export class NameQuestion {
|
||||
@Question({
|
||||
name: 'name',
|
||||
message: 'Name of the data migration script:',
|
||||
})
|
||||
parseName(val: string) {
|
||||
return val.trim();
|
||||
}
|
||||
}
|
||||
|
||||
@Command({
|
||||
name: 'create',
|
||||
arguments: '[name]',
|
||||
description: 'create a data migration script',
|
||||
})
|
||||
export class CreateCommand extends CommandRunner {
|
||||
@Injectable()
|
||||
export class CreateCommand {
|
||||
logger = new Logger(CreateCommand.name);
|
||||
constructor(private readonly inquirer: InquirerService) {
|
||||
super();
|
||||
}
|
||||
|
||||
override async run(inputs: string[]): Promise<void> {
|
||||
let name = inputs[0];
|
||||
async execute(name?: string): Promise<void> {
|
||||
let resolvedName = name;
|
||||
|
||||
if (!name) {
|
||||
name = (
|
||||
await this.inquirer.ask<{ name: string }>('name-questions', undefined)
|
||||
).name;
|
||||
if (!resolvedName) {
|
||||
resolvedName = (
|
||||
await input({
|
||||
message: 'Name of the data migration script:',
|
||||
validate(value) {
|
||||
return value.trim().length > 0 || 'A migration name is required';
|
||||
},
|
||||
})
|
||||
).trim();
|
||||
}
|
||||
|
||||
const timestamp = Date.now();
|
||||
const content = this.createScript(upperFirst(camelCase(name)) + timestamp);
|
||||
const content = this.createScript(
|
||||
upperFirst(camelCase(resolvedName)) + timestamp
|
||||
);
|
||||
const migrationDir = join(
|
||||
fileURLToPath(import.meta.url),
|
||||
'../../migrations'
|
||||
);
|
||||
const fileName = `${timestamp}-${kebabCase(name)}.ts`;
|
||||
const fileName = `${timestamp}-${kebabCase(resolvedName)}.ts`;
|
||||
const filePath = join(migrationDir, fileName);
|
||||
|
||||
this.logger.log(`Creating ${fileName}...`);
|
||||
|
||||
@@ -1,29 +1,25 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { resolve } from 'node:path';
|
||||
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { Command, CommandRunner } from 'nest-commander';
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
|
||||
import { ConfigFactory, InvalidAppConfigInput } from '../../base';
|
||||
import { Models } from '../../models';
|
||||
|
||||
@Command({
|
||||
name: 'import-config',
|
||||
arguments: '[name]',
|
||||
description: 'import config from a file',
|
||||
})
|
||||
export class ImportConfigCommand extends CommandRunner {
|
||||
@Injectable()
|
||||
export class ImportConfigCommand {
|
||||
logger = new Logger(ImportConfigCommand.name);
|
||||
|
||||
constructor(
|
||||
private readonly models: Models,
|
||||
private readonly configFactory: ConfigFactory
|
||||
) {
|
||||
super();
|
||||
}
|
||||
) {}
|
||||
|
||||
async execute(path?: string): Promise<void> {
|
||||
if (!path) {
|
||||
throw new Error('A config file path is required');
|
||||
}
|
||||
|
||||
override async run(inputs: string[]): Promise<void> {
|
||||
let path = inputs[0];
|
||||
path = resolve(process.cwd(), path);
|
||||
|
||||
const overrides: Record<string, Record<string, any>> = JSON.parse(
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { ModuleRef } from '@nestjs/core';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { once } from 'lodash-es';
|
||||
import { Command, CommandRunner } from 'nest-commander';
|
||||
|
||||
import * as migrationImports from '../migrations';
|
||||
|
||||
@@ -35,20 +34,15 @@ export const collectMigrations = once(() => {
|
||||
return migrations.sort((a, b) => a.order - b.order);
|
||||
});
|
||||
|
||||
@Command({
|
||||
name: 'run',
|
||||
description: 'Run all pending data migrations',
|
||||
})
|
||||
export class RunCommand extends CommandRunner {
|
||||
@Injectable()
|
||||
export class RunCommand {
|
||||
logger = new Logger(RunCommand.name);
|
||||
constructor(
|
||||
private readonly db: PrismaClient,
|
||||
private readonly injector: ModuleRef
|
||||
) {
|
||||
super();
|
||||
}
|
||||
) {}
|
||||
|
||||
override async run(): Promise<void> {
|
||||
async execute(): Promise<void> {
|
||||
const migrations = collectMigrations();
|
||||
const done: Migration[] = [];
|
||||
for (const migration of migrations) {
|
||||
@@ -116,7 +110,7 @@ export class RunCommand extends CommandRunner {
|
||||
});
|
||||
await migration.down(this.db, this.injector);
|
||||
this.logger.error('Failed to run data migration', e);
|
||||
process.exit(1);
|
||||
throw e;
|
||||
}
|
||||
|
||||
await this.db.dataMigration.update({
|
||||
@@ -130,23 +124,16 @@ export class RunCommand extends CommandRunner {
|
||||
}
|
||||
}
|
||||
|
||||
@Command({
|
||||
name: 'revert',
|
||||
arguments: '[name]',
|
||||
description: 'Revert one data migration with given name',
|
||||
})
|
||||
export class RevertCommand extends CommandRunner {
|
||||
@Injectable()
|
||||
export class RevertCommand {
|
||||
logger = new Logger(RevertCommand.name);
|
||||
|
||||
constructor(
|
||||
private readonly db: PrismaClient,
|
||||
private readonly injector: ModuleRef
|
||||
) {
|
||||
super();
|
||||
}
|
||||
) {}
|
||||
|
||||
override async run(inputs: string[]): Promise<void> {
|
||||
const name = inputs[0];
|
||||
async execute(name?: string): Promise<void> {
|
||||
if (!name) {
|
||||
throw new Error('A migration name is required');
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"devDependencies": {
|
||||
"@graphql-codegen/cli": "^5.0.7",
|
||||
"@graphql-codegen/typescript": "^4.1.6",
|
||||
"@graphql-codegen/typescript-operations": "^4.6.1",
|
||||
"@graphql-codegen/cli": "^6.2.1",
|
||||
"@graphql-codegen/typescript": "^5.0.9",
|
||||
"@graphql-codegen/typescript-operations": "^5.0.9",
|
||||
"@types/lodash-es": "^4.17.12",
|
||||
"prettier": "^3.7.4",
|
||||
"vitest": "^4.0.18"
|
||||
|
||||
Reference in New Issue
Block a user