33 * SPDX-License-Identifier: Apache-2.0
44 */
55
6+ /* eslint-disable no-restricted-imports */
67import * as proc from 'child_process'
8+ import * as fs from 'fs-extra'
79import * as path from 'path'
8- import { fs } from '../../src/shared'
910
1011const repoRoot = path . join ( process . cwd ( ) , '../../' ) // root/packages/toolkit -> root/
1112/**
@@ -32,17 +33,17 @@ async function generateServiceClients(serviceClientDefinitions: ServiceClientDef
3233}
3334
3435/** When cloning aws-sdk-js, we want to pull the version actually used in package-lock.json. */
35- async function getJsSdkVersion ( ) : Promise < string > {
36- const json = ( await fs . readFileBytes ( path . resolve ( repoRoot , 'package-lock.json' ) ) ) . toString ( )
36+ function getJsSdkVersion ( ) : string {
37+ const json = fs . readFileSync ( path . resolve ( repoRoot , 'package-lock.json' ) ) . toString ( )
3738 const packageLock = JSON . parse ( json )
3839
3940 return packageLock [ 'packages' ] [ 'node_modules/aws-sdk' ] [ 'version' ]
4041}
4142
4243async function cloneJsSdk ( dir : string ) : Promise < void > {
4344 // Output stderr while it clones so it doesn't look frozen
44- return new Promise < void > ( async ( resolve , reject ) => {
45- const sdkversion = await getJsSdkVersion ( )
45+ return new Promise < void > ( ( resolve , reject ) => {
46+ const sdkversion = getJsSdkVersion ( )
4647 if ( ! sdkversion ) {
4748 throw new Error ( 'failed to get sdk version from package-lock.json' )
4849 }
@@ -106,17 +107,17 @@ async function insertServiceClientsIntoJsSdk(
106107 jsSdkPath : string ,
107108 serviceClientDefinitions : ServiceClientDefinition [ ]
108109) : Promise < void > {
109- for ( const serviceClientDefinition of serviceClientDefinitions ) {
110- const apiVersion = await getApiVersion ( serviceClientDefinition . serviceJsonPath )
110+ serviceClientDefinitions . forEach ( ( serviceClientDefinition ) => {
111+ const apiVersion = getApiVersion ( serviceClientDefinition . serviceJsonPath )
111112
112113 // Copy the Service Json into the JS SDK for generation
113114 const jsSdkServiceJsonPath = path . join (
114115 jsSdkPath ,
115116 'apis' ,
116117 `${ serviceClientDefinition . serviceName . toLowerCase ( ) } -${ apiVersion } .normal.json`
117118 )
118- await fs . copy ( serviceClientDefinition . serviceJsonPath , jsSdkServiceJsonPath )
119- }
119+ fs . copyFileSync ( serviceClientDefinition . serviceJsonPath , jsSdkServiceJsonPath )
120+ } )
120121
121122 const apiMetadataPath = path . join ( jsSdkPath , 'apis' , 'metadata.json' )
122123 await patchServicesIntoApiMetadata (
@@ -131,8 +132,8 @@ interface ServiceJsonSchema {
131132 }
132133}
133134
134- async function getApiVersion ( serviceJsonPath : string ) : Promise < string > {
135- const json = ( await fs . readFileBytes ( serviceJsonPath ) ) . toString ( )
135+ function getApiVersion ( serviceJsonPath : string ) : string {
136+ const json = fs . readFileSync ( serviceJsonPath ) . toString ( )
136137 const serviceJson = JSON . parse ( json ) as ServiceJsonSchema
137138
138139 return serviceJson . metadata . apiVersion
@@ -148,14 +149,14 @@ interface ApiMetadata {
148149async function patchServicesIntoApiMetadata ( apiMetadataPath : string , serviceNames : string [ ] ) : Promise < void > {
149150 console . log ( `Patching services (${ serviceNames . join ( ', ' ) } ) into API Metadata...` )
150151
151- const apiMetadataJson = ( await fs . readFileBytes ( apiMetadataPath ) ) . toString ( )
152+ const apiMetadataJson = fs . readFileSync ( apiMetadataPath ) . toString ( )
152153 const apiMetadata = JSON . parse ( apiMetadataJson ) as ApiMetadata
153154
154155 serviceNames . forEach ( ( serviceName ) => {
155156 apiMetadata [ serviceName . toLowerCase ( ) ] = { name : serviceName }
156157 } )
157158
158- await fs . writeFile ( apiMetadataPath , JSON . stringify ( apiMetadata , undefined , 4 ) )
159+ fs . writeFileSync ( apiMetadataPath , JSON . stringify ( apiMetadata , undefined , 4 ) )
159160}
160161
161162/**
@@ -197,7 +198,7 @@ async function integrateServiceClient(repoPath: string, serviceJsonPath: string,
197198
198199 console . log ( `Integrating ${ typingsFilename } ...` )
199200
200- await fs . copy ( sourceClientPath , destinationClientPath )
201+ fs . copyFileSync ( sourceClientPath , destinationClientPath )
201202
202203 await sanitizeServiceClient ( destinationClientPath )
203204}
@@ -208,7 +209,7 @@ async function integrateServiceClient(repoPath: string, serviceJsonPath: string,
208209async function sanitizeServiceClient ( generatedClientPath : string ) : Promise < void > {
209210 console . log ( 'Altering Service Client to fit the codebase...' )
210211
211- let fileContents = ( await fs . readFileBytes ( generatedClientPath ) ) . toString ( )
212+ let fileContents = fs . readFileSync ( generatedClientPath ) . toString ( )
212213
213214 // Add a header stating the file is autogenerated
214215 fileContents = `
@@ -222,7 +223,7 @@ ${fileContents}
222223
223224 fileContents = fileContents . replace ( / ( i m p o r t .* f r o m .* ) \. \. ( .* ) / g, '$1aws-sdk$2' )
224225
225- await fs . writeFile ( generatedClientPath , fileContents )
226+ fs . writeFileSync ( generatedClientPath , fileContents )
226227}
227228
228229// ---------------------------------------------------------------------------------------------------------------------
0 commit comments