1
1
/* eslint-disable max-lines */
2
+ import { ExecutorContext } from '@nrwl/devkit' ;
2
3
import axios from 'axios' ;
3
4
import {
4
5
ChildProcessWithoutNullStreams ,
@@ -12,6 +13,7 @@ import { Inject, Service } from 'typedi';
12
13
13
14
import {
14
15
APTFILE ,
16
+ EXECUTOR_CONTEXT ,
15
17
HEROKU_BUILDPACK_APT ,
16
18
HEROKU_BUILDPACK_STATIC ,
17
19
PROCFILE ,
@@ -48,6 +50,7 @@ export class HerokuAppService {
48
50
constructor (
49
51
@Inject ( DEPLOY_EXECUTOR_SCHEMA )
50
52
private options : DeployExecutorSchema ,
53
+ @Inject ( EXECUTOR_CONTEXT ) private readonly context : ExecutorContext ,
51
54
@Logger ( ) private logger : LoggerInterface
52
55
) {
53
56
this . logger . debug = options . debug ;
@@ -77,7 +80,7 @@ export class HerokuAppService {
77
80
...options ,
78
81
} ;
79
82
this . logger . info ( `Deploying ${ projectName } on ${ appName } Heroku app...` ) ;
80
- await new HerokuApp ( extendedOptions , this . logger ) . run ( ) ;
83
+ await new HerokuApp ( extendedOptions , this . context , this . logger ) . run ( ) ;
81
84
}
82
85
}
83
86
@@ -98,12 +101,16 @@ export class HerokuAppService {
98
101
* 13. Run healthcheck (optional)
99
102
*/
100
103
class HerokuApp {
101
- // TODO: add property appsDir => context.nxJsonConfiguration.workspaceLayout?.appsDir ??= 'apps' ;
104
+ private readonly appsDir : string ;
102
105
103
106
constructor (
104
107
public options : ExtendedDeployExecutorSchema ,
108
+ public context : ExecutorContext ,
105
109
public logger : LoggerInterface
106
- ) { }
110
+ ) {
111
+ this . appsDir =
112
+ context . nxJsonConfiguration ?. workspaceLayout ?. appsDir || 'apps' ;
113
+ }
107
114
108
115
private async addAndCommit (
109
116
projectName : string ,
@@ -128,7 +135,7 @@ class HerokuApp {
128
135
private async createProcfile ( ) : Promise < void > {
129
136
const { procfile, projectName } = this . options ;
130
137
if ( procfile ) {
131
- const procfilePath = `apps /${ projectName } /${ PROCFILE } ` ;
138
+ const procfilePath = `${ this . appsDir } /${ projectName } /${ PROCFILE } ` ;
132
139
await writeFile ( join ( process . cwd ( ) , procfilePath ) , procfile ) ;
133
140
await this . addAndCommit ( projectName , PROCFILE ) ;
134
141
}
@@ -140,10 +147,9 @@ class HerokuApp {
140
147
) : Promise < void > {
141
148
const { buildPacks, projectName } = this . options ;
142
149
if ( buildPacks . includes ( buildPackName ) ) {
143
- // TODO: check nxConfig.appsDir
144
150
const srcPath = join (
145
151
process . cwd ( ) ,
146
- `apps /${ projectName } /${ buildPackFile } `
152
+ `${ this . appsDir } /${ projectName } /${ buildPackFile } `
147
153
) ;
148
154
const destPath = join ( process . cwd ( ) , buildPackFile ) ;
149
155
const srcBuildPackFile = await readFile ( srcPath , 'utf-8' ) ;
@@ -325,11 +331,11 @@ class HerokuApp {
325
331
//? if data contains `Everything up-to-date`, should we still restart the app
326
332
push . stdout
327
333
. setEncoding ( 'utf-8' )
328
- . on ( 'data' , ( data ) => this . logger . info ( data ) ) ;
334
+ . on ( 'data' , ( data ) => this . logger . info ( data ?. trim ( ) ) ) ;
329
335
330
336
push . stderr
331
337
. setEncoding ( 'utf-8' )
332
- . on ( 'data' , ( data ) => this . logger . info ( data ) ) ;
338
+ . on ( 'data' , ( data ) => this . logger . info ( data ?. trim ( ) ) ) ;
333
339
return push ;
334
340
}
335
341
0 commit comments