feat(build): implement artifact names

This commit is contained in:
2026-07-29 22:27:05 +02:00
parent 55599bd0a2
commit 4a3010b683
+8 -3
View File
@@ -18,6 +18,11 @@ import { exists, isDirectory } from './fileAccess.js';
import { cp, mkdir, writeFile } from 'node:fs/promises'; import { cp, mkdir, writeFile } from 'node:fs/promises';
import { dirname, join } from 'node:path'; import { dirname, join } from 'node:path';
const logWithName = function logWithName (message, name, loggingFunction = console.log) {
if (name) loggingFunction(`Artifact '${name}': ${message}`);
else loggingFunction(message);
};
const validateArtifact = function validateArtifact (artifact) { const validateArtifact = function validateArtifact (artifact) {
if (typeof artifact.path !== 'string') return false; if (typeof artifact.path !== 'string') return false;
if (artifact.type === 'text') { if (artifact.type === 'text') {
@@ -39,7 +44,7 @@ const validateArtifact = function validateArtifact (artifact) {
export const processArtifact = async function processArtifact (artifact, { srcBase = '.', distBase = '.' } = {}) { export const processArtifact = async function processArtifact (artifact, { srcBase = '.', distBase = '.' } = {}) {
if (!validateArtifact(artifact)) { if (!validateArtifact(artifact)) {
console.warn('Skipping artifact as it is invalid.'); logWithName('Skipping artifact as it is invalid.', artifact.name, console.warn);
return; return;
} }
const distPath = join(distBase, artifact.path); const distPath = join(distBase, artifact.path);
@@ -55,7 +60,7 @@ export const processArtifact = async function processArtifact (artifact, { srcBa
encoding: artifact.options.encoding ?? 'utf-8' encoding: artifact.options.encoding ?? 'utf-8'
} }
); );
console.log(`Wrote to ${distPath}`); logWithName(`Wrote to ${distPath}`, artifact.name);
} else if (artifact.type === 'copy') { } else if (artifact.type === 'copy') {
const srcPath = join( const srcPath = join(
srcBase, srcBase,
@@ -71,6 +76,6 @@ export const processArtifact = async function processArtifact (artifact, { srcBa
force: true force: true
} }
); );
console.log(`Copied ${srcPath} -> ${distPath}`); logWithName(`Copied ${srcPath} -> ${distPath}`, artifact.name);
} }
}; };