Skip to content

Commit df54f2f

Browse files
feat(cli): output props file in user specified output dir (#128)
* feat(cli): output props file in user specified output dir * Move astro output to a subdirectory of the output dir
1 parent ad520df commit df54f2f

File tree

7 files changed

+25
-36
lines changed

7 files changed

+25
-36
lines changed

cli/__tests__/buildPropsData.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const validConfigResponse = {
2020
},
2121
{ include: ['**/one/more/include/*'], exclude: [] },
2222
],
23+
outputDir: '/output/dir',
2324
}
2425

2526
const sharedPropData = [
@@ -81,15 +82,15 @@ const propsData = {
8182
}
8283

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

8687
expect(getConfig).toHaveBeenCalledWith('/config')
8788
})
8889

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

92-
await buildPropsData('/root/', '/astro/', '/config', false)
93+
await buildPropsData('/root/', '/config', false)
9394

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

103-
await buildPropsData('/root/', '/astro/', '/config', false)
104+
await buildPropsData('/root/', '/config', false)
104105

105106
expect(mockConsoleError).toHaveBeenCalledWith('No props data found in config')
106107
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
111112
;(glob as unknown as jest.Mock).mockResolvedValue(['files/one', 'files/two'])
112113
;(tsDocgen as jest.Mock).mockResolvedValue(validTsDocGenResponseOne)
113114

114-
await buildPropsData('/root/', '/astro/', '/config', false)
115+
await buildPropsData('/root/', '/config', false)
115116

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

141-
await buildPropsData('/root/', '/astro/', '/config', false)
142+
await buildPropsData('/root/', '/config', false)
142143

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

158-
await buildPropsData('/root/', '/astro/', '/config', false)
159+
await buildPropsData('/root/', '/config', false)
159160

160161
expect(writeFile).toHaveBeenCalledWith(
161-
'/astro/dist/props.json',
162+
'/output/dir/props.json',
162163
JSON.stringify(propsData),
163164
)
164165
})

cli/buildPropsData.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ async function getPropsData(files: string[], verbose: boolean) {
8585

8686
export async function buildPropsData(
8787
rootDir: string,
88-
astroRoot: string,
8988
configFile: string,
9089
verbose: boolean,
9190
) {
@@ -94,7 +93,7 @@ export async function buildPropsData(
9493
return
9594
}
9695

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

108107
const propsData = await getPropsData(files, verbose)
109108

110-
const propsFile = join(astroRoot, 'dist', 'props.json')
109+
const propsFile = join(outputDir, 'props.json')
110+
111+
if (verbose) {
112+
const absolutePropsFilePath = join(process.cwd(), propsFile)
113+
console.log(`Writing props data to ${absolutePropsFilePath}`)
114+
}
111115

112116
await writeFile(propsFile, JSON.stringify(propsData))
113117
}

cli/cli.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ async function generateProps(program: Command, forceProps: boolean = false) {
3838
console.log('Verbose mode enabled')
3939
}
4040

41-
buildPropsData(
42-
currentDir,
43-
astroRoot,
44-
`${currentDir}/pf-docs.config.mjs`,
45-
verbose,
46-
)
41+
buildPropsData(currentDir, `${currentDir}/pf-docs.config.mjs`, verbose)
4742
}
4843

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

8378
await transformMDContentToMDX()
8479

85-
build({ root: astroRoot, outDir: join(currentDir, config.outputDir) })
80+
build({
81+
root: astroRoot,
82+
outDir: join(currentDir, config.outputDir, 'docs'),
83+
})
8684

8785
return config
8886
}
@@ -104,7 +102,7 @@ async function deploy() {
104102

105103
// Deploy using Wrangler
106104
const { execSync } = await import('child_process')
107-
const outputPath = join(currentDir, config.outputDir)
105+
const outputPath = join(currentDir, config.outputDir, 'docs')
108106

109107
execSync(`npx wrangler pages deploy ${outputPath}`, {
110108
stdio: 'inherit',

cli/templates/pf-docs.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const config = {
1717
// },
1818
],
1919
navSectionOrder: ["get-started", "design-foundations"],
20-
outputDir: './dist/docs',
20+
outputDir: './dist',
2121
propsGlobs: [
2222
// {
2323
// include: ['*/@patternfly/react-core/src/**/*.tsx'],

pf-docs.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const config = {
1616
name: "react-component-docs",
1717
},
1818
],
19-
outputDir: './dist/docs',
19+
outputDir: './dist',
2020
propsGlobs: [
2121
{
2222
include: ['*/@patternfly/react-core/src/**/*.tsx'],

src/content.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1 @@
1-
export const content = [
2-
{ base: 'textContent', pattern: '*.{md,mdx}', name: 'textContent' },
3-
{ base: 'textContent', pattern: 'examples/*/*.mdx', name: 'examples' }
4-
// TODO: Remove. Uncomment for local testing.
5-
// {
6-
// "packageName":"@patternfly/react-core",
7-
// "pattern":"**/examples/**/*.md", // had to update this pattern to bring in demos docs
8-
// "name":"react-component-docs"
9-
// },
10-
// {
11-
// "packageName":"@patternfly/patternfly",
12-
// "pattern":"**/examples/**/*.md", // had to update this pattern to bring in demos docs
13-
// "name":"core-component-docs"
14-
// }
15-
]
1+
export const content = [{"packageName":"@patternfly/react-core","pattern":"**/components/**/*.md","name":"react-component-docs"}]

src/pf-docs.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ export const config = {
1616
// name: "react-component-docs",
1717
// },
1818
],
19-
outputDir: "./dist/docs",
19+
outputDir: "./dist",
2020
navSectionOrder: ["get-started", "design-foundations"]
2121
};

0 commit comments

Comments
 (0)