8000 fix return correct for curried function · TYPECASTINGSG/rpscript-api-open@60812f4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 60812f4

Browse files
committed
fix return correct for curried function
1 parent a967552 commit 60812f4

File tree

4 files changed

+48
-15
lines changed

4 files changed

+48
-15
lines changed

package-lock.json

Lines changed: 27 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"test": "mocha -r ts-node/register test/**.ts"
2424
},
2525
"dependencies": {
26+
"deasync-promise": "^1.0.1",
2627
"opn": "^5.3.0",
2728
"rpscript-interface": "^0.6.2"
2829
},

src/index.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
11
import opn from 'opn';
22
import {ChildProcess, execSync} from 'child_process';
33
import {RpsContext,RpsModule,rpsAction,R} from 'rpscript-interface';
4+
var deasyncPromise = require('deasync-promise');
45

56

67
/** Open a file or url in the user's preferred application.
7-
* @see {@link https://www.npmjs.com/package/opn|Opn}
8+
*
9+
* @see https://www.npmjs.com/package/opn {@link https://www.npmjs.com/package/opn|Opn}
810
* @namespace Open
11+
*
12+
* @example
13+
* rps install open
14+
*
915
*/
1016
@RpsModule("open")
1117
export default class RPSOpen {
1218

13-
/**
19+
/**
1420
* @function open
1521
* @memberof Open
1622
* @example
1723
* ;Opens a browser
1824
* open "http://www.google.com"
19-
* open "http://www.google.com" --app="firefox"
20-
* ;Opens a text file with preferred editor
21-
* open "test.txt"
22-
* @param {string} filepath file to be open
23-
* @param {string} preferredApp optional.
24-
* @returns {void}
25-
* @summary Make beep sound
25+
* open --app="firefox" "http://www.google.com"
26+
*
2627
*
27-
* @see {@link https://www.npmjs.com/package/opn}
28+
* @param {string} filepath file to open.
29+
* @param {*} options refer to Opn documentation.
30+
* @summary open :: String → ChildProcess
31+
* @description
2832
*
2933
*/
3034
@rpsAction({verbName:'open'})
31-
open (ctx:RpsContext,opts:Object, filepath?:string) : Promise<ChildProcess|Buffer>|Function{
35+
open (ctx:RpsContext,opts:Object, filepath?:string) : Promise<ChildProcess>|Function{
3236
if(!filepath){
3337
return function (filepath) {
34-
return opn(filepath,opts);
38+
return deasyncPromise(opn(filepath,opts));
3539
}
3640
}
37-
else opn(filepath,opts);
41+
else return opn(filepath,opts);
3842
}
3943

4044
private childProcessOpen (filepath:string) :Buffer {

test/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ m.describe('Open', () => {
1111

1212
await open.open(new RpsContext,{},"README.md");
1313

14-
await open.open(new RpsContext,{},"https://www.google.com.sg");
14+
let output = await open.open(new RpsContext,{},"https://www.google.com.sg");
15+
console.log(output);
1516

1617
let firefox:any = await open.open(new RpsContext,{app:'firefox'});
17-
firefox("https://www.google.com.sg");
18+
console.log(firefox("https://www.google.com.sg"));
1819

1920
}).timeout(0);
2021

0 commit comments

Comments
 (0)
0