-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(v2): docs versioning βοΈπ₯ #1983
Merged
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
2daebde
wip: versioning
endiliey b5fa5c2
wip again
endiliey 0d47a21
nits lint
endiliey d6b61ed
Merge branch 'master' into endi/versioning
endiliey f3f6d0c
refactor metadata code so that we can have inobject properties optimiβ¦
endiliey 6b72119
remove buggy permalink code
endiliey 9584826
modify versioned docs fixture such that foo/baz only exists in v1.0.0
endiliey 5d15c83
refactor metadata.ts so that there is less transformon object
endiliey e9f3d1b
more refactoring
endiliey be470d6
reduce test fixtures, refactoring
endiliey 6842d96
refactoring readability
endiliey 8cb5977
finish metadata part
endiliey 01000f9
refactor with readdir
endiliey e48b7b8
first pass of implementation
endiliey 3fd93f4
fix mdx laoder
endiliey 1e37e65
Merge branch 'master' into endi/versioning
endiliey 87c368f
Merge branch 'master' into endi/versioning
endiliey c54ef7f
split generated routes by version for performance & smaller bundle
endiliey 5ac4aef
test data for demo
endiliey 2568db0
refactor with set
endiliey 122b9c7
more tests
endiliey c4df12c
Merge branch 'master' into endi/versioning
endiliey 64302d0
typo
endiliey 31255ff
fix typo
endiliey 4bd3a1e
better temporary ui
endiliey 0180499
Merge branch 'master' into endi/versioning
endiliey 3fe3ea3
stronger typing & docsVersion command
endiliey 116df01
add 100% test coverage for docsVersion command
endiliey ec5602a
more test and delete manual docs cut
endiliey 92f115d
cut 2.0.0-alpha.35 docs
endiliey 1875da1
Merge branch 'master' into endi/versioning
endiliey dae70cc
cut alpha.36 instead
endiliey 1f3deab
copyright
endiliey d88bbd3
delete versioned docs
endiliey 3740613
stronger test on metadata
endiliey 5f88f8d
update typo
endiliey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -5,13 +5,7 @@ | |
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { | ||
Sidebar, | ||
SidebarItem, | ||
SidebarItemDoc, | ||
SidebarItemCategory, | ||
Order, | ||
} from './types'; | ||
import {Sidebar, SidebarItem, Order} from './types'; | ||
|
||
// Build the docs meta such as next, previous, category and sidebar. | ||
export default function createOrder(allSidebars: Sidebar = {}): Order { | ||
|
@@ -26,20 +20,16 @@ export default function createOrder(allSidebars: Sidebar = {}): Order { | |
switch (item.type) { | ||
case 'category': | ||
indexItems({ | ||
items: (item as SidebarItemCategory).items, | ||
items: item.items, | ||
}); | ||
break; | ||
case 'ref': | ||
case 'link': | ||
// Refs and links should not be shown in navigation. | ||
break; | ||
case 'doc': | ||
ids.push((item as SidebarItemDoc).id); | ||
ids.push(item.id); | ||
break; | ||
default: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a |
||
throw new Error( | ||
`Unknown item type: ${item.type}. Item: ${JSON.stringify(item)}`, | ||
); | ||
} | ||
}); | ||
}; | ||
|
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,113 @@ | ||
/** | ||
* Copyright (c) 2017-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { | ||
getVersionsJSONFile, | ||
getVersionedDocsDir, | ||
getVersionedSidebarsDir, | ||
} from './env'; | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
import {PluginOptions, Sidebar, SidebarItemCategory} from './types'; | ||
import loadSidebars from './sidebars'; | ||
|
||
export function docsVersion( | ||
version: string | null | undefined, | ||
siteDir: string, | ||
options: PluginOptions, | ||
) { | ||
if (!version) { | ||
throw new Error( | ||
'No version number specified!.\nPass the version you wish to create as an argument.\nEx: 1.0.0', | ||
); | ||
} | ||
if (version.includes('/')) { | ||
throw new Error( | ||
'Invalid version number specified! Do not include slash (/). Try something like: 1.0.0', | ||
); | ||
} | ||
|
||
// Load existing versions | ||
let versions = []; | ||
const versionsJSONFile = getVersionsJSONFile(siteDir); | ||
if (fs.existsSync(versionsJSONFile)) { | ||
versions = JSON.parse(fs.readFileSync(versionsJSONFile, 'utf8')); | ||
} | ||
|
||
// Check if version already exist | ||
if (versions.includes(version)) { | ||
throw new Error( | ||
'This version already exists!.\nSpecify a new version to create that does not already exist.', | ||
); | ||
} | ||
|
||
const {path: docsPath, sidebarPath} = options; | ||
|
||
// Copy docs files | ||
const docsDir = path.join(siteDir, docsPath); | ||
if (fs.existsSync(docsDir)) { | ||
const versionedDir = getVersionedDocsDir(siteDir); | ||
const newVersionDir = path.join(versionedDir, `version-${version}`); | ||
|
||
fs.copy(docsDir, newVersionDir); | ||
} | ||
|
||
// Load current sidebar and create a new versioned sidebars file | ||
if (fs.existsSync(sidebarPath)) { | ||
const loadedSidebars: Sidebar = loadSidebars([sidebarPath]); | ||
|
||
// Transform id in original sidebar to versioned id | ||
const normalizeCategory = ( | ||
category: SidebarItemCategory, | ||
): SidebarItemCategory => { | ||
const items = category.items.map(item => { | ||
switch (item.type) { | ||
case 'category': | ||
return normalizeCategory(item); | ||
case 'ref': | ||
case 'doc': | ||
return { | ||
type: item.type, | ||
id: `version-${version}/${item.id}`, | ||
}; | ||
} | ||
return item; | ||
}); | ||
return {...category, items}; | ||
}; | ||
|
||
const versionedSidebar: Sidebar = Object.entries(loadedSidebars).reduce( | ||
(acc: Sidebar, [sidebarId, sidebarItemCategories]) => { | ||
const newVersionedSidebarId = `version-${version}/${sidebarId}`; | ||
acc[ | ||
newVersionedSidebarId | ||
] = sidebarItemCategories.map(sidebarItemCategory => | ||
normalizeCategory(sidebarItemCategory), | ||
); | ||
return acc; | ||
}, | ||
{}, | ||
); | ||
|
||
const versionedSidebarsDir = getVersionedSidebarsDir(siteDir); | ||
const newSidebarFile = path.join( | ||
versionedSidebarsDir, | ||
`version-${version}-sidebars.json`, | ||
); | ||
fs.writeFileSync( | ||
newSidebarFile, | ||
`${JSON.stringify(versionedSidebar, null, 2)}\n`, | ||
'utf8', | ||
); | ||
} | ||
|
||
// update versions.json file | ||
versions.unshift(version); | ||
fs.writeFileSync(versionsJSONFile, `${JSON.stringify(versions, null, 2)}\n`); | ||
|
||
console.log(`Version ${version} created!\n`); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In future, i'll add
translation
to thisenv
. So this PR is like a building block for translated docs already