2022-06-13 12:36:43 -07:00
|
|
|
import path from 'path';
|
|
|
|
import { fileURLToPath } from 'url';
|
|
|
|
import shell from 'shelljs';
|
|
|
|
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
|
|
|
|
const ROOT_DIR = path.resolve(__dirname, '..');
|
|
|
|
const SPEC_FILENAME = 'openapi.yml';
|
|
|
|
const SPEC_THEME_FILENAME = 'swaggerTheme.css';
|
|
|
|
|
|
|
|
const userManagementEnabled = process.env.N8N_USER_MANAGEMENT_DISABLED !== 'true';
|
|
|
|
const publicApiEnabled = process.env.N8N_PUBLIC_API_DISABLED !== 'true';
|
|
|
|
|
|
|
|
if (userManagementEnabled) {
|
|
|
|
copyUserManagementEmailTemplates();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (publicApiEnabled) {
|
|
|
|
copySwaggerTheme();
|
|
|
|
bundleOpenApiSpecs();
|
|
|
|
}
|
|
|
|
|
|
|
|
function copyUserManagementEmailTemplates(rootDir = ROOT_DIR) {
|
|
|
|
const templates = {
|
|
|
|
source: path.resolve(rootDir, 'src', 'UserManagement', 'email', 'templates'),
|
2022-11-09 06:25:00 -08:00
|
|
|
destination: path.resolve(rootDir, 'dist', 'UserManagement', 'email'),
|
2022-06-13 12:36:43 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
shell.cp('-r', templates.source, templates.destination);
|
|
|
|
}
|
|
|
|
|
|
|
|
function copySwaggerTheme(rootDir = ROOT_DIR, themeFilename = SPEC_THEME_FILENAME) {
|
|
|
|
const swaggerTheme = {
|
|
|
|
source: path.resolve(rootDir, 'src', 'PublicApi', themeFilename),
|
2022-11-09 06:25:00 -08:00
|
|
|
destination: path.resolve(rootDir, 'dist', 'PublicApi'),
|
2022-06-13 12:36:43 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
shell.cp('-r', swaggerTheme.source, swaggerTheme.destination);
|
|
|
|
}
|
|
|
|
|
|
|
|
function bundleOpenApiSpecs(rootDir = ROOT_DIR, specFileName = SPEC_FILENAME) {
|
|
|
|
const publicApiDir = path.resolve(rootDir, 'src', 'PublicApi');
|
|
|
|
|
|
|
|
shell
|
|
|
|
.find(publicApiDir)
|
|
|
|
.reduce((acc, cur) => {
|
2022-11-09 06:25:00 -08:00
|
|
|
return cur.endsWith(specFileName) ? [...acc, path.relative('./src', cur)] : acc;
|
2022-06-13 12:36:43 -07:00
|
|
|
}, [])
|
|
|
|
.forEach((specPath) => {
|
|
|
|
const distSpecPath = path.resolve(rootDir, 'dist', specPath);
|
2022-11-09 06:25:00 -08:00
|
|
|
const command = `npm run swagger -- bundle src/${specPath} --type yaml --outfile ${distSpecPath}`;
|
2022-06-13 12:36:43 -07:00
|
|
|
shell.exec(command, { silent: true });
|
|
|
|
});
|
|
|
|
}
|