From f33d4b3f9e224d0f5bcd2268b0b94e70a041784b Mon Sep 17 00:00:00 2001 From: John Knox Date: Mon, 7 Sep 2020 03:39:23 -0700 Subject: [PATCH] Add internaldocs-fb-helpers lib Summary: This adds a new npm package "internaldocs-fb-helpers", and shows example usage in the flipper package. This will stop everyone from having to inline the function definitions everywhere as is currently the case. (It's using the old internaldocs name, to match the existing docusaurus-plugin-internaldocs-fb package - I don't think that's a big deal.) It currently exports two methods: * `fbContent(internalContent, publicContent)` * Allows you to return internal or external content based on build variant. * Has named args so you don't accidentally put internal stuff in the external arg. * `isInternal(): boolean` * Not strictly necessary, but helps if you want to write your docs using an boolean variable rather than a switching function every time. * `fbInternalOnly(internalContent)` * Convenience method for when you want internal content, or nothing. I could have put these inside the existing docusaurus plugin, but that has docu v2 as a peer dependency, and I want these helpers to work on v1 as well, so made it a standalone package. Reviewed By: passy Differential Revision: D23474462 fbshipit-source-id: 22e5be6de2f3233deb298f1542a06e3575b6555a --- website/docusaurus.config.js | 36 +++++++++++++++++------------------- website/package.json | 1 + website/sidebars.js | 22 +++++----------------- website/src/pages/index.js | 3 ++- website/yarn.lock | 5 +++++ 5 files changed, 30 insertions(+), 37 deletions(-) diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index 558f355d7..3c99eb3a1 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -6,24 +6,23 @@ * * @format */ -function FBInternalWithOssFallback(elements, fallback) { - return process.env.FB_INTERNAL ? elements : fallback; -} + +const {fbContent, fbInternalOnly} = require('internaldocs-fb-helpers'); const repoUrl = 'https://github.com/facebook/flipper'; const siteConfig = { - title: FBInternalWithOssFallback('Flipper @FB', 'Flipper'), + title: fbContent({internal: 'Flipper @FB', external: 'Flipper'}), tagline: 'Extensible mobile app debugging', - url: FBInternalWithOssFallback( - 'https://flipper.thefacebook.com/', - 'https://fbflipper.com/', - ), + url: fbContent({ + internal: 'https://flipper.thefacebook.com/', + external: 'https://fbflipper.com/', + }), baseUrl: '/', projectName: 'flipper', // TODO: T69061026 enable once sandy docs are complete: external_domain: 'fbflipper.com', themeConfig: { navbar: { - title: FBInternalWithOssFallback('Flipper @FB', 'Flipper'), + title: fbContent({internal: 'Flipper @FB', external: 'Flipper'}), logo: { alt: 'Flipper Logo', src: 'img/icon.png', @@ -49,7 +48,7 @@ const siteConfig = { label: 'GitHub', position: 'right', }, - ...FBInternalOnly([ + ...fbInternalOnly([ { to: 'docs/fb/index', label: 'FB Internal', @@ -127,11 +126,14 @@ const siteConfig = { src: 'img/mascot.png', }, }, - algolia: FBInternalWithOssFallback(undefined, { - apiKey: '2df980e7ffc95c19552790f7cad32666', - indexName: 'fbflipper', - algoliaOptions: { - hitsPerPage: 5, + algolia: fbContent({ + internal: undefined, + external: { + apiKey: '2df980e7ffc95c19552790f7cad32666', + indexName: 'fbflipper', + algoliaOptions: { + hitsPerPage: 5, + }, }, }), prism: { @@ -166,8 +168,4 @@ const siteConfig = { ], }; -function FBInternalOnly(elements, fallback) { - return process.env.FB_INTERNAL == 1 ? elements : fallback || []; -} - module.exports = siteConfig; diff --git a/website/package.json b/website/package.json index 275ba8847..95daba69b 100644 --- a/website/package.json +++ b/website/package.json @@ -18,6 +18,7 @@ "docusaurus-plugin-internaldocs-fb": "^0.3.6", "file-cli": "^1.2.0", "glob": "^7.1.3", + "internaldocs-fb-helpers": "1.0.0", "react": "^16.13.1", "react-docgen": "^5.2.1", "react-dom": "^16.13.1" diff --git a/website/sidebars.js b/website/sidebars.js index 6d3b7087c..ef86abe29 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -7,17 +7,7 @@ * @format */ -/** - Adds content only if building internal FB version of documentations - e.g. ...FBInternalOnly({'sected-id'}) -*/ -function NotInFBInternal(elements) { - return process.env.FB_INTERNAL ? [] : elements; -} - -function FBInternalOnly(elements, fallback) { - return process.env.FB_INTERNAL == 1 ? elements : fallback || []; -} +const {fbContent, fbInternalOnly} = require('internaldocs-fb-helpers'); module.exports = { features: { @@ -39,7 +29,7 @@ module.exports = { }, setup: { 'Getting Started': [ - ...FBInternalOnly(['getting-started/fb/using-flipper-at-facebook']), + ...fbInternalOnly(['getting-started/fb/using-flipper-at-facebook']), 'getting-started/index', 'getting-started/android-native', 'getting-started/ios-native', @@ -86,7 +76,7 @@ module.exports = { 'extending/error-handling', 'extending/testing', 'extending/debugging', - ...FBInternalOnly([ + ...fbInternalOnly([ 'extending/fb/desktop-plugin-releases', // TODO: Remove once sandy is public T69061061 'extending/fb/sandy/sandy-plugins', @@ -102,13 +92,11 @@ module.exports = { 'extending/arch', 'extending/layout-inspector', 'extending/testing-rn', - ...FBInternalOnly([ - 'extending/fb/launcher', - ]), + ...fbInternalOnly(['extending/fb/launcher']), ], }, 'fb-internal': { - 'FB Internal': FBInternalOnly([ + 'FB Internal': fbInternalOnly([ 'fb/troubleshooting', 'fb/Add-flipper-to-android-app', 'fb/Adding-flipper-to-ios-app', diff --git a/website/src/pages/index.js b/website/src/pages/index.js index b02210643..bae3b9b63 100644 --- a/website/src/pages/index.js +++ b/website/src/pages/index.js @@ -11,9 +11,10 @@ import React from 'react'; import Layout from '@theme/Layout'; import useBaseUrl from '@docusaurus/useBaseUrl'; import {usePluginData} from '@docusaurus/useGlobalData'; +import {isInternal} from 'internaldocs-fb-helpers'; export default function Index() { - const {FB_INTERNAL} = usePluginData('internaldocs-fb'); + const FB_INTERNAL = isInternal(); return ( diff --git a/website/yarn.lock b/website/yarn.lock index d652e1e2f..8d8c0c9bf 100644 --- a/website/yarn.lock +++ b/website/yarn.lock @@ -5879,6 +5879,11 @@ internal-ip@^4.3.0: default-gateway "^4.2.0" ipaddr.js "^1.9.0" +internaldocs-fb-helpers@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/internaldocs-fb-helpers/-/internaldocs-fb-helpers-1.0.0.tgz#143d65a55a9c957539c47112b06f252556c11651" + integrity sha512-8Z7R1D+HUR7GnF/ykgrx+TRZ5rsJlHP9dZBntxYntOiUrAmnea5IVQ9BMR+6OzcPNhdcnm5KoTpFlPDLAu7OQg== + interpret@^1.0.0: version "1.2.0" resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.2.0.tgz#d5061a6224be58e8083985f5014d844359576296"