Skip to content

Commit ee1682d

Browse files
committed
undo changes
1 parent 334dfbf commit ee1682d

File tree

5 files changed

+92
-104
lines changed

5 files changed

+92
-104
lines changed

scripts/createRelease.ts

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,61 +8,58 @@
88
//
99

1010
import * as child_process from 'child_process'
11+
import * as fs from 'fs-extra'
1112
import * as path from 'path'
12-
import { fs } from '../packages/core/src/shared'
13-
import { readdirSync } from 'fs'
1413

15-
async function main() {
16-
// Must run from a subproject root folder, e.g packages/toolkit
17-
const cwd = process.cwd()
18-
const fileContents = await fs.readFileText('./package.json')
19-
const packageJson = JSON.parse(fileContents)
20-
const changesDirectory = path.join(cwd, '.changes')
21-
const nextReleaseDirectory = path.join(changesDirectory, 'next-release')
22-
const changesFile = path.join(changesDirectory, `${packageJson.version}.json`)
14+
// Must run from a subproject root folder, e.g packages/toolkit
15+
const cwd = process.cwd()
16+
const packageJson = JSON.parse(fs.readFileSync('./package.json', { encoding: 'utf-8' }))
17+
const changesDirectory = path.join(cwd, '.changes')
18+
const nextReleaseDirectory = path.join(changesDirectory, 'next-release')
19+
const changesFile = path.join(changesDirectory, `${packageJson.version}.json`)
2320

24-
await fs.mkdir(nextReleaseDirectory)
21+
fs.mkdirpSync(nextReleaseDirectory)
2522

26-
const changeFiles = readdirSync(nextReleaseDirectory)
27-
if (changeFiles.length === 0) {
28-
console.warn('no changes to release (missing .changes/ directory)')
29-
process.exit()
30-
}
31-
if (await fs.exists(changesFile)) {
32-
console.log(`error: changelog data file already exists: ${changesFile}`)
33-
process.exit(-1)
34-
}
35-
36-
const timestamp = new Date().toISOString().split('T')[0]
37-
const changelog: any = {
38-
date: timestamp,
39-
version: packageJson.version,
40-
entries: [],
41-
}
23+
const changeFiles = fs.readdirSync(nextReleaseDirectory)
24+
if (changeFiles.length === 0) {
25+
console.warn('no changes to release (missing .changes/ directory)')
26+
process.exit()
27+
}
28+
try {
29+
fs.accessSync(changesFile)
30+
console.log(`error: changelog data file already exists: ${changesFile}`)
31+
process.exit(-1)
32+
} catch (err) {
33+
// This is what we want to happen, the file should not exist
34+
}
4235

43-
for (const changeFile of changeFiles) {
44-
const file = JSON.parse(fs.readFileBytes(path.join(nextReleaseDirectory, changeFile)).toString())
45-
changelog.entries.push(file)
46-
}
36+
const timestamp = new Date().toISOString().split('T')[0]
37+
const changelog: any = {
38+
date: timestamp,
39+
version: packageJson.version,
40+
entries: [],
41+
}
4742

48-
changelog.entries.sort((x: { type: string }, y: { type: string }) => x.type.localeCompare(y.type))
43+
for (const changeFile of changeFiles) {
44+
const file = JSON.parse(fs.readFileSync(path.join(nextReleaseDirectory, changeFile)).toString())
45+
changelog.entries.push(file)
46+
}
4947

50-
// Write changelog file
51-
await fs.writeFile(changesFile, JSON.stringify(changelog, undefined, '\t'))
52-
const fileData = fs.readFileBytes(path.join(cwd, 'CHANGELOG.md'))
53-
let append = `## ${packageJson.version} ${timestamp}\n\n`
54-
for (const file of changelog.entries) {
55-
append += `- **${file.type}** ${file.description}\n`
56-
}
48+
changelog.entries.sort((x: { type: string }, y: { type: string }) => x.type.localeCompare(y.type))
5749

58-
append += '\n' + fileData.toString()
59-
await fs.writeFile('CHANGELOG.md', append)
50+
// Write changelog file
51+
fs.writeFileSync(changesFile, JSON.stringify(changelog, undefined, '\t'))
52+
const fileData = fs.readFileSync(path.join(cwd, 'CHANGELOG.md'))
53+
let append = `## ${packageJson.version} ${timestamp}\n\n`
54+
for (const file of changelog.entries) {
55+
append += `- **${file.type}** ${file.description}\n`
56+
}
6057

61-
child_process.execSync(`git add ${changesDirectory}`)
62-
child_process.execSync(`git rm -rf ${nextReleaseDirectory}`)
63-
child_process.execSync('git add CHANGELOG.md')
58+
append += '\n' + fileData.toString()
59+
fs.writeFileSync('CHANGELOG.md', append)
6460

65-
console.log(changesFile)
66-
}
61+
child_process.execSync(`git add ${changesDirectory}`)
62+
child_process.execSync(`git rm -rf ${nextReleaseDirectory}`)
63+
child_process.execSync('git add CHANGELOG.md')
6764

68-
void main()
65+
console.log(changesFile)

scripts/generateNonCodeFiles.ts

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

66
import * as child_process from 'child_process'
7+
import * as fs from 'fs-extra'
78
import { marked } from 'marked'
89
import * as path from 'path'
9-
import { fs } from '../packages/core/src/shared'
1010

1111
// doesn't use path utils as this should be formatted for finding images with HTML markup
1212
const projectRoot = process.cwd()
@@ -19,22 +19,22 @@ const projectRoot = process.cwd()
1919
* @param outputFile Filepath to output HTML to
2020
* @param cn Converts "AWS" to "Amazon" for CN-based compute.
2121
*/
22-
async function translateReadmeToHtml(
22+
function translateReadmeToHtml(
2323
root: string,
2424
inputFile: string,
2525
outputFile: string,
2626
throwIfNotExists: boolean,
2727
cn: boolean = false
2828
) {
2929
const inputPath = path.join(root, inputFile)
30-
if (!(await fs.exists(inputPath))) {
30+
if (!fs.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 = (await fs.readFileBytes(path.join(root, inputFile))).toString()
37+
const fileText = fs.readFileSync(path.join(root, inputFile)).toString()
3838
const relativePathRegex = /]\(\.\//g
3939
let transformedText = fileText.replace(relativePathRegex, '](!!EXTENSIONROOT!!/')
4040
if (cn) {
@@ -45,32 +45,27 @@ async function translateReadmeToHtml(
4545
if (typeof r !== 'string') {
4646
throw Error()
4747
}
48-
await fs.writeFile(path.join(root, outputFile), r)
48+
fs.writeFileSync(path.join(root, outputFile), r)
4949
}
5050

5151
/**
5252
* Do a best effort job of generating a git hash and putting it into the package
5353
*/
54-
async function generateFileHash(root: string) {
54+
function generateFileHash(root: string) {
5555
try {
5656
const response = child_process.execSync('git rev-parse HEAD')
57-
await fs.mkdir(root)
58-
await fs.writeFile(path.join(root, '.gitcommit'), response)
57+
fs.outputFileSync(path.join(root, '.gitcommit'), response)
5958
} catch (e) {
6059
console.log(`Getting commit hash failed ${e}`)
6160
}
6261
}
6362

64-
async function main() {
65-
try {
66-
await translateReadmeToHtml(projectRoot, 'README.md', 'quickStartVscode.html', true)
67-
await translateReadmeToHtml(projectRoot, 'README.quickstart.cloud9.md', 'quickStartCloud9.html', false)
68-
await translateReadmeToHtml(projectRoot, 'README.quickstart.cloud9.md', 'quickStartCloud9-cn.html', false, true)
69-
await generateFileHash(projectRoot)
70-
} catch (error) {
71-
console.error(error)
72-
process.exit(100)
73-
}
63+
try {
64+
translateReadmeToHtml(projectRoot, 'README.md', 'quickStartVscode.html', true)
65+
translateReadmeToHtml(projectRoot, 'README.quickstart.cloud9.md', 'quickStartCloud9.html', false)
66+
translateReadmeToHtml(projectRoot, 'README.quickstart.cloud9.md', 'quickStartCloud9-cn.html', false, true)
67+
generateFileHash(projectRoot)
68+
} catch (error) {
69+
console.error(error)
70+
process.exit(100)
7471
}
75-
76-
void main()

scripts/generateSettings.ts

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

6+
import * as fs from 'fs-extra'
67
import * as path from 'path'
7-
import { fs } from '../packages/core/src/shared'
88

99
/**
1010
* Generate a settings type based on `package.json:contributes.configuration`.
@@ -14,10 +14,10 @@ import { fs } from '../packages/core/src/shared'
1414
* This script is meant to be run from individual from subprojects.
1515
*/
1616

17-
async function main() {
17+
function main() {
1818
const ext = path.basename(process.cwd())
1919
const packageJsonFile = './package.json'
20-
const packageJson = JSON.parse(await fs.readFileText(packageJsonFile))
20+
const packageJson = JSON.parse(fs.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-
await fs.writeFile(genFile, contents)
53+
fs.writeFileSync(genFile, contents)
5454
}
5555

56-
void main()
56+
main()

scripts/newChange.ts

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

66
import * as child_process from 'child_process'
7+
import * as fs from 'fs-extra'
78
import { join } from 'path'
89
import * as readlineSync from 'readline-sync'
910
import * as crypto from 'crypto'
10-
import { fs } from '../packages/core/src/shared'
1111

1212
const directory = join(process.cwd(), '.changes', 'next-release')
1313
const changeTypes = ['Breaking Change', 'Feature', 'Bug Fix', 'Deprecation', 'Removal', 'Test']
@@ -40,22 +40,18 @@ function promptForChange(): string {
4040
}
4141
}
4242

43-
async function main() {
44-
await fs.mkdir(directory)
43+
fs.mkdirpSync(directory)
4544

46-
const type = promptForType()
47-
const description = promptForChange()
48-
const contents: NewChange = {
49-
type: type,
50-
description: description,
51-
}
52-
const fileName = `${type}-${crypto.randomUUID()}.json`
53-
const path = join(directory, fileName)
54-
await fs.writeFile(path, JSON.stringify(contents, undefined, '\t') + '\n')
55-
56-
console.log(`Change log written to ${path}`)
57-
child_process.execSync(`git add ${directory}`)
58-
console.log('Change log added to git working directory')
45+
const type = promptForType()
46+
const description = promptForChange()
47+
const contents: NewChange = {
48+
type: type,
49+
description: description,
5950
}
51+
const fileName = `${type}-${crypto.randomUUID()}.json`
52+
const path = join(directory, fileName)
53+
fs.writeFileSync(path, JSON.stringify(contents, undefined, '\t') + '\n')
6054

61-
void main()
55+
console.log(`Change log written to ${path}`)
56+
child_process.execSync(`git add ${directory}`)
57+
console.log('Change log added to git working directory')

scripts/package.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
//
1919

2020
import * as child_process from 'child_process'
21+
import * as fs from 'fs-extra'
2122
import * as path from 'path'
22-
import { fs } from '../packages/core/src/shared'
2323

2424
function parseArgs() {
2525
// Invoking this script with argument "foo":
@@ -105,7 +105,7 @@ function getVersionSuffix(feature: string, debug: boolean): string {
105105
return `${debugSuffix}${featureSuffix}${commitSuffix}`
106106
}
107107

108-
async function main() {
108+
function main() {
109109
const args = parseArgs()
110110
// It is expected that this will package from a packages/{subproject} folder.
111111
// There is a base config in packages/
@@ -114,7 +114,7 @@ async function main() {
114114
const webpackConfigJsFile = '../webpack.base.config.js'
115115
const backupWebpackConfigFile = `${webpackConfigJsFile}.package.bk`
116116

117-
if (!(await fs.exists(packageJsonFile))) {
117+
if (!fs.existsSync(packageJsonFile)) {
118118
throw new Error(`package.json not found, cannot package this directory: ${process.cwd()}`)
119119
}
120120

@@ -127,8 +127,8 @@ async function main() {
127127
throw new Error('Cannot package VSIX as both a release and a beta simultaneously')
128128
}
129129
// Create backup file so we can restore the originals later.
130-
await fs.copy(packageJsonFile, backupJsonFile)
131-
const packageJson = JSON.parse(await fs.readFileText(packageJsonFile))
130+
fs.copyFileSync(packageJsonFile, backupJsonFile)
131+
const packageJson = JSON.parse(fs.readFileSync(packageJsonFile, { encoding: 'utf-8' }))
132132

133133
if (!release || args.debug) {
134134
const versionSuffix = getVersionSuffix(args.feature, args.debug)
@@ -148,13 +148,13 @@ async function main() {
148148
}
149149

150150
if (args.debug) {
151-
await fs.copy(webpackConfigJsFile, backupWebpackConfigFile)
152-
const webpackConfigJs = await fs.readFileText(webpackConfigJsFile)
153-
await fs.writeFile(webpackConfigJsFile, webpackConfigJs.replace(/minimize: true/, 'minimize: false'))
151+
fs.copyFileSync(webpackConfigJsFile, backupWebpackConfigFile)
152+
const webpackConfigJs = fs.readFileSync(webpackConfigJsFile, { encoding: 'utf-8' })
153+
fs.writeFileSync(webpackConfigJsFile, webpackConfigJs.replace(/minimize: true/, 'minimize: false'))
154154
}
155155
}
156156

157-
await fs.writeFile(packageJsonFile, JSON.stringify(packageJson, undefined, ' '))
157+
fs.writeFileSync(packageJsonFile, JSON.stringify(packageJson, undefined, ' '))
158158
child_process.execFileSync(
159159
'vsce',
160160
[
@@ -181,19 +181,19 @@ async function main() {
181181
// TODO: Once we can support releasing multiple artifacts,
182182
// let's just keep the .vsix in its respective project folder in packages/
183183
const vsixName = `${packageJson.name}-${packageJson.version}.vsix`
184-
await fs.rename(vsixName, `../../${vsixName}`)
184+
fs.moveSync(vsixName, `../../${vsixName}`, { overwrite: true })
185185
} catch (e) {
186186
console.log(e)
187187
throw Error('package.ts: failed')
188188
} finally {
189189
// Restore the original files.
190-
await fs.copy(backupJsonFile, packageJsonFile)
191-
await fs.delete(backupJsonFile)
190+
fs.copyFileSync(backupJsonFile, packageJsonFile)
191+
fs.unlinkSync(backupJsonFile)
192192
if (args.debug) {
193-
await fs.copy(backupWebpackConfigFile, webpackConfigJsFile)
194-
await fs.delete(backupWebpackConfigFile)
193+
fs.copyFileSync(backupWebpackConfigFile, webpackConfigJsFile)
194+
fs.unlinkSync(backupWebpackConfigFile)
195195
}
196196
}
197197
}
198198

199-
void main()
199+
main()

0 commit comments

Comments
 (0)