diff --git a/cli/__tests__/buildPropsData.test.ts b/cli/__tests__/buildPropsData.test.ts index 35baa8f..4fd3f43 100644 --- a/cli/__tests__/buildPropsData.test.ts +++ b/cli/__tests__/buildPropsData.test.ts @@ -20,6 +20,7 @@ const validConfigResponse = { }, { include: ['**/one/more/include/*'], exclude: [] }, ], + outputDir: '/output/dir', } const sharedPropData = [ @@ -81,7 +82,7 @@ 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') }) @@ -89,7 +90,7 @@ it('should call getConfig with the passed config file location', async () => { 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() }) @@ -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() @@ -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, @@ -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') @@ -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), ) }) diff --git a/cli/buildPropsData.ts b/cli/buildPropsData.ts index a89f1ed..8e9b0a4 100644 --- a/cli/buildPropsData.ts +++ b/cli/buildPropsData.ts @@ -85,7 +85,6 @@ async function getPropsData(files: string[], verbose: boolean) { export async function buildPropsData( rootDir: string, - astroRoot: string, configFile: string, verbose: boolean, ) { @@ -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 @@ -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)) } diff --git a/cli/cli.ts b/cli/cli.ts index b8bd759..b6ec892 100755 --- a/cli/cli.ts +++ b/cli/cli.ts @@ -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() { @@ -82,7 +77,10 @@ async function buildProject(): Promise { await transformMDContentToMDX() - build({ root: astroRoot, outDir: join(currentDir, config.outputDir) }) + build({ + root: astroRoot, + outDir: join(currentDir, config.outputDir, 'docs'), + }) return config } @@ -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', diff --git a/cli/templates/pf-docs.config.mjs b/cli/templates/pf-docs.config.mjs index c769289..a2d288c 100644 --- a/cli/templates/pf-docs.config.mjs +++ b/cli/templates/pf-docs.config.mjs @@ -17,7 +17,7 @@ export const config = { // }, ], navSectionOrder: ["get-started", "design-foundations"], - outputDir: './dist/docs', + outputDir: './dist', propsGlobs: [ // { // include: ['*/@patternfly/react-core/src/**/*.tsx'], diff --git a/pf-docs.config.mjs b/pf-docs.config.mjs index 55f9844..9e60e72 100644 --- a/pf-docs.config.mjs +++ b/pf-docs.config.mjs @@ -16,7 +16,7 @@ export const config = { name: "react-component-docs", }, ], - outputDir: './dist/docs', + outputDir: './dist', propsGlobs: [ { include: ['*/@patternfly/react-core/src/**/*.tsx'], diff --git a/src/content.ts b/src/content.ts index 2986362..b615fe5 100644 --- a/src/content.ts +++ b/src/content.ts @@ -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"}] \ No newline at end of file diff --git a/src/pf-docs.config.mjs b/src/pf-docs.config.mjs index b9685c0..0fcb697 100644 --- a/src/pf-docs.config.mjs +++ b/src/pf-docs.config.mjs @@ -16,6 +16,6 @@ export const config = { // name: "react-component-docs", // }, ], - outputDir: "./dist/docs", + outputDir: "./dist", navSectionOrder: ["get-started", "design-foundations"] };