Skip to content

Commit 7015886

Browse files
authored
Website - fixing build with path issues (#675)
* website - fixing build with path issues * update to handle pathing * updating the name README
1 parent 44d2cf8 commit 7015886

File tree

2 files changed

+50
-17
lines changed

2 files changed

+50
-17
lines changed

.github/workflows/deploy-website.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: deploy-website
33
on:
44
push:
55
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
68

79
jobs:
810
setup-build-deploy:

packages/website/src/docs.ts

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import * as fs from "fs-extra";
22

33
async function main() {
4-
await copyGettingStarted();
5-
await copyCachingDocs();
6-
await copyStorageAdapters();
7-
await copyCompressionDocs();
8-
await copyTestSuite();
4+
5+
console.log("packages path:" + getRelativePackagePath());
6+
console.log("docs path:" + getRelativeDocsPath());
7+
8+
await copyGettingStarted();
9+
await copyCachingDocs();
10+
await copyStorageAdapters();
11+
await copyCompressionDocs();
12+
await copyTestSuite();
913
};
1014

1115
async function copyGettingStarted() {
12-
const originalFileText = await fs.readFile("../../docs/getting-started/index.md", "utf8");
16+
const docsPath = getRelativeDocsPath();
17+
const packagesPath = getRelativePackagePath();
18+
const originalFileText = await fs.readFile(`${docsPath}/getting-started/index.md`, "utf8");
1319
let newFileText = "---\n";
1420
newFileText += `title: 'Getting Started Guide'\n`;
1521
newFileText += `permalink: /docs/\n`;
@@ -19,28 +25,32 @@ async function copyGettingStarted() {
1925
newFileText += originalFileText;
2026

2127
console.log("Adding Getting Started Guide");
22-
await fs.writeFile("site/docs/index.md", newFileText);
28+
await fs.writeFile(`${packagesPath}/website/site/docs/index.md`, newFileText);
2329
}
2430

2531
async function copyCachingDocs() {
26-
console.log("Adding in Caching Docs");
27-
await fs.copy("../../docs/caching/", "site/docs/caching");
32+
const docsPath = getRelativeDocsPath();
33+
const packagesPath = getRelativePackagePath();
34+
console.log("Adding Caching Docs");
35+
await fs.copy(`${docsPath}/caching/`, `${packagesPath}/website/site/docs/caching`);
2836
}
2937

3038
async function copyStorageAdapters() {
31-
const storageAdapters = await fs.readdir("../../packages");
39+
const packagesPath = getRelativePackagePath();
40+
const storageAdapters = await fs.readdir(`${packagesPath}`);
3241
const filterList = ["keyv", "website", "compress-brotli", "compress-gzip", "test-suite"];
3342

3443
for (const storageAdapter of storageAdapters) {
3544
if((filterList.indexOf(storageAdapter) > -1) !== true ) {
3645
console.log("Adding storage adapter: " + storageAdapter);
37-
await createDoc(storageAdapter, "../../packages", "site/docs/storage-adapters", "Storage Adapters");
46+
await createDoc(storageAdapter, `${packagesPath}`, `${packagesPath}/website/site/docs/storage-adapters`, "Storage Adapters");
3847
}
3948
};
4049
}
4150

4251
async function copyTestSuite() {
43-
const originalFileText = await fs.readFile("../../packages/test-suite/readme.md", "utf8");
52+
const packagesPath = getRelativePackagePath();
53+
const originalFileText = await fs.readFile(`${packagesPath}/test-suite/README.md`, "utf8");
4454
let newFileText = "---\n";
4555
newFileText += `title: 'Test Suite'\n`;
4656
newFileText += `permalink: /docs/test-suite/\n`;
@@ -50,16 +60,17 @@ async function copyTestSuite() {
5060

5161
newFileText = cleanDocumentFromImage(newFileText);
5262

53-
console.log("Adding in Test Suite");
54-
await fs.writeFile("site/docs/test-suite/index.md", newFileText);
63+
console.log("Adding Test Suite");
64+
await fs.writeFile(`${packagesPath}/website/site/docs/test-suite/index.md`, newFileText);
5565
}
5666

5767
async function copyCompressionDocs() {
58-
const compressionAdapters = await fs.readdir("../../packages");
68+
const packagesPath = getRelativePackagePath();
69+
const compressionAdapters = await fs.readdir(`${packagesPath}`);
5970
for(const compressionAdapter of compressionAdapters) {
6071
if(compressionAdapter.startsWith("compress-")) {
6172
console.log("Adding compression adapter: " + compressionAdapter);
62-
await createDoc(compressionAdapter, "../../packages", "site/docs/compression", "Compression");
73+
await createDoc(compressionAdapter, `${packagesPath}`, `${packagesPath}/website/site/docs/compression`, "Compression");
6374
}
6475
}
6576
}
@@ -69,8 +80,28 @@ function cleanDocumentFromImage(document: string) {
6980
return document;
7081
};
7182

83+
function getRelativePackagePath() {
84+
if(fs.pathExistsSync("packages")) {
85+
//we are in the root
86+
return "packages";
87+
}
88+
89+
//we are in the website folder
90+
return "../../packages"
91+
}
92+
93+
function getRelativeDocsPath() {
94+
if(fs.pathExistsSync("docs")) {
95+
//we are in the root
96+
return "docs";
97+
}
98+
99+
//we are in the website folder
100+
return "../../docs"
101+
}
102+
72103
async function createDoc(adapterName: string, path: string, outputPath: string, parent:string) {
73-
const originalFileName = "readme.md";
104+
const originalFileName = "README.md";
74105
const newFileName = `${adapterName}.md`;
75106
const packageJSONPath = `${path}/${adapterName}/package.json`;
76107
const packageJSON = await fs.readJSON(packageJSONPath);

0 commit comments

Comments
 (0)