Skip to content

Commit fe73175

Browse files
authored
Merge branch 'aws:master' into master
2 parents 7ef73df + 7d6a975 commit fe73175

File tree

7 files changed

+60
-58
lines changed

7 files changed

+60
-58
lines changed

packages/core/scripts/build/generateServiceClient.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
/* eslint-disable no-restricted-imports */
76
import * as proc from 'child_process'
8-
import * as fs from 'fs-extra'
7+
import * as nodefs from 'fs'
98
import * as path from 'path'
109

1110
const repoRoot = path.join(process.cwd(), '../../') // root/packages/toolkit -> root/
@@ -34,7 +33,7 @@ async function generateServiceClients(serviceClientDefinitions: ServiceClientDef
3433

3534
/** When cloning aws-sdk-js, we want to pull the version actually used in package-lock.json. */
3635
function getJsSdkVersion(): string {
37-
const json = fs.readFileSync(path.resolve(repoRoot, 'package-lock.json')).toString()
36+
const json = nodefs.readFileSync(path.resolve(repoRoot, 'package-lock.json')).toString()
3837
const packageLock = JSON.parse(json)
3938

4039
return packageLock['packages']['node_modules/aws-sdk']['version']
@@ -116,7 +115,7 @@ async function insertServiceClientsIntoJsSdk(
116115
'apis',
117116
`${serviceClientDefinition.serviceName.toLowerCase()}-${apiVersion}.normal.json`
118117
)
119-
fs.copyFileSync(serviceClientDefinition.serviceJsonPath, jsSdkServiceJsonPath)
118+
nodefs.copyFileSync(serviceClientDefinition.serviceJsonPath, jsSdkServiceJsonPath)
120119
})
121120

122121
const apiMetadataPath = path.join(jsSdkPath, 'apis', 'metadata.json')
@@ -133,7 +132,7 @@ interface ServiceJsonSchema {
133132
}
134133

135134
function getApiVersion(serviceJsonPath: string): string {
136-
const json = fs.readFileSync(serviceJsonPath).toString()
135+
const json = nodefs.readFileSync(serviceJsonPath).toString()
137136
const serviceJson = JSON.parse(json) as ServiceJsonSchema
138137

139138
return serviceJson.metadata.apiVersion
@@ -149,14 +148,14 @@ interface ApiMetadata {
149148
async function patchServicesIntoApiMetadata(apiMetadataPath: string, serviceNames: string[]): Promise<void> {
150149
console.log(`Patching services (${serviceNames.join(', ')}) into API Metadata...`)
151150

152-
const apiMetadataJson = fs.readFileSync(apiMetadataPath).toString()
151+
const apiMetadataJson = nodefs.readFileSync(apiMetadataPath).toString()
153152
const apiMetadata = JSON.parse(apiMetadataJson) as ApiMetadata
154153

155154
serviceNames.forEach((serviceName) => {
156155
apiMetadata[serviceName.toLowerCase()] = { name: serviceName }
157156
})
158157

159-
fs.writeFileSync(apiMetadataPath, JSON.stringify(apiMetadata, undefined, 4))
158+
nodefs.writeFileSync(apiMetadataPath, JSON.stringify(apiMetadata, undefined, 4))
160159
}
161160

162161
/**
@@ -198,7 +197,7 @@ async function integrateServiceClient(repoPath: string, serviceJsonPath: string,
198197

199198
console.log(`Integrating ${typingsFilename} ...`)
200199

201-
fs.copyFileSync(sourceClientPath, destinationClientPath)
200+
nodefs.copyFileSync(sourceClientPath, destinationClientPath)
202201

203202
await sanitizeServiceClient(destinationClientPath)
204203
}
@@ -209,7 +208,7 @@ async function integrateServiceClient(repoPath: string, serviceJsonPath: string,
209208
async function sanitizeServiceClient(generatedClientPath: string): Promise<void> {
210209
console.log('Altering Service Client to fit the codebase...')
211210

212-
let fileContents = fs.readFileSync(generatedClientPath).toString()
211+
let fileContents = nodefs.readFileSync(generatedClientPath).toString()
213212

214213
// Add a header stating the file is autogenerated
215214
fileContents = `
@@ -223,7 +222,7 @@ ${fileContents}
223222

224223
fileContents = fileContents.replace(/(import .* from.*)\.\.(.*)/g, '$1aws-sdk$2')
225224

226-
fs.writeFileSync(generatedClientPath, fileContents)
225+
nodefs.writeFileSync(generatedClientPath, fileContents)
227226
}
228227

229228
// ---------------------------------------------------------------------------------------------------------------------

scripts/createRelease.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@
88
//
99

1010
import * as child_process from 'child_process'
11-
import * as fs from 'fs-extra'
11+
import * as nodefs from 'fs'
1212
import * as path from 'path'
1313

1414
// Must run from a subproject root folder, e.g packages/toolkit
1515
const cwd = process.cwd()
16-
const packageJson = JSON.parse(fs.readFileSync('./package.json', { encoding: 'utf-8' }))
16+
const packageJson = JSON.parse(nodefs.readFileSync('./package.json', { encoding: 'utf-8' }))
1717
const changesDirectory = path.join(cwd, '.changes')
1818
const nextReleaseDirectory = path.join(changesDirectory, 'next-release')
1919
const changesFile = path.join(changesDirectory, `${packageJson.version}.json`)
2020

21-
fs.mkdirpSync(nextReleaseDirectory)
21+
nodefs.mkdirSync(nextReleaseDirectory, { recursive: true })
2222

23-
const changeFiles = fs.readdirSync(nextReleaseDirectory)
23+
const changeFiles = nodefs.readdirSync(nextReleaseDirectory)
2424
if (changeFiles.length === 0) {
2525
console.warn('no changes to release (missing .changes/ directory)')
2626
process.exit()
2727
}
2828
try {
29-
fs.accessSync(changesFile)
29+
nodefs.accessSync(changesFile)
3030
console.log(`error: changelog data file already exists: ${changesFile}`)
3131
process.exit(-1)
3232
} catch (err) {
@@ -41,22 +41,22 @@ const changelog: any = {
4141
}
4242

4343
for (const changeFile of changeFiles) {
44-
const file = JSON.parse(fs.readFileSync(path.join(nextReleaseDirectory, changeFile)).toString())
44+
const file = JSON.parse(nodefs.readFileSync(path.join(nextReleaseDirectory, changeFile)).toString())
4545
changelog.entries.push(file)
4646
}
4747

4848
changelog.entries.sort((x: { type: string }, y: { type: string }) => x.type.localeCompare(y.type))
4949

5050
// Write changelog file
51-
fs.writeFileSync(changesFile, JSON.stringify(changelog, undefined, '\t'))
52-
const fileData = fs.readFileSync(path.join(cwd, 'CHANGELOG.md'))
51+
nodefs.writeFileSync(changesFile, JSON.stringify(changelog, undefined, '\t'))
52+
const fileData = nodefs.readFileSync(path.join(cwd, 'CHANGELOG.md'))
5353
let append = `## ${packageJson.version} ${timestamp}\n\n`
5454
for (const file of changelog.entries) {
5555
append += `- **${file.type}** ${file.description}\n`
5656
}
5757

5858
append += '\n' + fileData.toString()
59-
fs.writeFileSync('CHANGELOG.md', append)
59+
nodefs.writeFileSync('CHANGELOG.md', append)
6060

6161
child_process.execSync(`git add ${changesDirectory}`)
6262
child_process.execSync(`git rm -rf ${nextReleaseDirectory}`)

scripts/generateIcons.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
import webfont from 'webfont'
77
import * as path from 'path'
8-
import * as fs from 'fs-extra'
8+
import * as nodefs from 'fs'
99

1010
const fontId = 'aws-toolkit-icons'
1111
const projectDir = process.cwd() // root/packages/toolkit
1212
const rootDir = path.join(projectDir, '../..') // root/
1313
const iconsDir = path.join(projectDir, 'resources', 'icons')
1414
const fontsDir = path.join(projectDir, 'resources', 'fonts')
1515
const stylesheetsDir = path.join(projectDir, 'resources', 'css')
16-
const packageJson = JSON.parse(fs.readFileSync(path.join(projectDir, 'package.json'), { encoding: 'utf-8' }))
16+
const packageJson = JSON.parse(nodefs.readFileSync(path.join(projectDir, 'package.json'), { encoding: 'utf-8' }))
1717
const iconSources = [
1818
// Paths relative to packages/toolkit
1919
`resources/icons/**/*.svg`,
@@ -69,7 +69,7 @@ async function updatePackage(fontPath: string, icons: [id: string, icon: Package
6969

7070
// prettier adds a newline to JSON files
7171
const newPackage = `${JSON.stringify(packageJson, undefined, 4)}\n`
72-
await fs.writeFile(path.join(projectDir, 'package.json'), newPackage)
72+
nodefs.writeFileSync(path.join(projectDir, 'package.json'), newPackage)
7373
console.log('Updated package.json')
7474
}
7575

@@ -81,15 +81,15 @@ const themes = {
8181
async function generateCloud9Icons(targets: { name: string; path: string }[], destination: string): Promise<void> {
8282
console.log('Generating icons for Cloud9')
8383

84-
async function replaceColor(file: string, color: string, dst: string): Promise<void> {
85-
const contents = await fs.readFile(file, 'utf-8')
84+
function replaceColor(file: string, color: string, dst: string): void {
85+
const contents = nodefs.readFileSync(file, 'utf-8')
8686
const replaced = contents.replace(/currentColor/g, color)
87-
await fs.writeFile(dst, replaced)
87+
nodefs.writeFileSync(dst, replaced)
8888
}
8989

9090
for (const [theme, color] of Object.entries(themes)) {
9191
const themeDest = path.join(destination, theme)
92-
await fs.mkdirp(themeDest)
92+
nodefs.mkdirSync(themeDest, { recursive: true })
9393
await Promise.all(targets.map((t) => replaceColor(t.path, color, path.join(themeDest, `${t.name}.svg`))))
9494
}
9595
}
@@ -169,9 +169,11 @@ ${result.template}
169169
const cloud9Dest = path.join(iconsDir, 'cloud9', 'generated')
170170
const isValidIcon = (i: (typeof icons)[number]): i is Required<typeof i> => i.data !== undefined
171171

172-
await fs.mkdirp(fontsDir)
173-
await fs.writeFile(dest, result.woff)
174-
await fs.writeFile(stylesheetPath, template)
172+
nodefs.mkdirSync(fontsDir, { recursive: true })
173+
if (result.woff) {
174+
nodefs.writeFileSync(dest, result.woff)
175+
}
176+
nodefs.writeFileSync(stylesheetPath, template)
175177
await updatePackage(
176178
`./${relativeDest}`,
177179
icons.filter(isValidIcon).map((i) => [i.name, i.data])
@@ -182,7 +184,7 @@ ${result.template}
182184
generated.addEntry(stylesheetPath)
183185
generated.addEntry(cloud9Dest)
184186

185-
await generated.emit(path.join(projectDir, 'dist'))
187+
generated.emit(path.join(projectDir, 'dist'))
186188
}
187189

188190
class GeneratedFilesManifest {
@@ -192,17 +194,17 @@ class GeneratedFilesManifest {
192194
this.files.push(file)
193195
}
194196

195-
public async emit(dir: string): Promise<void> {
197+
public emit(dir: string): void {
196198
const dest = path.join(dir, 'generated.buildinfo')
197199
const data = JSON.stringify(this.files, undefined, 4)
198-
await fs.mkdirp(dir)
199-
await fs.writeFile(dest, data)
200+
nodefs.mkdirSync(dir, { recursive: true })
201+
nodefs.writeFileSync(dest, data)
200202
}
201203
}
202204

203205
async function loadCodiconMappings(): Promise<Record<string, number | undefined>> {
204206
const codicons = path.join(rootDir, 'node_modules', '@vscode', 'codicons', 'src')
205-
const data = JSON.parse(await fs.readFile(path.join(codicons, 'template', 'mapping.json'), 'utf-8'))
207+
const data = JSON.parse(nodefs.readFileSync(path.join(codicons, 'template', 'mapping.json'), 'utf-8'))
206208
const mappings: Record<string, number | undefined> = {}
207209
for (const [k, v] of Object.entries(data)) {
208210
if (typeof k === 'string' && typeof v === 'number') {

scripts/generateNonCodeFiles.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import * as child_process from 'child_process'
7-
import * as fs from 'fs-extra'
7+
import * as nodefs from 'fs'
88
import { marked } from 'marked'
99
import * as path from 'path'
1010

@@ -27,14 +27,14 @@ function translateReadmeToHtml(
2727
cn: boolean = false
2828
) {
2929
const inputPath = path.join(root, inputFile)
30-
if (!fs.existsSync(inputPath)) {
30+
if (!nodefs.existsSync(inputPath)) {
3131
if (throwIfNotExists) {
3232
throw Error(`File ${inputFile} was not found, but it is required.`)
3333
}
3434
console.log(`File ${inputFile} was not found, skipping transformation...`)
3535
return
3636
}
37-
const fileText = fs.readFileSync(path.join(root, inputFile)).toString()
37+
const fileText = nodefs.readFileSync(path.join(root, inputFile)).toString()
3838
const relativePathRegex = /]\(\.\//g
3939
let transformedText = fileText.replace(relativePathRegex, '](!!EXTENSIONROOT!!/')
4040
if (cn) {
@@ -45,7 +45,7 @@ function translateReadmeToHtml(
4545
if (typeof r !== 'string') {
4646
throw Error()
4747
}
48-
fs.writeFileSync(path.join(root, outputFile), r)
48+
nodefs.writeFileSync(path.join(root, outputFile), r)
4949
}
5050

5151
/**
@@ -54,7 +54,8 @@ function translateReadmeToHtml(
5454
function generateFileHash(root: string) {
5555
try {
5656
const response = child_process.execSync('git rev-parse HEAD')
57-
fs.outputFileSync(path.join(root, '.gitcommit'), response)
57+
nodefs.mkdirSync(root, { recursive: true })
58+
nodefs.writeFileSync(path.join(root, '.gitcommit'), response)
5859
} catch (e) {
5960
console.log(`Getting commit hash failed ${e}`)
6061
}

scripts/generateSettings.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import * as fs from 'fs-extra'
6+
import * as nodefs from 'fs'
77
import * as path from 'path'
88

99
/**
@@ -17,7 +17,7 @@ import * as path from 'path'
1717
function main() {
1818
const ext = path.basename(process.cwd())
1919
const packageJsonFile = './package.json'
20-
const packageJson = JSON.parse(fs.readFileSync(packageJsonFile, { encoding: 'utf-8' }))
20+
const packageJson = JSON.parse(nodefs.readFileSync(packageJsonFile, { encoding: 'utf-8' }))
2121

2222
const genFile = `../core/src/shared/settings-${ext}.gen.ts`
2323
type Configuration = { [key: string]: { [key: string]: {} } }
@@ -50,7 +50,7 @@ export const ${ext}Settings = ${JSON.stringify(settings, undefined, ' ')}
5050
export default ${ext}Settings
5151
`
5252

53-
fs.writeFileSync(genFile, contents)
53+
nodefs.writeFileSync(genFile, contents)
5454
}
5555

5656
main()

scripts/newChange.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import * as child_process from 'child_process'
7-
import * as fs from 'fs-extra'
7+
import * as nodefs from 'fs'
88
import { join } from 'path'
99
import * as readlineSync from 'readline-sync'
1010
import * as crypto from 'crypto'
@@ -40,7 +40,7 @@ function promptForChange(): string {
4040
}
4141
}
4242

43-
fs.mkdirpSync(directory)
43+
nodefs.mkdirSync(directory, { recursive: true })
4444

4545
const type = promptForType()
4646
const description = promptForChange()
@@ -50,7 +50,7 @@ const contents: NewChange = {
5050
}
5151
const fileName = `${type}-${crypto.randomUUID()}.json`
5252
const path = join(directory, fileName)
53-
fs.writeFileSync(path, JSON.stringify(contents, undefined, '\t') + '\n')
53+
nodefs.writeFileSync(path, JSON.stringify(contents, undefined, '\t') + '\n')
5454

5555
console.log(`Change log written to ${path}`)
5656
child_process.execSync(`git add ${directory}`)

0 commit comments

Comments
 (0)