-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadd-template-suffix.ts
More file actions
48 lines (40 loc) · 1.25 KB
/
add-template-suffix.ts
File metadata and controls
48 lines (40 loc) · 1.25 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
import * as fs from 'fs';
const path = process.argv[2];
if (!path) {
console.error('Path is required.');
process.exit(1);
}
const suffix = '.template';
console.log(`Renaming files in ${path}...`);
const files = getRecursiveFileList(path).filter(
(file) => !file.endsWith(suffix)
);
if (!files.length) {
console.log('No files to rename.');
process.exit(0);
}
for (const file of files) {
if (file.endsWith(".meta") || file.endsWith(".png") || file.endsWith(".dll")|| file.endsWith(".unity")) {
continue;
}
const newFile = `${file}${suffix}`;
fs.renameSync(file, newFile);
console.log(` - Renamed ${file} to ${newFile}`);
}
// Point method at path and return a list of all the files in the directory recursively
function getRecursiveFileList(path: string): string[] {
const files: string[] = [];
const items = fs.readdirSync(path);
items.forEach((item) => {
// Check out if it's a directory or a file
const isDir = fs.statSync(`${path}/${item}`).isDirectory();
if (isDir) {
// If it's a directory, recursively call the method
files.push(...getRecursiveFileList(`${path}/${item}`));
} else {
// If it's a file, add it to the array of files
files.push(`${path}/${item}`);
}
});
return files;
}