-
Notifications
You must be signed in to change notification settings - Fork 34
/
check.ts
38 lines (32 loc) · 1016 Bytes
/
check.ts
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
import path from 'path';
import {globby} from 'globby';
import {logger} from '@reskript/core';
const ALLOWED_EXISTING_FILES = new Set([
'package.json',
'README.md',
'LICENSE',
'.gitignore',
'.npmrc',
'.yarnrc',
'.yarnrc.yml',
'.yarn',
'.git',
]);
const checkDirectoryHasTooManyFiles = async (cwd: string) => {
const files = await globby(`${cwd}/**`, {dot: true, onlyFiles: false, deep: 1});
if (files.length > ALLOWED_EXISTING_FILES.size) {
return true;
}
return files.some(f => !ALLOWED_EXISTING_FILES.has(path.basename(f)));
};
export default async (cwd: string) => {
const directoryHasTooManyFiles = await checkDirectoryHasTooManyFiles(cwd);
if (directoryHasTooManyFiles) {
const message = `
Your directory has too many file existing
all files allowed before initialization are: ${[...ALLOWED_EXISTING_FILES.values()].join(', ')}
`;
logger.error(message);
process.exit(24);
}
};