Commit 3994995 1 parent 85929be commit 3994995 Copy full SHA for 3994995
File tree 4 files changed +34
-8
lines changed
4 files changed +34
-8
lines changed Original file line number Diff line number Diff line change 1
1
node_modules
2
2
dist
3
- * .env
3
+ * .env
4
+ /logs /app.log
Original file line number Diff line number Diff line change @@ -29,7 +29,8 @@ import {
29
29
execPromise ,
30
30
exists ,
31
31
installDependencies ,
32
- isIAllApps
32
+ isIAllApps ,
33
+ logProcessOutput
33
34
} from './utils/utils' ;
34
35
35
36
import { PackageError } from '@metacall/protocol/package' ;
@@ -236,12 +237,8 @@ export const deploy = catchAsync(
236
237
currentFile
237
238
} ) ;
238
239
239
- proc . stdout ?. on ( 'data' , ( data : Buffer ) => {
240
- console . log ( data . toString ( ) . green ) ;
241
- } ) ;
242
- proc . stderr ?. on ( 'data' , ( data : Buffer ) => {
243
- console . log ( data . toString ( ) . red ) ;
244
- } ) ;
240
+ logProcessOutput ( proc . stdout , 'green' ) ;
241
+ logProcessOutput ( proc . stderr , 'red' ) ;
245
242
246
243
proc . on ( 'message' , ( data : childProcessResponse ) => {
247
244
if ( data . type === protocol . g ) {
Original file line number Diff line number Diff line change
1
+ import * as fs from 'fs' ;
2
+ import * as path from 'path' ;
3
+
4
+ const logFilePath = path . join ( __dirname , '../../logs/' ) ;
5
+ const logFileName = 'app.log' ;
6
+ const logFileFullPath = path . join ( logFilePath , logFileName ) ;
7
+
8
+ export const logger = {
9
+ log : ( message : string ) : void => {
10
+ const timeStamp = new Date ( ) . toISOString ( ) ;
11
+ const logMessage = `${ timeStamp } - ${ message } \n` ;
12
+ console . log ( message ) ;
13
+ if ( ! fs . existsSync ( logFileFullPath ) ) {
14
+ fs . writeFileSync ( logFileFullPath , '' , { encoding : 'utf-8' } ) ;
15
+ }
16
+ fs . appendFileSync ( logFileFullPath , logMessage , { encoding : 'utf-8' } ) ;
17
+ }
18
+ } ;
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import {
13
13
IAllApps ,
14
14
InspectObject
15
15
} from '../constants' ;
16
+ import { logger } from './logger' ;
16
17
17
18
export const dirName = ( gitUrl : string ) : string =>
18
19
String ( gitUrl . split ( '/' ) [ gitUrl . split ( '/' ) . length - 1 ] ) . replace ( '.git' , '' ) ;
@@ -139,3 +140,12 @@ export const diff = (
139
140
export function isIAllApps ( data : unknown ) : data is IAllApps {
140
141
return typeof data === 'object' && data !== null ;
141
142
}
143
+
144
+ export function logProcessOutput (
145
+ proc : NodeJS . ReadableStream | null ,
146
+ color : 'green' | 'red'
147
+ ) : void {
148
+ proc ?. on ( 'data' , ( data : Buffer ) => {
149
+ logger . log ( data . toString ( ) [ color ] ) ;
150
+ } ) ;
151
+ }
You can’t perform that action at this time.
0 commit comments