Skip to content

Commit

Permalink
fix(core): Fix Public API failing to build on Windows (#3499)
Browse files Browse the repository at this point in the history
* ✨ Add build script

* 📦 Add dependencies

* 📦 Update package-lock.json

* 👕 Ignore `build.mjs`
  • Loading branch information
ivov authored Jun 13, 2022
1 parent 955db0a commit c121952
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 5 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
packages/editor-ui
packages/design-system
packages/cli/scripts/build.mjs
65 changes: 63 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
"bin": "n8n"
},
"scripts": {
"build": "run-script-os",
"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\"/{} \\;",
"build:windows": "tsc && xcopy /E /I src\\UserManagement\\email\\templates dist\\src\\UserManagement\\email\\templates",
"build": "node scripts/build.mjs",
"dev": "concurrently -k -n \"TypeScript,Node\" -c \"yellow.bold,cyan.bold\" \"npm run watch\" \"nodemon\"",
"format": "cd ../.. && node_modules/prettier/bin-prettier.js packages/cli/**/**.ts --write",
"lint": "cd ../.. && node_modules/eslint/bin/eslint.js packages/cli",
Expand Down Expand Up @@ -100,6 +98,7 @@
"@rudderstack/rudder-sdk-node": "1.0.6",
"@types/json-diff": "^0.5.1",
"@types/jsonwebtoken": "^8.5.2",
"@types/shelljs": "^0.8.11",
"@types/swagger-ui-express": "^4.1.3",
"@types/yamljs": "^0.2.31",
"basic-auth": "^2.0.1",
Expand Down Expand Up @@ -146,6 +145,7 @@
"pg": "^8.3.0",
"prom-client": "^13.1.0",
"request-promise-native": "^1.0.7",
"shelljs": "^0.8.5",
"sqlite3": "^5.0.2",
"sse-channel": "^3.1.1",
"swagger-ui-express": "^4.3.0",
Expand Down
59 changes: 59 additions & 0 deletions packages/cli/scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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';

shell.rm('-rf', path.resolve(ROOT_DIR, 'dist'));

shell.exec('tsc');

if (userManagementEnabled) {
copyUserManagementEmailTemplates();
}

if (publicApiEnabled) {
copySwaggerTheme();
bundleOpenApiSpecs();
}

function copyUserManagementEmailTemplates(rootDir = ROOT_DIR) {
const templates = {
source: path.resolve(rootDir, 'src', 'UserManagement', 'email', 'templates'),
destination: path.resolve(rootDir, 'dist', 'src', 'UserManagement', 'email'),
};

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),
destination: path.resolve(rootDir, 'dist', 'src', 'PublicApi'),
};

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) => {
return cur.endsWith(specFileName) ? [...acc, path.relative('.', cur)] : acc;
}, [])
.forEach((specPath) => {
const distSpecPath = path.resolve(rootDir, 'dist', specPath);
const command = `swagger-cli bundle ${specPath} --type yaml --outfile ${distSpecPath}`;
shell.exec(command, { silent: true });
});
}

0 comments on commit c121952

Please sign in to comment.