Skip to content

Commit 02eb7f3

Browse files
authored
Merge pull request #19 from ngfelixl/refactor/remove-opn
package: remove opn
2 parents 241e6b8 + 164e7da commit 02eb7f3

File tree

7 files changed

+49
-90
lines changed

7 files changed

+49
-90
lines changed

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,10 @@ the plots in real-time.
184184
[![twitter](https://img.shields.io/badge/twitter-%40ngfelixl-blue.svg?logo=twitter)](https://twitter.com/intent/follow?screen_name=ngfelixl)
185185
[![github](https://img.shields.io/badge/github-%40ngfelixl-blue.svg?logo=github)](https://github.com/ngfelixl)
186186

187-
Hi, I am Felix,
188-
Software developer and Angular, NgRX contributor
187+
Hi, I am Felix,<br>
188+
Senior Angular developer and Angular, RxJS and NgRX contributor.
189189

190190
![avatar](https://avatars2.githubusercontent.com/u/24190530?s=200&v=4)
191191

192192
If you like this library, think about giving it a star or follow me on twitter or github or check out my personal
193-
the [website](https://felixlemke.com).
194-
195-
## Dependencies
196-
197-
- [opn](https://www.npmjs.com/package/opn)
193+
the [website](https://felixlemke.dev).

package-lock.json

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

package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nodeplotlib",
3-
"version": "0.6.3",
3+
"version": "0.6.4",
44
"description": "NodeJS frontend-less plotting lib using plotly.js inspired by matplotlib",
55
"main": "dist/lib/index.js",
66
"types": "dist/lib/index.d.ts",
@@ -26,7 +26,6 @@
2626
"prepare": "npm run clean && npm run prepare-copy-files && npm run test && npm run build ",
2727
"prepublishOnly": "npm test && npm run lint",
2828
"preversion": "npm run lint",
29-
"precommit": "npm run format && npm run test",
3029
"build-copy-files": "node ./scripts/build.js",
3130
"prepare-copy-files": "node ./scripts/prepare.js"
3231
},
@@ -42,14 +41,11 @@
4241
],
4342
"author": "Felix Lemke <[email protected]> (https://felixlemke.com)",
4443
"license": "MIT",
45-
"dependencies": {
46-
"opn": "^5.5.0"
47-
},
44+
"dependencies": {},
4845
"devDependencies": {
4946
"@types/d3": "^5.7.1",
5047
"@types/jest": "^24.0.1",
5148
"@types/node": "^10.10.1",
52-
"@types/opn": "^5.1.0",
5349
"@types/plotly.js": "^1.43.1",
5450
"@types/request": "^2.48.1",
5551
"copyfiles": "^2.1.0",

src/server.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { exec } from 'child_process';
12
import { readFile } from 'fs';
23
import { createServer, IncomingMessage, Server as HttpServer, ServerResponse } from 'http';
34
import { Socket } from 'net';
4-
import opn from 'opn';
5+
import { type } from 'os';
56
import { join } from 'path';
67
import { IPlotsContainer } from './models';
78

@@ -66,11 +67,19 @@ export class Server {
6667
for (const plotEntry of Object.entries(this.plotsContainer)) {
6768
if (!plotEntry[1].opened && !plotEntry[1].pending) {
6869
plotEntry[1].pending = true;
69-
opn(`http://localhost:${this.port}/plots/${plotEntry[0]}/index.html`);
70+
this.openWindow(`http://localhost:${this.port}/plots/${plotEntry[0]}/index.html`);
7071
}
7172
}
7273
}
7374

75+
private openWindow(location: string) {
76+
switch (type()) {
77+
case 'Linux': exec(`xdg-open ${location}`); break;
78+
case 'Darwin': exec(`open ${location}`); break;
79+
case 'Windows_NT': exec(`start ${location}`); break;
80+
}
81+
}
82+
7483
/**
7584
* Creates the Webserver instance
7685
*/

test/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const plot = require('../dist/lib');
2+
plot.stack([{ x: [0], y: [1], type: 'line'}])
3+
plot.plot()

test/server.spec.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import opn from 'opn';
1+
import { exec } from 'child_process';
22
import request from 'request';
33
import { Server } from '../src/server';
44

@@ -9,7 +9,7 @@ const validData = {
99
plots: [{data: [{ x: [1], y: [2]}]}]
1010
};
1111

12-
jest.mock('opn');
12+
jest.mock('child_process');
1313
jest.mock('fs', () => ({readFile: (path: any, options: any, callback: (err: any, data: any) => void) => {
1414
callback('Error', null);
1515
}}));
@@ -21,7 +21,6 @@ describe('Server', () => {
2121
server = new Server(port);
2222
});
2323

24-
2524
it('should instantiate', () => {
2625
expect(server).toBeTruthy();
2726
});
@@ -33,7 +32,7 @@ describe('Server', () => {
3332
plots: []
3433
}});
3534

36-
expect(opn).toHaveBeenCalledTimes(1);
35+
expect(exec).toHaveBeenCalledTimes(1);
3736
});
3837

3938
it('should serve the data', (done) => {
@@ -116,9 +115,4 @@ describe('Server', () => {
116115
server.clean();
117116
server = null;
118117
});
119-
120-
// afterAll(() => {
121-
// console.log((process as any)._getActiveRequests());
122-
// console.log((process as any)._getActiveHandles()[0]);
123-
// });
124118
});

test/server.www.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const validData = {
99
plots: [{data: [{ x: [1], y: [2]}]}]
1010
};
1111

12-
jest.mock('opn');
12+
jest.mock('child_process');
1313
jest.mock('fs', () => ({readFile: (path: any, options: any, callback: (err: any, data: any) => void) => {
1414
switch (path) {
1515
case join(__dirname, '..', 'www', 'index.html'): callback(null, 'index.html data'); break;

0 commit comments

Comments
 (0)