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
This commit is contained in:
John Knox
2020-09-07 03:39:23 -07:00
committed by Facebook GitHub Bot
parent d4d2937c80
commit f33d4b3f9e
5 changed files with 30 additions and 37 deletions

View File

@@ -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',