@@ -6,10 +6,15 @@ import { promisify } from "util";
66const asyncExec = promisify ( cpExec ) ;
77
88export function createExec ( cwd :string ) {
9- return function exec (
9+ return async function exec (
1010command :string
11- ) :Promise < { stdout :string ; stderr :string } > | never {
12- return asyncExec ( command , { cwd} ) ;
11+ ) :Promise < { stdout :string | null ; stderr :string } > {
12+ try {
13+ const result = await asyncExec ( command , { cwd} ) ;
14+ return result ;
15+ } catch ( e ) {
16+ return { stdout :null , stderr :e . message } ;
17+ }
1318} ;
1419}
1520
@@ -31,46 +36,57 @@ export function createCherryPick(cwd: string) {
3136}
3237
3338export function createCommandRunner ( cwd :string ) {
34- return async function runCommands ( commands :string [ ] , dir ?:string ) {
39+ return async function runCommands (
40+ commands :string [ ] ,
41+ dir ?:string
42+ ) :Promise < boolean > {
43+ let errors = [ ] ;
3544for ( const command of commands ) {
3645try {
3746console . log ( `>${ command } ` ) ;
3847let cwdDir = cwd ;
3948if ( dir ) {
4049cwdDir = path . join ( cwd , dir ) ;
4150}
42- await createExec ( cwdDir ) ( command ) ;
51+ const { stdout, stderr} = await createExec ( cwdDir ) ( command ) ;
52+
53+ console . warn ( stderr ) ;
54+ console . log ( stdout ) ;
4355} catch ( e ) {
44- console . log ( `Setup command failed: "${ command } "` ) ;
45- console . log ( e . message ) ;
56+ console . error ( `Command failed: "${ command } "` ) ;
57+ console . warn ( e . message ) ;
58+ errors . push ( e . message ) ;
4659}
4760}
61+ return ! ! errors . length ;
4862} ;
4963}
5064
51- function isAbsolute ( p :string ) {
52- return path . normalize ( p + "/" ) === path . normalize ( path . resolve ( p ) + "/" ) ;
53- }
65+ // function isAbsolute(p: string) {
66+ // return path.normalize(p + "/") === path.normalize(path.resolve(p) + "/");
67+ // }
5468
5569export function createTestRunner ( cwd :string , config :T . TestRunnerConfig ) {
5670const { command, args, directory} = config ;
5771
58- const commandIsAbsolute = isAbsolute ( command ) ;
72+ // const commandIsAbsolute = isAbsolute(command);
5973
60- let runnerPath ;
61- if ( commandIsAbsolute ) {
62- // absolute path
63- runnerPath = command ;
64- } else {
65- // relative path
66- runnerPath = path . join ( cwd , directory || "" , command ) ;
74+ let wd = cwd ;
75+ if ( directory ) {
76+ wd = path . join ( cwd , directory ) ;
6777}
6878
69- const commandWithArgs = `${ runnerPath } ${ args . tap } ` ;
79+ const commandWithArgs = `${ command } ${ args . tap } ` ;
7080
71- return async function runTest ( ) {
72- const { stdout, stderr} = await createExec ( cwd ) ( commandWithArgs ) ;
73- console . log ( stdout ) ;
74- console . warn ( stderr ) ;
81+ return async function runTest ( ) :Promise < {
82+ stdout :string | null ;
83+ stderr :string | null ;
84+ } > {
85+ try {
86+ // console.log(await createExec(wd)("ls -a node_modules/.bin"));
87+ return await createExec ( wd ) ( commandWithArgs ) ;
88+ } catch ( e ) {
89+ return Promise . resolve ( { stdout :null , stderr :e . message } ) ;
90+ }
7591} ;
7692}