@@ -3,6 +3,30 @@ import path from 'node:path';
33const quoteFiles = ( files ) =>
44 files . map ( ( file ) => JSON . stringify ( path . relative ( process . cwd ( ) , file ) ) ) . join ( ' ' ) ;
55
6+ const toAbsolutePath = ( file ) => ( path . isAbsolute ( file ) ? file : path . resolve ( process . cwd ( ) , file ) ) ;
7+
8+ const quoteDocumentFiles = ( files ) =>
9+ files
10+ . map ( ( file ) =>
11+ JSON . stringify ( path . relative ( path . join ( process . cwd ( ) , 'document' ) , toAbsolutePath ( file ) ) )
12+ )
13+ . join ( ' ' ) ;
14+
15+ const quoteDocumentArtifactPaths = ( ) =>
16+ [
17+ 'document/data/doc-last-modified.json' ,
18+ 'document/content/toc.mdx' ,
19+ 'document/content/toc.en.mdx'
20+ ]
21+ . map ( ( file ) => JSON . stringify ( file ) )
22+ . join ( ' ' ) ;
23+
24+ const withoutTranslatedDocumentFiles = ( files ) =>
25+ files . filter ( ( file ) => {
26+ const documentPath = path . relative ( path . join ( process . cwd ( ) , 'document' ) , toAbsolutePath ( file ) ) ;
27+ return ! / \. [ a - z ] { 2 } \. m d x $ / . test ( documentPath ) ;
28+ } ) ;
29+
630const withoutIgnoredPaths = ( files ) =>
731 files . filter ( ( file ) => {
832 const relativePath = path . relative ( process . cwd ( ) , file ) ;
@@ -17,17 +41,29 @@ const withoutIgnoredPaths = (files) =>
1741 } ) ;
1842
1943export default {
20- './document/**/**/*.mdx' : ( files ) =>
21- files . length === 0
22- ? [ ]
23- : [
24- 'pnpm -C ./document run format-doc' ,
25- 'pnpm -C ./document run initDocTime' ,
26- 'pnpm -C ./document run initDocToc' ,
27- 'pnpm -C ./document run checkDocRefs' ,
28- 'pnpm -C ./document run removeInvalidImg' ,
29- 'git add .'
30- ] ,
44+ './document/**/**/*.mdx' : ( files ) => {
45+ if ( files . length === 0 ) return [ ] ;
46+
47+ const filenames = quoteDocumentFiles ( files ) ;
48+ const textlintFiles = withoutTranslatedDocumentFiles ( files ) ;
49+ const textlintFilenames = quoteDocumentFiles ( textlintFiles ) ;
50+
51+ return [
52+ ...( textlintFiles . length > 0
53+ ? [ `pnpm -C ./document exec textlint --fix ${ textlintFilenames } ` ]
54+ : [ ] ) ,
55+ `pnpm -C ./document exec prettier --config ../.prettierrc.js --write ${ filenames } ` ,
56+ ...( textlintFiles . length > 0
57+ ? [ `pnpm -C ./document exec textlint ${ textlintFilenames } ` ]
58+ : [ ] ) ,
59+ 'pnpm -C ./document run initDocTime' ,
60+ 'pnpm -C ./document run initDocToc' ,
61+ 'pnpm -C ./document run checkDocRefs' ,
62+ 'pnpm -C ./document run removeInvalidImg' ,
63+ `git add -- ${ quoteDocumentArtifactPaths ( ) } ` ,
64+ 'git add -u -- document/public/imgs'
65+ ] ;
66+ } ,
3167 '**/*.{ts,tsx}' : ( files ) => {
3268 const lintFiles = withoutIgnoredPaths ( files ) ;
3369 if ( lintFiles . length === 0 ) return [ ] ;
0 commit comments