Skip to content

Commit b6d4034

Browse files
committed
Improved copying of resources
- if resources appear globally, they’ll be copied to all format output directories
1 parent 128c9b0 commit b6d4034

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

src/command/render/project.ts

+27-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import * as colors from "fmt/colors.ts";
1414
import { copyMinimal, copyTo } from "../../core/copy.ts";
1515
import * as ld from "../../core/lodash.ts";
1616

17-
import { kKeepMd } from "../../config/constants.ts";
17+
import { kKeepMd, kTargetFormat } from "../../config/constants.ts";
1818

1919
import {
2020
kProjectExecuteDir,
@@ -63,6 +63,7 @@ import {
6363
import { asArray } from "../../core/array.ts";
6464
import { normalizePath } from "../../core/path.ts";
6565
import { isSubdir } from "fs/_util.ts";
66+
import { Format } from "../../config/types.ts";
6667

6768
export async function renderProject(
6869
context: ProjectContext,
@@ -461,12 +462,31 @@ export async function renderProject(
461462
// srcPath -> Set<destinationPaths>
462463
const resourceFilesToCopy: Record<string, Set<string>> = {};
463464

464-
// Process the project resources
465-
context.files.resources?.forEach((resource) => {
466-
resourceFilesToCopy[resource] = resourceFilesToCopy[resource] ||
467-
new Set();
468-
const relativePath = relative(context.dir, resource);
469-
resourceFilesToCopy[resource].add(join(projOutputDir, relativePath));
465+
const projectFormats: Record<string, Format> = {};
466+
projResults.files.forEach((file) => {
467+
if (
468+
file.format.identifier[kTargetFormat] &&
469+
projectFormats[file.format.identifier[kTargetFormat]] === undefined
470+
) {
471+
projectFormats[file.format.identifier[kTargetFormat]] = file.format;
472+
}
473+
});
474+
475+
Object.values(projectFormats).forEach((format) => {
476+
// Process the project resources
477+
const formatOutputDir = projectFormatOutputDir(
478+
format,
479+
context,
480+
projType,
481+
);
482+
context.files.resources?.forEach((resource) => {
483+
resourceFilesToCopy[resource] = resourceFilesToCopy[resource] ||
484+
new Set();
485+
const relativePath = relative(context.dir, resource);
486+
resourceFilesToCopy[resource].add(
487+
join(formatOutputDir, relativePath),
488+
);
489+
});
470490
});
471491

472492
// Process the resources provided by the files themselves

0 commit comments

Comments
 (0)