Skip to content

Commit 403d1de

Browse files
author
Eric Hayes
committed
feat(types): add typescript type generation as part of build process. Add named export run that exports middleware/queues in arena.
1 parent 5673ca9 commit 403d1de

File tree

8 files changed

+155
-10
lines changed

8 files changed

+155
-10
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
.tsbuildinfo
2+
dist
13
node_modules
24
package-lock.json
35
*.DS_Store
46
.vscode
57
.idea
68
*.tern-port
79
*.sublime-workspace
8-
dump.rdb
10+
dump.rdb

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
*.hbs
22
*.min.js
33
*.min.css
4+
*.d.ts
5+
tsconfig.json
46
pull_request_template.md

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,41 @@ router.use('/', arena);
171171
- `useCdn` - set false to use the bundled js and css files (default: true)
172172
- `customCssPath` - an URL to an external stylesheet (default: null)
173173

174+
In addition to the default export, you can also access both arena and the underlying queues using the named export `run`:
175+
176+
```js
177+
const Arena = require('bull-arena').run;
178+
179+
const express = require('express');
180+
const router = express.Router();
181+
182+
const arena = Arena({
183+
// Include a reference to the bee-queue or bull libraries, depending on the library being used.
184+
185+
queues: [
186+
{
187+
// First queue configuration
188+
},
189+
{
190+
// Second queue configuration
191+
},
192+
{
193+
// And so on...
194+
},
195+
],
196+
});
197+
198+
// manage arena queues using queue
199+
//app.queues.list()
200+
201+
router.use('/', arena.app);
202+
```
203+
204+
When calling the named export `run` the following are returned:
205+
206+
- `app` - the arena middleware
207+
- `queues` - the underlying queues in arena
208+
174209
##### Example config (for bull)
175210

176211
```js

index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,18 @@ function run(config, listenOpts = {}) {
2525
});
2626
}
2727

28-
return app;
28+
return {
29+
app,
30+
queues: Queues,
31+
};
2932
}
3033

31-
module.exports = run;
34+
function runDefault(config, listenOpts = {}) {
35+
return run(config, listenOpts).app;
36+
}
37+
38+
// default export remains unchanged
39+
module.exports = runDefault;
40+
41+
// named exports
42+
module.exports.run = run;

package-lock.json

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bull-arena",
33
"description": "An interactive UI dashboard for Bee Queue",
4-
"main": "index.js",
4+
"main": "dist/index.js",
55
"author": "Mixmax <[email protected]>",
66
"license": "MIT",
77
"dependencies": {
@@ -23,6 +23,7 @@
2323
"@semantic-release/github": "^7.0.7",
2424
"@semantic-release/npm": "^7.0.5",
2525
"@semantic-release/release-notes-generator": "^9.0.1",
26+
"@types/express": "^4.17.11",
2627
"bee-queue": "^1.2.3",
2728
"bull": "^3.16.0",
2829
"conventional-changelog-conventionalcommits": "^4.3.0",
@@ -33,12 +34,15 @@
3334
"lint-staged": "^10.5.4",
3435
"prettier": "^2.0.5",
3536
"pretty-quick": "^3.1.0",
36-
"semantic-release": "^17.4.2"
37+
"rimraf": "^3.0.2",
38+
"semantic-release": "^17.4.2",
39+
"typescript": "^4.2.4"
3740
},
3841
"scripts": {
39-
"ci": "npm run lint && if [ -z \"$CI\" ]; then npm run ci:commitlint; fi",
42+
"ci": "npm run build && npm run lint && if [ -z \"$CI\" ]; then npm run ci:commitlint; fi",
4043
"ci:commitlint": "commitlint --from \"origin/${GITHUB_BASE_REF:-master}\"",
4144
"dry:run": "npm publish --dry-run",
45+
"build": "rimraf dist && tsc",
4246
"lint": "prettier -c .",
4347
"lint:staged": "lint-staged",
4448
"prepare": "husky install",
@@ -48,9 +52,8 @@
4852
"node": ">=7.6.0"
4953
},
5054
"files": [
51-
"index.js",
52-
"public",
53-
"src"
55+
"dist",
56+
"public"
5457
],
5558
"repository": "https://github.com/bee-queue/arena.git",
5659
"version": "3.21.0"

src/server/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ module.exports = function (config) {
3636

3737
return {
3838
app,
39-
Queues: app.locals.Queues,
39+
Queues: queues,
4040
};
4141
};

tsconfig.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"include": ["index.js","src"],
3+
"compilerOptions": {
4+
"allowJs": true,
5+
"declaration": true,
6+
"composite": true,
7+
"outDir": "dist",
8+
"target": "es2017"
9+
}
10+
}

0 commit comments

Comments
 (0)