🎨 Set up linting and formatting (#2120)

* ⬆️ Upgrade TS to 4.3.5

* 👕 Add ESLint configs

* 🎨 Add Prettier config

* 📦 Add deps and commands

*  Adjust global .editorconfig to new ruleset

* 🔥 Remove unneeded local .editorconfig

* 📦 Update deps in editor-ui

* 🔨 Limit Prettier to only TS files

*  Add recommended VSCode extensions

* 👕 Fix build

* 🔥 Remove Vue setting from global config

*  Disable prefer-default-export per feedback

* ✏️ Add forgotten divider

* 👕 Disable no-plusplus

* 👕 Disable class-methods-use-this

* ✏️ Alphabetize overrides

* 👕 Add one-var consecutive override

*  Revert one-var consecutive override

This reverts commit b9252cf935659ba6d76727ad484a1d3c00008fcc.

* 🎨 👕 Lint and format workflow package (#2121)

* 🎨 Format /workflow package

* 👕 Lint /workflow package

* 🎨 Re-format /workflow package

* 👕 Re-lint /workflow package

* ✏️ Fix typo

*  Consolidate if-checks

* 🔥 Remove prefer-default-export exceptions

* 🔥 Remove no-plusplus exceptions

* 🔥 Remove class-methods-use-this exceptions

* 🎨 👕 Lint and format node-dev package (#2122)

* 🎨 Format /node-dev package

*  Exclude templates from ESLint config

This keeps the templates consistent with the codebase while preventing lint exceptions from being made part of the templates.

* 👕 Lint /node-dev package

* 🔥 Remove prefer-default-export exceptions

* 🔥 Remove no-plusplus exceptions

* 🎨 👕 Lint and format core package (#2123)

* 🎨 Format /core package

* 👕 Lint /core package

* 🎨 Re-format /core package

* 👕 Re-lint /core package

* 🔥 Remove prefer-default-export exceptions

* 🔥 Remove no-plusplus exceptions

* 🔥 Remove class-methods-use-this exceptions

* 🎨 👕 Lint and format cli package (#2124)

* 🎨 Format /cli package

* 👕 Exclude migrations from linting

* 👕 Lint /cli package

* 🎨 Re-format /cli package

* 👕 Re-lint /cli package

* 👕 Fix build

* 🔥 Remove prefer-default-export exceptions

*  Update exceptions in ActiveExecutions

* 🔥 Remove no-plusplus exceptions

* 🔥 Remove class-methods-use-this exceptions

* 👕 fix lint issues

* 🔧 use package specific linter, remove tslint command

* 🔨 resolve build issue, sync dependencies

* 🔧 change lint command

Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com>
This commit is contained in:
Iván Ovejero
2021-08-29 20:58:11 +02:00
committed by GitHub
parent 223cd75685
commit 56c4c6991f
108 changed files with 11832 additions and 8416 deletions

View File

@@ -1,26 +1,23 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { ChildProcess, spawn } from 'child_process';
const copyfiles = require('copyfiles');
import {
readFile as fsReadFile,
} from 'fs/promises';
import {
write as fsWrite,
} from 'fs';
import { readFile as fsReadFile } from 'fs/promises';
import { write as fsWrite } from 'fs';
import { join } from 'path';
import { file } from 'tmp-promise';
import { promisify } from 'util';
const fsReadFileAsync = promisify(fsReadFile);
const fsWriteAsync = promisify(fsWrite);
import { UserSettings } from 'n8n-core';
// eslint-disable-next-line import/no-cycle
import { IBuildOptions } from '.';
import {
UserSettings,
} from 'n8n-core';
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires
const copyfiles = require('copyfiles');
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const fsReadFileAsync = promisify(fsReadFile);
const fsWriteAsync = promisify(fsWrite);
/**
* Create a custom tsconfig file as tsc currently has no way to define a base
@@ -30,23 +27,26 @@ import {
* @export
* @returns
*/
export async function createCustomTsconfig () {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export async function createCustomTsconfig() {
// Get path to simple tsconfig file which should be used for build
const tsconfigPath = join(__dirname, '../../src/tsconfig-build.json');
// Read the tsconfi file
const tsConfigString = await fsReadFile(tsconfigPath, { encoding: 'utf8'}) as string;
const tsConfigString = await fsReadFile(tsconfigPath, { encoding: 'utf8' });
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const tsConfig = JSON.parse(tsConfigString);
// Set absolute include paths
const newIncludeFiles = [];
// eslint-disable-next-line no-restricted-syntax
for (const includeFile of tsConfig.include) {
newIncludeFiles.push(join(process.cwd(), includeFile));
}
tsConfig.include = newIncludeFiles;
// Write new custom tsconfig file
// eslint-disable-next-line @typescript-eslint/unbound-method
const { fd, path, cleanup } = await file({ dir: process.cwd() });
await fsWriteAsync(fd, Buffer.from(JSON.stringify(tsConfig, null, 2), 'utf8'));
@@ -56,7 +56,6 @@ export async function createCustomTsconfig () {
};
}
/**
* Builds and copies credentials and nodes
*
@@ -64,7 +63,8 @@ export async function createCustomTsconfig () {
* @param {IBuildOptions} [options] Options to overwrite default behaviour
* @returns {Promise<string>}
*/
export async function buildFiles (options?: IBuildOptions): Promise<string> {
export async function buildFiles(options?: IBuildOptions): Promise<string> {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing, no-param-reassign
options = options || {};
let typescriptPath;
@@ -79,24 +79,31 @@ export async function buildFiles (options?: IBuildOptions): Promise<string> {
const tsconfigData = await createCustomTsconfig();
const outputDirectory = options.destinationFolder || UserSettings.getUserN8nFolderCustomExtensionPath();
const outputDirectory =
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
options.destinationFolder || UserSettings.getUserN8nFolderCustomExtensionPath();
// Supply a node base path so that it finds n8n-core and n8n-workflow
const nodeModulesPath = join(__dirname, '../../node_modules/');
let buildCommand = `${tscPath} --p ${tsconfigData.path} --outDir ${outputDirectory} --rootDir ${process.cwd()} --baseUrl ${nodeModulesPath}`;
let buildCommand = `${tscPath} --p ${
tsconfigData.path
} --outDir ${outputDirectory} --rootDir ${process.cwd()} --baseUrl ${nodeModulesPath}`;
if (options.watch === true) {
buildCommand += ' --watch';
}
let buildProcess: ChildProcess;
try {
buildProcess = spawn('node', buildCommand.split(' '), { windowsVerbatimArguments: true, cwd: process.cwd() });
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
//@ts-ignore
// @ts-ignore
buildProcess.stdout.pipe(process.stdout);
//@ts-ignore
// @ts-ignore
buildProcess.stderr.pipe(process.stderr);
// Make sure that the child process gets also always terminated
@@ -105,27 +112,33 @@ export async function buildFiles (options?: IBuildOptions): Promise<string> {
buildProcess.kill();
});
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
let errorMessage = error.message;
if (error.stdout !== undefined) {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
errorMessage = `${errorMessage}\nGot following output:\n${error.stdout}`;
}
// Remove the tmp tsconfig file
// eslint-disable-next-line @typescript-eslint/no-floating-promises
tsconfigData.cleanup();
throw new Error(errorMessage);
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
return new Promise((resolve, reject) => {
['*.png', '*.node.json'].forEach(filenamePattern => {
copyfiles(
[join(process.cwd(), `./${filenamePattern}`), outputDirectory],
{ up: true },
() => resolve(outputDirectory));
['*.png', '*.node.json'].forEach((filenamePattern) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
copyfiles([join(process.cwd(), `./${filenamePattern}`), outputDirectory], { up: true }, () =>
resolve(outputDirectory),
);
});
buildProcess.on('exit', code => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
buildProcess.on('exit', (code) => {
// Remove the tmp tsconfig file
// eslint-disable-next-line @typescript-eslint/no-floating-promises
tsconfigData.cleanup();
});
});