2023-10-23 04:39:35 -07:00
|
|
|
import { Container } from 'typedi';
|
2024-01-22 09:25:36 -08:00
|
|
|
import { Command, Flags } from '@oclif/core';
|
2023-10-23 04:39:35 -07:00
|
|
|
import { InstanceSettings } from 'n8n-core';
|
2019-08-28 02:03:01 -07:00
|
|
|
|
2023-01-27 05:56:56 -08:00
|
|
|
import type { IBuildOptions } from '../src';
|
|
|
|
import { buildFiles } from '../src';
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2019-08-28 02:03:01 -07:00
|
|
|
export class Build extends Command {
|
|
|
|
static description = 'Builds credentials and nodes and copies it to n8n custom extension folder';
|
|
|
|
|
|
|
|
static examples = [
|
2022-12-29 03:20:43 -08:00
|
|
|
'$ n8n-node-dev build',
|
|
|
|
'$ n8n-node-dev build --destination ~/n8n-nodes',
|
|
|
|
'$ n8n-node-dev build --watch',
|
2019-08-28 02:03:01 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
static flags = {
|
2024-01-22 09:25:36 -08:00
|
|
|
help: Flags.help({ char: 'h' }),
|
|
|
|
destination: Flags.string({
|
2019-08-28 02:03:01 -07:00
|
|
|
char: 'd',
|
2023-10-23 04:39:35 -07:00
|
|
|
description: `The path to copy the compiled files to [default: ${
|
|
|
|
Container.get(InstanceSettings).customExtensionDir
|
|
|
|
}]`,
|
2019-08-28 02:03:01 -07:00
|
|
|
}),
|
2024-01-22 09:25:36 -08:00
|
|
|
watch: Flags.boolean({
|
2019-08-28 02:03:01 -07:00
|
|
|
description:
|
|
|
|
'Starts in watch mode and automatically builds and copies file whenever they change',
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
|
|
|
async run() {
|
2024-01-22 09:25:36 -08:00
|
|
|
const { flags } = await this.parse(Build);
|
2019-08-28 02:03:01 -07:00
|
|
|
|
|
|
|
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;
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
2019-08-28 02:03:01 -07:00
|
|
|
const outputDirectory = await buildFiles(options);
|
|
|
|
|
2022-09-21 00:36:44 -07:00
|
|
|
this.log(`The nodes got built and saved into the following folder:\n${outputDirectory}`);
|
2019-08-28 02:03:01 -07:00
|
|
|
} catch (error) {
|
2023-07-31 02:00:48 -07:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
2019-09-19 22:54:13 -07:00
|
|
|
this.log(`\nGOT ERROR: "${error.message}"`);
|
|
|
|
this.log('====================================');
|
2023-07-31 02:00:48 -07:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument
|
2019-09-19 22:54:13 -07:00
|
|
|
this.log(error.stack);
|
2019-08-28 02:03:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|