Skip to content

Commit c56dcaf

Browse files
authored
Merge pull request #244 from semantic-release/fix/readme
fix: Fixed readme copying
2 parents 2e9a023 + 93ebc0a commit c56dcaf

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

lib/prepare.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import { replaceVersions } from './utils/replace-versions.js';
1010
import { copyFiles } from './utils/copy-files.js';
1111
import { copyAssets } from './utils/copy-assets.js';
1212

13+
function getReadmePath(workDir: string): string | undefined {
14+
return ['.wordpress-org/readme.txt', 'readme.txt'].reduce(
15+
(acc, p) => (fs.existsSync(path.join(workDir, p)) ? p : acc),
16+
undefined,
17+
);
18+
}
19+
1320
export async function prepare(
1421
config: PluginConfig,
1522
context: PrepareContext,
@@ -32,14 +39,9 @@ export async function prepare(
3239
await fs.copy(path.resolve(config.path), workDir);
3340
}
3441

35-
if (config.withReadme) {
36-
const readmePath = ['.wordpress-org/readme.txt', 'readme.txt'].reduce(
37-
(acc, p) => (fs.existsSync(path.join(workDir, p)) ? p : acc),
38-
undefined,
39-
);
42+
const readmePath = config.withReadme ? getReadmePath(workDir) : undefined;
4043

41-
readmePath && files.push(readmePath);
42-
}
44+
readmePath && files.push(readmePath);
4345

4446
errors.push(
4547
...(await replaceVersions(workDir, files, context.nextRelease.version)),
@@ -49,7 +51,7 @@ export async function prepare(
4951
throw new AggregateError(errors);
5052
}
5153

52-
errors.push(...(await copyFiles(config, workDir)));
54+
errors.push(...(await copyFiles(config, workDir, readmePath)));
5355

5456
if (errors.length) {
5557
throw new AggregateError(errors);

lib/utils/copy-files.ts

+16
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export function getIgnore(workDir: string, files?: string[]): string[] {
6363
export async function copyFiles(
6464
config: PluginConfig,
6565
workDir: string,
66+
readmePath?: string,
6667
): Promise<SemanticReleaseError[]> {
6768
const errors: SemanticReleaseError[] = [];
6869
const releasePath = path.resolve(config.releasePath, config.slug);
@@ -91,5 +92,20 @@ export async function copyFiles(
9192
}
9293
}
9394

95+
if (config.withReadme && readmePath) {
96+
try {
97+
fs.cpSync(
98+
path.resolve(path.join(workDir, readmePath)),
99+
path.resolve(path.join(releasePath, 'readme.txt')),
100+
{
101+
preserveTimestamps: true,
102+
recursive: true,
103+
},
104+
);
105+
} catch (err) {
106+
errors.push(getError('EFILECOPY', readmePath));
107+
}
108+
}
109+
94110
return errors;
95111
}

test/2-prepare-plugin.spec.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,7 @@ describe('Package preparation - cusom work directory', () => {
103103
);
104104

105105
const readme = fs.readFileSync(
106-
path.join(
107-
getWorkDir(workDir),
108-
'plugin-with-readme/.wordpress-org/readme.txt',
109-
),
106+
path.join(releasePath, 'plugin-with-readme/readme.txt'),
110107
'utf8',
111108
);
112109

0 commit comments

Comments
 (0)