From 403d1de5af4c3d573a89ad87ccc0f92d3380e2c8 Mon Sep 17 00:00:00 2001 From: Eric Hayes Date: Wed, 19 May 2021 11:37:07 -0700 Subject: [PATCH] feat(types): add typescript type generation as part of build process. Add named export run that exports middleware/queues in arena. --- .gitignore | 4 ++- .prettierignore | 2 ++ README.md | 35 ++++++++++++++++++++ index.js | 15 +++++++-- package-lock.json | 82 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 15 +++++---- src/server/app.js | 2 +- tsconfig.json | 10 ++++++ 8 files changed, 155 insertions(+), 10 deletions(-) create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index 314eccf7..bd891b16 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.tsbuildinfo +dist node_modules package-lock.json *.DS_Store @@ -5,4 +7,4 @@ package-lock.json .idea *.tern-port *.sublime-workspace -dump.rdb \ No newline at end of file +dump.rdb diff --git a/.prettierignore b/.prettierignore index eb677cd6..e5290ed6 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,4 +1,6 @@ *.hbs *.min.js *.min.css +*.d.ts +tsconfig.json pull_request_template.md diff --git a/README.md b/README.md index d0067f3e..d5b46df6 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,41 @@ router.use('/', arena); - `useCdn` - set false to use the bundled js and css files (default: true) - `customCssPath` - an URL to an external stylesheet (default: null) +In addition to the default export, you can also access both arena and the underlying queues using the named export `run`: + +```js +const Arena = require('bull-arena').run; + +const express = require('express'); +const router = express.Router(); + +const arena = Arena({ + // Include a reference to the bee-queue or bull libraries, depending on the library being used. + + queues: [ + { + // First queue configuration + }, + { + // Second queue configuration + }, + { + // And so on... + }, + ], +}); + +// manage arena queues using queue +//app.queues.list() + +router.use('/', arena.app); +``` + +When calling the named export `run` the following are returned: + +- `app` - the arena middleware +- `queues` - the underlying queues in arena + ##### Example config (for bull) ```js diff --git a/index.js b/index.js index 76a5a1c6..39e12313 100644 --- a/index.js +++ b/index.js @@ -25,7 +25,18 @@ function run(config, listenOpts = {}) { }); } - return app; + return { + app, + queues: Queues, + }; } -module.exports = run; +function runDefault(config, listenOpts = {}) { + return run(config, listenOpts).app; +} + +// default export remains unchanged +module.exports = runDefault; + +// named exports +module.exports.run = run; diff --git a/package-lock.json b/package-lock.json index 75d952f8..f6018cfa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -760,6 +760,54 @@ "integrity": "sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==", "dev": true }, + "@types/body-parser": { + "version": "1.19.0", + "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.0.tgz", + "integrity": "sha512-W98JrE0j2K78swW4ukqMleo8R7h/pFETjM2DQ90MF6XK2i4LO4W3gQ71Lt4w3bfm2EvVSyWHplECvB5sK22yFQ==", + "dev": true, + "requires": { + "@types/connect": "*", + "@types/node": "*" + } + }, + "@types/connect": { + "version": "3.4.34", + "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.34.tgz", + "integrity": "sha512-ePPA/JuI+X0vb+gSWlPKOY0NdNAie/rPUqX2GUPpbZwiKTkSPhjXWuee47E4MtE54QVzGCQMQkAL6JhV2E1+cQ==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, + "@types/express": { + "version": "4.17.11", + "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.11.tgz", + "integrity": "sha512-no+R6rW60JEc59977wIxreQVsIEOAYwgCqldrA/vkpCnbD7MqTefO97lmoBe4WE0F156bC4uLSP1XHDOySnChg==", + "dev": true, + "requires": { + "@types/body-parser": "*", + "@types/express-serve-static-core": "^4.17.18", + "@types/qs": "*", + "@types/serve-static": "*" + } + }, + "@types/express-serve-static-core": { + "version": "4.17.19", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.19.tgz", + "integrity": "sha512-DJOSHzX7pCiSElWaGR8kCprwibCB/3yW6vcT8VG3P0SJjnv19gnWG/AZMfM60Xj/YJIp/YCaDHyvzsFVeniARA==", + "dev": true, + "requires": { + "@types/node": "*", + "@types/qs": "*", + "@types/range-parser": "*" + } + }, + "@types/mime": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.2.tgz", + "integrity": "sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw==", + "dev": true + }, "@types/minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.4.tgz", @@ -772,6 +820,12 @@ "integrity": "sha512-fZQQafSREFyuZcdWFAExYjBiCL7AUCdgsk80iO0q4yihYYdcIiH28CcuPTGFgLOCC8RlW49GSQxdHwZP+I7CNg==", "dev": true }, + "@types/node": { + "version": "15.3.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-15.3.0.tgz", + "integrity": "sha512-8/bnjSZD86ZfpBsDlCIkNXIvm+h6wi9g7IqL+kmFkQ+Wvu3JrasgLElfiPgoo8V8vVfnEi0QVS12gbl94h9YsQ==", + "dev": true + }, "@types/normalize-package-data": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz", @@ -784,12 +838,34 @@ "integrity": "sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==", "dev": true }, + "@types/qs": { + "version": "6.9.6", + "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.6.tgz", + "integrity": "sha512-0/HnwIfW4ki2D8L8c9GVcG5I72s9jP5GSLVF0VIXDW00kmIpA6O33G7a8n59Tmh7Nz0WUC3rSb7PTY/sdW2JzA==", + "dev": true + }, + "@types/range-parser": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.3.tgz", + "integrity": "sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA==", + "dev": true + }, "@types/retry": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.0.tgz", "integrity": "sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==", "dev": true }, + "@types/serve-static": { + "version": "1.13.9", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.9.tgz", + "integrity": "sha512-ZFqF6qa48XsPdjXV5Gsz0Zqmux2PerNd3a/ktL45mHpa19cuMi/cL8tcxdAx497yRh+QtYPuofjT9oWw9P7nkA==", + "dev": true, + "requires": { + "@types/mime": "^1", + "@types/node": "*" + } + }, "JSONStream": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.5.tgz", @@ -6797,6 +6873,12 @@ "mime-types": "~2.1.24" } }, + "typescript": { + "version": "4.2.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.4.tgz", + "integrity": "sha512-V+evlYHZnQkaz8TRBuxTA92yZBPotr5H+WhQ7bD3hZUndx5tGOa1fuCgeSjxAzM1RiN5IzvadIXTVefuuwZCRg==", + "dev": true + }, "uglify-js": { "version": "3.13.3", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.13.3.tgz", diff --git a/package.json b/package.json index 4c39528d..507f682f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "bull-arena", "description": "An interactive UI dashboard for Bee Queue", - "main": "index.js", + "main": "dist/index.js", "author": "Mixmax ", "license": "MIT", "dependencies": { @@ -23,6 +23,7 @@ "@semantic-release/github": "^7.0.7", "@semantic-release/npm": "^7.0.5", "@semantic-release/release-notes-generator": "^9.0.1", + "@types/express": "^4.17.11", "bee-queue": "^1.2.3", "bull": "^3.16.0", "conventional-changelog-conventionalcommits": "^4.3.0", @@ -33,12 +34,15 @@ "lint-staged": "^10.5.4", "prettier": "^2.0.5", "pretty-quick": "^3.1.0", - "semantic-release": "^17.4.2" + "rimraf": "^3.0.2", + "semantic-release": "^17.4.2", + "typescript": "^4.2.4" }, "scripts": { - "ci": "npm run lint && if [ -z \"$CI\" ]; then npm run ci:commitlint; fi", + "ci": "npm run build && npm run lint && if [ -z \"$CI\" ]; then npm run ci:commitlint; fi", "ci:commitlint": "commitlint --from \"origin/${GITHUB_BASE_REF:-master}\"", "dry:run": "npm publish --dry-run", + "build": "rimraf dist && tsc", "lint": "prettier -c .", "lint:staged": "lint-staged", "prepare": "husky install", @@ -48,9 +52,8 @@ "node": ">=7.6.0" }, "files": [ - "index.js", - "public", - "src" + "dist", + "public" ], "repository": "https://github.com/bee-queue/arena.git", "version": "3.21.0" diff --git a/src/server/app.js b/src/server/app.js index 7d7eb6cb..71efd100 100644 --- a/src/server/app.js +++ b/src/server/app.js @@ -36,6 +36,6 @@ module.exports = function (config) { return { app, - Queues: app.locals.Queues, + Queues: queues, }; }; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..ae459f6d --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,10 @@ +{ + "include": ["index.js","src"], + "compilerOptions": { + "allowJs": true, + "declaration": true, + "composite": true, + "outDir": "dist", + "target": "es2017" + } +}