Skip to content

Commit a5d05e2

Browse files
authoredJul 24, 2023
[test] Fail the CI when new unexpected files are created (#38039)
1 parent 5a043b6 commit a5d05e2

File tree

2 files changed

+46
-42
lines changed

2 files changed

+46
-42
lines changed
 

‎.circleci/config.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ jobs:
136136
steps:
137137
- run:
138138
name: Should not have any git not staged
139-
command: git diff --exit-code
139+
command: git add -A && git diff --exit-code --staged
140140
- run:
141141
name: Check for duplicated packages
142142
command: yarn deduplicate
@@ -222,35 +222,35 @@ jobs:
222222
command: yarn proptypes
223223
- run:
224224
name: '`yarn proptypes` changes committed?'
225-
command: git diff --exit-code
225+
command: git add -A && git diff --exit-code --staged
226226
- run:
227227
name: 'Write "use client" directive'
228228
command: yarn rsc:build
229229
- run:
230230
name: '`yarn rsc:build` changes detected, "use client" missing from exports'
231-
command: git diff --exit-code
231+
command: git add -A && git diff --exit-code --staged
232232
- run:
233233
name: Generate the documentation
234234
command: yarn docs:api
235235
- run:
236236
name: '`yarn docs:api` changes committed?'
237-
command: git diff --exit-code
237+
command: git add -A && git diff --exit-code --staged
238238
- run:
239239
name: Update the navigation translations
240240
command: yarn docs:i18n
241241
- run:
242242
name: '`yarn docs:i18n` changes committed?'
243-
command: git diff --exit-code
243+
command: git add -A && git diff --exit-code --staged
244244
- run:
245245
name: '`yarn extract-error-codes` changes committed?'
246246
command: |
247247
yarn extract-error-codes
248-
git diff --exit-code
248+
git add -A && git diff --exit-code --staged
249249
- run:
250250
name: '`yarn docs:link-check` changes committed?'
251251
command: |
252252
yarn docs:link-check
253-
git diff --exit-code
253+
git add -A && git diff --exit-code --staged
254254
test_types:
255255
<<: *defaults
256256
resource_class: 'medium+'

‎packages/api-docs-builder/buildApiUtils.ts

+39-35
Original file line numberDiff line numberDiff line change
@@ -589,14 +589,47 @@ export function generateBaseUIApiPages() {
589589
) {
590590
const { components, hooks } = markdownHeaders;
591591

592+
const tokens = markdown.pathname.split('/');
593+
const name = tokens[tokens.length - 1];
594+
const importStatement = `docs/data${markdown.pathname}/${name}.md`;
595+
const demosSource = `
596+
import * as React from 'react';
597+
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocsV2';
598+
import AppFrame from 'docs/src/modules/components/AppFrame';
599+
import * as pageProps from '${importStatement}?@mui/markdown';
600+
601+
export default function Page(props) {
602+
const { userLanguage, ...other } = props;
603+
return <MarkdownDocs {...pageProps} {...other} />;
604+
}
605+
606+
Page.getLayout = (page) => {
607+
return <AppFrame>{page}</AppFrame>;
608+
};
609+
`;
610+
611+
const componentPageDirectory = `docs/pages/${productName}-ui/react-${componentName}/`;
612+
if (!fs.existsSync(componentPageDirectory)) {
613+
fs.mkdirSync(componentPageDirectory, { recursive: true });
614+
}
615+
writePrettifiedFile(
616+
path.join(process.cwd(), `${componentPageDirectory}/index.js`),
617+
demosSource,
618+
);
619+
620+
if ((!components || components.length === 0) && (!hooks || hooks.length === 0)) {
621+
// Early return if it's a markdown file without components/hooks.
622+
return;
623+
}
624+
592625
let apiTabImportStatements = '';
593626
let staticProps = 'export const getStaticProps = () => {';
594627
let componentsApiDescriptions = '';
595628
let componentsPageContents = '';
596629
let hooksApiDescriptions = '';
597630
let hooksPageContents = '';
598631

599-
if (components) {
632+
if (components && components.length > 0) {
600633
components.forEach((component: string) => {
601634
const componentNameKebabCase = kebabCase(component);
602635
apiTabImportStatements += `import ${component}ApiJsonPageContent from '../../api/${componentNameKebabCase}.json';`;
@@ -613,7 +646,7 @@ export function generateBaseUIApiPages() {
613646
});
614647
}
615648

616-
if (hooks) {
649+
if (hooks && hooks.length > 0) {
617650
hooks.forEach((hook: string) => {
618651
const hookNameKebabCase = kebabCase(hook);
619652
apiTabImportStatements += `import ${hook}ApiJsonPageContent from '../../api/${hookNameKebabCase}.json';`;
@@ -645,25 +678,6 @@ export function generateBaseUIApiPages() {
645678

646679
staticProps += ` },},};};`;
647680

648-
const tokens = markdown.pathname.split('/');
649-
const name = tokens[tokens.length - 1];
650-
const importStatement = `docs/data${markdown.pathname}/${name}.md`;
651-
const demosSource = `
652-
import * as React from 'react';
653-
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocsV2';
654-
import AppFrame from 'docs/src/modules/components/AppFrame';
655-
import * as pageProps from '${importStatement}?@mui/markdown';
656-
657-
export default function Page(props) {
658-
const { userLanguage, ...other } = props;
659-
return <MarkdownDocs {...pageProps} {...other} />;
660-
}
661-
662-
Page.getLayout = (page) => {
663-
return <AppFrame>{page}</AppFrame>;
664-
};
665-
`;
666-
667681
const tabsApiSource = `
668682
import * as React from 'react';
669683
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocsV2';
@@ -691,24 +705,14 @@ export const getStaticPaths = () => {
691705
${staticProps}
692706
`;
693707

694-
const componentPageDirectory = `docs/pages/${productName}-ui/react-${componentName}/`;
695-
if (!fs.existsSync(componentPageDirectory)) {
696-
fs.mkdirSync(componentPageDirectory, { recursive: true });
697-
}
698-
const demosSourcePath = path.join(process.cwd(), `${componentPageDirectory}/index.js`);
699-
writePrettifiedFile(demosSourcePath, demosSource);
700-
701-
if ((components ?? []).length === 0 && (hooks ?? []).length === 0) {
702-
// Early return if it's a markdown file without components/hooks.
703-
return;
704-
}
705-
706708
const docsTabsPagesDirectory = `${componentPageDirectory}/[docsTab]`;
707709
if (!fs.existsSync(docsTabsPagesDirectory)) {
708710
fs.mkdirSync(docsTabsPagesDirectory, { recursive: true });
709711
}
710-
const tabsApiPath = path.join(process.cwd(), `${docsTabsPagesDirectory}/index.js`);
711-
writePrettifiedFile(tabsApiPath, tabsApiSource);
712+
writePrettifiedFile(
713+
path.join(process.cwd(), `${docsTabsPagesDirectory}/index.js`),
714+
tabsApiSource,
715+
);
712716
}
713717
});
714718
}

0 commit comments

Comments
 (0)
Please sign in to comment.