-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Expand file tree
/
Copy pathlint-staged.config.mjs
More file actions
80 lines (68 loc) · 2.59 KB
/
Copy pathlint-staged.config.mjs
File metadata and controls
80 lines (68 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import path from 'node:path';
const quoteFiles = (files) =>
files.map((file) => JSON.stringify(path.relative(process.cwd(), file))).join(' ');
const toAbsolutePath = (file) => (path.isAbsolute(file) ? file : path.resolve(process.cwd(), file));
const quoteDocumentFiles = (files) =>
files
.map((file) =>
JSON.stringify(path.relative(path.join(process.cwd(), 'document'), toAbsolutePath(file)))
)
.join(' ');
const quoteDocumentArtifactPaths = () =>
[
'document/data/doc-last-modified.json',
'document/content/toc.mdx',
'document/content/toc.en.mdx'
]
.map((file) => JSON.stringify(file))
.join(' ');
const withoutTranslatedDocumentFiles = (files) =>
files.filter((file) => {
const documentPath = path.relative(path.join(process.cwd(), 'document'), toAbsolutePath(file));
return !/\.[a-z]{2}\.mdx$/.test(documentPath);
});
const withoutIgnoredPaths = (files) =>
files.filter((file) => {
const relativePath = path.relative(process.cwd(), file);
return !(
relativePath.startsWith('document/') ||
relativePath.startsWith('projects/marketplace/') ||
relativePath.startsWith('deploy/') ||
relativePath.includes('/scripts/') ||
relativePath.endsWith('/next-env.d.ts')
);
});
export default {
'./document/**/**/*.mdx': (files) => {
if (files.length === 0) return [];
const filenames = quoteDocumentFiles(files);
const textlintFiles = withoutTranslatedDocumentFiles(files);
const textlintFilenames = quoteDocumentFiles(textlintFiles);
return [
...(textlintFiles.length > 0
? [`pnpm -C ./document exec textlint --fix ${textlintFilenames}`]
: []),
`pnpm -C ./document exec prettier --config ../.prettierrc.js --write ${filenames}`,
...(textlintFiles.length > 0
? [`pnpm -C ./document exec textlint ${textlintFilenames}`]
: []),
'pnpm -C ./document run initDocTime',
'pnpm -C ./document run initDocToc',
'pnpm -C ./document run checkDocRefs',
'pnpm -C ./document run removeInvalidImg',
`git add -- ${quoteDocumentArtifactPaths()}`,
'git add -u -- document/public/imgs'
];
},
'**/*.{ts,tsx}': (files) => {
const lintFiles = withoutIgnoredPaths(files);
if (lintFiles.length === 0) return [];
const filenames = quoteFiles(lintFiles);
return [`eslint --fix ${filenames}`, `prettier --config ./.prettierrc.js --write ${filenames}`];
},
'**/*.scss': (files) => {
if (files.length === 0) return [];
const filenames = quoteFiles(files);
return `prettier --config ./.prettierrc.js --write ${filenames}`;
}
};