UNPKG

@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 (73 loc) 3.03 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _chunkJVKCJMCKjs = require('./chunk-JVKCJMCK.js'); var _chunkKTEGKYAHjs = require('./chunk-KTEGKYAH.js'); // src/utilities/copy-assets.ts var _copyassetshandler = require('@nx/js/src/utils/assets/copy-assets-handler'); var _glob = require('glob'); var _promises = require('fs/promises'); var copyAssets = async (config, assets, outputPath, projectRoot, sourceRoot, generatePackageJson = true, includeSrc = false, banner, footer) => { const pendingAssets = Array.from(_nullishCoalesce(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/" }); } _chunkKTEGKYAHjs.writeTrace.call(void 0, `\u{1F4DD} Copying the following assets to the output directory: ${pendingAssets.map((pendingAsset) => typeof pendingAsset === "string" ? ` - ${pendingAsset} -> ${outputPath}` : ` - ${pendingAsset.input}/${pendingAsset.glob} -> ${_chunkJVKCJMCKjs.joinPaths.call(void 0, outputPath, pendingAsset.output)}`).join("\n")}`, config ); const assetHandler = new (0, _copyassetshandler.CopyAssetsHandler)({ projectDir: projectRoot, rootDir: config.workspaceRoot, outputDir: outputPath, assets: pendingAssets }); await assetHandler.processAllAssetsOnce(); _chunkKTEGKYAHjs.writeTrace.call(void 0, "Completed copying assets to the output directory", config); if (includeSrc === true) { _chunkKTEGKYAHjs.writeDebug.call(void 0, `\u{1F4DD} Adding banner and writing source files: ${_chunkJVKCJMCKjs.joinPaths.call(void 0, outputPath, "src" )}`, config ); const files = await _glob.glob.call(void 0, [ _chunkJVKCJMCKjs.joinPaths.call(void 0, config.workspaceRoot, outputPath, "src/**/*.ts"), _chunkJVKCJMCKjs.joinPaths.call(void 0, config.workspaceRoot, outputPath, "src/**/*.tsx"), _chunkJVKCJMCKjs.joinPaths.call(void 0, config.workspaceRoot, outputPath, "src/**/*.js"), _chunkJVKCJMCKjs.joinPaths.call(void 0, config.workspaceRoot, outputPath, "src/**/*.jsx") ]); await Promise.allSettled( files.map( async (file) => _promises.writeFile.call(void 0, file, `${banner && typeof banner === "string" ? banner.startsWith("//") ? banner : `// ${banner}` : ""} ${await _promises.readFile.call(void 0, file, "utf8")} ${footer && typeof footer === "string" ? footer.startsWith("//") ? footer : `// ${footer}` : ""}` ) ) ); } }; exports.copyAssets = copyAssets;