forked from Handyfon/diceaddiction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenameAndSort.js
27 lines (27 loc) · 3.13 KB
/
renameAndSort.js
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
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const promises_1 = require("fs/promises");
const random_words_1 = __importDefault(require("random-words"));
const generateRandomName = () => {
const randWords = (0, random_words_1.default)({ exactly: 2, wordsPerString: 3, separator: ' ' })[0];
const pascalCaseWords = randWords.split(' ')
.map(e => e.slice(0, 1).toUpperCase().concat(e.slice(1))).join('');
// Convert to camelCase and return
return pascalCaseWords.slice(0, 1).toLowerCase().concat(pascalCaseWords.slice(1));
};
(async () => {
const files = await (0, promises_1.readdir)('./rename');
const filesMoved = await Promise.all(files.map(async (fileName, index) => {
const fileNamePrefix = generateRandomName();
const fileNameExtension = fileName.split('.').pop();
const fileStream = await (0, promises_1.readFile)(`./rename/${fileName}`);
await (0, promises_1.writeFile)(`./assets/textures/${fileNamePrefix}.${fileNameExtension}`, fileStream);
await (0, promises_1.unlink)(`./rename/${fileName}`);
return `${fileNamePrefix}.${fileNameExtension}`;
}));
console.log(`Finished renaming and sorting ${filesMoved.length} files.`);
})();
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVuYW1lQW5kU29ydC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInJlbmFtZUFuZFNvcnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSwwQ0FBa0U7QUFDbEUsZ0VBQXNDO0FBRXRDLE1BQU0sa0JBQWtCLEdBQUcsR0FBRyxFQUFFO0lBQzlCLE1BQU0sU0FBUyxHQUFHLElBQUEsc0JBQVcsRUFBQyxFQUFFLE9BQU8sRUFBRSxDQ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