2021-08-29 11:58:11 -07:00
|
|
|
import { UserSettings } from 'n8n-core';
|
2019-08-28 02:03:01 -07:00
|
|
|
import { Command, flags } from '@oclif/command';
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
import { buildFiles, IBuildOptions } 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 = {
|
|
|
|
help: flags.help({ char: 'h' }),
|
|
|
|
destination: flags.string({
|
|
|
|
char: 'd',
|
|
|
|
description: `The path to copy the compiles files to [default: ${UserSettings.getUserN8nFolderCustomExtensionPath()}]`,
|
|
|
|
}),
|
|
|
|
watch: flags.boolean({
|
2021-08-29 11:58:11 -07:00
|
|
|
description:
|
|
|
|
'Starts in watch mode and automatically builds and copies file whenever they change',
|
2019-08-28 02:03:01 -07:00
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
2019-08-28 02:03:01 -07:00
|
|
|
async run() {
|
2021-08-29 11:58:11 -07:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
2019-08-28 02:03:01 -07:00
|
|
|
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;
|
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) {
|
2021-08-29 11:58:11 -07:00
|
|
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-member-access
|
2019-09-19 22:54:13 -07:00
|
|
|
this.log(`\nGOT ERROR: "${error.message}"`);
|
|
|
|
this.log('====================================');
|
2022-07-24 08:25:01 -07:00
|
|
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|