1- /* eslint-disable @typescript-eslint /no-var-requires */
1+ /* eslint-disable node /no-unpublished-import */
22/* eslint-disable no-console */
33
4- const aws = require ( 'aws-sdk' ) ;
5- const { Route53Client, GetHostedZoneCommand } = require ( "@aws-sdk/client-route-53" ) ;
6- const { STSClient, GetCallerIdentityCommand } = require ( "@aws-sdk/client-sts" ) ;
7- const commander = require ( 'commander' ) ;
8- const AwsArchitect = require ( 'aws-architect' ) ;
9- const path = require ( 'path' ) ;
10- const yaml = require ( 'js-yaml' ) ;
11- const fs = require ( 'fs-extra' ) ;
4+ import aws from 'aws-sdk' ;
5+ import { Route53Client , ListHostedZonesByNameCommand } from '@aws-sdk/client-route-53' ;
6+ import { STSClient , GetCallerIdentityCommand } from '@aws-sdk/client-sts' ;
7+ import commander from 'commander' ;
8+ import AwsArchitect from 'aws-architect' ;
9+ import path from 'path' ;
10+ import fs from 'fs-extra' ;
11+
12+ import stackTemplateProvider from './template/cloudFormationWebsiteTemplate.js' ;
1213
1314aws . config . update ( { region : 'us-east-1' } ) ;
1415
15- const packageMetadataFile = path . join ( __dirname , 'package.json' ) ;
16- const packageMetadata = require ( packageMetadataFile ) ;
16+ const underscoreDirname = path . dirname ( import . meta. url ) . replace ( 'file:' , '' ) ;
17+ const packageMetadataFile = path . join ( underscoreDirname , 'package.json' ) ;
18+ const packageMetadata = await fs . readJson ( packageMetadataFile ) ;
1719
1820function getVersion ( ) {
1921 let release_version = '0.0' ;
2022 const pull_request = '' ;
2123 const branch = process . env . GITHUB_REF ;
2224 const build_number = process . env . GITHUB_RUN_NUMBER ;
2325
24- //Builds of pull requests
26+ // Builds of pull requests
2527 if ( pull_request && ! pull_request . match ( / f a l s e / i) ) {
2628 release_version = `0.${ pull_request } ` ;
2729 } else if ( ! branch || ! branch . match ( / ^ ( r e f s \/ h e a d s \/ ) ? r e l e a s e [ / - ] / i) ) {
28- //Builds of branches that aren't master or release
30+ // Builds of branches that aren't master or release
2931 release_version = '0.0' ;
3032 } else {
31- //Builds of release branches (or locally or on server)
33+ // Builds of release branches (or locally or on server)
3234 release_version = branch . match ( / ^ (?: r e f s \/ h e a d s \/ ) ? r e l e a s e [ / - ] ( \d + (?: \. \d + ) { 0 , 3 } ) $ / i) [ 1 ] ;
3335 }
3436 return `${ release_version } .${ ( build_number || '0' ) } .0.0.0.0` . split ( '.' ) . slice ( 0 , 3 ) . join ( '.' ) ;
3537}
3638const version = getVersion ( ) ;
3739commander . version ( version ) ;
3840
39-
4041const parameters = { hostedName : 'dev0ps.fyi' } ;
4142
4243const contentOptions = {
4344 bucket : parameters . hostedName ,
44- contentDirectory : path . join ( __dirname , 'build' )
45+ contentDirectory : path . join ( underscoreDirname , 'build' )
4546} ;
4647
4748/**
@@ -51,24 +52,22 @@ commander
5152. command ( 'build' )
5253. description ( 'Setup require build files for npm package.' )
5354. action ( async ( ) => {
54- let package_metadata = require ( './package.json' ) ;
55- package_metadata . version = version ;
56- await fs . writeJson ( './package.json' , package_metadata , { spaces : 2 } ) ;
55+ packageMetadata . version = version ;
56+ await fs . writeJson ( './package.json' , packageMetadata , { spaces : 2 } ) ;
5757
58- console . log ( 'Building package %s (%s)' , package_metadata . name , version ) ;
58+ console . log ( 'Building package %s (%s)' , packageMetadata . name , version ) ;
5959 console . log ( '' ) ;
6060} ) ;
6161
6262commander
6363. command ( 'deploy' )
6464. description ( 'Deploying website to AWS.' )
6565. action ( async ( ) => {
66- // eslint-disable-next-line @typescript-eslint/no-var-requires
67- const stackTemplateProvider = require ( './template/cloudFormationWebsiteTemplate' ) ;
68- const requestInterceptorLambdaFunction = await fs . readFile ( path . join ( __dirname , 'template/requestInterceptorLambdaFunction.js' ) ) ;
66+ const requestInterceptorLambdaFunction = await fs . readFile ( path . join ( underscoreDirname , 'template/requestInterceptorLambdaFunction.js' ) ) ;
6967 const stackTemplate = stackTemplateProvider . getStack ( requestInterceptorLambdaFunction . toString ( ) ) ;
7068
71- const callerIdentityResponse = await client . send ( new GetCallerIdentityCommand ( { } ) ) ;
69+ const stsClient = new STSClient ( { } ) ;
70+ const callerIdentityResponse = await stsClient . send ( new GetCallerIdentityCommand ( { } ) ) ;
7271 const apiOptions = {
7372 deploymentBucket : `rhosys-deployments-artifacts-${ callerIdentityResponse . Account } -${ aws . config . region } `
7473 } ;
@@ -86,16 +85,15 @@ commander
8685 automaticallyProtectStack : true
8786 } ;
8887
89- const config = { } ;
90- const client = new Route53Client ( config ) ;
88+ const route53Client = new Route53Client ( { } ) ;
9189 const command = new ListHostedZonesByNameCommand ( { DNSName : parameters . hostedName } ) ;
92- const response = await client . send ( command ) ;
90+ const response = await route53Client . send ( command ) ;
9391 const hostedZoneId = response . HostedZones [ 0 ] . Id ;
9492 parameters . hostedZoneId = hostedZoneId ;
9593 await awsArchitect . deployTemplate ( stackTemplate , stackConfiguration , parameters ) ;
9694 }
9795
98- console . log ( `Deployed to ${ deploymentLocation } ` ) ;
96+ console . log ( 'Deployment Success!' ) ;
9997 } catch ( failure ) {
10098 console . log ( `Failed to upload website ${ failure } - ${ JSON . stringify ( failure , null , 2 ) } ` ) ;
10199 process . exit ( 1 ) ;
0 commit comments