2022-06-13 12:36:43 -07:00
|
|
|
import path from 'path';
|
2024-07-16 09:46:12 -07:00
|
|
|
import { writeFileSync } from 'fs';
|
2022-06-13 12:36:43 -07:00
|
|
|
import { fileURLToPath } from 'url';
|
|
|
|
import shell from 'shelljs';
|
2024-07-16 09:46:12 -07:00
|
|
|
import { rawTimeZones } from '@vvo/tzdb';
|
2022-06-13 12:36:43 -07:00
|
|
|
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
|
|
|
|
const ROOT_DIR = path.resolve(__dirname, '..');
|
|
|
|
const SPEC_FILENAME = 'openapi.yml';
|
2024-08-28 04:59:27 -07:00
|
|
|
const SPEC_THEME_FILENAME = 'swagger-theme.css';
|
2022-06-13 12:36:43 -07:00
|
|
|
|
|
|
|
const publicApiEnabled = process.env.N8N_PUBLIC_API_DISABLED !== 'true';
|
|
|
|
|
2023-06-07 07:53:53 -07:00
|
|
|
copyUserManagementEmailTemplates();
|
2024-07-16 09:46:12 -07:00
|
|
|
generateTimezoneData();
|
2022-06-13 12:36:43 -07:00
|
|
|
|
|
|
|
if (publicApiEnabled) {
|
|
|
|
copySwaggerTheme();
|
|
|
|
bundleOpenApiSpecs();
|
|
|
|
}
|
|
|
|
|
2024-07-16 09:46:12 -07:00
|
|
|
function copyUserManagementEmailTemplates() {
|
2022-06-13 12:36:43 -07:00
|
|
|
const templates = {
|
2024-08-22 02:10:37 -07:00
|
|
|
source: path.resolve(ROOT_DIR, 'src', 'user-management', 'email', 'templates'),
|
|
|
|
destination: path.resolve(ROOT_DIR, 'dist', 'user-management', 'email'),
|
2022-06-13 12:36:43 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
shell.cp('-r', templates.source, templates.destination);
|
|
|
|
}
|
|
|
|
|
2024-07-16 09:46:12 -07:00
|
|
|
function copySwaggerTheme() {
|
2022-06-13 12:36:43 -07:00
|
|
|
const swaggerTheme = {
|
2024-08-28 04:59:27 -07:00
|
|
|
source: path.resolve(ROOT_DIR, 'src', 'public-api', SPEC_THEME_FILENAME),
|
|
|
|
destination: path.resolve(ROOT_DIR, 'dist', 'public-api'),
|
2022-06-13 12:36:43 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
shell.cp('-r', swaggerTheme.source, swaggerTheme.destination);
|
|
|
|
}
|
|
|
|
|
2024-07-16 09:46:12 -07:00
|
|
|
function bundleOpenApiSpecs() {
|
2024-08-28 04:59:27 -07:00
|
|
|
const publicApiDir = path.resolve(ROOT_DIR, 'src', 'public-api');
|
2022-06-13 12:36:43 -07:00
|
|
|
|
|
|
|
shell
|
|
|
|
.find(publicApiDir)
|
|
|
|
.reduce((acc, cur) => {
|
2024-07-16 09:46:12 -07:00
|
|
|
return cur.endsWith(SPEC_FILENAME) ? [...acc, path.relative('./src', cur)] : acc;
|
2022-06-13 12:36:43 -07:00
|
|
|
}, [])
|
|
|
|
.forEach((specPath) => {
|
2024-07-16 09:46:12 -07:00
|
|
|
const distSpecPath = path.resolve(ROOT_DIR, 'dist', specPath);
|
2024-01-19 09:15:33 -08:00
|
|
|
const command = `pnpm openapi bundle src/${specPath} --output ${distSpecPath}`;
|
2022-06-13 12:36:43 -07:00
|
|
|
shell.exec(command, { silent: true });
|
|
|
|
});
|
|
|
|
}
|
2024-07-16 09:46:12 -07:00
|
|
|
|
|
|
|
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 }));
|
|
|
|
}
|