Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions cli/__tests__/buildPropsData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const validConfigResponse = {
},
{ include: ['**/one/more/include/*'], exclude: [] },
],
outputDir: '/output/dir',
}

const sharedPropData = [
Expand Down Expand Up @@ -81,15 +82,15 @@ const propsData = {
}

it('should call getConfig with the passed config file location', async () => {
await buildPropsData('/root/', '/astro/', '/config', false)
await buildPropsData('/root/', '/config', false)

expect(getConfig).toHaveBeenCalledWith('/config')
})

it('should not proceed if config is not found', async () => {
;(getConfig as jest.Mock).mockResolvedValue(undefined)

await buildPropsData('/root/', '/astro/', '/config', false)
await buildPropsData('/root/', '/config', false)

expect(writeFile).not.toHaveBeenCalled()
})
Expand All @@ -100,7 +101,7 @@ it('should send an error to the console if the config file does not have a props
const mockConsoleError = jest.fn()
jest.spyOn(console, 'error').mockImplementation(mockConsoleError)

await buildPropsData('/root/', '/astro/', '/config', false)
await buildPropsData('/root/', '/config', false)

expect(mockConsoleError).toHaveBeenCalledWith('No props data found in config')
expect(writeFile).not.toHaveBeenCalled()
Expand All @@ -111,7 +112,7 @@ it('should call glob with the propGlobs in the config file and the cwd set to th
;(glob as unknown as jest.Mock).mockResolvedValue(['files/one', 'files/two'])
;(tsDocgen as jest.Mock).mockResolvedValue(validTsDocGenResponseOne)

await buildPropsData('/root/', '/astro/', '/config', false)
await buildPropsData('/root/', '/config', false)

expect(glob).toHaveBeenNthCalledWith(
1,
Expand All @@ -138,7 +139,7 @@ it('should call tsDocGen with each file that glob returns', async () => {
;(tsDocgen as jest.Mock).mockReset()
;(tsDocgen as jest.Mock).mockResolvedValue(validTsDocGenResponseOne)

await buildPropsData('/root/', '/astro/', '/config', false)
await buildPropsData('/root/', '/config', false)

expect(tsDocgen).toHaveBeenNthCalledWith(1, 'files/one')
expect(tsDocgen).toHaveBeenNthCalledWith(2, 'files/two')
Expand All @@ -155,10 +156,10 @@ it('should call writeFile with the returned prop data in JSON form', async () =>
;(tsDocgen as jest.Mock).mockResolvedValueOnce(validTsDocGenResponseTwo)
;(writeFile as jest.Mock).mockReset()

await buildPropsData('/root/', '/astro/', '/config', false)
await buildPropsData('/root/', '/config', false)

expect(writeFile).toHaveBeenCalledWith(
'/astro/dist/props.json',
'/output/dir/props.json',
JSON.stringify(propsData),
)
})
10 changes: 7 additions & 3 deletions cli/buildPropsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ async function getPropsData(files: string[], verbose: boolean) {

export async function buildPropsData(
rootDir: string,
astroRoot: string,
configFile: string,
verbose: boolean,
) {
Expand All @@ -94,7 +93,7 @@ export async function buildPropsData(
return
}

const { propsGlobs } = config
const { propsGlobs, outputDir } = config
if (!propsGlobs) {
console.error('No props data found in config')
return
Expand All @@ -107,7 +106,12 @@ export async function buildPropsData(

const propsData = await getPropsData(files, verbose)

const propsFile = join(astroRoot, 'dist', 'props.json')
const propsFile = join(outputDir, 'props.json')

if (verbose) {
const absolutePropsFilePath = join(process.cwd(), propsFile)
console.log(`Writing props data to ${absolutePropsFilePath}`)
}

await writeFile(propsFile, JSON.stringify(propsData))
}
14 changes: 6 additions & 8 deletions cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ async function generateProps(program: Command, forceProps: boolean = false) {
console.log('Verbose mode enabled')
}

buildPropsData(
currentDir,
astroRoot,
`${currentDir}/pf-docs.config.mjs`,
verbose,
)
buildPropsData(currentDir, `${currentDir}/pf-docs.config.mjs`, verbose)
}

async function transformMDContentToMDX() {
Expand Down Expand Up @@ -82,7 +77,10 @@ async function buildProject(): Promise<DocsConfig | undefined> {

await transformMDContentToMDX()

build({ root: astroRoot, outDir: join(currentDir, config.outputDir) })
build({
root: astroRoot,
outDir: join(currentDir, config.outputDir, 'docs'),
})

return config
}
Expand All @@ -104,7 +102,7 @@ async function deploy() {

// Deploy using Wrangler
const { execSync } = await import('child_process')
const outputPath = join(currentDir, config.outputDir)
const outputPath = join(currentDir, config.outputDir, 'docs')

execSync(`npx wrangler pages deploy ${outputPath}`, {
stdio: 'inherit',
Expand Down
2 changes: 1 addition & 1 deletion cli/templates/pf-docs.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const config = {
// },
],
navSectionOrder: ["get-started", "design-foundations"],
outputDir: './dist/docs',
outputDir: './dist',
propsGlobs: [
// {
// include: ['*/@patternfly/react-core/src/**/*.tsx'],
Expand Down
2 changes: 1 addition & 1 deletion pf-docs.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const config = {
name: "react-component-docs",
},
],
outputDir: './dist/docs',
outputDir: './dist',
propsGlobs: [
{
include: ['*/@patternfly/react-core/src/**/*.tsx'],
Expand Down
16 changes: 1 addition & 15 deletions src/content.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1 @@
export const content = [
{ base: 'textContent', pattern: '*.{md,mdx}', name: 'textContent' },
{ base: 'textContent', pattern: 'examples/*/*.mdx', name: 'examples' }
// TODO: Remove. Uncomment for local testing.
// {
// "packageName":"@patternfly/react-core",
// "pattern":"**/examples/**/*.md", // had to update this pattern to bring in demos docs
// "name":"react-component-docs"
// },
// {
// "packageName":"@patternfly/patternfly",
// "pattern":"**/examples/**/*.md", // had to update this pattern to bring in demos docs
// "name":"core-component-docs"
// }
]
export const content = [{"packageName":"@patternfly/react-core","pattern":"**/components/**/*.md","name":"react-component-docs"}]
2 changes: 1 addition & 1 deletion src/pf-docs.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export const config = {
// name: "react-component-docs",
// },
],
outputDir: "./dist/docs",
outputDir: "./dist",
navSectionOrder: ["get-started", "design-foundations"]
};