33import fs from 'fs'
44import path from 'path'
55import { execSync } from 'child_process'
6+ import { program } from 'commander'
67import fpt from '../../lib/non-enterprise-default-version.js'
78import { allVersionKeys } from '../../lib/all-versions.js'
89import { liquid } from '../../lib/render-content/index.js'
@@ -15,6 +16,19 @@ const staticDirName = 'script/dev-toc/static'
1516const staticDir = path . posix . join ( process . cwd ( ) , staticDirName )
1617if ( ! fs . existsSync ( staticDir ) ) fs . mkdirSync ( staticDir )
1718
19+ program
20+ . description ( 'Generate a local TOC of the docs website and open it in your browser' )
21+ . option (
22+ '-o, --openSections [product-ids...]' ,
23+ 'open sections for one or more product IDs by default (e.g., "-o codespaces pull-requests")'
24+ )
25+ . parse ( process . argv )
26+
27+ const options = program . opts ( )
28+
29+ const openSections = options . openSections || ''
30+ const defaultOpenSections = Array . isArray ( openSections ) ? openSections : [ openSections ]
31+
1832main ( )
1933
2034async function main ( ) {
@@ -38,6 +52,9 @@ async function main() {
3852 // Add the tree to the req.context.
3953 req . context . currentEnglishTree = req . context . siteTree . en [ req . context . currentVersion ]
4054
55+ // Add any defaultOpenSections to the context.
56+ req . context . defaultOpenSections = defaultOpenSections
57+
4158 // Parse the layout in script/dev-toc/layout.html with the context we created above.
4259 const outputHtml = await liquid . parseAndRender ( layout , Object . assign ( { } , req . context ) )
4360
0 commit comments