copy-assets.mjs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { copyFile, mkdir, readdir } from "node:fs/promises";
  2. import { dirname, extname, join, resolve } from "node:path";
  3. import { fileURLToPath } from "node:url";
  4. const FILE_PATHS = [
  5. "core/export-html/template.html",
  6. "core/export-html/template.css",
  7. "core/export-html/template.js",
  8. ];
  9. async function copyPath(sourceRoot, distRoot, relativePath) {
  10. const destination = resolve(distRoot, relativePath);
  11. await mkdir(dirname(destination), { recursive: true });
  12. await copyFile(resolve(sourceRoot, relativePath), destination);
  13. }
  14. async function copyMatchingFiles(sourceRoot, distRoot, relativeDir, extension) {
  15. const entries = await readdir(resolve(sourceRoot, relativeDir), { withFileTypes: true });
  16. await Promise.all(
  17. entries
  18. .filter((entry) => entry.isFile() && extname(entry.name) === extension)
  19. .map((entry) => copyPath(sourceRoot, distRoot, join(relativeDir, entry.name))),
  20. );
  21. }
  22. export async function copyCodingAgentAssets({ sourceRoot, distRoot }) {
  23. await Promise.all([
  24. ...FILE_PATHS.map((relativePath) => copyPath(sourceRoot, distRoot, relativePath)),
  25. copyMatchingFiles(sourceRoot, distRoot, "modes/interactive/theme", ".json"),
  26. copyMatchingFiles(sourceRoot, distRoot, "modes/interactive/assets", ".png"),
  27. copyMatchingFiles(sourceRoot, distRoot, "core/export-html/vendor", ".js"),
  28. ]);
  29. }
  30. const isMain = process.argv[1] && fileURLToPath(import.meta.url) === resolve(process.argv[1]);
  31. if (isMain) {
  32. await copyCodingAgentAssets({ sourceRoot: resolve("src"), distRoot: resolve("dist") });
  33. }