Skip to content

Commit f10598a

Browse files
committed
Write version and date to changelog when packaging
The version in "package.json" will be baseline, each type of extension packaging can control the version string for that version of the log
1 parent 24c9799 commit f10598a

File tree

7 files changed

+203
-7
lines changed

7 files changed

+203
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changelog
22

3-
## 2.6.0 - TBD
3+
## {{releaseVersion}} - {{releaseDate}}
44

55
### Added
66

package-lock.json

Lines changed: 130 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1675,7 +1675,7 @@
16751675
"unit-test": "npm test -- --label unitTests",
16761676
"coverage": "npm test -- --coverage",
16771677
"compile-tests": "del-cli ./assets/test/**/.build && npm run compile",
1678-
"package": "vsce package",
1678+
"package": "tsx ./scripts/package.ts",
16791679
"dev-package": "tsx ./scripts/dev_package.ts",
16801680
"preview-package": "tsx ./scripts/preview_package.ts",
16811681
"tag": "./scripts/tag_release.sh $npm_package_version",
@@ -1721,6 +1721,7 @@
17211721
"node-pty": "^1.0.0",
17221722
"octokit": "^3.2.2",
17231723
"prettier": "^3.5.3",
1724+
"replace-in-file": "^8.3.0",
17241725
"semver": "^7.7.2",
17251726
"simple-git": "^3.28.0",
17261727
"sinon": "^20.0.0",

scripts/dev_package.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//===----------------------------------------------------------------------===//
1414
/* eslint-disable no-console */
1515

16-
import { exec, getExtensionVersion, getRootDirectory, main } from "./lib/utilities";
16+
import { exec, getExtensionVersion, getRootDirectory, main, updateChangelog } from "./lib/utilities";
1717

1818
// eslint-disable-next-line @typescript-eslint/no-floating-promises
1919
main(async () => {
@@ -22,6 +22,8 @@ main(async () => {
2222
// Increment the patch version from the package.json
2323
const patch = version.patch + 1;
2424
const devVersion = `${version.major}.${version.minor}.${patch}-dev`;
25+
// Update version in CHANGELOG
26+
await updateChangelog(devVersion);
2527
// Use VSCE to package the extension
2628
await exec("npx", ["vsce", "package", "--no-update-package-json", devVersion], {
2729
cwd: rootDirectory,

scripts/lib/utilities.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { mkdtemp, readFile, rm } from "fs/promises";
1818
import * as path from "path";
1919
import * as os from "os";
2020
import * as semver from "semver";
21+
import { replaceInFile } from "replace-in-file";
2122

2223
/**
2324
* Executes the provided main function for the script while logging any errors.
@@ -42,12 +43,27 @@ export function getRootDirectory(): string {
4243
return path.join(__dirname, "..", "..");
4344
}
4445

46+
/**
47+
* Returns the path to the extension manifest.
48+
*/
49+
export function getManifest(): string {
50+
return path.join(getRootDirectory(), "package.json");
51+
}
52+
53+
/**
54+
* Returns the path to the extension changelog.
55+
*/
56+
export function getChangelog(): string {
57+
return path.join(getRootDirectory(), "CHANGELOG.md");
58+
}
59+
60+
4561
/**
4662
* Retrieves the version number from the package.json.
4763
*/
4864
export async function getExtensionVersion(): Promise<semver.SemVer> {
4965
const packageJSON = JSON.parse(
50-
await readFile(path.join(getRootDirectory(), "package.json"), "utf-8")
66+
await readFile(getManifest(), "utf-8")
5167
);
5268
if (typeof packageJSON.version !== "string") {
5369
throw new Error("Version number in package.json is not a string");
@@ -112,3 +128,20 @@ export async function withTemporaryDirectory<T>(
112128
});
113129
}
114130
}
131+
132+
export async function updateChangelog(version: string): Promise<void> {
133+
await replaceInFile({
134+
files: getChangelog(),
135+
from: /{{releaseVersion}}/g,
136+
to: version,
137+
});
138+
const date = new Date();
139+
const year = date.getUTCFullYear().toString().padStart(4, "0");
140+
const month = (date.getUTCMonth() + 1).toString().padStart(2, "0");
141+
const day = date.getUTCDate().toString().padStart(2, "0");
142+
await replaceInFile({
143+
files: getChangelog(),
144+
from: /{{releaseDate}}/g,
145+
to: `${year}-${month}-${day}`,
146+
});
147+
}

scripts/package.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the VS Code Swift open source project
4+
//
5+
// Copyright (c) 2025 the VS Code Swift project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of VS Code Swift project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
/* eslint-disable no-console */
15+
16+
import { exec, getExtensionVersion, getRootDirectory, main, updateChangelog } from "./lib/utilities";
17+
18+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
19+
main(async () => {
20+
const rootDirectory = getRootDirectory();
21+
const version = await getExtensionVersion();
22+
const versionString = `${version.major}.${version.minor}.${version.patch}`;
23+
// Update version in CHANGELOG
24+
await updateChangelog(versionString);
25+
// Use VSCE to package the extension
26+
await exec("npx", ["vsce", "package"], {
27+
cwd: rootDirectory,
28+
});
29+
});

scripts/preview_package.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414
/* eslint-disable no-console */
15-
16-
import { exec, getExtensionVersion, getRootDirectory, main } from "./lib/utilities";
15+
import { exec, getExtensionVersion, getRootDirectory, main, updateChangelog } from "./lib/utilities";
1716

1817
/**
1918
* Formats the given date as a string in the form "YYYYMMdd".
@@ -40,9 +39,11 @@ main(async () => {
4039
if (minor % 2 !== 1) {
4140
throw new Error(
4241
`The minor version for the pre-release extension is even (${previewVersion}).` +
43-
" The version in the package.json has probably been incorrectly set to an odd minor version."
42+
" The version in the package.json has probably been incorrectly set to an odd minor version."
4443
);
4544
}
45+
// Update version in CHANGELOG
46+
await updateChangelog(previewVersion);
4647
// Use VSCE to package the extension
4748
await exec(
4849
"npx",

0 commit comments

Comments
 (0)