-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Output full logs of all processes in temporary directory
- Loading branch information
1 parent
2e6c007
commit 6bff023
Showing
5 changed files
with
48 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,37 @@ | ||
import * as fs from '../utils/fs' | ||
import * as pathUtils from 'path' | ||
import { ExecaChildProcess } from 'execa' | ||
import { Observable } from 'rxjs' | ||
|
||
export default function observeProcess(process: ExecaChildProcess): Observable<string> { | ||
export default function observeProcess( | ||
process: ExecaChildProcess, | ||
logName: string, | ||
): Observable<string> { | ||
return new Observable(subscriber => { | ||
process | ||
.then(() => subscriber.complete()) | ||
.catch(error => subscriber.error(error)) | ||
(async () => { | ||
await fs.mkdir('logs', { recursive: true }) | ||
|
||
process.stdout.on('data', (data: Buffer) => { | ||
subscriber.next(data.toString().trim()) | ||
}) | ||
const fileName = pathUtils.join('logs', `${logName}.log`) | ||
const failedFileName = pathUtils.join('logs', `${logName}.failed.log`) | ||
const stream = fs.createWriteStream(fileName) | ||
|
||
process | ||
.then(() => { | ||
stream.close() | ||
subscriber.complete() | ||
}) | ||
.catch(async error => { | ||
stream.close() | ||
await fs.rename(fileName, failedFileName) | ||
|
||
subscriber.error(error) | ||
}) | ||
|
||
process.stdout.on('data', (data: Buffer) => { | ||
subscriber.next(data.toString().trim()) | ||
stream.write(data) | ||
}) | ||
process.stderr.on('data', (data: Buffer) => stream.write(data)) | ||
})() | ||
}) | ||
} |