mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
Initial commit to release
This commit is contained in:
63
packages/node-dev/src/Build.ts
Normal file
63
packages/node-dev/src/Build.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { join } from 'path';
|
||||
import { ChildProcess, spawn } from 'child_process';
|
||||
|
||||
import { IBuildOptions } from '.';
|
||||
|
||||
import {
|
||||
UserSettings,
|
||||
} from "n8n-core";
|
||||
|
||||
|
||||
/**
|
||||
* Builds and copies credentials and nodes
|
||||
*
|
||||
* @export
|
||||
* @param {IBuildOptions} [options] Options to overwrite default behaviour
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
export async function buildFiles (options?: IBuildOptions): Promise<string> {
|
||||
options = options || {};
|
||||
|
||||
// Get the path of the TypeScript cli of this project
|
||||
const tscPath = join(__dirname, '../../node_modules/typescript/bin/tsc');
|
||||
|
||||
// Get path to simple tsconfig file which should be used for build
|
||||
const tsconfigPath = join(__dirname, '../../src/tsconfig-build.json');
|
||||
|
||||
const outputDirectory = options.destinationFolder || UserSettings.getUserN8nFolderCustomExtensionPath();
|
||||
|
||||
let buildCommand = `${tscPath} --p ${tsconfigPath} --outDir ${outputDirectory}`;
|
||||
if (options.watch === true) {
|
||||
buildCommand += ' --watch';
|
||||
}
|
||||
|
||||
let buildProcess: ChildProcess;
|
||||
try {
|
||||
buildProcess = spawn('node', buildCommand.split(' '), { windowsVerbatimArguments: true, cwd: process.cwd() });
|
||||
|
||||
// Forward the output of the child process to the main one
|
||||
// that the user can see what is happening
|
||||
buildProcess.stdout.pipe(process.stdout);
|
||||
buildProcess.stderr.pipe(process.stderr);
|
||||
|
||||
// Make sure that the child process gets also always terminated
|
||||
// when the main process does
|
||||
process.on('exit', () => {
|
||||
buildProcess.kill();
|
||||
});
|
||||
} catch (error) {
|
||||
let errorMessage = error.message;
|
||||
|
||||
if (error.stdout !== undefined) {
|
||||
errorMessage = `${errorMessage}\nGot following output:\n${error.stdout}`;
|
||||
}
|
||||
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
buildProcess.on('exit', code => {
|
||||
resolve(outputDirectory);
|
||||
});
|
||||
});
|
||||
}
|
||||
36
packages/node-dev/src/Create.ts
Normal file
36
packages/node-dev/src/Create.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
import * as fs from 'fs';
|
||||
import replaceInFile, { ReplaceInFileConfig } from 'replace-in-file';
|
||||
|
||||
const { promisify } = require('util');
|
||||
const fsCopyFile = promisify(fs.copyFile);
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new credentials or node
|
||||
*
|
||||
* @export
|
||||
* @param {string} sourceFilePath The path to the source template file
|
||||
* @param {string} destinationFilePath The path the write the new file to
|
||||
* @param {object} replaceValues The values to replace in the template file
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function createTemplate(sourceFilePath: string, destinationFilePath: string, replaceValues: object): Promise<void> {
|
||||
|
||||
// Copy the file to then replace the values in it
|
||||
await fsCopyFile(sourceFilePath, destinationFilePath);
|
||||
|
||||
// Replace the variables in the template file
|
||||
const options: ReplaceInFileConfig = {
|
||||
files: [
|
||||
destinationFilePath
|
||||
],
|
||||
from: [],
|
||||
to: [],
|
||||
};
|
||||
options.from = Object.keys(replaceValues).map((key) => {
|
||||
return new RegExp(key, 'g');
|
||||
});
|
||||
options.to = Object.values(replaceValues);
|
||||
await replaceInFile(options);
|
||||
}
|
||||
4
packages/node-dev/src/Interfaces.ts
Normal file
4
packages/node-dev/src/Interfaces.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export interface IBuildOptions {
|
||||
destinationFolder?: string;
|
||||
watch?: boolean;
|
||||
}
|
||||
3
packages/node-dev/src/index.ts
Normal file
3
packages/node-dev/src/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './Build';
|
||||
export * from './Create';
|
||||
export * from './Interfaces';
|
||||
27
packages/node-dev/src/tsconfig-build.json
Normal file
27
packages/node-dev/src/tsconfig-build.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"lib": [
|
||||
"es2017"
|
||||
],
|
||||
"types": [
|
||||
"node"
|
||||
],
|
||||
"module": "commonjs",
|
||||
"importHelpers": true,
|
||||
"noImplicitAny": true,
|
||||
"removeComments": true,
|
||||
"strictNullChecks": true,
|
||||
"strict": true,
|
||||
"preserveConstEnums": true,
|
||||
"declaration": true,
|
||||
"target": "es2017",
|
||||
"sourceMap": true
|
||||
},
|
||||
"include": [
|
||||
"../*.credentials.ts",
|
||||
"../*.node.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user