mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-21 11:49:59 +00:00
refactor(core): Use use up-to-date timezone data (#10073)
Co-authored-by: Danny Martini <danny@n8n.io>
This commit is contained in:
committed by
GitHub
parent
3bbeae47f3
commit
5e57b0d71e
@@ -74,6 +74,7 @@
|
||||
"@types/ws": "^8.5.4",
|
||||
"@types/xml2js": "^0.4.14",
|
||||
"@types/yamljs": "^0.2.31",
|
||||
"@vvo/tzdb": "^6.141.0",
|
||||
"chokidar": "^3.5.2",
|
||||
"concurrently": "^8.2.0",
|
||||
"ioredis-mock": "^8.8.1",
|
||||
@@ -116,7 +117,6 @@
|
||||
"flat": "5.0.2",
|
||||
"flatted": "3.2.7",
|
||||
"formidable": "3.5.1",
|
||||
"google-timezones-json": "1.1.0",
|
||||
"handlebars": "4.7.8",
|
||||
"helmet": "7.1.0",
|
||||
"infisical-node": "1.3.0",
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import path from 'path';
|
||||
import { writeFileSync } from 'fs';
|
||||
import { fileURLToPath } from 'url';
|
||||
import shell from 'shelljs';
|
||||
import { rawTimeZones } from '@vvo/tzdb';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
@@ -12,41 +14,50 @@ const SPEC_THEME_FILENAME = 'swaggerTheme.css';
|
||||
const publicApiEnabled = process.env.N8N_PUBLIC_API_DISABLED !== 'true';
|
||||
|
||||
copyUserManagementEmailTemplates();
|
||||
generateTimezoneData();
|
||||
|
||||
if (publicApiEnabled) {
|
||||
copySwaggerTheme();
|
||||
bundleOpenApiSpecs();
|
||||
}
|
||||
|
||||
function copyUserManagementEmailTemplates(rootDir = ROOT_DIR) {
|
||||
function copyUserManagementEmailTemplates() {
|
||||
const templates = {
|
||||
source: path.resolve(rootDir, 'src', 'UserManagement', 'email', 'templates'),
|
||||
destination: path.resolve(rootDir, 'dist', 'UserManagement', 'email'),
|
||||
source: path.resolve(ROOT_DIR, 'src', 'UserManagement', 'email', 'templates'),
|
||||
destination: path.resolve(ROOT_DIR, 'dist', 'UserManagement', 'email'),
|
||||
};
|
||||
|
||||
shell.cp('-r', templates.source, templates.destination);
|
||||
}
|
||||
|
||||
function copySwaggerTheme(rootDir = ROOT_DIR, themeFilename = SPEC_THEME_FILENAME) {
|
||||
function copySwaggerTheme() {
|
||||
const swaggerTheme = {
|
||||
source: path.resolve(rootDir, 'src', 'PublicApi', themeFilename),
|
||||
destination: path.resolve(rootDir, 'dist', 'PublicApi'),
|
||||
source: path.resolve(ROOT_DIR, 'src', 'PublicApi', SPEC_THEME_FILENAME),
|
||||
destination: path.resolve(ROOT_DIR, 'dist', 'PublicApi'),
|
||||
};
|
||||
|
||||
shell.cp('-r', swaggerTheme.source, swaggerTheme.destination);
|
||||
}
|
||||
|
||||
function bundleOpenApiSpecs(rootDir = ROOT_DIR, specFileName = SPEC_FILENAME) {
|
||||
const publicApiDir = path.resolve(rootDir, 'src', 'PublicApi');
|
||||
function bundleOpenApiSpecs() {
|
||||
const publicApiDir = path.resolve(ROOT_DIR, 'src', 'PublicApi');
|
||||
|
||||
shell
|
||||
.find(publicApiDir)
|
||||
.reduce((acc, cur) => {
|
||||
return cur.endsWith(specFileName) ? [...acc, path.relative('./src', cur)] : acc;
|
||||
return cur.endsWith(SPEC_FILENAME) ? [...acc, path.relative('./src', cur)] : acc;
|
||||
}, [])
|
||||
.forEach((specPath) => {
|
||||
const distSpecPath = path.resolve(rootDir, 'dist', specPath);
|
||||
const distSpecPath = path.resolve(ROOT_DIR, 'dist', specPath);
|
||||
const command = `pnpm openapi bundle src/${specPath} --output ${distSpecPath}`;
|
||||
shell.exec(command, { silent: true });
|
||||
});
|
||||
}
|
||||
|
||||
function generateTimezoneData() {
|
||||
const timezones = rawTimeZones.reduce((acc, tz) => {
|
||||
acc[tz.name] = tz.name.replaceAll('_', ' ');
|
||||
return acc;
|
||||
}, {});
|
||||
writeFileSync(path.resolve(ROOT_DIR, 'dist/timezones.json'), JSON.stringify({ data: timezones }));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Container, Service } from 'typedi';
|
||||
import { exec as callbackExec } from 'child_process';
|
||||
import { resolve } from 'path';
|
||||
import { access as fsAccess } from 'fs/promises';
|
||||
import { promisify } from 'util';
|
||||
import cookieParser from 'cookie-parser';
|
||||
@@ -9,12 +10,10 @@ import { GlobalConfig } from '@n8n/config';
|
||||
import { InstanceSettings } from 'n8n-core';
|
||||
import type { IN8nUISettings } from 'n8n-workflow';
|
||||
|
||||
// @ts-expect-error missing types
|
||||
import timezones from 'google-timezones-json';
|
||||
|
||||
import config from '@/config';
|
||||
|
||||
import {
|
||||
CLI_DIR,
|
||||
EDITOR_UI_DIST_DIR,
|
||||
inDevelopment,
|
||||
inE2ETests,
|
||||
@@ -229,11 +228,8 @@ export class Server extends AbstractServer {
|
||||
// ----------------------------------------
|
||||
|
||||
// Returns all the available timezones
|
||||
this.app.get(
|
||||
`/${this.restEndpoint}/options/timezones`,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
ResponseHelper.send(async () => timezones),
|
||||
);
|
||||
const tzDataFile = resolve(CLI_DIR, 'dist/timezones.json');
|
||||
this.app.get(`/${this.restEndpoint}/options/timezones`, (_, res) => res.sendFile(tzDataFile));
|
||||
|
||||
// ----------------------------------------
|
||||
// Settings
|
||||
|
||||
Reference in New Issue
Block a user