refactor(core): Overhaul commands setup. Add support for module commands (#16709)

Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2025-07-01 19:14:22 +02:00
committed by GitHub
parent 346bc84093
commit 9f8d3d3bc8
41 changed files with 1061 additions and 541 deletions

View File

@@ -2,8 +2,8 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { LICENSE_FEATURES } from '@n8n/constants';
import { ExecutionRepository, SettingsRepository } from '@n8n/db';
import { Command } from '@n8n/decorators';
import { Container } from '@n8n/di';
import { Flags } from '@oclif/core';
import glob from 'fast-glob';
import { createReadStream, createWriteStream, existsSync } from 'fs';
import { mkdir } from 'fs/promises';
@@ -11,6 +11,7 @@ import { jsonParse, randomString, type IWorkflowExecutionDataProcess } from 'n8n
import path from 'path';
import replaceStream from 'replacestream';
import { pipeline } from 'stream/promises';
import { z } from 'zod';
import { ActiveExecutions } from '@/active-executions';
import { ActiveWorkflowManager } from '@/active-workflow-manager';
@@ -36,32 +37,29 @@ import { BaseCommand } from './base-command';
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires
const open = require('open');
export class Start extends BaseCommand {
static description = 'Starts n8n. Makes Web-UI available and starts active workflows';
static examples = [
'$ n8n start',
'$ n8n start --tunnel',
'$ n8n start -o',
'$ n8n start --tunnel -o',
];
static flags = {
help: Flags.help({ char: 'h' }),
open: Flags.boolean({
char: 'o',
description: 'opens the UI automatically in browser',
}),
tunnel: Flags.boolean({
description:
'runs the webhooks via a hooks.n8n.cloud tunnel server. Use only for testing and development!',
}),
reinstallMissingPackages: Flags.boolean({
description:
'Attempts to self heal n8n if packages with nodes are missing. Might drastically increase startup times.',
}),
};
const flagsSchema = z.object({
open: z.boolean().alias('o').describe('opens the UI automatically in browser').optional(),
tunnel: z
.boolean()
.describe(
'runs the webhooks via a hooks.n8n.cloud tunnel server. Use only for testing and development!',
)
.optional(),
reinstallMissingPackages: z
.boolean()
.describe(
'Attempts to self heal n8n if packages with nodes are missing. Might drastically increase startup times.',
)
.optional(),
});
@Command({
name: 'start',
description: 'Starts n8n. Makes Web-UI available and starts active workflows',
examples: ['', '--tunnel', '-o', '--tunnel -o'],
flagsSchema,
})
export class Start extends BaseCommand<z.infer<typeof flagsSchema>> {
protected activeWorkflowManager: ActiveWorkflowManager;
protected server = Container.get(Server);
@@ -181,7 +179,7 @@ export class Start extends BaseCommand {
scopedLogger.debug(`Host ID: ${this.instanceSettings.hostId}`);
}
const { flags } = await this.parse(Start);
const { flags } = this;
const { communityPackages } = this.globalConfig.nodes;
// cli flag overrides the config env variable
if (flags.reinstallMissingPackages) {
@@ -272,7 +270,7 @@ export class Start extends BaseCommand {
}
async run() {
const { flags } = await this.parse(Start);
const { flags } = this;
// Load settings from database and set them to config.
const databaseSettings = await Container.get(SettingsRepository).findBy({