6
6
'use strict'
7
7
8
8
const fs = require ( 'fs' )
9
- const packageJson = require ( './package.json' )
9
+ const path = require ( 'path' )
10
+
11
+ const rootDir = path . resolve ( __dirname , '..' )
12
+ const packageJson = require ( `${ rootDir } /package.json` )
10
13
const config = packageJson . config
11
14
12
- modifyApigClient ( config . apiGatewayApiId , config . primaryAwsRegion )
13
- modifyDevPortalJs ( config . cognitoIdentityPoolId , config . primaryAwsRegion , config . cognitoRegion , config . cognitoUserPoolId , config . cognitoClientId )
14
- modifySwaggerFile ( config . accountId , config . primaryAwsRegion , config . apiGatewayApiName )
15
- modifyExpressServer ( config . siteS3Bucket , config . primaryAwsRegion )
16
- modifyCloudFormation ( config . cognitoIdentityPoolId )
17
- modifyPackageFile ( config )
18
- modifyUiPackageFile ( config . siteS3Bucket , config . primaryAwsRegion )
15
+ module . exports = function ( ) {
16
+ modifyApigClient ( config . apiGatewayApiId , config . primaryAwsRegion )
17
+ modifyDevPortalJs ( config . cognitoIdentityPoolId , config . primaryAwsRegion , config . cognitoRegion , config . cognitoUserPoolId , config . cognitoClientId )
18
+ modifySwaggerFile ( config . accountId , config . primaryAwsRegion , config . apiGatewayApiName )
19
+ modifyExpressServer ( config . siteS3Bucket , config . primaryAwsRegion )
20
+ modifyCloudFormation ( config . cognitoIdentityPoolId )
21
+ modifyPackageFile ( config )
22
+ modifyUiPackageFile ( config . siteS3Bucket , config . primaryAwsRegion )
23
+ }
19
24
20
25
function modifyApigClient ( apiGatewayApiId , primaryAwsRegion ) {
21
- const apigClientPath = '. /dev-portal/public/apigateway-js-sdk/apigClient.js'
26
+ const apigClientPath = ` ${ rootDir } /dev-portal/public/apigateway-js-sdk/apigClient.js`
22
27
const apigClient = fs . readFileSync ( apigClientPath , 'utf8' )
23
28
const apiGatewayApiIdRegex = new RegExp ( apiGatewayApiId , 'g' )
24
29
const primaryAwsRegionRegex = new RegExp ( primaryAwsRegion , 'g' )
@@ -30,7 +35,7 @@ function modifyApigClient(apiGatewayApiId, primaryAwsRegion) {
30
35
}
31
36
32
37
function modifyDevPortalJs ( cognitoIdentityPoolId , primaryAwsRegion , cognitoRegion , cognitoUserPoolId , cognitoClientId ) {
33
- const htmlPath = '. /dev-portal/src/services/aws.js'
38
+ const htmlPath = ` ${ rootDir } /dev-portal/src/services/aws.js`
34
39
const html = fs . readFileSync ( htmlPath , 'utf8' )
35
40
const cognitoIdentityPoolIdRegex = new RegExp ( cognitoIdentityPoolId , 'g' )
36
41
const cognitoRegionRegex = new RegExp ( `const cognitoRegion = '${ cognitoRegion } '` , 'g' )
@@ -48,7 +53,7 @@ function modifyDevPortalJs(cognitoIdentityPoolId, primaryAwsRegion, cognitoRegio
48
53
}
49
54
50
55
function modifySwaggerFile ( accountId , primaryAwsRegion , apiGatewayApiName ) {
51
- const swaggerDefinitionPath = '. /lambdas/backend/dev-portal-express-proxy-api.yaml'
56
+ const swaggerDefinitionPath = ` ${ rootDir } /lambdas/backend/dev-portal-express-proxy-api.yaml`
52
57
const swaggerDefinition = fs . readFileSync ( swaggerDefinitionPath , 'utf8' )
53
58
const accountIdRegex = new RegExp ( accountId , 'g' )
54
59
const apiGatewayApiNameRegex = new RegExp ( apiGatewayApiName , 'g' )
@@ -62,7 +67,7 @@ function modifySwaggerFile(accountId, primaryAwsRegion, apiGatewayApiName) {
62
67
}
63
68
64
69
function modifyExpressServer ( siteS3Bucket , primaryAwsRegion ) {
65
- const expressServerPath = '. /lambdas/backend/express-server.js'
70
+ const expressServerPath = ` ${ rootDir } /lambdas/backend/express-server.js`
66
71
const expressServer = fs . readFileSync ( expressServerPath , 'utf8' )
67
72
const siteS3BucketRegex = new RegExp ( siteS3Bucket , 'g' )
68
73
const primaryAwsRegionRegex = new RegExp ( primaryAwsRegion , 'g' )
@@ -74,7 +79,7 @@ function modifyExpressServer(siteS3Bucket, primaryAwsRegion) {
74
79
}
75
80
76
81
function modifyCloudFormation ( cognitoIdentityPoolId ) {
77
- const cloudFormationPath = '. /cloudformation/base.yaml'
82
+ const cloudFormationPath = ` ${ rootDir } /cloudformation/base.yaml`
78
83
const cloudFormation = fs . readFileSync ( cloudFormationPath , 'utf8' )
79
84
const cognitoIdentityPoolIdRegex = new RegExp ( cognitoIdentityPoolId , 'g' )
80
85
const cloudFormationModified = cloudFormation
@@ -84,7 +89,7 @@ function modifyCloudFormation(cognitoIdentityPoolId) {
84
89
}
85
90
86
91
function modifyPackageFile ( config ) {
87
- const packageJsonPath = '. /package.json'
92
+ const packageJsonPath = ` ${ rootDir } /package.json`
88
93
const packageJson = fs . readFileSync ( packageJsonPath , 'utf8' )
89
94
const artifactsS3BucketRegex = new RegExp ( `"artifactsS3Bucket": "${ config . artifactsS3Bucket } "` , 'g' )
90
95
const siteS3BucketRegex = new RegExp ( config . siteS3Bucket , 'g' )
@@ -114,7 +119,7 @@ function modifyPackageFile(config) {
114
119
}
115
120
116
121
function modifyUiPackageFile ( siteS3Bucket , primaryAwsRegion ) {
117
- const packageJsonPath = '. /dev-portal/package.json'
122
+ const packageJsonPath = ` ${ rootDir } /dev-portal/package.json`
118
123
const packageJson = fs . readFileSync ( packageJsonPath , 'utf8' )
119
124
const primaryAwsRegionRegex = new RegExp ( primaryAwsRegion , 'g' )
120
125
const siteS3BucketRegex = new RegExp ( siteS3Bucket , 'g' )
0 commit comments