Skip to content

Commit

Permalink
updating website
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredwray committed Sep 7, 2024
1 parent 820c52f commit 3957448
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"test:services:stop": "docker compose -f ./docker-compose.yaml down -v",
"test:services-arm64:start": "docker compose -f ./docker-compose-arm64.yaml up -d",
"test:services-arm64:stop": "docker compose -f ./docker-compose-arm64.yaml down -v",
"website:build": "yarn workspace @keyv/website run build",
"website:build": "yarn workspace @keyv/website run website:build",
"website:serve": "yarn workspace @keyv/website run website:serve",
"clean": "rm -rf node_modules && rm -rf yarn.lock && yarn workspaces run clean"
},
"devDependencies": {
Expand Down
9 changes: 4 additions & 5 deletions packages/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
"scripts": {
"test:ci": "echo 'no tests needed'",
"test": "echo 'no tests needed'",
"generate-docs": "ts-node ./src/docs.ts",
"build": "yarn clean && yarn generate-docs && docula build",
"generate-docs": "rimraf ./dist && ts-node ./src/docs.ts",
"build": "yarn generate-docs && docula build",
"build-serve": "yarn clean && yarn generate-docs && docula serve",
"clean": "rimraf ./dist ./docs/compression ./docs/test-suite ./docs/storage-adapters",
"serve": "docula serve"
"website:serve": "docula serve"
},
"devDependencies": {
"@types/fs-extra": "^11.0.4",
"docula": "^0.9.0",
"rimraf": "^6.0.1",
"ts-node": "^10.9.2"
},
"dependencies": {
"fs-extra": "^11.2.0"
}
}
52 changes: 31 additions & 21 deletions packages/website/src/docs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as fs from "fs-extra";
import fs from "node:fs";

async function main() {

console.log("packages path:" + getRelativePackagePath());
console.log("docs path:" + getRelativeDocsPath());
console.log("packages path:" + await getRelativePackagePath());
console.log("docs path:" + await getRelativeDocsPath());

await copyStorageAdapters();
await copyCompressionDocs();
Expand All @@ -12,8 +12,8 @@ async function main() {
};

async function copyStorageAdapters() {
const packagesPath = getRelativePackagePath();
const storageAdapters = await fs.readdir(`${packagesPath}`);
const packagesPath = await getRelativePackagePath();
const storageAdapters = await fs.promises.readdir(`${packagesPath}`);
const filterList = ["keyv", "website", "compress-brotli", "compress-gzip", "test-suite", ".DS_Store", "serialize", "third-party"];

for (const storageAdapter of storageAdapters) {
Expand All @@ -25,8 +25,8 @@ async function copyStorageAdapters() {
}

async function copyTestSuite() {
const packagesPath = getRelativePackagePath();
const originalFileText = await fs.readFile(`${packagesPath}/test-suite/README.md`, "utf8");
const packagesPath = await getRelativePackagePath();
const originalFileText = await fs.promises.readFile(`${packagesPath}/test-suite/README.md`, "utf8");
let newFileText = "---\n";
newFileText += `title: 'Test Suite'\n`;
newFileText += `permalink: /docs/test-suite/\n`;
Expand All @@ -38,12 +38,12 @@ async function copyTestSuite() {
newFileText = cleanDocumentFromImage(newFileText);

console.log("Adding Test Suite");
await fs.writeFile(`${packagesPath}/website/site/docs/test-suite.md`, newFileText);
await fs.promises.writeFile(`${packagesPath}/website/site/docs/test-suite.md`, newFileText);
}

async function copyKeyvAPI() {
const packagesPath = getRelativePackagePath();
const originalFileText = await fs.readFile(`${packagesPath}/keyv/README.md`, "utf8");
const packagesPath = await getRelativePackagePath();
const originalFileText = await fs.promises.readFile(`${packagesPath}/keyv/README.md`, "utf8");
let newFileText = "---\n";
newFileText += `title: 'Keyv API'\n`;
newFileText += `order: 3\n`;
Expand All @@ -54,12 +54,12 @@ async function copyKeyvAPI() {
newFileText = cleanDocumentFromImage(newFileText);

console.log("Adding Keyv API");
await fs.writeFile(`${packagesPath}/website/site/docs/keyv.md`, newFileText);
await fs.promises.writeFile(`${packagesPath}/website/site/docs/keyv.md`, newFileText);
}

async function copyCompressionDocs() {
const packagesPath = getRelativePackagePath();
const compressionAdapters = await fs.readdir(`${packagesPath}`);
const packagesPath = await getRelativePackagePath();
const compressionAdapters = await fs.promises.readdir(`${packagesPath}`);
for(const compressionAdapter of compressionAdapters) {
if(compressionAdapter.startsWith("compress-")) {
console.log("Adding compression adapter: " + compressionAdapter);
Expand All @@ -74,8 +74,8 @@ function cleanDocumentFromImage(document: string) {
return document;
};

function getRelativePackagePath() {
if(fs.pathExistsSync("packages")) {
async function getRelativePackagePath() {
if(await directoryExists("packages")) {
//we are in the root
return "packages";
}
Expand All @@ -84,8 +84,17 @@ function getRelativePackagePath() {
return "../../packages"
}

function getRelativeDocsPath() {
if(fs.pathExistsSync("docs")) {
async function directoryExists(path: string): Promise<boolean> {
try {
const stats = await fs.promises.stat(path);
return stats.isDirectory();
} catch {
return false;
}
}

async function getRelativeDocsPath() {
if(await directoryExists("docs")) {
//we are in the root
return "docs";
}
Expand All @@ -98,8 +107,9 @@ async function createDoc(adapterName: string, path: string, outputPath: string,
const originalFileName = "README.md";
const newFileName = `${adapterName}.md`;
const packageJSONPath = `${path}/${adapterName}/package.json`;
const packageJSON = await fs.readJSON(packageJSONPath);
const originalFileText = await fs.readFile(`${path}/${adapterName}/${originalFileName}`, "utf8");
const packageJSONContent = await fs.promises.readFile(packageJSONPath);
const packageJSON = JSON.parse(packageJSONContent.toString());
const originalFileText = await fs.promises.readFile(`${path}/${adapterName}/${originalFileName}`, "utf8");
let newFileText = "---\n";
newFileText += `title: '${packageJSON.name}'\n`;
newFileText += `sidebarTitle: '${packageJSON.name}'\n`;
Expand All @@ -110,8 +120,8 @@ async function createDoc(adapterName: string, path: string, outputPath: string,

newFileText = cleanDocumentFromImage(newFileText);

await fs.ensureDir(outputPath);
await fs.writeFile(`${outputPath}/${newFileName}`, newFileText);
await fs.promises.mkdir(outputPath, {recursive: true});
await fs.promises.writeFile(`${outputPath}/${newFileName}`, newFileText);
}

main();

0 comments on commit 3957448

Please sign in to comment.