1
1
/* eslint-disable max-lines */
2
2
import axios from 'axios' ;
3
- import { ChildProcessWithoutNullStreams , spawn } from 'child_process' ;
3
+ import {
4
+ ChildProcessWithoutNullStreams ,
5
+ ExecException ,
6
+ spawn ,
7
+ } from 'child_process' ;
4
8
import { readFile , writeFile } from 'fs/promises' ;
5
9
import { toNumber } from 'lodash' ;
6
10
import { join } from 'path' ;
@@ -10,6 +14,7 @@ import {
10
14
APTFILE ,
11
15
HEROKU_BUILDPACK_APT ,
12
16
HEROKU_BUILDPACK_STATIC ,
17
+ PROCFILE ,
13
18
STATIC_JSON ,
14
19
} from '../../common/constants' ;
15
20
import { getGitLocalBranchName , getGitRemoteBranch } from '../../common/git' ;
@@ -95,23 +100,32 @@ class HerokuApp {
95
100
public logger : LoggerInterface
96
101
) { }
97
102
103
+ private async addAndCommit (
104
+ projectName : string ,
105
+ pattern : string
106
+ ) : Promise < void > {
107
+ try {
108
+ //? allow custom commit message
109
+ await exec (
110
+ `git add ${ pattern } && git commit -m "ci(${ projectName } ): add ${ pattern } " -n --no-gpg-sign`
111
+ ) ;
112
+ this . logger . info ( `Wrote ${ pattern } with custom configuration.` ) ;
113
+ } catch ( error ) {
114
+ const ex = error as ExecException ;
115
+ // there is (probably) nothing to commit
116
+ this . logger . warn ( ex . message ) ;
117
+ this . logger . warn ( ex . code ?. toString ( ) ) ;
118
+ }
119
+ }
98
120
/*
99
121
* @description create Procfile from options
100
122
*/
101
123
private async createProcfile ( ) : Promise < void > {
102
124
const { procfile, projectName } = this . options ;
103
125
if ( procfile ) {
104
- const procfilePath = `apps/${ projectName } /Procfile ` ;
126
+ const procfilePath = `apps/${ projectName } /${ PROCFILE } ` ;
105
127
await writeFile ( join ( process . cwd ( ) , procfilePath ) , procfile ) ;
106
- try {
107
- //? allow custom commit message
108
- await exec (
109
- `git add ${ procfilePath } && git commit -m "ci(${ projectName } ): add Procfile" -n --no-gpg-sign`
110
- ) ;
111
- this . logger . info ( 'Written Procfile with custom configuration' ) ;
112
- } catch ( err ) {
113
- // there is nothing to commit
114
- }
128
+ await this . addAndCommit ( projectName , PROCFILE ) ;
115
129
}
116
130
}
117
131
@@ -121,6 +135,7 @@ class HerokuApp {
121
135
) : Promise < void > {
122
136
const { buildPacks, projectName } = this . options ;
123
137
if ( buildPacks . includes ( buildPackName ) ) {
138
+ // TODO: check nxConfig.appsDir
124
139
const srcPath = join (
125
140
process . cwd ( ) ,
126
141
`apps/${ projectName } /${ buildPackFile } `
@@ -132,11 +147,7 @@ class HerokuApp {
132
147
if ( destBuildPackFile === srcBuildPackFile ) return ;
133
148
134
149
await writeFile ( destPath , srcBuildPackFile ) ;
135
- //? allow for custom commit message
136
- await exec (
137
- `git add ${ buildPackFile } && git commit -m "ci(${ projectName } ): add ${ buildPackFile } " -n --no-gpg-sign`
138
- ) ;
139
- this . logger . info ( `Written ${ buildPackFile } with custom configuration` ) ;
150
+ await this . addAndCommit ( projectName , buildPackFile ) ;
140
151
}
141
152
}
142
153
@@ -409,8 +420,8 @@ class HerokuApp {
409
420
throw new Error ( 'Failed to match the `checkString`' ) ;
410
421
}
411
422
this . logger . info ( body ) ;
412
- } catch ( err ) {
413
- this . logger . warn ( err . message ) ;
423
+ } catch ( error ) {
424
+ this . logger . warn ( error . message ) ;
414
425
await this . healthcheckFailed ( ) ;
415
426
}
416
427
}
0 commit comments