Repository navigation
Expand file tree
/
Copy pathformat-non-workspace.mjs
More file actions
89 lines (75 loc) · 2.52 KB
/
Copy pathformat-non-workspace.mjs
File metadata and controls
89 lines (75 loc) · 2.52 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
81
82
83
84
85
86
87
88
89
#!/usr/bin/env node
import { glob } from 'tinyglobby';
import { $ } from 'zx';
const ROOT_FILE_PATTERNS = ['*.cjs', '*.js', '*.json', '*.md', '*.mjs', '*.ts', '*.yaml'];
const NON_WORKSPACE_PATTERNS = [
'docs/**/*.{js,jsx,ts,tsx,json,md,mdx}',
'integration/**/*.{js,jsx,ts,tsx,json,md,mdx}',
'scripts/**/*.{js,jsx,ts,tsx,json,md,mdx}',
];
async function getExistingFiles() {
const existingFiles = [];
for (const pattern of ROOT_FILE_PATTERNS) {
try {
const matches = await glob(pattern, {
ignore: ['node_modules/**', '**/node_modules/**', 'packages/**'],
});
existingFiles.push(...matches);
} catch {
// Pattern didn't match any files, skip it
}
}
for (const pattern of NON_WORKSPACE_PATTERNS) {
try {
const matches = await glob(pattern, {
ignore: [
'node_modules/**',
'**/node_modules/**',
'**/dist/**',
'**/build/**',
'**/coverage/**',
'**/.turbo/**',
'**/.next/**',
'**/.tsup/**',
'**/.cache/**',
],
});
existingFiles.push(...matches);
} catch {
// Pattern didn't match any files, skip it
}
}
return existingFiles.filter(Boolean);
}
async function formatNonWorkspaceFiles() {
const isCheck = process.argv.includes('--check');
const isVerbose = process.argv.includes('--verbose');
const baseArgs = isCheck
? ['prettier', '--cache', '--check', '--ignore-unknown', '--ignore-path', '.prettierignore']
: ['prettier', '--write', '--ignore-unknown', '--ignore-path', '.prettierignore'];
console.log(`${isCheck ? 'Checking' : 'Formatting'} non-workspace files...`);
try {
const existingFiles = await getExistingFiles();
if (existingFiles.length === 0) {
console.log('ℹ️ No non-workspace files found to format');
return;
}
console.log(`📁 Found ${existingFiles.length} files/directories to format`);
if (isVerbose) {
console.log('\n📄 Files to be formatted:');
existingFiles.forEach((file, index) => {
console.log(` ${index + 1}. ${file}`);
});
console.log('');
}
await $`pnpm ${baseArgs} ${existingFiles}`;
console.log(`✅ Non-workspace files ${isCheck ? 'check passed' : 'formatted successfully'}`);
} catch (error) {
console.error(`❌ Non-workspace files ${isCheck ? 'check failed' : 'formatting failed'}`);
if (error.stderr) {
console.error(error.stderr);
}
process.exit(1);
}
}
formatNonWorkspaceFiles().catch(console.error);