2021-05-04 17:04:14 +02:00
|
|
|
import {promises as fs} from "fs";
|
|
|
|
import path from "path";
|
|
|
|
|
|
|
|
import {logger} from "../Logger.js";
|
|
|
|
import AssetPreCompiler from "./AssetPreCompiler.js";
|
|
|
|
|
|
|
|
export default class CopyAssetPreCompiler extends AssetPreCompiler {
|
|
|
|
protected readonly actualTargetDir: string;
|
|
|
|
|
|
|
|
public constructor(
|
|
|
|
targetDir: string,
|
|
|
|
assetType: string,
|
|
|
|
extension: string,
|
|
|
|
additionalFallbackAssetPaths: string[] = [],
|
|
|
|
outputToPublic: boolean = true,
|
|
|
|
overrideTargetAssetType?: string,
|
|
|
|
) {
|
|
|
|
super(targetDir, assetType, extension, outputToPublic, ...additionalFallbackAssetPaths);
|
|
|
|
this.actualTargetDir = overrideTargetAssetType ?
|
|
|
|
path.join(targetDir, overrideTargetAssetType) :
|
|
|
|
this.targetDir;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async preCompile(canonicalName: string): Promise<void> {
|
2021-05-13 14:11:10 +02:00
|
|
|
const inputFile = await this.resolveFileFromCanonicalNameOrFail(canonicalName);
|
2021-05-04 17:04:14 +02:00
|
|
|
const outputFile = path.join(this.actualTargetDir, canonicalName);
|
|
|
|
logger.info('Copying', inputFile, '->', outputFile);
|
|
|
|
await fs.mkdir(path.dirname(outputFile), {recursive: true});
|
|
|
|
await fs.copyFile(inputFile, outputFile);
|
|
|
|
}
|
|
|
|
}
|