From 7d34ca9b1eeab25540b13e77b4ba96776692311f Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 22 Aug 2018 11:50:21 +0200 Subject: [PATCH] feat: use package-table vs custom script docs: add note on how to generate table --- README.md | 2 + package-list.json | 85 +++++++++++ scripts/generate-package-table-for-readme.js | 146 ------------------- 3 files changed, 87 insertions(+), 146 deletions(-) create mode 100644 package-list.json delete mode 100644 scripts/generate-package-table-for-readme.js diff --git a/README.md b/README.md index 0c178e2da9..ddb0dfa9be 100644 --- a/README.md +++ b/README.md @@ -479,6 +479,8 @@ N/A List of packages currently in existence for libp2p +> This table is generated using the module `package-table` with `package-table --data=package-list.json`. + | Package | Version | Deps | CI | Coverage | | ---------|---------|---------|---------|--------- | | **Libp2p** | diff --git a/package-list.json b/package-list.json new file mode 100644 index 0000000000..2f1db5d514 --- /dev/null +++ b/package-list.json @@ -0,0 +1,85 @@ +{ + "columns": [ + "Package", + "Version", + "Deps", + "CI", + "Coverage" + ], + "rows": [ + "Libp2p", + ["libp2p/interface-libp2p", "interface-libp2p"], + ["libp2p/js-libp2p", "libp2p"], + + "Connection", + ["libp2p/interface-connection", "interface-connection"], + + "Transport", + ["libp2p/interface-transport", "interface-transport"], + ["libp2p/js-libp2p-tcp", "libp2p-tcp"], + ["libp2p/js-libp2p-udp", "libp2p-udp"], + ["libp2p/js-libp2p-udt", "libp2p-udt"], + ["libp2p/js-libp2p-utp", "libp2p-utp"], + ["libp2p/js-libp2p-webrtc-direct", "libp2p-webrtc-direct"], + ["libp2p/js-libp2p-webrtc-star", "libp2p-webrtc-star"], + ["libp2p/js-libp2p-websockets", "libp2p-websockets"], + ["libp2p/js-libp2p-websocket-star", "libp2p-websocket-star"], + ["libp2p/js-libp2p-websocket-star-rendezvous", "libp2p-websocket-star-rendezvous"], + + "Crypto Channels", + ["libp2p/js-libp2p-secio", "libp2p-secio"], + + "Stream Muxers", + ["libp2p/interface-stream-muxer", "interface-stream-muxer"], + ["libp2p/js-libp2p-mplex", "libp2p-mplex"], + ["libp2p/js-libp2p-spdy", "libp2p-spdy"], + + "Discovery", + ["libp2p/interface-peer-discovery", "interface-peer-discovery"], + ["libp2p/js-libp2p-bootstrap", "libp2p-bootstrap"], + ["libp2p/js-libp2p-kad-dht", "libp2p-kad-dht"], + ["libp2p/js-libp2p-mdns", "libp2p-mdns"], + ["libp2p/js-libp2p-rendezvous", "libp2p-rendezvous"], + ["libp2p/js-libp2p-webrtc-star", "libp2p-webrtc-star"], + ["libp2p/js-libp2p-websocket-star", "libp2p-websocket-star"], + + "NAT Traversal", + ["libp2p/js-libp2p-circuit", "libp2p-circuit"], + ["libp2p/js-libp2p-nat-mngr", "libp2p-nat-mngr"], + + "Data Types", + ["libp2p/js-peer-book", "peer-book"], + ["libp2p/js-peer-id", "peer-id"], + ["libp2p/js-peer-info", "peer-info"], + + "Content Routing", + ["libp2p/interface-content-routing", "interface-content-routing"], + ["libp2p/js-libp2p-delegated-content-routing", "libp2p-delegated-content-routing"], + ["libp2p/js-libp2p-kad-dht", "libp2p-kad-dht"], + + "Peer Routing", + ["libp2p/interface-peer-routing", "interface-peer-routing"], + ["libp2p/js-libp2p-delegated-peer-routing", "libp2p-delegated-peer-routing"], + ["libp2p/js-libp2p-kad-dht", "libp2p-kad-dht"], + + "Record Store", + ["libp2p/interface-record-store", "interface-record-store"], + ["libp2p/js-libp2p-record", "libp2p-record"], + + "Generics", + ["libp2p/js-libp2p-connection-manager", "libp2p-connection-manager"], + ["libp2p/js-libp2p-crypto", "libp2p-crypto"], + ["libp2p/js-libp2p-crypto-secp256k1", "libp2p-crypto-secp256k1"], + ["libp2p/js-libp2p-switch", "libp2p-switch"], + + "Extensions", + ["libp2p/js-libp2p-floodsub", "libp2p-floodsub"], + ["libp2p/js-libp2p-identify", "libp2p-identify"], + ["libp2p/js-libp2p-keychain", "libp2p-keychain"], + ["libp2p/js-libp2p-ping", "libp2p-ping"], + ["libp2p/js-libp2p-pnet", "libp2p-pnet"], + + "Utilities", + ["libp2p/js-p2pcat", "p2pcat"] + ] +} diff --git a/scripts/generate-package-table-for-readme.js b/scripts/generate-package-table-for-readme.js deleted file mode 100644 index e23ac5462a..0000000000 --- a/scripts/generate-package-table-for-readme.js +++ /dev/null @@ -1,146 +0,0 @@ -#! /usr/bin/env node - -'use strict' - -// This script generates the table of packages you can see in the readme - -// Columns to show at the header of the table -const columns = [ - 'Package', - 'Version', - 'Deps', - 'CI', - 'Coverage' -] - -// Headings are a string -// Arrays are packages. Index 0 is the GitHub repo and index 1 is the npm package -const rows = [ - 'Libp2p', - ['libp2p/interface-libp2p', 'interface-libp2p'], - ['libp2p/js-libp2p', 'libp2p'], - - 'Connection', - ['libp2p/interface-connection', 'interface-connection'], - - 'Transport', - ['libp2p/interface-transport', 'interface-transport'], - ['libp2p/js-libp2p-circuit', 'libp2p-circuit'], // should this be NAT Traversal only? - ['libp2p/js-libp2p-tcp', 'libp2p-tcp'], - ['libp2p/js-libp2p-udp', 'libp2p-udp'], - ['libp2p/js-libp2p-udt', 'libp2p-udt'], - ['libp2p/js-libp2p-utp', 'libp2p-utp'], - ['libp2p/js-libp2p-webrtc-direct', 'libp2p-webrtc-direct'], - ['libp2p/js-libp2p-webrtc-star', 'libp2p-webrtc-star'], - ['libp2p/js-libp2p-websockets', 'libp2p-websockets'], - ['libp2p/js-libp2p-websocket-star', 'libp2p-websocket-star'], - ['libp2p/js-libp2p-websocket-star-rendezvous', 'libp2p-websocket-star-rendezvous'], - - 'Crypto Channels', - ['libp2p/js-libp2p-secio', 'libp2p-secio'], - - 'Stream Muxers', - ['libp2p/interface-stream-muxer', 'interface-stream-muxer'], - ['libp2p/js-libp2p-mplex', 'libp2p-mplex'], - ['libp2p/js-libp2p-spdy', 'libp2p-spdy'], - - 'Discovery', - ['libp2p/interface-peer-discovery', 'interface-peer-discovery'], - ['libp2p/js-libp2p-bootstrap', 'libp2p-bootstrap'], - ['libp2p/js-libp2p-kad-dht', 'libp2p-kad-dht'], // should this be here? - ['libp2p/js-libp2p-mdns', 'libp2p-mdns'], - ['libp2p/js-libp2p-rendezvous', 'libp2p-rendezvous'], - ['libp2p/js-libp2p-webrtc-star', 'libp2p-webrtc-star'], - ['libp2p/js-libp2p-websocket-star', 'libp2p-websocket-star'], - - 'NAT Traversal', - ['libp2p/js-libp2p-circuit', 'libp2p-circuit'], - ['libp2p/js-libp2p-nat-mngr', 'libp2p-nat-mngr'], - - 'Data Types', - ['libp2p/js-peer-book', 'peer-book'], - ['libp2p/js-peer-id', 'peer-id'], - ['libp2p/js-peer-info', 'peer-info'], - - 'Content Routing', - ['libp2p/interface-content-routing', 'interface-content-routing'], - ['libp2p/js-libp2p-delegated-content-routing', 'libp2p-delegated-content-routing'], - ['libp2p/js-libp2p-kad-dht', 'libp2p-kad-dht'], - - 'Peer Routing', - ['libp2p/interface-peer-routing', 'interface-peer-routing'], - ['libp2p/js-libp2p-delegated-peer-routing', 'libp2p-delegated-peer-routing'], - ['libp2p/js-libp2p-kad-dht', 'libp2p-kad-dht'], - - 'Record Store', - ['libp2p/interface-record-store', 'interface-record-store'], - ['libp2p/js-libp2p-record', 'libp2p-record'], - - 'Generics', - ['libp2p/js-libp2p-connection-manager', 'libp2p-connection-manager'], - ['libp2p/js-libp2p-crypto', 'libp2p-crypto'], - ['libp2p/js-libp2p-crypto-secp256k1', 'libp2p-crypto-secp256k1'], - ['libp2p/js-libp2p-switch', 'libp2p-switch'], - - 'Extensions', - ['libp2p/js-libp2p-floodsub', 'libp2p-floodsub'], - ['libp2p/js-libp2p-identify', 'libp2p-identify'], - ['libp2p/js-libp2p-keychain', 'libp2p-keychain'], - ['libp2p/js-libp2p-ping', 'libp2p-ping'], - ['libp2p/js-libp2p-pnet', 'libp2p-pnet'], - - 'Utilities', - ['libp2p/js-p2pcat', 'p2pcat'] -] - -const isItemPackage = (item) => { - return Array.isArray(item) -} - -const packageBadges = [ - // Package - (gh, npm) => `[\`${npm}\`](//github.com/${gh})`, - // Version - (gh, npm) => `[![npm](https://img.shields.io/npm/v/${npm}.svg?maxAge=86400&style=flat-square)](//github.com/${gh}/releases)`, - // Deps - (gh, npm) => `[![Deps](https://david-dm.org/${gh}.svg?style=flat-square)](https://david-dm.org/${gh})`, - // CI - (gh, npm) => { - // Need to fix the path for jenkins links, as jenkins adds `/job/` between everything - const jenkinsPath = gh.split('/').join('/job/') - return `[![jenkins](https://ci.ipfs.team/buildStatus/icon?job=${gh}/master)](https://ci.ipfs.team/job/${jenkinsPath}/job/master/)` - }, - // Coverage - (gh, npm) => `[![codecov](https://codecov.io/gh/${gh}/branch/master/graph/badge.svg)](https://codecov.io/gh/${gh})` -] - -// Creates the table row for a package -const generatePackageRow = (item) => { - const row = packageBadges.map((func) => { - // First string is GitHub path, second is npm package name - return func(item[0], item[1]) - }).join(' | ') - const fullRow = `| ${row} |` - return fullRow -} - -// Generates a row for the table, depending if it's a package or a heading -const generateRow = (item) => { - if (isItemPackage(item)) { - return generatePackageRow(item) - } else { - return `| **${item}** |` - } -} - -const header = `| ${columns.join(' | ')} |` -const hr = `| ${columns.map(() => '---------').join('|')} |` - -const toPrint = [ - header, - hr, - rows.map((row) => generateRow(row)).join('\n') -] - -toPrint.forEach((t) => console.log(t)) -