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:
DarkSky
2026-04-03 19:36:18 +08:00
committed by GitHub
parent d0607b5ce7
commit d3ec008b0c
8 changed files with 659 additions and 833 deletions
+2 -8
View File
@@ -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');
}