Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust static file staging location handling #2741

Merged
merged 5 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/build/run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { PathInfo } from "../lib/paths.mjs";
import { CONTENT_TYPES } from "./partition-content.mjs";
// Direct importing of JSON files isn't supported yet in ES modules. This is a workaround.
import { createRequire } from "module";

const require = createRequire(import.meta.url);
const CONFIG = require("../../config.json");

Expand Down Expand Up @@ -40,7 +41,17 @@ if (code) {
process.exitCode = code;
}

// Stage static files, standardizing to lowercase paths but leaving filenames alone
function formatURLPart(str) {
// Defines formatting of URL parts for static content staging
return (
str
.replace(/([a-z])([A-Z])/g, "$1-$2")
// .replace(/_/g, "-") (test w/o underscore to kebab)
.toLowerCase()
);
}

// Stage static files, standardizing to kebab-lowercase paths but leaving filenames alone
function stageStaticContent(srcDir, destDir) {
// Build glob pattern from defined copyFileExts (image, mov, etc. extensions)
const pattern = path.join(srcDir, `**/*.{${CONFIG.build.copyFileExts.join(",")}}`);
Expand All @@ -51,7 +62,15 @@ function stageStaticContent(srcDir, destDir) {
// Compute the new destination path
const relativePath = path.relative(srcDir, file);

const destPath = path.join(destDir, path.dirname(relativePath).toLowerCase(), path.basename(relativePath));
const fileName = path.basename(relativePath);
const filePath = path.dirname(relativePath);

// break part path, map kebab-case, and rejoin
const parts = filePath.split(path.sep);
const kebabParts = parts.map((part) => formatURLPart(part));
const kebabPath = kebabParts.join(path.sep);

const destPath = path.join(destDir, kebabPath, fileName);

// Ensure the directory structure exists
fs.ensureDir(path.dirname(destPath))
Expand Down
23 changes: 4 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9892,7 +9892,7 @@ lodash.flatten@~4.4.0:
lodash.kebabcase@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz#8489b1cb0d29ff88195cceca448ff6d6cc295c36"
integrity sha1-hImxyw0p/4gZXM7KRI/21swpXDY=
integrity sha512-N8XRTIMMqqDgSy4VLKPnJ/+hpGZN+PHQiJnSenYqPaVV/NCqEogTnAdZLQiGKhxX+JCs8waWq2t1XHWKOmlY8g==

lodash.memoize@^4.1.2:
version "4.1.2"
Expand Down Expand Up @@ -13737,7 +13737,8 @@ stringify-entities@^3.0.1:
character-entities-legacy "^1.0.0"
xtend "^4.0.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.1:
name strip-ansi-cjs
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -13779,13 +13780,6 @@ strip-ansi@^6.0.0:
dependencies:
ansi-regex "^5.0.0"

strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.0.1.tgz#61740a08ce36b61e50e65653f07060d000975fb2"
Expand Down Expand Up @@ -15844,7 +15838,7 @@ worker-farm@^1.7.0:
dependencies:
errno "~0.1.7"

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -15870,15 +15864,6 @@ wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down
Loading