Skip to content

Commit 2d5a0bc

Browse files
authored
[infra] Support project-specific changelog in build scripts (#46425)
1 parent b8e48fc commit 2d5a0bc

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

scripts/copyFiles.mjs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable no-console */
22
import path from 'path';
3+
import { stat } from 'fs/promises';
34
import { createPackageFile, includeFileInBuild, prepend } from './copyFilesUtils.mjs';
45

56
const packagePath = process.cwd();
@@ -34,8 +35,15 @@ async function run() {
3435
try {
3536
const packageData = await createPackageFile(true);
3637

38+
let changlogPath;
39+
if (await fileExists(path.join(packagePath, './CHANGELOG.md'))) {
40+
changlogPath = './CHANGELOG.md';
41+
} else {
42+
changlogPath = '../../CHANGELOG.md';
43+
}
44+
3745
await Promise.all(
38-
['./README.md', '../../CHANGELOG.md', '../../LICENSE', ...extraFiles].map(async (file) => {
46+
['./README.md', changlogPath, '../../LICENSE', ...extraFiles].map(async (file) => {
3947
const [sourcePath, targetPath] = file.split(':');
4048
await includeFileInBuild(sourcePath, targetPath);
4149
}),
@@ -48,4 +56,16 @@ async function run() {
4856
}
4957
}
5058

59+
async function fileExists(filePath) {
60+
try {
61+
await stat(filePath);
62+
return true;
63+
} catch (err) {
64+
if (err.code === 'ENOENT') {
65+
return false;
66+
}
67+
throw err;
68+
}
69+
}
70+
5171
run();

0 commit comments

Comments
 (0)