diff --git a/.eslintignore b/.eslintignore index 2bbcd4d8ebd7c..610f89d8430fb 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ packages/editor-ui packages/design-system +packages/cli/scripts/build.mjs diff --git a/package-lock.json b/package-lock.json index be39ad75f6031..b942848b34209 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "n8n", - "version": "0.180.0", + "version": "0.181.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "n8n", - "version": "0.180.0", + "version": "0.181.2", "dependencies": { "@apidevtools/swagger-cli": "4.0.0", "@babel/core": "^7.14.6", @@ -77,6 +77,7 @@ "@types/redis": "^2.8.11", "@types/request-promise-native": "~1.0.15", "@types/sanitize-html": "^2.6.2", + "@types/shelljs": "^0.8.11", "@types/showdown": "^1.9.4", "@types/snowflake-sdk": "^1.5.1", "@types/ssh2-sftp-client": "^5.1.0", @@ -232,6 +233,7 @@ "sanitize-html": "2.7.0", "sass": "^1.26.5", "sass-loader": "^8.0.2", + "shelljs": "^0.8.5", "showdown": "^2.0.3", "simple-git": "^3.5.0", "snowflake-sdk": "^1.5.3", @@ -14576,6 +14578,15 @@ "@types/node": "*" } }, + "node_modules/@types/shelljs": { + "version": "0.8.11", + "resolved": "https://registry.npmjs.org/@types/shelljs/-/shelljs-0.8.11.tgz", + "integrity": "sha512-x9yaMvEh5BEaZKeVQC4vp3l+QoFj3BXcd4aYfuKSzIIyihjdVARAadYy3SMNIz0WCCdS2vB9JL/U6GQk5PaxQw==", + "dependencies": { + "@types/glob": "*", + "@types/node": "*" + } + }, "node_modules/@types/showdown": { "version": "1.9.4", "resolved": "https://registry.npmjs.org/@types/showdown/-/showdown-1.9.4.tgz", @@ -51378,6 +51389,30 @@ "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.7.3.tgz", "integrity": "sha512-Vpfqwm4EnqGdlsBFNmHhxhElJYrdfcxPThu+ryKS5J8L/fhAwLazFZtq+S+TWZ9ANj2piSQLGj6NQg+lKPmxrw==" }, + "node_modules/shelljs": { + "version": "0.8.5", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.5.tgz", + "integrity": "sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==", + "dependencies": { + "glob": "^7.0.0", + "interpret": "^1.0.0", + "rechoir": "^0.6.2" + }, + "bin": { + "shjs": "bin/shjs" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/shelljs/node_modules/interpret": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", + "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==", + "engines": { + "node": ">= 0.10" + } + }, "node_modules/shellwords": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/shellwords/-/shellwords-0.1.1.tgz", @@ -71951,6 +71986,15 @@ "@types/node": "*" } }, + "@types/shelljs": { + "version": "0.8.11", + "resolved": "https://registry.npmjs.org/@types/shelljs/-/shelljs-0.8.11.tgz", + "integrity": "sha512-x9yaMvEh5BEaZKeVQC4vp3l+QoFj3BXcd4aYfuKSzIIyihjdVARAadYy3SMNIz0WCCdS2vB9JL/U6GQk5PaxQw==", + "requires": { + "@types/glob": "*", + "@types/node": "*" + } + }, "@types/showdown": { "version": "1.9.4", "resolved": "https://registry.npmjs.org/@types/showdown/-/showdown-1.9.4.tgz", @@ -100906,6 +100950,23 @@ "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.7.3.tgz", "integrity": "sha512-Vpfqwm4EnqGdlsBFNmHhxhElJYrdfcxPThu+ryKS5J8L/fhAwLazFZtq+S+TWZ9ANj2piSQLGj6NQg+lKPmxrw==" }, + "shelljs": { + "version": "0.8.5", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.5.tgz", + "integrity": "sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==", + "requires": { + "glob": "^7.0.0", + "interpret": "^1.0.0", + "rechoir": "^0.6.2" + }, + "dependencies": { + "interpret": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", + "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==" + } + } + }, "shellwords": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/shellwords/-/shellwords-0.1.1.tgz", diff --git a/packages/cli/package.json b/packages/cli/package.json index 10f760dae395f..85b9ca1894161 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -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", @@ -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", @@ -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", diff --git a/packages/cli/scripts/build.mjs b/packages/cli/scripts/build.mjs new file mode 100644 index 0000000000000..ea9102b795eda --- /dev/null +++ b/packages/cli/scripts/build.mjs @@ -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 }); + }); +}