n8n/packages/node-dev/commands/build.ts
कारतोफ्फेलस्क्रिप्ट™ b6de910cbe
refactor(core): Abstract away InstanceSettings and encryptionKey into injectable services (no-changelog) (#7471)
This change ensures that things like `encryptionKey` and `instanceId`
are always available directly where they are needed, instead of passing
them around throughout the code.
2023-10-23 13:39:35 +02:00

60 lines
1.7 KiB
TypeScript

import { Container } from 'typedi';
import { InstanceSettings } from 'n8n-core';
import { Command, flags } from '@oclif/command';
import type { IBuildOptions } from '../src';
import { buildFiles } from '../src';
export class Build extends Command {
static description = 'Builds credentials and nodes and copies it to n8n custom extension folder';
static examples = [
'$ n8n-node-dev build',
'$ n8n-node-dev build --destination ~/n8n-nodes',
'$ n8n-node-dev build --watch',
];
static flags = {
help: flags.help({ char: 'h' }),
destination: flags.string({
char: 'd',
description: `The path to copy the compiled files to [default: ${
Container.get(InstanceSettings).customExtensionDir
}]`,
}),
watch: flags.boolean({
description:
'Starts in watch mode and automatically builds and copies file whenever they change',
}),
};
async run() {
// eslint-disable-next-line @typescript-eslint/no-shadow
const { flags } = this.parse(Build);
this.log('\nBuild credentials and nodes');
this.log('=========================');
try {
const options: IBuildOptions = {};
if (flags.destination) {
options.destinationFolder = flags.destination;
}
if (flags.watch) {
options.watch = true;
}
const outputDirectory = await buildFiles(options);
this.log(`The nodes got built and saved into the following folder:\n${outputDirectory}`);
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
this.log(`\nGOT ERROR: "${error.message}"`);
this.log('====================================');
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument
this.log(error.stack);
}
}
}