@@ -31,6 +31,45 @@ npm i --save @hyperse/exec-program
3131
3232### Usage
3333
34+ ### runTsScript
35+
36+ ``` ts
37+ import { dirname , join } from ' node:path' ;
38+ import { fileURLToPath } from ' node:url' ;
39+ import { runTsScript } from ' @hyperse/exec-program' ;
40+
41+ const getDirname = (url : string , ... paths : string []) => {
42+ return join (dirname (fileURLToPath (url )), ... paths );
43+ };
44+
45+ const cliPath = getDirname (import .meta .url , ' ./cli-test.ts' );
46+ const { stderr, stdout } = await runTsScript (cliPath );
47+ console .log (stderr , stdout );
48+ ```
49+
50+ ### exec
51+
52+ import { exec } from '@hyperse/exec-program ';
53+
54+ ``` ts
55+ const { stdout, stderr } = await exec (
56+ ' npm' ,
57+ [' i' , ' --no-save' , ' --no-package-lock' , ... toInstall ],
58+ {
59+ cwd: target .directory ,
60+ maxBuffer: TEN_MEGA_BYTE ,
61+ env: this .options .npmEnv ,
62+ }
63+ );
64+ ```
65+
66+ ``` ts
67+ await exec (' npm' , [' pack' , directory ], {
68+ cwd: this .uniqueDir ,
69+ maxBuffer: TEN_MEGA_BYTE ,
70+ });
71+ ```
72+
3473#### unit test
3574
36751 . config ` tsconfig.json `
@@ -83,7 +122,7 @@ const cliPath = getDirname(import.meta.url, './cli-test.ts');
83122
84123describe (' test suites of exec program' , () => {
85124 it (' should correct invoke cli.ts' , async () => {
86- const { stderr, stdout } = await runTsScript (cliPath , {} );
125+ const { stderr, stdout } = await runTsScript (cliPath );
87126 console .log (stderr , stdout );
88127 expect (stderr ).toBe (' ' );
89128 expect (stdout ).toMatch (/ cli... / );
0 commit comments