-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add a table of contents and a tool to generate it. Saves us having to tell people what's missing! - Prioritise Anchor, deprioritize Seahorse, and spell 'onchain' correctly. - Move note re: not needing to make onchain programs up. Remove unnecessary detail. - Mention onchain programs are called smart contracts on other blockchains for SEO purposes
- Loading branch information
1 parent
2c4cb8f
commit 22be08c
Showing
2 changed files
with
233 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Usage: esrun make-table-of-contents.ts | ||
import { readdir } from 'node:fs/promises'; | ||
const log = console.log; | ||
|
||
// A serial async map function (because we like do things in order and performance doesn't matter) | ||
const asyncMap = async (array, asyncFunction) => { | ||
for (const item of array) { | ||
await asyncFunction(item); | ||
} | ||
}; | ||
|
||
const PROJECT_TYPES = ['anchor', 'native', 'solidity', 'seahorse']; | ||
const CATEGORIES = ['basics', 'tokens', 'tokens/token-2022', 'compression', 'oracles']; | ||
|
||
interface LinkMap { | ||
[key: string]: boolean; | ||
} | ||
|
||
// Loop through the folders in CATEGORIES and for each folder, find child directories that contain a folder matching a project type | ||
await asyncMap(CATEGORIES, async (category) => { | ||
const path = `./${category}`; | ||
const exampleFolders = (await readdir(path, { withFileTypes: true })).filter((item) => item.isDirectory()).map((dir) => dir.name); | ||
// Loop through the folders and log each folder | ||
log(`\n\n## ${category}`); | ||
await asyncMap(exampleFolders, async (exampleFolder) => { | ||
// Check if the folder has a subfolder that matches a project type | ||
const projectTypeFolders = (await readdir(`./${category}/${exampleFolder}`, { withFileTypes: true })) | ||
.filter((item) => item.isDirectory()) | ||
.filter((dir) => PROJECT_TYPES.includes(dir.name)); | ||
|
||
// If there are no subfolders that match a project type, we can skip this folder - it's not example code | ||
if (projectTypeFolders.length === 0) { | ||
return; | ||
} | ||
log(`\n### ${exampleFolder}`); | ||
|
||
// We can now create a map of the project types that are present in the example folder | ||
const linkMap: LinkMap = {}; | ||
PROJECT_TYPES.forEach((projectType) => { | ||
linkMap[projectType] = projectTypeFolders.some((dir) => dir.name === projectType); | ||
}); | ||
|
||
const links: Array<string> = []; | ||
// Go through the link map and log a markdown link to the folder if the linkmap value is true | ||
// otherwise log 'create me' as a placeholder | ||
for (const [projectType, exists] of Object.entries(linkMap)) { | ||
const link = `./${category}/${exampleFolder}/${projectType}`; | ||
if (exists) { | ||
links.push(`[${projectType}](${link})`); | ||
} | ||
} | ||
log(links.join(', ')); | ||
}); | ||
}); |