Initial commit to release

This commit is contained in:
Jan Oberhauser
2019-06-23 12:35:23 +02:00
commit 9cb9804eee
257 changed files with 42436 additions and 0 deletions

View 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);
});
});
}

View 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);
}

View File

@@ -0,0 +1,4 @@
export interface IBuildOptions {
destinationFolder?: string;
watch?: boolean;
}

View File

@@ -0,0 +1,3 @@
export * from './Build';
export * from './Create';
export * from './Interfaces';

View 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"
]
}