Skip to content

Commit ea51e05

Browse files
committed
feat(docs-generator): add better support for scoped packages
1 parent 4566246 commit ea51e05

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

packages/docs-generator/src/utils/compileScssModule.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ const canonicalize: Importer<"sync">["canonicalize"] = (url) => {
2626
return new URL("_colors.scss", `${FILE_URL}/@react-md/core/dist/`);
2727
}
2828

29-
if (url.endsWith("@react-md/code")) {
30-
return new URL("_code.scss", `${FILE_URL}/@react-md/code/dist/`);
29+
// NOTE: If the regexp updates, update in getScssCodeFile as well
30+
const [packageName, packageScope] =
31+
url.match(/@react-md\/([-a-z0-9]+)$/) || [];
32+
if (packageScope) {
33+
return new URL(`_${packageScope}.scss`, `${FILE_URL}/${packageName}/dist/`);
3134
}
3235

3336
let urlWithExtension = url;

packages/docs-generator/src/utils/getScssCodeFile.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ import { getProjectRootDir } from "./getProjectRootDir.js";
88

99
const rootDir = getProjectRootDir();
1010
const packagesDir = resolve(rootDir, "packages");
11-
const coreRoot = resolve(packagesDir, "core");
12-
const codeRoot = resolve(packagesDir, "code");
1311
const docsRoot = resolve(rootDir, "apps", "docs");
1412

1513
export function loadDemoScssInNode(fileUrl: string): string {
1614
const url = fileUrl.replace(FILE_URL, "");
1715

18-
let filePath: string;
16+
let filePath = url;
1917
if (url.startsWith("/docs")) {
2018
const name = url.replace("/docs/", "");
2119

2220
filePath = join(docsRoot, name);
23-
} else if (url.includes("/code/")) {
24-
const name = url.replace("/@react-md/code/", "");
25-
filePath = join(codeRoot, name);
2621
} else {
27-
const name = url.replace("/@react-md/core/", "");
28-
filePath = join(coreRoot, name);
22+
// NOTE: If the regexp updates, update in compileScssModule as well
23+
const [packageName = "", packageScope = ""] =
24+
url.match(/\/@react-md\/([-a-z0-9]+)\//) || [];
25+
if (packageScope) {
26+
const name = url.replace(packageName, "");
27+
filePath = join(packagesDir, packageScope, name);
28+
}
2929
}
3030

3131
return readFileSync(filePath, "utf8");

0 commit comments

Comments
 (0)