Skip to content

Commit c121952

Browse files
authored
fix(core): Fix Public API failing to build on Windows (n8n-io#3499)
* ✨ Add build script * 📦 Add dependencies * 📦 Update package-lock.json * 👕 Ignore `build.mjs`
1 parent 955db0a commit c121952

File tree

4 files changed

+126
-5
lines changed

4 files changed

+126
-5
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
packages/editor-ui
22
packages/design-system
3+
packages/cli/scripts/build.mjs

package-lock.json

+63-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
"bin": "n8n"
2020
},
2121
"scripts": {
22-
"build": "run-script-os",
23-
"build:default": "tsc && cp -r ./src/UserManagement/email/templates ./dist/src/UserManagement/email && cp ./src/PublicApi/swaggerTheme.css ./dist/src/PublicApi/swaggerTheme.css; find ./src/PublicApi -iname 'openapi.yml' -exec swagger-cli bundle {} --type yaml --outfile \"./dist\"/{} \\;",
24-
"build:windows": "tsc && xcopy /E /I src\\UserManagement\\email\\templates dist\\src\\UserManagement\\email\\templates",
22+
"build": "node scripts/build.mjs",
2523
"dev": "concurrently -k -n \"TypeScript,Node\" -c \"yellow.bold,cyan.bold\" \"npm run watch\" \"nodemon\"",
2624
"format": "cd ../.. && node_modules/prettier/bin-prettier.js packages/cli/**/**.ts --write",
2725
"lint": "cd ../.. && node_modules/eslint/bin/eslint.js packages/cli",
@@ -100,6 +98,7 @@
10098
"@rudderstack/rudder-sdk-node": "1.0.6",
10199
"@types/json-diff": "^0.5.1",
102100
"@types/jsonwebtoken": "^8.5.2",
101+
"@types/shelljs": "^0.8.11",
103102
"@types/swagger-ui-express": "^4.1.3",
104103
"@types/yamljs": "^0.2.31",
105104
"basic-auth": "^2.0.1",
@@ -146,6 +145,7 @@
146145
"pg": "^8.3.0",
147146
"prom-client": "^13.1.0",
148147
"request-promise-native": "^1.0.7",
148+
"shelljs": "^0.8.5",
149149
"sqlite3": "^5.0.2",
150150
"sse-channel": "^3.1.1",
151151
"swagger-ui-express": "^4.3.0",

packages/cli/scripts/build.mjs

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import path from 'path';
2+
import { fileURLToPath } from 'url';
3+
import shell from 'shelljs';
4+
5+
const __filename = fileURLToPath(import.meta.url);
6+
const __dirname = path.dirname(__filename);
7+
8+
const ROOT_DIR = path.resolve(__dirname, '..');
9+
const SPEC_FILENAME = 'openapi.yml';
10+
const SPEC_THEME_FILENAME = 'swaggerTheme.css';
11+
12+
const userManagementEnabled = process.env.N8N_USER_MANAGEMENT_DISABLED !== 'true';
13+
const publicApiEnabled = process.env.N8N_PUBLIC_API_DISABLED !== 'true';
14+
15+
shell.rm('-rf', path.resolve(ROOT_DIR, 'dist'));
16+
17+
shell.exec('tsc');
18+
19+
if (userManagementEnabled) {
20+
copyUserManagementEmailTemplates();
21+
}
22+
23+
if (publicApiEnabled) {
24+
copySwaggerTheme();
25+
bundleOpenApiSpecs();
26+
}
27+
28+
function copyUserManagementEmailTemplates(rootDir = ROOT_DIR) {
29+
const templates = {
30+
source: path.resolve(rootDir, 'src', 'UserManagement', 'email', 'templates'),
31+
destination: path.resolve(rootDir, 'dist', 'src', 'UserManagement', 'email'),
32+
};
33+
34+
shell.cp('-r', templates.source, templates.destination);
35+
}
36+
37+
function copySwaggerTheme(rootDir = ROOT_DIR, themeFilename = SPEC_THEME_FILENAME) {
38+
const swaggerTheme = {
39+
source: path.resolve(rootDir, 'src', 'PublicApi', themeFilename),
40+
destination: path.resolve(rootDir, 'dist', 'src', 'PublicApi'),
41+
};
42+
43+
shell.cp('-r', swaggerTheme.source, swaggerTheme.destination);
44+
}
45+
46+
function bundleOpenApiSpecs(rootDir = ROOT_DIR, specFileName = SPEC_FILENAME) {
47+
const publicApiDir = path.resolve(rootDir, 'src', 'PublicApi');
48+
49+
shell
50+
.find(publicApiDir)
51+
.reduce((acc, cur) => {
52+
return cur.endsWith(specFileName) ? [...acc, path.relative('.', cur)] : acc;
53+
}, [])
54+
.forEach((specPath) => {
55+
const distSpecPath = path.resolve(rootDir, 'dist', specPath);
56+
const command = `swagger-cli bundle ${specPath} --type yaml --outfile ${distSpecPath}`;
57+
shell.exec(command, { silent: true });
58+
});
59+
}

0 commit comments

Comments
 (0)