Skip to content

Commit

Permalink
feat: integrated plugins.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Eomm committed Jan 11, 2023
1 parent 23e5211 commit d3262d7
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 1,319 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ versioned_docs/*

versioned_sidebars/*
!versioned_sidebars/.keep

static/generated/*.json
88 changes: 54 additions & 34 deletions scripts/build-plugin-list.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,52 @@
'use strict'

const { promises: fs } = require('fs')
const path = require('path')

const log = require('pino')({
level: process.env.LOG_LEVEL || 'debug',
transport: {
target: 'pino-pretty',
options: {
colorize: true,
},
},
})

const LATEST_ECOSYSTEM_FILE = path.join(__dirname, '../versioned_docs/version-latest/Guides/Ecosystem.md')
const OUTPUT_FILE = path.join(__dirname, '../static/generated/plugins.json')

generateEcosystemJson({
ecosystemFile: LATEST_ECOSYSTEM_FILE,
outputFile: OUTPUT_FILE,
})

async function generateEcosystemJson({ ecosystemFile, outputFile }) {
log.info('Generating ecosystem data file from source %s', ecosystemFile)
const plugins = await extractEcosystemFromFile(ecosystemFile)
log.debug('Read the ecosystem file')

await fs.writeFile(outputFile, JSON.stringify(plugins, null, 2))
log.info('Wrote the ecosystem plugin file to %s', outputFile)
}

async function extractEcosystemFromFile(file) {
const content = await fs.readFile(file, 'utf8')

const extractPlugins = (pluginContent) => {
const [, pluginText] = content.split('#### [Core](#core)\n')

const [
corePluginsContent, //
communityPluginsContent, //
] = pluginText.split('#### [Community](#community)')

return {
corePlugins: extractPlugins(corePluginsContent),
communityPlugins: extractPlugins(communityPluginsContent),
}
}

function extractPlugins(pluginContent) {
const lines = pluginContent.split('\n').filter(Boolean) // remove empty lines

// if a line doesn't start with "-" merge it back with the previous item
Expand All @@ -12,6 +58,7 @@ const extractPlugins = (pluginContent) => {
}
return acc
}, [])

const re = /\[`([-a-zA-Z\d./@]+)`\]\(([^)]+)\)(\s*(.+))?/
const plugins = mergedLines.map((line) => {
const match = re.exec(line)
Expand All @@ -23,40 +70,13 @@ const extractPlugins = (pluginContent) => {

const name = match[1]
const url = match[2]
const description = match[3] ? match[3].trim() : ''
const description = match[3] ? match[3].trim().replace(/ {2,}/g, '') : ''

return { name, url, description }
return {
name,
url,
description: description.charAt(0).toUpperCase() + description.slice(1)
}
})
return plugins
}

async function extractEcosystemFromFile(file) {
let data
try {
data = await fs.readFile(file, 'utf8')
} catch (e) {
if (e.code === 'ENOENT') {
const legacyEcosystemFile = file.replace('Guides', '')
data = await fs.readFile(legacyEcosystemFile, 'utf8')
}
}

const content = data.toString()
const corePluginsContent = content.split('#### [Core](#core)\n')[1].split('#### [Community](#community)')[0]

const communityPluginsContent = content.split('#### [Core](#core)\n')[1].split('#### [Community](#community)')[1]

const plugins = {
corePlugins: extractPlugins(corePluginsContent),
communityPlugins: extractPlugins(communityPluginsContent),
}

return { plugins }
}

async function process() {
const plugins = await extractEcosystemFromFile('Ecosystem.md')
console.log(JSON.stringify(plugins['plugins']['communityPlugins']))
}

process()
2 changes: 1 addition & 1 deletion scripts/build-website.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ node ./scripts/process-releases.js

####### Data Generation Phase

# TODO node build-plugin-list.js
node ./scripts/build-plugin-list.js

####### Build Phase

Expand Down
15 changes: 9 additions & 6 deletions src/pages/ecosystem.mdx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
---
edit_url: http://google.it
editUrl: http://google.it
---

import PluginsTable from '@site/src/components/Ecosystem/PluginsTable'
import Link from '@docusaurus/Link'
import plugins from './plugins.json'
import plugins from '@site/static/generated/plugins.json'

export function PluginCount(props) {
return <b>{props.plugins.length}</b>
}

<br />

## Ecosystem
# Ecosystem

- There are <PluginCount plugins={plugins.corePlugins}/> core plugins and <PluginCount plugins={plugins.communityPlugins}/> community plugins
- A core plugin is a plugin maintained by the fastify team, and we do our best to maintain them according to the Fastify [Long Term Support](https://github.com/fastify/fastify/blob/main/docs/Reference/LTS.md) policy.
Expand All @@ -17,12 +20,12 @@ export function PluginCount(props) {

<br />

### Core Plugins
## Core Plugins

<PluginsTable plugins={plugins.corePlugins} />

<br />

### Community Plugins
## Community Plugins

<PluginsTable plugins={plugins.communityPlugins} />
7 changes: 0 additions & 7 deletions src/pages/markdown-page.md

This file was deleted.

Loading

0 comments on commit d3262d7

Please sign in to comment.