Skip to content

Commit 9e0717d

Browse files
add more code comments
1 parent 67d5aac commit 9e0717d

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

scripts/lib/utilities.ts

+24-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the VS Code Swift open source project
44
//
5-
// Copyright (c) 2024 the VS Code Swift project authors
5+
// Copyright (c) 2025 the VS Code Swift project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -15,6 +15,29 @@
1515

1616
import * as child_process from "child_process";
1717

18+
/**
19+
* Executes the provided main function for the script while logging any errors.
20+
*
21+
* If an error is caught then the process will exit with code 1.
22+
*
23+
* @param mainFn The main function of the script that will be run.
24+
*/
25+
export async function main(mainFn: () => Promise<void>): Promise<void> {
26+
try {
27+
await mainFn();
28+
} catch (error) {
29+
console.error(error);
30+
process.exit(1);
31+
}
32+
}
33+
34+
/**
35+
* Executes the given command, inheriting the current process' stdio.
36+
*
37+
* @param command The command to execute.
38+
* @param args The arguments to provide to the command.
39+
* @param options The options for executing the command.
40+
*/
1841
export async function exec(
1942
command: string,
2043
args: string[],

scripts/preview_package.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the VS Code Swift open source project
44
//
5-
// Copyright (c) 2024 the VS Code Swift project authors
5+
// Copyright (c) 2025 the VS Code Swift project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -16,7 +16,7 @@
1616
import * as path from "path";
1717
import * as semver from "semver";
1818
import { readFile } from "fs/promises";
19-
import { exec } from "./lib/utilities";
19+
import { exec, main } from "./lib/utilities";
2020

2121
/**
2222
* Formats the given date as a string in the form "YYYYMMddhhmm".
@@ -33,7 +33,7 @@ function formatDate(date: Date): string {
3333
return year + month + day + hour + minutes;
3434
}
3535

36-
(async () => {
36+
main(async () => {
3737
const rootDirectory = path.join(__dirname, "..");
3838
// Grab the existing version number from the package.json
3939
const packageJSON = JSON.parse(
@@ -55,7 +55,4 @@ function formatDate(date: Date): string {
5555
["vsce", "package", "--pre-release", "--no-update-package-json", previewVersion],
5656
{ cwd: rootDirectory }
5757
);
58-
})().catch(error => {
59-
console.error(error);
60-
process.exit(1);
6158
});

scripts/update_swift_docc_render.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { stat, mkdtemp, mkdir, rm, readdir } from "fs/promises";
1818
import * as path from "path";
1919
import { tmpdir } from "os";
2020
import * as semver from "semver";
21-
import { exec } from "./lib/utilities";
21+
import { exec, main } from "./lib/utilities";
2222

2323
function checkNodeVersion() {
2424
const nodeVersion = semver.parse(process.versions.node);
@@ -57,7 +57,7 @@ async function cloneSwiftDocCRender(buildDirectory: string): Promise<string> {
5757
return swiftDocCRenderDirectory;
5858
}
5959

60-
(async () => {
60+
main(async () => {
6161
const outputDirectory = path.join(__dirname, "..", "assets", "swift-docc-render");
6262
if (process.argv.includes("postinstall")) {
6363
try {
@@ -88,7 +88,4 @@ async function cloneSwiftDocCRender(buildDirectory: string): Promise<string> {
8888
console.error(error);
8989
});
9090
}
91-
})().catch(error => {
92-
console.error(error);
93-
process.exit(1);
9491
});

0 commit comments

Comments
 (0)