-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombine.js
More file actions
117 lines (94 loc) · 3.19 KB
/
Copy pathcombine.js
File metadata and controls
117 lines (94 loc) · 3.19 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
// Configuration
const TEST_SCHEMA_GENERATION_DIR = 'test-schema-generation';
const OUTPUT_FILE = 'combined.ts';
// Define the expected file structure with priority ordering
const FILE_STRUCTURE = [
'api-client.ts',
'barrel.ts',
'hooks.ts',
'index.ts',
'types.ts'
];
// Utility functions
function logInfo(message) {
console.log(`[INFO] ${message}`);
}
function logWarn(message) {
console.warn(`[WARN] ${message}`);
}
function logError(message) {
console.error(`[ERROR] ${message}`);
process.exit(1);
}
// Generate file header with metadata
function generateHeader(dirName) {
const timestamp = new Date().toISOString();
return [
`// Combined TypeScript Module`,
`// Generated: ${timestamp}`,
`// Source Directory: ${dirName}`,
`// Architecture: Modular API client with hooks and type definitions`,
''
].join('\n');
}
// Process files strictly in defined order
function combineFiles(targetDir) {
const dirName = path.basename(targetDir);
const outputPath = path.join(targetDir, OUTPUT_FILE);
let content = generateHeader(dirName);
let processedCount = 0;
for (const file of FILE_STRUCTURE) {
const filePath = path.join(targetDir, file);
if (fs.existsSync(filePath)) {
logInfo(`Appending ${file} from ${dirName}`);
const fileContent = fs.readFileSync(filePath, 'utf8');
// Add comment separator for the file
content += `// ${file.replace('.ts', '')}\n`;
content += fileContent;
content += '\n\n';
processedCount++;
} else {
logWarn(`Missing expected file: ${file} in ${dirName}`);
}
}
if (processedCount === 0) {
logWarn(`No TypeScript files were combined in ${dirName} – none of the expected files were found.`);
return;
}
// Write the combined file
fs.writeFileSync(outputPath, content, 'utf8');
logInfo(`Successfully combined ${processedCount} files into ${outputPath}`);
}
// Main execution
function main() {
const testSchemaDir = path.resolve(TEST_SCHEMA_GENERATION_DIR);
if (!fs.existsSync(testSchemaDir)) {
logError(`Directory '${testSchemaDir}' does not exist`);
}
logInfo(`Processing directory: ${testSchemaDir}`);
// Get all subdirectories
const entries = fs.readdirSync(testSchemaDir, { withFileTypes: true });
const directories = entries
.filter(entry => entry.isDirectory())
.map(entry => entry.name);
if (directories.length === 0) {
logWarn('No subdirectories found in test-schema-generation');
return;
}
logInfo(`Found ${directories.length} directories to process: ${directories.join(', ')}`);
// Process each directory
for (const dir of directories) {
const dirPath = path.join(testSchemaDir, dir);
logInfo(`\nProcessing directory: ${dir}`);
combineFiles(dirPath);
}
logInfo('\nFile combination complete for all directories');
}
// Run the script
if (require.main === module) {
main();
}
module.exports = { combineFiles, generateHeader };