@storm-software/build-tools
Version:
A comprehensive set of tools for building and managing projects within a Storm workspace. Includes builders such as rollup, rolldown, tsup, and unbuild, along with various utilities.
84 lines (79 loc) • 2.48 kB
JavaScript
import {
joinPaths
} from "./chunk-MXKJT3OE.mjs";
import {
writeDebug,
writeTrace
} from "./chunk-R2HS3O2S.mjs";
// src/utilities/copy-assets.ts
import { CopyAssetsHandler } from "@nx/js/src/utils/assets/copy-assets-handler";
import { glob } from "glob";
import { readFile, writeFile } from "node:fs/promises";
var copyAssets = async (config, assets, outputPath, projectRoot, sourceRoot, generatePackageJson = true, includeSrc = false, banner, footer) => {
const pendingAssets = Array.from(assets ?? []);
pendingAssets.push({
input: projectRoot,
glob: "*.md",
output: "."
});
pendingAssets.push({
input: ".",
glob: "LICENSE",
output: "."
});
if (generatePackageJson === false) {
pendingAssets.push({
input: projectRoot,
glob: "package.json",
output: "."
});
}
if (includeSrc === true) {
pendingAssets.push({
input: sourceRoot,
glob: "**/{*.ts,*.tsx,*.js,*.jsx}",
output: "src/"
});
}
writeTrace(
`\u{1F4DD} Copying the following assets to the output directory:
${pendingAssets.map((pendingAsset) => typeof pendingAsset === "string" ? ` - ${pendingAsset} -> ${outputPath}` : ` - ${pendingAsset.input}/${pendingAsset.glob} -> ${joinPaths(outputPath, pendingAsset.output)}`).join("\n")}`,
config
);
const assetHandler = new CopyAssetsHandler({
projectDir: projectRoot,
rootDir: config.workspaceRoot,
outputDir: outputPath,
assets: pendingAssets
});
await assetHandler.processAllAssetsOnce();
writeTrace("Completed copying assets to the output directory", config);
if (includeSrc === true) {
writeDebug(
`\u{1F4DD} Adding banner and writing source files: ${joinPaths(
outputPath,
"src"
)}`,
config
);
const files = await glob([
joinPaths(config.workspaceRoot, outputPath, "src/**/*.ts"),
joinPaths(config.workspaceRoot, outputPath, "src/**/*.tsx"),
joinPaths(config.workspaceRoot, outputPath, "src/**/*.js"),
joinPaths(config.workspaceRoot, outputPath, "src/**/*.jsx")
]);
await Promise.allSettled(
files.map(
async (file) => writeFile(
file,
`${banner && typeof banner === "string" ? banner.startsWith("//") ? banner : `// ${banner}` : ""}
${await readFile(file, "utf8")}
${footer && typeof footer === "string" ? footer.startsWith("//") ? footer : `// ${footer}` : ""}`
)
)
);
}
};
export {
copyAssets
};